当前位置: 首页>>代码示例>>PHP>>正文


PHP user_get_user_details函数代码示例

本文整理汇总了PHP中user_get_user_details函数的典型用法代码示例。如果您正苦于以下问题:PHP user_get_user_details函数的具体用法?PHP user_get_user_details怎么用?PHP user_get_user_details使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了user_get_user_details函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_participant

 /**
  * Get the user participating in the given assignment. An error with code 'usernotincourse'
  * is thrown is the user isn't a participant of the given assignment.
  *
  * @param int $assignid the assign instance id
  * @param int $userid the user id
  * @param bool $embeduser return user details (only applicable if not blind marking)
  * @return array of warnings and status result
  * @since Moodle 3.1
  * @throws moodle_exception
  */
 public static function get_participant($assignid, $userid, $embeduser)
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . "/mod/assign/locallib.php";
     require_once $CFG->dirroot . "/user/lib.php";
     $params = self::validate_parameters(self::get_participant_parameters(), array('assignid' => $assignid, 'userid' => $userid, 'embeduser' => $embeduser));
     list($assign, $course, $cm, $context) = self::validate_assign($params['assignid']);
     $assign->require_view_grades();
     $participant = $assign->get_participant($params['userid']);
     if (!$participant) {
         // No participant found so we can return early.
         throw new moodle_exception('usernotincourse');
     }
     $return = array('id' => $participant->id, 'fullname' => $participant->fullname, 'submitted' => $participant->submitted, 'requiregrading' => $participant->requiregrading, 'blindmarking' => $assign->is_blind_marking());
     if (!empty($participant->groupid)) {
         $return['groupid'] = $participant->groupid;
     }
     if (!empty($participant->groupname)) {
         $return['groupname'] = $participant->groupname;
     }
     // Skip the expensive lookup of user detail if we're blind marking or the caller
     // hasn't asked for user details to be embedded.
     if (!$assign->is_blind_marking() && $embeduser) {
         $return['user'] = user_get_user_details($participant, $course);
     }
     return $return;
 }
开发者ID:janeklb,项目名称:moodle,代码行数:38,代码来源:externallib.php

示例2: user_get_user_details_courses

/**
 * Tries to obtain user details, either recurring directly to the user's system profile
 * or through one of the user's course enrollments (course profile).
 *
 * @param object $user The user.
 * @return array if unsuccessful or the allowed user details.
 */
function user_get_user_details_courses($user)
{
    global $USER;
    $userdetails = null;
    //  Get the courses that the user is enrolled in (only active).
    $courses = enrol_get_users_courses($user->id, true);
    $systemprofile = false;
    if (can_view_user_details_cap($user) || $user->id == $USER->id || has_coursecontact_role($user->id)) {
        $systemprofile = true;
    }
    // Try using system profile.
    if ($systemprofile) {
        $userdetails = user_get_user_details($user, null);
    } else {
        // Try through course profile.
        foreach ($courses as $course) {
            if (can_view_user_details_cap($user, $course) || $user->id == $USER->id || has_coursecontact_role($user->id)) {
                $userdetails = user_get_user_details($user, $course);
            }
        }
    }
    return $userdetails;
}
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:30,代码来源:lib.php

示例3: get_enrolled_users


//.........这里部分代码省略.........
                 $groupid = (int) $option['value'];
                 break;
             case 'onlyactive':
                 $onlyactive = !empty($option['value']);
                 break;
             case 'userfields':
                 $thefields = explode(',', $option['value']);
                 foreach ($thefields as $f) {
                     $userfields[] = clean_param($f, PARAM_ALPHANUMEXT);
                 }
                 break;
             case 'limitfrom':
                 $limitfrom = clean_param($option['value'], PARAM_INT);
                 break;
             case 'limitnumber':
                 $limitnumber = clean_param($option['value'], PARAM_INT);
                 break;
             case 'sortby':
                 $sortallowedvalues = array('id', 'firstname', 'lastname', 'siteorder');
                 if (!in_array($option['value'], $sortallowedvalues)) {
                     throw new invalid_parameter_exception('Invalid value for sortby parameter (value: ' . $option['value'] . '),' . 'allowed values are: ' . implode(',', $sortallowedvalues));
                 }
                 if ($option['value'] == 'siteorder') {
                     list($sortby, $sortparams) = users_order_by_sql('us');
                 } else {
                     $sortby = 'us.' . $option['value'];
                 }
                 break;
             case 'sortdirection':
                 $sortdirection = strtoupper($option['value']);
                 $directionallowedvalues = array('ASC', 'DESC');
                 if (!in_array($sortdirection, $directionallowedvalues)) {
                     throw new invalid_parameter_exception('Invalid value for sortdirection parameter
                     (value: ' . $sortdirection . '),' . 'allowed values are: ' . implode(',', $directionallowedvalues));
                 }
                 break;
         }
     }
     $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
     $coursecontext = context_course::instance($courseid, IGNORE_MISSING);
     if ($courseid == SITEID) {
         $context = context_system::instance();
     } else {
         $context = $coursecontext;
     }
     try {
         self::validate_context($context);
     } catch (Exception $e) {
         $exceptionparam = new stdClass();
         $exceptionparam->message = $e->getMessage();
         $exceptionparam->courseid = $params['courseid'];
         throw new moodle_exception('errorcoursecontextnotvalid', 'webservice', '', $exceptionparam);
     }
     if ($courseid == SITEID) {
         require_capability('moodle/site:viewparticipants', $context);
     } else {
         require_capability('moodle/course:viewparticipants', $context);
     }
     // to overwrite this parameter, you need role:review capability
     if ($withcapability) {
         require_capability('moodle/role:review', $coursecontext);
     }
     // need accessallgroups capability if you want to overwrite this option
     if (!empty($groupid) && !groups_is_member($groupid)) {
         require_capability('moodle/site:accessallgroups', $coursecontext);
     }
     // to overwrite this option, you need course:enrolereview permission
     if ($onlyactive) {
         require_capability('moodle/course:enrolreview', $coursecontext);
     }
     list($enrolledsql, $enrolledparams) = get_enrolled_sql($coursecontext, $withcapability, $groupid, $onlyactive);
     $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
     $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = u.id AND ctx.contextlevel = :contextlevel)";
     $enrolledparams['contextlevel'] = CONTEXT_USER;
     $groupjoin = '';
     if (empty($groupid) && groups_get_course_groupmode($course) == SEPARATEGROUPS && !has_capability('moodle/site:accessallgroups', $coursecontext)) {
         // Filter by groups the user can view.
         $usergroups = groups_get_user_groups($course->id);
         if (!empty($usergroups['0'])) {
             list($groupsql, $groupparams) = $DB->get_in_or_equal($usergroups['0'], SQL_PARAMS_NAMED);
             $groupjoin = "JOIN {groups_members} gm ON (u.id = gm.userid AND gm.groupid {$groupsql})";
             $enrolledparams = array_merge($enrolledparams, $groupparams);
         } else {
             // User doesn't belong to any group, so he can't see any user. Return an empty array.
             return array();
         }
     }
     $sql = "SELECT us.*\n                  FROM {user} us\n                  JOIN (\n                      SELECT DISTINCT u.id {$ctxselect}\n                        FROM {user} u {$ctxjoin} {$groupjoin}\n                       WHERE u.id IN ({$enrolledsql})\n                  ) q ON q.id = us.id\n                ORDER BY {$sortby} {$sortdirection}";
     $enrolledparams = array_merge($enrolledparams, $sortparams);
     $enrolledusers = $DB->get_recordset_sql($sql, $enrolledparams, $limitfrom, $limitnumber);
     $users = array();
     foreach ($enrolledusers as $user) {
         context_helper::preload_from_record($user);
         if ($userdetails = user_get_user_details($user, $course, $userfields)) {
             $users[] = $userdetails;
         }
     }
     $enrolledusers->close();
     return $users;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:externallib.php

示例4: get_course_user_profiles

 /**
  * Get course participant's details
  *
  * @param array $userlist  array of user ids and according course ids
  * @return array An array of arrays describing course participants
  * @since Moodle 2.2
  */
 public static function get_course_user_profiles($userlist)
 {
     global $CFG, $USER, $DB;
     require_once $CFG->dirroot . "/user/lib.php";
     $params = self::validate_parameters(self::get_course_user_profiles_parameters(), array('userlist' => $userlist));
     $userids = array();
     $courseids = array();
     foreach ($params['userlist'] as $value) {
         $userids[] = $value['userid'];
         $courseids[$value['userid']] = $value['courseid'];
     }
     // cache all courses
     $courses = array();
     list($cselect, $cjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
     list($sqlcourseids, $params) = $DB->get_in_or_equal(array_unique($courseids));
     $coursesql = "SELECT c.* {$cselect}\n                        FROM {course} c {$cjoin}\n                       WHERE c.id {$sqlcourseids}";
     $rs = $DB->get_recordset_sql($coursesql, $params);
     foreach ($rs as $course) {
         // adding course contexts to cache
         context_instance_preload($course);
         // cache courses
         $courses[$course->id] = $course;
     }
     $rs->close();
     list($uselect, $ujoin) = context_instance_preload_sql('u.id', CONTEXT_USER, 'ctx');
     list($sqluserids, $params) = $DB->get_in_or_equal($userids);
     $usersql = "SELECT u.* {$uselect}\n                      FROM {user} u {$ujoin}\n                     WHERE u.id {$sqluserids}";
     $users = $DB->get_recordset_sql($usersql, $params);
     $result = array();
     foreach ($users as $user) {
         if (!empty($user->deleted)) {
             continue;
         }
         context_instance_preload($user);
         $course = $courses[$courseids[$user->id]];
         $context = context_course::instance($courseids[$user->id], IGNORE_MISSING);
         self::validate_context($context);
         if ($userarray = user_get_user_details($user, $course)) {
             $result[] = $userarray;
         }
     }
     $users->close();
     return $result;
 }
开发者ID:vinoth4891,项目名称:clinique,代码行数:51,代码来源:externallib.php

示例5: get_users_by_courseid

    /**
     * Get course participants details
     * @param int $courseid  course id
     * @param array $options options {
     *          'name' => option name
     *          'value' => option value
     * }
     * @return array An array of users
     */
    public static function get_users_by_courseid($courseid, $options) {
        global $CFG, $USER, $DB;
        require_once($CFG->dirroot . "/user/lib.php");

        $params = self::validate_parameters(
            self::get_users_by_courseid_parameters(),
            array(
                'courseid'=>$courseid,
                'options'=>$options
            )
        );
        $withcapability = '';
        $groupid        = 0;
        $onlyactive     = false;
        foreach ($options as $option) {
            switch ($option['name']) {
            case 'withcapability':
                $withcapability = $option['value'];
                break;
            case 'groupid':
                $groupid = (int)$option['value'];
                break;
            case 'onlyactive':
                $onlyactive = !empty($option['value']);
                break;
            }
        }

        // to overwrite this parameter, you need role:review capability
        if ($withcapability) {
            require_capability('moodle/role:review', $coursecontext);
        }
        // need accessallgroups capability if you want to overwrite this option
        if (!empty($groupid) && groups_is_member($groupid)) {
            require_capability('moodle/site:accessallgroups', $context);
        }
        // to overwrite this option, you need course:enrolereview permission
        if ($onlyactive) {
            require_capability('moodle/course:enrolreview', $coursecontext);
        }

        list($coursectxselect, $coursectxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
        $coursesql = "SELECT c.* $coursectxselect
                        FROM {course} c $coursectxjoin
                       WHERE c.id = $courseid";
        $course = $DB->get_record_sql($coursesql);
        context_instance_preload($course);
        $coursecontext = get_context_instance(CONTEXT_COURSE, $params['courseid']);
        if ($courseid == SITEID) {
            $context = get_system_context();
        } else {
            $context = $coursecontext;
        }
        try {
            self::validate_context($context);
        } catch (Exception $e) {
            $exceptionparam = new stdClass();
            $exceptionparam->message = $e->getMessage();
            $exceptionparam->courseid = $params['courseid'];
            throw new moodle_exception(get_string('errorcoursecontextnotvalid' , 'webservice', $exceptionparam));
        }

        list($enrolledsql, $enrolledparams) = get_enrolled_sql($coursecontext, $withcapability, $groupid, $onlyactive);
        list($ctxselect, $ctxjoin) = context_instance_preload_sql('u.id', CONTEXT_USER, 'ctx');
        $records = $DB->get_records_sql($enrolledsql, $enrolledparams);
        $sqlparams['courseid'] = $courseid;
        $sql = "SELECT u.* $ctxselect
                  FROM {user} u $ctxjoin
                 WHERE u.id IN ($enrolledsql)
                 ORDER BY u.id ASC";
        $enrolledusers = $DB->get_recordset_sql($sql, $enrolledparams);
        $users = array();
        foreach ($enrolledusers as $user) {
            if (!empty($user->deleted)) {
                continue;
            }
            context_instance_preload($user);
            if ($userdetails = user_get_user_details($user, $course)) {
                $users[] = $userdetails;
            }
        }
        $enrolledusers->close();

        return $users;
    }
开发者ID:ravivare,项目名称:moodle-1,代码行数:94,代码来源:externallib.php

示例6: get_enrolled_users

 /**
  * Get course participants details
  *
  * @param int $courseid  course id
  * @param array $options options {
  *                                'name' => option name
  *                                'value' => option value
  *                               }
  * @return array An array of users
  */
 public static function get_enrolled_users($courseid, $options = array())
 {
     global $CFG, $USER, $DB;
     require_once $CFG->dirroot . "/user/lib.php";
     $params = self::validate_parameters(self::get_enrolled_users_parameters(), array('courseid' => $courseid, 'options' => $options));
     $withcapability = '';
     $groupid = 0;
     $onlyactive = false;
     $userfields = array();
     $limitfrom = 0;
     $limitnumber = 0;
     foreach ($options as $option) {
         switch ($option['name']) {
             case 'withcapability':
                 $withcapability = $option['value'];
                 break;
             case 'groupid':
                 $groupid = (int) $option['value'];
                 break;
             case 'onlyactive':
                 $onlyactive = !empty($option['value']);
                 break;
             case 'userfields':
                 $thefields = explode(',', $option['value']);
                 foreach ($thefields as $f) {
                     $userfields[] = clean_param($f, PARAM_ALPHANUMEXT);
                 }
             case 'limitfrom':
                 $limitfrom = clean_param($option['value'], PARAM_INT);
                 break;
             case 'limitnumber':
                 $limitnumber = clean_param($option['value'], PARAM_INT);
                 break;
         }
     }
     $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
     $coursecontext = context_course::instance($courseid, IGNORE_MISSING);
     if ($courseid == SITEID) {
         $context = get_system_context();
     } else {
         $context = $coursecontext;
     }
     try {
         self::validate_context($context);
     } catch (Exception $e) {
         $exceptionparam = new stdClass();
         $exceptionparam->message = $e->getMessage();
         $exceptionparam->courseid = $params['courseid'];
         throw new moodle_exception('errorcoursecontextnotvalid', 'webservice', '', $exceptionparam);
     }
     if ($courseid == SITEID) {
         require_capability('moodle/site:viewparticipants', $context);
     } else {
         require_capability('moodle/course:viewparticipants', $context);
     }
     // to overwrite this parameter, you need role:review capability
     if ($withcapability) {
         require_capability('moodle/role:review', $coursecontext);
     }
     // need accessallgroups capability if you want to overwrite this option
     if (!empty($groupid) && groups_is_member($groupid)) {
         require_capability('moodle/site:accessallgroups', $coursecontext);
     }
     // to overwrite this option, you need course:enrolereview permission
     if ($onlyactive) {
         require_capability('moodle/course:enrolreview', $coursecontext);
     }
     list($enrolledsql, $enrolledparams) = get_enrolled_sql($coursecontext, $withcapability, $groupid, $onlyactive);
     list($ctxselect, $ctxjoin) = context_instance_preload_sql('u.id', CONTEXT_USER, 'ctx');
     $sqlparams['courseid'] = $courseid;
     $sql = "SELECT u.* {$ctxselect}\n                  FROM {user} u {$ctxjoin}\n                 WHERE u.id IN ({$enrolledsql})\n                 ORDER BY u.id ASC";
     $enrolledusers = $DB->get_recordset_sql($sql, $enrolledparams, $limitfrom, $limitnumber);
     $users = array();
     foreach ($enrolledusers as $user) {
         context_instance_preload($user);
         if ($userdetails = user_get_user_details($user, $course, $userfields)) {
             $users[] = $userdetails;
         }
     }
     $enrolledusers->close();
     return $users;
 }
开发者ID:JP-Git,项目名称:moodle,代码行数:92,代码来源:externallib.php

示例7: get_course_user_profiles

 /**
  * Get course participant's details
  *
  * @param array $userlist  array of user ids and according course ids
  * @return array An array of arrays describing course participants
  * @since Moodle 2.2
  */
 public static function get_course_user_profiles($userlist)
 {
     global $CFG, $USER, $DB;
     require_once $CFG->dirroot . "/user/lib.php";
     $params = self::validate_parameters(self::get_course_user_profiles_parameters(), array('userlist' => $userlist));
     $userids = array();
     $courseids = array();
     foreach ($params['userlist'] as $value) {
         $userids[] = $value['userid'];
         $courseids[$value['userid']] = $value['courseid'];
     }
     // Cache all courses.
     $courses = array();
     list($sqlcourseids, $params) = $DB->get_in_or_equal(array_unique($courseids), SQL_PARAMS_NAMED);
     $cselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
     $cjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
     $params['contextlevel'] = CONTEXT_COURSE;
     $coursesql = "SELECT c.* {$cselect}\n                        FROM {course} c {$cjoin}\n                       WHERE c.id {$sqlcourseids}";
     $rs = $DB->get_recordset_sql($coursesql, $params);
     foreach ($rs as $course) {
         // Adding course contexts to cache.
         context_helper::preload_from_record($course);
         // Cache courses.
         $courses[$course->id] = $course;
     }
     $rs->close();
     list($sqluserids, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
     $uselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
     $ujoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = u.id AND ctx.contextlevel = :contextlevel)";
     $params['contextlevel'] = CONTEXT_USER;
     $usersql = "SELECT u.* {$uselect}\n                      FROM {user} u {$ujoin}\n                     WHERE u.id {$sqluserids}";
     $users = $DB->get_recordset_sql($usersql, $params);
     $result = array();
     foreach ($users as $user) {
         if (!empty($user->deleted)) {
             continue;
         }
         context_helper::preload_from_record($user);
         $course = $courses[$courseids[$user->id]];
         $context = context_course::instance($courseids[$user->id], IGNORE_MISSING);
         self::validate_context($context);
         if ($userarray = user_get_user_details($user, $course)) {
             $result[] = $userarray;
         }
     }
     $users->close();
     return $result;
 }
开发者ID:educakanchay,项目名称:campus,代码行数:55,代码来源:externallib.php

示例8: get_participant

    /**
     * Get the user participating in the given assignment. An error with code 'usernotincourse'
     * is thrown is the user isn't a participant of the given assignment.
     *
     * @param int $assignid the assign instance id
     * @param int $userid the user id
     * @param bool $embeduser return user details (only applicable if not blind marking)
     * @return array of warnings and status result
     * @since Moodle 3.1
     * @throws moodle_exception
     */
    public static function get_participant($assignid, $userid, $embeduser) {
        global $DB, $CFG;
        require_once($CFG->dirroot . "/mod/assign/locallib.php");
        require_once($CFG->dirroot . "/user/lib.php");

        $params = self::validate_parameters(self::get_participant_parameters(), array(
            'assignid' => $assignid,
            'userid' => $userid,
            'embeduser' => $embeduser
        ));

        list($assign, $course, $cm, $context) = self::validate_assign($params['assignid']);
        $assign->require_view_grades();

        $participant = $assign->get_participant($params['userid']);

        // Update assign with override information.
        $assign->update_effective_access($params['userid']);

        if (!$participant) {
            // No participant found so we can return early.
            throw new moodle_exception('usernotincourse');
        }

        $return = array(
            'id' => $participant->id,
            'fullname' => $participant->fullname,
            'submitted' => $participant->submitted,
            'requiregrading' => $participant->requiregrading,
            'blindmarking' => $assign->is_blind_marking(),
            'allowsubmissionsfromdate' => $assign->get_instance()->allowsubmissionsfromdate,
            'duedate' => $assign->get_instance()->duedate,
            'cutoffdate' => $assign->get_instance()->cutoffdate,
            'duedatestr' => userdate($assign->get_instance()->duedate, get_string('strftimedatetime', 'langconfig')),
        );

        if (!empty($participant->groupid)) {
            $return['groupid'] = $participant->groupid;
        }
        if (!empty($participant->groupname)) {
            $return['groupname'] = $participant->groupname;
        }

        // Skip the expensive lookup of user detail if we're blind marking or the caller
        // hasn't asked for user details to be embedded.
        if (!$assign->is_blind_marking() && $embeduser) {
            $return['user'] = user_get_user_details($participant, $course);
        }

        return $return;
    }
开发者ID:EsdrasCaleb,项目名称:moodle,代码行数:62,代码来源:externallib.php

示例9: test_create_user

 public function test_create_user()
 {
     global $DB, $CFG;
     require_once $CFG->dirroot . '/user/lib.php';
     $this->resetAfterTest(true);
     $generator = $this->getDataGenerator();
     $count = $DB->count_records('user');
     $this->setCurrentTimeStart();
     $user = $generator->create_user();
     $this->assertEquals($count + 1, $DB->count_records('user'));
     $this->assertSame($user->username, clean_param($user->username, PARAM_USERNAME));
     $this->assertSame($user->email, clean_param($user->email, PARAM_EMAIL));
     $this->assertSame(AUTH_PASSWORD_NOT_CACHED, $user->password);
     $this->assertNotEmpty($user->firstnamephonetic);
     $this->assertNotEmpty($user->lastnamephonetic);
     $this->assertNotEmpty($user->alternatename);
     $this->assertNotEmpty($user->middlename);
     $this->assertSame('manual', $user->auth);
     $this->assertSame('en', $user->lang);
     $this->assertSame('1', $user->confirmed);
     $this->assertSame('0', $user->deleted);
     $this->assertTimeCurrent($user->timecreated);
     $this->assertSame($user->timecreated, $user->timemodified);
     $this->assertSame('0.0.0.0', $user->lastip);
     $record = array('auth' => 'email', 'firstname' => 'Žluťoučký', 'lastname' => 'Koníček', 'firstnamephonetic' => 'Zhlutyoucky', 'lastnamephonetic' => 'Koniiczek', 'middlename' => 'Hopper', 'alternatename' => 'horse', 'idnumber' => 'abc1', 'mnethostid' => (string) $CFG->mnet_localhost_id, 'username' => 'konic666', 'password' => 'password1', 'email' => 'email@example.com', 'confirmed' => '1', 'lang' => 'cs', 'maildisplay' => '1', 'mailformat' => '0', 'maildigest' => '1', 'autosubscribe' => '0', 'trackforums' => '0', 'deleted' => '0', 'timecreated' => '666');
     $user = $generator->create_user($record);
     $this->assertEquals($count + 2, $DB->count_records('user'));
     foreach ($record as $k => $v) {
         if ($k === 'password') {
             $this->assertTrue(password_verify($v, $user->password));
         } else {
             $this->assertSame($v, $user->{$k});
         }
     }
     $record = array('firstname' => 'Some', 'lastname' => 'User', 'idnumber' => 'def', 'username' => 'user666', 'email' => 'email666@example.com', 'deleted' => '1');
     $user = $generator->create_user($record);
     $this->assertEquals($count + 3, $DB->count_records('user'));
     $this->assertSame('', $user->idnumber);
     $this->assertSame(md5($record['username']), $user->email);
     $this->assertFalse(context_user::instance($user->id, IGNORE_MISSING));
     // Test generating user with interests.
     $user = $generator->create_user(array('interests' => 'Cats, Dogs'));
     $userdetails = user_get_user_details($user);
     $this->assertSame('Cats, Dogs', $userdetails['interests']);
 }
开发者ID:matiasma,项目名称:moodle,代码行数:45,代码来源:generator_test.php

示例10: search_contacts

    /**
     * Search contacts.
     *
     * @param string $searchtext query string.
     * @param bool $onlymycourses limit the search to the user's courses only.
     * @return external_description
     * @since 2.5
     */
    public static function search_contacts($searchtext, $onlymycourses = false) {
        global $CFG, $USER;
        require_once($CFG->libdir . '/enrollib.php');

        $params = array('searchtext' => $searchtext, 'onlymycourses' => $onlymycourses);
        $params = self::validate_parameters(self::search_contacts_parameters(), $params);

        // Extra validation, we do not allow empty queries.
        if ($params['searchtext'] === '') {
            throw new moodle_exception('querystringcannotbeempty');
        }

        $courseids = array();
        if ($params['onlymycourses']) {
            $mycourses = enrol_get_my_courses(array('id'));
            foreach ($mycourses as $mycourse) {
                $courseids[] = $mycourse->id;
            }
        } else {
            $courseids[] = SITEID;
        }

        // Retrieving the users matching the query.
        $users = message_search_users($courseids, $params['searchtext']);
        $results = array();
        foreach ($users as $user) {
            $results[$user->id] = $user;
        }

        // Reorganising information.
        foreach ($results as &$user) {
            $newuser = array(
                'id' => $user->id,
                'fullname' => fullname($user)
            );

            // Avoid undefined property notice as phone not specified.
            $user->phone1 = null;
            $user->phone2 = null;

            // Try to get the user picture, but sometimes this method can return null.
            $userdetails = user_get_user_details($user, null, array('profileimageurl', 'profileimageurlsmall'));
            if (!empty($userdetails)) {
                $newuser['profileimageurl'] = $userdetails['profileimageurl'];
                $newuser['profileimageurlsmall'] = $userdetails['profileimageurlsmall'];
            }

            $user = $newuser;
        }

        return $results;
    }
开发者ID:Burick,项目名称:moodle,代码行数:60,代码来源:externallib.php

示例11: get_users_by_id

 /**
  * 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
  * @since Moodle 2.2
  */
 public static function get_users_by_id($userids)
 {
     global $CFG, $USER, $DB;
     require_once $CFG->dirroot . "/user/lib.php";
     //iteramos los parametros y reemplazamos por los ID
     if (is_array($userids)) {
         foreach ($userids as $indice => $dni) {
             $u = $DB->get_record('user', array('username' => $dni));
             if (is_object($u)) {
                 $userids[$indice] = $u->id;
             }
         }
     }
     $params = self::validate_parameters(self::get_users_by_id_parameters(), array('userids' => $userids));
     list($uselect, $ujoin) = context_instance_preload_sql('u.id', CONTEXT_USER, 'ctx');
     list($sqluserids, $params) = $DB->get_in_or_equal($userids);
     $usersql = "SELECT u.* {$uselect}\n                      FROM {user} u {$ujoin}\n                     WHERE u.id {$sqluserids}";
     $users = $DB->get_recordset_sql($usersql, $params);
     $result = array();
     $hasuserupdatecap = has_capability('moodle/user:update', get_system_context());
     foreach ($users as $user) {
         if (!empty($user->deleted)) {
             continue;
         }
         context_instance_preload($user);
         $usercontext = get_context_instance(CONTEXT_USER, $user->id);
         self::validate_context($usercontext);
         $currentuser = $user->id == $USER->id;
         if ($userarray = user_get_user_details($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;
             }
             $result[] = $userarray;
         }
     }
     $users->close();
     return $result;
 }
开发者ID:jrevillaa,项目名称:local_atypaxreports,代码行数:55,代码来源:externallib.php

示例12: get_profile

 /**
  * Returns the profile information for a contact for a user.
  *
  * @param int $userid The user id
  * @param int $otheruserid The id of the user whose profile we want to view.
  * @return \stdClass
  */
 public static function get_profile($userid, $otheruserid)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/user/lib.php';
     if ($user = \core_user::get_user($otheruserid)) {
         // Create the data we are going to pass to the renderable.
         $userfields = user_get_user_details($user, null, array('city', 'country', 'email', 'profileimageurl', 'profileimageurlsmall', 'lastaccess'));
         if ($userfields) {
             $data = new \stdClass();
             $data->userid = $userfields['id'];
             $data->fullname = $userfields['fullname'];
             $data->city = isset($userfields['city']) ? $userfields['city'] : '';
             $data->country = isset($userfields['country']) ? $userfields['country'] : '';
             $data->email = isset($userfields['email']) ? $userfields['email'] : '';
             $data->profileimageurl = isset($userfields['profileimageurl']) ? $userfields['profileimageurl'] : '';
             if (isset($userfields['profileimageurlsmall'])) {
                 $data->profileimageurlsmall = $userfields['profileimageurlsmall'];
             } else {
                 $data->profileimageurlsmall = '';
             }
             if (isset($userfields['lastaccess'])) {
                 $data->isonline = helper::is_online($userfields['lastaccess']);
             } else {
                 $data->isonline = false;
             }
         } else {
             // Technically the access checks in user_get_user_details are correct,
             // but messaging has never obeyed them. In order to keep messaging working
             // we at least need to return a minimal user record.
             $data = new \stdClass();
             $data->userid = $otheruserid;
             $data->fullname = fullname($user);
             $data->city = '';
             $data->country = '';
             $data->email = '';
             $data->profileimageurl = '';
             $data->profileimageurlsmall = '';
             $data->isonline = false;
         }
         // Check if the contact has been blocked.
         $contact = $DB->get_record('message_contacts', array('userid' => $userid, 'contactid' => $otheruserid));
         if ($contact) {
             $data->isblocked = (bool) $contact->blocked;
             $data->iscontact = true;
         } else {
             $data->isblocked = false;
             $data->iscontact = false;
         }
         return $data;
     }
 }
开发者ID:dg711,项目名称:moodle,代码行数:58,代码来源:api.php

示例13: get_profile

 /**
  * Returns the profile information for a contact for a user.
  *
  * @param int $userid The user id
  * @param int $otheruserid The id of the user whose profile we want to view.
  * @return \stdClass
  */
 public static function get_profile($userid, $otheruserid)
 {
     global $CFG, $DB, $PAGE;
     require_once $CFG->dirroot . '/user/lib.php';
     $user = \core_user::get_user($otheruserid, '*', MUST_EXIST);
     // Create the data we are going to pass to the renderable.
     $data = new \stdClass();
     $data->userid = $otheruserid;
     $data->fullname = fullname($user);
     $data->city = '';
     $data->country = '';
     $data->email = '';
     $data->isonline = null;
     // Get the user picture data - messaging has always shown these to the user.
     $userpicture = new \user_picture($user);
     $userpicture->size = 1;
     // Size f1.
     $data->profileimageurl = $userpicture->get_url($PAGE)->out(false);
     $userpicture->size = 0;
     // Size f2.
     $data->profileimageurlsmall = $userpicture->get_url($PAGE)->out(false);
     $userfields = user_get_user_details($user, null, array('city', 'country', 'email', 'lastaccess'));
     if ($userfields) {
         if (isset($userfields['city'])) {
             $data->city = $userfields['city'];
         }
         if (isset($userfields['country'])) {
             $data->country = $userfields['country'];
         }
         if (isset($userfields['email'])) {
             $data->email = $userfields['email'];
         }
         if (isset($userfields['lastaccess'])) {
             $data->isonline = helper::is_online($userfields['lastaccess']);
         }
     }
     // Check if the contact has been blocked.
     $contact = $DB->get_record('message_contacts', array('userid' => $userid, 'contactid' => $otheruserid));
     if ($contact) {
         $data->isblocked = (bool) $contact->blocked;
         $data->iscontact = true;
     } else {
         $data->isblocked = false;
         $data->iscontact = false;
     }
     return $data;
 }
开发者ID:Chocolate-lightning,项目名称:moodle,代码行数:54,代码来源:api.php

示例14: test_user_get_user_details

    /**
     * Test user_get_user_details
     */
    public function test_user_get_user_details() {
        global $DB;

        $this->resetAfterTest();

        // Create user and modify user profile.
        $teacher = $this->getDataGenerator()->create_user();
        $student = $this->getDataGenerator()->create_user();
        $studentfullname = fullname($student);

        $course1 = $this->getDataGenerator()->create_course();
        $coursecontext = context_course::instance($course1->id);
        $teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
        $studentrole = $DB->get_record('role', array('shortname' => 'student'));
        $this->getDataGenerator()->enrol_user($teacher->id, $course1->id);
        $this->getDataGenerator()->enrol_user($student->id, $course1->id);
        role_assign($teacherrole->id, $teacher->id, $coursecontext->id);
        role_assign($studentrole->id, $student->id, $coursecontext->id);

        accesslib_clear_all_caches_for_unit_testing();

        // Get student details as a user with super system capabilities.
        $result = user_get_user_details($student, $course1);
        $this->assertEquals($student->id, $result['id']);
        $this->assertEquals($studentfullname, $result['fullname']);
        $this->assertEquals($course1->id, $result['enrolledcourses'][0]['id']);

        $this->setUser($teacher);
        // Get student details as a user who can only see this user in a course.
        $result = user_get_user_details($student, $course1);
        $this->assertEquals($student->id, $result['id']);
        $this->assertEquals($studentfullname, $result['fullname']);
        $this->assertEquals($course1->id, $result['enrolledcourses'][0]['id']);

        // Get student details with required fields.
        $result = user_get_user_details($student, $course1, array('id', 'fullname'));
        $this->assertCount(2, $result);
        $this->assertEquals($student->id, $result['id']);
        $this->assertEquals($studentfullname, $result['fullname']);

        // Get exception for invalid required fields.
        $this->expectException('moodle_exception');
        $result = user_get_user_details($student, $course1, array('wrongrequiredfield'));
    }
开发者ID:rezaies,项目名称:moodle,代码行数:47,代码来源:userlib_test.php

示例15: show_online_status

 /**
  * Helper function for checking if we should show the user's online status.
  *
  * @param \stdClass $user
  * @return boolean
  */
 public static function show_online_status($user)
 {
     global $CFG;
     require_once $CFG->dirroot . '/user/lib.php';
     if ($lastaccess = user_get_user_details($user, null, array('lastaccess'))) {
         if (isset($lastaccess['lastaccess'])) {
             return true;
         }
     }
     return false;
 }
开发者ID:Chocolate-lightning,项目名称:moodle,代码行数:17,代码来源:helper.php


注:本文中的user_get_user_details函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。