Merge branch 'master_MDL-27404' of git://github.com/danmarsden/moodle
authorSam Hemelryk <sam@moodle.com>
Mon, 13 Jun 2011 06:53:37 +0000 (14:53 +0800)
committerSam Hemelryk <sam@moodle.com>
Mon, 13 Jun 2011 06:53:37 +0000 (14:53 +0800)
17 files changed:
lang/en/plugin.php
lib/adminlib.php
lib/completionlib.php
lib/db/services.php
lib/moodlelib.php
lib/questionlib.php
lib/upgradelib.php
mod/assignment/lib.php
mod/lesson/format.php
mod/quiz/db/upgradelib.php
question/format.php
question/type/randomsamatch/questiontype.php
theme/formal_white/db/install.php
theme/formal_white/style/core.css
theme/formal_white/style/formal_white.css
user/externallib.php
version.php

index 6c11d79..f8e82ed 100644 (file)
@@ -18,7 +18,7 @@
  * Defines names of plugin types and some strings used at the plugin managment
  *
  * @package    core
- * @subpackage admin
+ * @subpackage plugin
  * @copyright  2011 David Mudrak <david@moodle.com>
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
index afe282d..f69425b 100644 (file)
@@ -6569,11 +6569,17 @@ class admin_setting_enablemobileservice extends admin_setting_configcheckbox {
      */
     public function get_setting() {
         global $CFG;
-        $webservicesystem = $CFG->enablewebservices;
+
+        // For install cli script, $CFG->defaultuserroleid is not set so return 0
+        // Or if web services aren't enabled this can't be,
+        if (empty($CFG->defaultuserroleid) || empty($CFG->enablewebservices)) {
+            return 0;
+        }
+
         require_once($CFG->dirroot . '/webservice/lib.php');
         $webservicemanager = new webservice();
         $mobileservice = $webservicemanager->get_external_service_by_shortname(MOODLE_OFFICIAL_MOBILE_SERVICE);
-        if ($mobileservice->enabled and !empty($webservicesystem) and $this->is_xmlrpc_cap_allowed()) {
+        if ($mobileservice->enabled and $this->is_xmlrpc_cap_allowed()) {
             return $this->config_read($this->name); //same as returning 1
         } else {
             return 0;
@@ -6588,6 +6594,12 @@ class admin_setting_enablemobileservice extends admin_setting_configcheckbox {
      */
     public function write_setting($data) {
         global $DB, $CFG;
+
+        //for install cli script, $CFG->defaultuserroleid is not set so do nothing
+        if (empty($CFG->defaultuserroleid)) {
+            return '';
+        }
+
         $servicename = MOODLE_OFFICIAL_MOBILE_SERVICE;
 
         require_once($CFG->dirroot . '/webservice/lib.php');
index 7f79c95..4c8467b 100644 (file)
@@ -185,13 +185,18 @@ class completion_info {
      *   for a course-module.
      */
     public function is_enabled($cm=null) {
-        global $CFG;
+        global $CFG, $DB;
 
         // First check global completion
         if (!isset($CFG->enablecompletion) || $CFG->enablecompletion == COMPLETION_DISABLED) {
             return COMPLETION_DISABLED;
         }
 
+        // Load data if we do not have enough
+        if (!isset($this->course->enablecompletion)) {
+            $this->course->enablecompletion = $DB->get_field('course', 'enablecompletion', array('id' => $this->course->id));
+        }
+
         // Check course completion
         if ($this->course->enablecompletion == COMPLETION_DISABLED) {
             return COMPLETION_DISABLED;
index 5086f9c..37cb7c1 100644 (file)
@@ -126,7 +126,7 @@ $functions = array(
         'classpath'   => 'user/externallib.php',
         'description' => 'Get users by id.',
         'type'        => 'read',
-        'capabilities'=> 'moodle/user:viewalldetails',
+        'capabilities'=> 'moodle/user:viewdetails, moodle/user:viewhiddendetails, moodle/course:useremail, moodle/user:update',
     ),
 
     'moodle_user_delete_users' => array(
@@ -245,7 +245,10 @@ $services = array(
         'functions' => array (
             'moodle_enrol_get_users_courses',
             'moodle_enrol_get_enrolled_users',
-            'moodle_user_get_users_by_id'),
+            'moodle_user_get_users_by_id',
+            'moodle_webservice_get_siteinfo',
+            'moodle_notes_create_notes',
+            'moodle_message_send_messages'),
         'enabled' => 0,
         'restrictedusers' => 0,
         'shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE
index e159340..62e8041 100644 (file)
@@ -7043,6 +7043,7 @@ function get_core_subsystems() {
             'pagetype'    => NULL,
             'pix'         => NULL,
             'plagiarism'  => 'plagiarism',
+            'plugin'      => NULL,
             'portfolio'   => 'portfolio',
             'publish'     => 'course/publish',
             'question'    => 'question',
index 8371f3b..92c6566 100644 (file)
@@ -41,22 +41,6 @@ require_once($CFG->dirroot . '/question/type/questiontypebase.php');
 
 /// CONSTANTS ///////////////////////////////////
 
-/**#@+
- * The core question types.
- */
-define("SHORTANSWER",   "shortanswer");
-define("TRUEFALSE",     "truefalse");
-define("MULTICHOICE",   "multichoice");
-define("RANDOM",        "random");
-define("MATCH",         "match");
-define("RANDOMSAMATCH", "randomsamatch");
-define("DESCRIPTION",   "description");
-define("NUMERICAL",     "numerical");
-define("MULTIANSWER",   "multianswer");
-define("CALCULATED",    "calculated");
-define("ESSAY",         "essay");
-/**#@-*/
-
 /**
  * Constant determines the number of answer boxes supplied in the editing
  * form for multiple choice and similar question types.
index a5f9ba9..f6e6c74 100644 (file)
@@ -907,10 +907,6 @@ function external_update_descriptions($component) {
         $service['shortname'] = !isset($service['shortname']) ? null : $service['shortname'];
 
         $update = false;
-        if ($dbservice->enabled != $service['enabled']) {
-            $dbservice->enabled = $service['enabled'];
-            $update = true;
-        }
         if ($dbservice->requiredcapability != $service['requiredcapability']) {
             $dbservice->requiredcapability = $service['requiredcapability'];
             $update = true;
index 09f8013..66741fd 100644 (file)
@@ -1141,20 +1141,6 @@ class assignment_base {
         //hook to allow plagiarism plugins to update status/print links.
         plagiarism_update_status($this->course, $this->cm);
 
-        /// Print quickgrade form around the table
-        if ($quickgrade) {
-            $formattrs = array();
-            $formattrs['action'] = new moodle_url('/mod/assignment/submissions.php');
-            $formattrs['id'] = 'fastg';
-            $formattrs['method'] = 'post';
-
-            echo html_writer::start_tag('form', $formattrs);
-            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id',      'value'=> $this->cm->id));
-            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'mode',    'value'=> 'fastgrade'));
-            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'page',    'value'=> $page));
-            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=> sesskey()));
-        }
-
         $course_context = get_context_instance(CONTEXT_COURSE, $course->id);
         if (has_capability('gradereport/grader:view', $course_context) && has_capability('moodle/grade:viewall', $course_context)) {
             echo '<div class="allcoursegrades"><a href="' . $CFG->wwwroot . '/grade/report/grader/index.php?id=' . $course->id . '">'
@@ -1174,6 +1160,20 @@ class assignment_base {
         $currentgroup = groups_get_activity_group($cm, true);
         groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $this->cm->id);
 
+        /// Print quickgrade form around the table
+        if ($quickgrade) {
+            $formattrs = array();
+            $formattrs['action'] = new moodle_url('/mod/assignment/submissions.php');
+            $formattrs['id'] = 'fastg';
+            $formattrs['method'] = 'post';
+
+            echo html_writer::start_tag('form', $formattrs);
+            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'id',      'value'=> $this->cm->id));
+            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'mode',    'value'=> 'fastgrade'));
+            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'page',    'value'=> $page));
+            echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=> sesskey()));
+        }
+
         /// Get all ppl that are allowed to submit assignments
         list($esql, $params) = get_enrolled_sql($context, 'mod/assignment:view', $currentgroup);
 
index 5a2ea0c..8fded7b 100644 (file)
 
 defined('MOODLE_INTERNAL') || die();
 
+/**#@+
+ * The core question types.
+ *
+ * These used to be in lib/questionlib.php, but are being deprecated. Copying them
+ * here to keep this code working for now.
+ */
+if (!defined('SHORTANSWER')) {
+    define("SHORTANSWER",   "shortanswer");
+    define("TRUEFALSE",     "truefalse");
+    define("MULTICHOICE",   "multichoice");
+    define("RANDOM",        "random");
+    define("MATCH",         "match");
+    define("RANDOMSAMATCH", "randomsamatch");
+    define("DESCRIPTION",   "description");
+    define("NUMERICAL",     "numerical");
+    define("MULTIANSWER",   "multianswer");
+    define("CALCULATED",    "calculated");
+    define("ESSAY",         "essay");
+}
+/**#@-*/
+
 /**
  * Given some question info and some data about the the answers
  * this function parses, organises and saves the question
index bc2874d..0b458ef 100644 (file)
@@ -49,7 +49,7 @@ function quiz_upgrade_very_old_question_sessions($attempt) {
     // newgraded pointing to this state.
     // Actually we only do this for states whose question is actually listed in $attempt->layout.
     // We do not do it for states associated to wrapped questions like for example the questions
-    // used by a RANDOM question
+    // used by a random question
     $session = new stdClass();
     $session->attemptid = $attempt->uniqueid;
     $session->sumpenalty = 0;
index 663e917..8cdbfbd 100644 (file)
 defined('MOODLE_INTERNAL') || die();
 
 
+/**#@+
+ * The core question types.
+ *
+ * These used to be in lib/questionlib.php, but are being deprecated. Copying
+ * them here to keep the import/export code working for now (there are 135
+ * references to these constants which I don't want to try to fix at the moment.)
+ */
+if (!defined('SHORTANSWER')) {
+    define("SHORTANSWER",   "shortanswer");
+    define("TRUEFALSE",     "truefalse");
+    define("MULTICHOICE",   "multichoice");
+    define("RANDOM",        "random");
+    define("MATCH",         "match");
+    define("RANDOMSAMATCH", "randomsamatch");
+    define("DESCRIPTION",   "description");
+    define("NUMERICAL",     "numerical");
+    define("MULTIANSWER",   "multianswer");
+    define("CALCULATED",    "calculated");
+    define("ESSAY",         "essay");
+}
+/**#@-*/
+
+
 /**
  * Base class for question import and export formats.
  *
@@ -697,7 +720,7 @@ class qformat_default {
             }
 
             // do not export random questions
-            if ($question->qtype==RANDOM) {
+            if ($question->qtype == 'random') {
                 continue;
             }
 
index b88006b..74e1dcb 100644 (file)
@@ -116,7 +116,7 @@ class qtype_randomsamatch extends question_type {
                 available for this question, therefore it is not available in  this
                 quiz. Please inform your teacher.";
             // Treat this as a description from this point on
-            $question->qtype = DESCRIPTION;
+            $question->qtype = 'description';
             return true;
         }
 
@@ -174,7 +174,7 @@ class qtype_randomsamatch extends question_type {
              available for this question, therefore it is not available in  this
              quiz. Please inform your teacher.";
             // Treat this as a description from this point on
-            $question->qtype = DESCRIPTION;
+            $question->qtype = 'description';
         } else {
             $responses = explode(',', $state->responses['']);
             $responses = array_map(create_function('$val',
index 5efe9ca..9e890ea 100644 (file)
 defined('MOODLE_INTERNAL') || die();
 
 function xmldb_theme_formal_white_install() {
-    $currentsetting = get_config('theme_formal_white');
 
-    // Remove all the useless settings of the first pre-release
-    // Remove backgroundcolor
-    unset_config('backgroundcolor', 'theme_formal_white');
-    // Remove regionwidth
-    unset_config('regionwidth', 'theme_formal_white');
-    // Remove alwayslangmenu
-    unset_config('alwayslangmenu', 'theme_formal_white');
+    // We need here to check whether or not the theme has been installed.
+    // If it has been installed then we need to change the name of the settings to the new names.
+    // If it is not installed it won't have any settings yet and we won't need to worry about this.
+    $currentsetting = get_config('theme_formal_white');
+    if (!empty($currentsetting)) {
+        // Remove the settings that are no longer used by this theme
+        // Remove regionwidth
+        unset_config('regionwidth', 'theme_formal_white');
+        // Remove alwayslangmenu
+        unset_config('alwayslangmenu', 'theme_formal_white');
 
-    // Create a new config setting called lblockcolumnbgc and give it blockcolumnbgc's value.
-    set_config('lblockcolumnbgc', $currentsetting->blockcolumnbgc, 'theme_formal_white');
-    // Remove blockcolumnbgc
-    unset_config('blockcolumnbgc', 'theme_formal_white');
+        // previous releases of formal_white them were not equipped with version number
+        // so I can not know if a theme specific variable exists or not.
+        // This is the reason why I try to use them both.
+        if (!empty($currentsetting->backgroundcolor)) {
+            // Create a new config setting called lblockcolumnbgc and give it backgroundcolor's value.
+            set_config('lblockcolumnbgc', $currentsetting->backgroundcolor, 'theme_formal_white');
+            // Remove backgroundcolor
+            unset_config('backgroundcolor', 'theme_formal_white');
+        } elseif (!empty($currentsetting->blockcolumnbgc)) {
+            // Create a new config setting called lblockcolumnbgc and give it blockcolumnbgc's value.
+            set_config('lblockcolumnbgc', $currentsetting->blockcolumnbgc, 'theme_formal_white');
+            // Remove blockcolumnbgc
+            unset_config('blockcolumnbgc', 'theme_formal_white');
+        }
+    }
 
     return true;
 }
\ No newline at end of file
index 07915dc..c41162a 100644 (file)
@@ -183,12 +183,19 @@ input[type="radio"] {
     margin-left: 21%;
 }
 
+/* Admin management
+-----------------------*/
+.plugincompattable {
+    font-size: 100%;
+    text-align: left;
+}
+
 /* User
 -----------------------*/
 
 .userinfobox {
-border-color: #ddd;
-padding: 0
+    border-color: #ddd;
+    padding: 0
 }
 
 .userinfobox .content {
index fb89a13..f89b032 100644 (file)
@@ -70,7 +70,7 @@ h1.headerheading {margin:14px 11px 8px 11px;float:left;font-size:200%;}
 .breadcrumb {margin-left:0.8em;}
 
 /* generalbox */
-.generalbox {border-color:#E3DFD4;}
+.generalbox {border-color:#E3DFD4;padding:1em;}
 
 /* generalbox */
 #page-admin-setting-manageauths .generalbox {border:none;}
@@ -88,12 +88,14 @@ h1.headerheading {margin:14px 11px 8px 11px;float:left;font-size:200%;}
 #page-admin-course-category .generalbox td,
 #attempts th,
 #attempts td,
+.plugincompattable th,
+.plugincompattable td,
 .environmenttable th,
 .environmenttable td,
 .forumheaderlist td,
 .forumheaderlist th {
-       border: 1px solid #E3DFD4;
-       border-collapse: collapse;
+    border: 1px solid #E3DFD4;
+    border-collapse: collapse;
 }
 th.header,
 .formtable tbody th,
index 2472025..3717a47 100644 (file)
@@ -346,63 +346,226 @@ class moodle_user_external extends external_api {
 
     /**
      * Get user information
-     *
+     * - This function is matching the permissions of /user/profil.php
+     * - It is also matching some permissions from /user/editadvanced.php for the following fields:
+     *   auth, confirmed, idnumber, lang, theme, timezone, mailformat
      * @param array $userids  array of user ids
      * @return array An array of arrays describing users
      */
     public static function get_users_by_id($userids) {
-        global $CFG;
+        global $CFG, $USER, $DB;
         require_once($CFG->dirroot . "/user/lib.php");
-        //required for customfields related function
-        //TODO: move the functions somewhere else as
-        //they are "user" related
-        require_once($CFG->dirroot . "/user/profile/lib.php");
+        require_once($CFG->dirroot . "/user/profile/lib.php"); //custom field library
+
+        $isadmin = is_siteadmin($USER);
 
         $params = self::validate_parameters(self::get_users_by_id_parameters(),
                 array('userids'=>$userids));
 
-        //TODO: check if there is any performance issue: we do one DB request to retrieve
-        //  all user, then for each user the profile_load_data does at least two DB requests
+        $userscontexts = get_context_instance(CONTEXT_USER, $params['userids']);
 
         $users = user_get_users_by_id($params['userids']);
         $result = array();
         foreach ($users as $user) {
 
-            $context = get_context_instance(CONTEXT_USER, $user->id);
-            require_capability('moodle/user:viewalldetails', $context);
+            $context = $userscontexts[$user->id];
+            $hasviewdetailscap = has_capability('moodle/user:viewdetails', $context);
+            $hasuserupdatecap = has_capability('moodle/user:update', get_system_context());
+
             self::validate_context($context);
 
+            $currentuser = ($user->id == $USER->id);
+
             if (empty($user->deleted)) {
 
+                if (!$currentuser && !$hasviewdetailscap && !has_coursecontact_role($user->id)) {
+                    throw new moodle_exception('usernotavailable', 'error');
+                }
+
                 $userarray = array();
-               //we want to return an array not an object
-                /// now we transfert all profile_field_xxx into the customfields
-                // external_multiple_structure required by description
+
+                //basic fields
                 $userarray['id'] = $user->id;
-                $userarray['username'] = $user->username;
-                $userarray['firstname'] = $user->firstname;
-                $userarray['lastname'] = $user->lastname;
-                $userarray['email'] = $user->email;
-                $userarray['auth'] = $user->auth;
-                $userarray['confirmed'] = $user->confirmed;
-                $userarray['idnumber'] = $user->idnumber;
-                $userarray['lang'] = $user->lang;
-                $userarray['theme'] = $user->theme;
-                $userarray['timezone'] = $user->timezone;
-                $userarray['mailformat'] = $user->mailformat;
-                $userarray['description'] = $user->description;
-                $userarray['descriptionformat'] = $user->descriptionformat;
-                $userarray['city'] = $user->city;
-                $userarray['country'] = $user->country;
+                if ($isadmin) {
+                    $userarray['username'] = $user->username;
+                }
+                if ($isadmin or has_capability('moodle/site:viewfullnames', $context)) {
+                    $userarray['firstname'] = $user->firstname;
+                    $userarray['lastname'] = $user->lastname;
+                }
+                $userarray['fullname'] = fullname($user);
+
+                //fields matching permissions from /user/editadvanced.php
+                if ($currentuser or $hasuserupdatecap) {
+                    $userarray['auth'] = $user->auth;
+                    $userarray['confirmed'] = $user->confirmed;
+                    $userarray['idnumber'] = $user->idnumber;
+                    $userarray['lang'] = $user->lang;
+                    $userarray['theme'] = $user->theme;
+                    $userarray['timezone'] = $user->timezone;
+                    $userarray['mailformat'] = $user->mailformat;
+                }
+
+                //Custom fields (matching /user/profil/lib.php - profile_display_fields code logic)
                 $userarray['customfields'] = array();
-                $customfields = profile_user_record($user->id);
-                $customfields = (array) $customfields;
-                foreach ($customfields as $key => $value) {
-                    $userarray['customfields'][] = array('type' => $key, 'value' => $value);
+                if ($categories = $DB->get_records('user_info_category', null, 'sortorder ASC')) {
+                    foreach ($categories as $category) {
+                        if ($fields = $DB->get_records('user_info_field', array('categoryid'=>$category->id), 'sortorder ASC')) {
+                            foreach ($fields as $field) {
+                                require_once($CFG->dirroot.'/user/profile/field/'.$field->datatype.'/field.class.php');
+                                $newfield = 'profile_field_'.$field->datatype;
+                                $formfield = new $newfield($field->id, $user->id);
+                                if ($formfield->is_visible() and !$formfield->is_empty()) {
+                                    $userarray['customfields'][] =
+                                        array('name' => $formfield->field->name, 'value' => $formfield->data,
+                                            'type' => $field->datatype, 'shortname' => $formfield->field->shortname);
+                                }
+                            }
+                        }
+                    }
+                }
+
+                //image profiles urls (public, no permission required in fact)
+                $profileimageurl = moodle_url::make_pluginfile_url($context->id, 'user', 'icon', NULL, '/', 'f1');
+                $userarray['profileimageurl'] = $profileimageurl->out(false);
+                $profileimageurlsmall = moodle_url::make_pluginfile_url($context->id, 'user', 'icon', NULL, '/', 'f2');
+                $userarray['profileimageurlsmall'] = $profileimageurlsmall->out(false);
+
+                //hidden user field
+                if (has_capability('moodle/user:viewhiddendetails', $context)) {
+                    $hiddenfields = array();
+                } else {
+                    $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
                 }
 
-                $result[] = $userarray;
+                if (isset($user->description) && (!isset($hiddenfields['description']) or $isadmin)) {
+                    if (empty($CFG->profilesforenrolledusersonly) || $currentuser) {
+                        $user->description = file_rewrite_pluginfile_urls($user->description, 'pluginfile.php', $context->id, 'user', 'profile', null);
+                        $userarray['description'] = $user->description;
+                        $userarray['descriptionformat'] = $user->descriptionformat;
+                    }
+                }
+
+                if ((! isset($hiddenfields['country']) or $isadmin) && $user->country) {
+                    $userarray['country'] = $user->country;
+                }
+
+                if ((! isset($hiddenfields['city']) or $isadmin) && $user->city) {
+                    $userarray['city'] = $user->city;
+                }
+
+                if (has_capability('moodle/user:viewhiddendetails', $context)) {
+                    if ($user->address) {
+                        $userarray['address'] = $user->address;
+                    }
+                    if ($user->phone1) {
+                        $userarray['phone1'] = $user->phone1;
+                    }
+                    if ($user->phone2) {
+                        $userarray['phone2'] = $user->phone2;
+                    }
+                }
+
+                if ($currentuser
+                  or $user->maildisplay == 1
+                  or has_capability('moodle/course:useremail', $context)
+                  or ($user->maildisplay == 2 and enrol_sharing_course($user, $USER))) {
+                    $userarray['email'] = $user->email;;
+                }
+
+                if ($user->url && (!isset($hiddenfields['webpage']) or $isadmin)) {
+                    $url = $user->url;
+                    if (strpos($user->url, '://') === false) {
+                        $url = 'http://'. $url;
+                    }
+                    $user->url = clean_param($user->url, PARAM_URL);
+                    $userarray['url'] = $user->url;
+                }
+
+                if ($user->icq && (!isset($hiddenfields['icqnumber']) or $isadmin)) {
+                    $userarray['icq'] = $user->icq;
+                }
+
+                if ($user->skype && (!isset($hiddenfields['skypeid']) or $isadmin)) {
+                    $userarray['skype'] = $user->skype;
+                }
+                if ($user->yahoo && (!isset($hiddenfields['yahooid']) or $isadmin)) {
+                    $userarray['yahoo'] = $user->yahoo;
+                }
+                if ($user->aim && (!isset($hiddenfields['aimid']) or $isadmin)) {
+                    $userarray['aim'] = $user->aim;
+                }
+                if ($user->msn && (!isset($hiddenfields['msnid']) or $isadmin)) {
+                    $userarray['msn'] = $user->msn;
+                }
+
+                if ((!isset($hiddenfields['firstaccess'])) or $isadmin) {
+                    if ($user->firstaccess) {
+                        $userarray['firstaccess'] = $user->firstaccess;
+                    } else {
+                        $userarray['firstaccess'] = 0;
+                    }
+                }
+                if ((!isset($hiddenfields['lastaccess'])) or $isadmin) {
+                    if ($user->lastaccess) {
+                        $userarray['lastaccess'] = $user->lastaccess;
+                    } else {
+                        $userarray['lastaccess'] = 0;
+                    }
+                }
+                /// Printing tagged interests
+                if (!empty($CFG->usetags)) {
+                    require_once($CFG->dirroot . '/tag/lib.php');
+                    if ($interests = tag_get_tags_csv('user', $user->id, TAG_RETURN_TEXT) ) {
+                        $userarray['interests'] = $interests;
+                    }
+                }
+
+                //Departement/Institution are not displayed on any profile, however you can get them from editing profile.
+                if ($isadmin or $currentuser) {
+                    if ($user->institution) {
+                        $userarray['institution'] = $user->institution;
+                    }
+                    if (isset($user->department)) { //isset because it's ok to have department 0
+                        $userarray['department'] = $user->department;
+                    }
+                }
+
+                //list of courses where the user is enrolled
+                $enrolledcourses = array();
+                if (!isset($hiddenfields['mycourses'])) {
+                    if ($mycourses = enrol_get_users_courses($user->id, true, NULL, 'visible DESC,sortorder ASC')) {
+                        $courselisting = '';
+                        foreach ($mycourses as $mycourse) {
+                            if ($mycourse->category) {
+                                if ($mycourse->visible == 0) {
+                                    $ccontext = get_context_instance(CONTEXT_COURSE, $mycourse->id);
+                                    if (!has_capability('moodle/course:viewhiddencourses', $ccontext)) {
+                                        continue;
+                                    }
+                                }
+                                $enrolledcourse = array();
+                                $enrolledcourse['id'] = $mycourse->id;
+                                $enrolledcourse['fullname'] = $mycourse->fullname;
+                                $enrolledcourses[] = $enrolledcourse;
+                            }
+                        }
+                        $userarray['enrolledcourses'] = $enrolledcourses;
+                    }
+                }
+
+                //user preferences
+                if ($currentuser) {
+                    $preferences = array();
+                    $userpreferences = get_user_preferences();
+                     foreach($userpreferences as $prefname => $prefvalue) {
+                        $preferences[] = array('name' => $prefname, 'value' => $prefvalue);
+                     }
+                     $userarray['preferences'] = $preferences;
+                }
             }
+
+            $result[] = $userarray;
         }
 
         return $result;
@@ -417,28 +580,61 @@ class moodle_user_external extends external_api {
                 new external_single_structure(
                         array(
                     'id'    => new external_value(PARAM_NUMBER, 'ID of the user'),
-                    'username'    => new external_value(PARAM_RAW, 'Username policy is defined in Moodle security config'),
-                    'firstname'   => new external_value(PARAM_NOTAGS, 'The first name(s) of the user'),
-                    'lastname'    => new external_value(PARAM_NOTAGS, 'The family name of the user'),
-                    'email'       => new external_value(PARAM_TEXT, 'An email address - allow email as root@localhost'),
-                    'auth'        => new external_value(PARAM_SAFEDIR, 'Auth plugins include manual, ldap, imap, etc'),
-                    'confirmed'   => new external_value(PARAM_NUMBER, 'Active user: 1 if confirmed, 0 otherwise'),
-                    'idnumber'    => new external_value(PARAM_RAW, 'An arbitrary ID code number perhaps from the institution'),
-                    'lang'        => new external_value(PARAM_SAFEDIR, 'Language code such as "en", must exist on server'),
-                    'theme'       => new external_value(PARAM_SAFEDIR, 'Theme name such as "standard", must exist on server'),
-                    'timezone'    => new external_value(PARAM_ALPHANUMEXT, 'Timezone code such as Australia/Perth, or 99 for default'),
-                    'mailformat'  => new external_value(PARAM_INTEGER, 'Mail format code is 0 for plain text, 1 for HTML etc'),
-                    'description' => new external_value(PARAM_RAW, 'User profile description'),
-                    'descriptionformat' => new external_value(PARAM_INT, 'User profile description format'),
-                    'city'        => new external_value(PARAM_NOTAGS, 'Home city of the user'),
-                    'country'     => new external_value(PARAM_ALPHA, 'Home country code of the user, such as AU or CZ'),
+                    'username'    => new external_value(PARAM_RAW, 'Username policy is defined in Moodle security config', VALUE_OPTIONAL),
+                    'firstname'   => new external_value(PARAM_NOTAGS, 'The first name(s) of the user', VALUE_OPTIONAL),
+                    'lastname'    => new external_value(PARAM_NOTAGS, 'The family name of the user', VALUE_OPTIONAL),
+                    'fullname'    => new external_value(PARAM_NOTAGS, 'The fullname of the user'),
+                    'email'       => new external_value(PARAM_TEXT, 'An email address - allow email as root@localhost', VALUE_OPTIONAL),
+                    'address'     => new external_value(PARAM_MULTILANG, 'Postal address', VALUE_OPTIONAL),
+                    'phone1'      => new external_value(PARAM_NOTAGS, 'Phone 1', VALUE_OPTIONAL),
+                    'phone2'      => new external_value(PARAM_NOTAGS, 'Phone 2', VALUE_OPTIONAL),
+                    'icq'         => new external_value(PARAM_NOTAGS, 'icq number', VALUE_OPTIONAL),
+                    'skype'       => new external_value(PARAM_NOTAGS, 'skype id', VALUE_OPTIONAL),
+                    'yahoo'       => new external_value(PARAM_NOTAGS, 'yahoo id', VALUE_OPTIONAL),
+                    'aim'         => new external_value(PARAM_NOTAGS, 'aim id', VALUE_OPTIONAL),
+                    'msn'         => new external_value(PARAM_NOTAGS, 'msn number', VALUE_OPTIONAL),
+                    'department'  => new external_value(PARAM_TEXT, 'department', VALUE_OPTIONAL),
+                    'institution' => new external_value(PARAM_TEXT, 'institution', VALUE_OPTIONAL),
+                    'interests'   => new external_value(PARAM_TEXT, 'user interests (separated by commas)', VALUE_OPTIONAL),
+                    'firstaccess' => new external_value(PARAM_INT, 'first access to the site (0 if never)', VALUE_OPTIONAL),
+                    'lastaccess'  => new external_value(PARAM_INT, 'last access to the site (0 if never)', VALUE_OPTIONAL),
+                    'auth'        => new external_value(PARAM_SAFEDIR, 'Auth plugins include manual, ldap, imap, etc', VALUE_OPTIONAL),
+                    'confirmed'   => new external_value(PARAM_NUMBER, 'Active user: 1 if confirmed, 0 otherwise', VALUE_OPTIONAL),
+                    'idnumber'    => new external_value(PARAM_RAW, 'An arbitrary ID code number perhaps from the institution', VALUE_OPTIONAL),
+                    'lang'        => new external_value(PARAM_SAFEDIR, 'Language code such as "en", must exist on server', VALUE_OPTIONAL),
+                    'theme'       => new external_value(PARAM_SAFEDIR, 'Theme name such as "standard", must exist on server', VALUE_OPTIONAL),
+                    'timezone'    => new external_value(PARAM_ALPHANUMEXT, 'Timezone code such as Australia/Perth, or 99 for default', VALUE_OPTIONAL),
+                    'mailformat'  => new external_value(PARAM_INTEGER, 'Mail format code is 0 for plain text, 1 for HTML etc', VALUE_OPTIONAL),
+                    'description' => new external_value(PARAM_RAW, 'User profile description', VALUE_OPTIONAL),
+                    'descriptionformat' => new external_value(PARAM_INT, 'User profile description format', VALUE_OPTIONAL),
+                    'city'        => new external_value(PARAM_NOTAGS, 'Home city of the user', VALUE_OPTIONAL),
+                    'url'         => new external_value(PARAM_URL, 'URL of the user', VALUE_OPTIONAL),
+                    'country'     => new external_value(PARAM_ALPHA, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL),
+                    'profileimageurlsmall' => new external_value(PARAM_URL, 'User image profile URL - small version'),
+                    'profileimageurl' => new external_value(PARAM_URL, 'User image profile URL - big version'),
                     'customfields' => new external_multiple_structure(
                                     new external_single_structure(
                                             array(
-                                                'type'  => new external_value(PARAM_ALPHANUMEXT, 'The name of the custom field'),
-                                                'value' => new external_value(PARAM_RAW, 'The value of the custom field')
+                                                'type'  => new external_value(PARAM_ALPHANUMEXT, 'The type of the custom field - text field, checkbox...'),
+                                                'value' => new external_value(PARAM_RAW, 'The value of the custom field'),
+                                                'name' => new external_value(PARAM_RAW, 'The name of the custom field'),
+                                                'shortname' => new external_value(PARAM_RAW, 'The shortname of the custom field - to be able to build the field class in the code'),
                                             )
-                                    ), 'User custom fields (also known as user profil fields)', VALUE_OPTIONAL)
+                                    ), 'User custom fields (also known as user profil fields)', VALUE_OPTIONAL),
+                    'preferences' => new external_multiple_structure(
+                            new external_single_structure(
+                                    array(
+                                        'name'  => new external_value(PARAM_ALPHANUMEXT, 'The name of the preferences'),
+                                        'value' => new external_value(PARAM_RAW, 'The value of the custom field'),
+                                    )
+                            ), 'User preferences', VALUE_OPTIONAL),
+                    'enrolledcourses' => new external_multiple_structure(
+                            new external_single_structure(
+                                    array(
+                                        'id'  => new external_value(PARAM_INT, 'Id of the course'),
+                                        'fullname' => new external_value(PARAM_RAW, 'Fullname of the course')
+                                    )
+                            ), 'Courses where the user is enrolled - limited by which courses the user is able to see', VALUE_OPTIONAL)
                         )
                 )
         );
index 6ab3fd0..ec45c32 100644 (file)
@@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die();
 
 
 
-$version  = 2011060900.00;              // YYYYMMDD      = weekly release date of this DEV branch
+$version  = 2011060900.01;              // YYYYMMDD      = weekly release date of this DEV branch
                                         //         RR    = release increments - 00 in DEV branches
                                         //           .XX = incremental changes