Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * User profile set indicator.
  19   *
  20   * @package   core_user
  21   * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_user\analytics\indicator;
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * User profile set indicator.
  31   *
  32   * @package   core_user
  33   * @copyright 2016 David Monllao {@link http://www.davidmonllao.com}
  34   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class user_profile_set extends \core_analytics\local\indicator\linear {
  37  
  38      /**
  39       * Returns the name.
  40       *
  41       * If there is a corresponding '_help' string this will be shown as well.
  42       *
  43       * @return \lang_string
  44       */
  45      public static function get_name() : \lang_string {
  46          return new \lang_string('indicator:completeduserprofile');
  47      }
  48  
  49      /**
  50       * required_sample_data
  51       *
  52       * @return string[]
  53       */
  54      public static function required_sample_data() {
  55          return array('user');
  56      }
  57  
  58      /**
  59       * calculate_sample
  60       *
  61       * @param int $sampleid
  62       * @param string $sampleorigin
  63       * @param int $starttime
  64       * @param int $endtime
  65       * @return float
  66       */
  67      protected function calculate_sample($sampleid, $sampleorigin, $starttime = false, $endtime = false) {
  68          global $CFG;
  69  
  70          $user = $this->retrieve('user', $sampleid);
  71  
  72          // Nothing set results in -1.
  73          $calculatedvalue = self::MIN_VALUE;
  74  
  75          if (\core_user::awaiting_action($user)) {
  76              return self::MIN_VALUE;
  77          }
  78  
  79          if (!$user->confirmed) {
  80              return self::MIN_VALUE;
  81          }
  82  
  83          if ($user->description != '') {
  84              $calculatedvalue += 1;
  85          }
  86  
  87          if ($user->picture != '') {
  88              $calculatedvalue += 1;
  89          }
  90  
  91          // 0.2 for any of the following fields being set (some of them may even be compulsory or have a default).
  92          $fields = array('institution', 'department', 'address', 'city', 'country');
  93          foreach ($fields as $fieldname) {
  94              if ($user->{$fieldname} != '') {
  95                  $calculatedvalue += 0.2;
  96              }
  97          }
  98  
  99          return $this->limit_value($calculatedvalue);
 100      }
 101  }