[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/competency/classes/external/ -> user_summary_exporter.php (source)

   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   * Class for exporting a user summary from an stdClass.
  19   *
  20   * @package    core_competency
  21   * @copyright  2015 Damyon Wiese
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace core_competency\external;
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  use renderer_base;
  28  use moodle_url;
  29  
  30  /**
  31   * Class for exporting a user summary from an stdClass.
  32   *
  33   * @copyright  2015 Damyon Wiese
  34   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class user_summary_exporter extends exporter {
  37  
  38      protected function get_other_values(renderer_base $output) {
  39          global $PAGE, $CFG;
  40  
  41          // Add user picture.
  42          $userpicture = new \user_picture($this->data);
  43          $userpicture->size = 1; // Size f1.
  44          $profileimageurl = $userpicture->get_url($PAGE)->out(false);
  45          $userpicture->size = 0; // Size f2.
  46          $profileimageurlsmall = $userpicture->get_url($PAGE)->out(false);
  47  
  48          $profileurl = (new moodle_url('/user/profile.php', array('id' => $this->data->id)))->out(false);
  49  
  50          $identityfields = array_flip(explode(',', $CFG->showuseridentity));
  51          $data = $this->data;
  52          foreach ($identityfields as $field => $index) {
  53              if (!empty($data->$field)) {
  54                  $identityfields[$field] = $data->$field;
  55              } else {
  56                  unset($identityfields[$field]);
  57              }
  58          }
  59          $identity = implode(', ', $identityfields);
  60          return array(
  61              'fullname' => fullname($this->data),
  62              'profileimageurl' => $profileimageurl,
  63              'profileimageurlsmall' => $profileimageurlsmall,
  64              'profileurl' => $profileurl,
  65              'identity' => $identity
  66          );
  67      }
  68  
  69      public static function define_properties() {
  70          return array(
  71              'id' => array(
  72                  'type' => \core_user::get_property_type('id'),
  73              ),
  74              'email' => array(
  75                  'type' => \core_user::get_property_type('email'),
  76                  'default' => ''
  77              ),
  78              'idnumber' => array(
  79                  'type' => \core_user::get_property_type('idnumber'),
  80                  'default' => ''
  81              ),
  82              'phone1' => array(
  83                  'type' => \core_user::get_property_type('phone1'),
  84                  'default' => ''
  85              ),
  86              'phone2' => array(
  87                  'type' => \core_user::get_property_type('phone2'),
  88                  'default' => ''
  89              ),
  90              'department' => array(
  91                  'type' => \core_user::get_property_type('department'),
  92                  'default' => ''
  93              ),
  94              'institution' => array(
  95                  'type' => \core_user::get_property_type('institution'),
  96                  'default' => ''
  97              )
  98          );
  99      }
 100  
 101      public static function define_other_properties() {
 102          return array(
 103              'fullname' => array(
 104                  'type' => PARAM_RAW
 105              ),
 106              'identity' => array(
 107                  'type' => PARAM_RAW
 108              ),
 109              'profileurl' => array(
 110                  'type' => PARAM_URL
 111              ),
 112              'profileimageurl' => array(
 113                  'type' => PARAM_URL
 114              ),
 115              'profileimageurlsmall' => array(
 116                  'type' => PARAM_URL
 117              ),
 118          );
 119      }
 120  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1