コード例 #1
0
 function definition_after_data()
 {
     global $CFG, $DB;
     $mform =& $this->_form;
     $userid = $mform->getElementValue('id');
     // if language does not exist, use site default lang
     if ($langsel = $mform->getElementValue('lang')) {
         $lang = reset($langsel);
         // missing _utf8 in language, add it before further processing. MDL-11829 MDL-16845
         if (strpos($lang, '_utf8') === false) {
             $lang = $lang . '_utf8';
             $lang_el =& $mform->getElement('lang');
             $lang_el->setValue($lang);
         }
         // check lang exists
         if (!file_exists($CFG->dataroot . '/lang/' . $lang) and !file_exists($CFG->dirroot . '/lang/' . $lang)) {
             $lang_el =& $mform->getElement('lang');
             $lang_el->setValue($CFG->lang);
         }
     }
     if ($user = $DB->get_record('user', array('id' => $userid))) {
         // remove description
         if (empty($user->description) && !empty($CFG->profilesforenrolledusersonly) && !$DB->record_exists('role_assignments', array('userid' => $userid))) {
             $mform->removeElement('description');
         }
         // print picture
         if (!empty($CFG->gdversion)) {
             $image_el =& $mform->getElement('currentpicture');
             if ($user and $user->picture) {
                 $image_el->setValue(print_user_picture($user, SITEID, $user->picture, 64, true, false, '', true));
             } else {
                 $image_el->setValue(get_string('none'));
             }
         }
         /// disable fields that are locked by auth plugins
         $fields = get_user_fieldnames();
         $authplugin = get_auth_plugin($user->auth);
         foreach ($fields as $field) {
             if (!$mform->elementExists($field)) {
                 continue;
             }
             $configvariable = 'field_lock_' . $field;
             if (isset($authplugin->config->{$configvariable})) {
                 if ($authplugin->config->{$configvariable} === 'locked') {
                     $mform->hardFreeze($field);
                     $mform->setConstant($field, $user->{$field});
                 } else {
                     if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $user->{$field} != '') {
                         $mform->hardFreeze($field);
                         $mform->setConstant($field, $user->{$field});
                     }
                 }
             }
         }
         /// Next the customisable profile fields
         profile_definition_after_data($mform, $user->id);
     } else {
         profile_definition_after_data($mform, 0);
     }
 }
コード例 #2
0
ファイル: edit_form.php プロジェクト: EmmanuelYupit/educursos
 function definition_after_data()
 {
     global $CFG, $DB, $OUTPUT;
     $mform =& $this->_form;
     $userid = $mform->getElementValue('id');
     // if language does not exist, use site default lang
     if ($langsel = $mform->getElementValue('lang')) {
         $lang = reset($langsel);
         // check lang exists
         if (!get_string_manager()->translation_exists($lang, false)) {
             $lang_el =& $mform->getElement('lang');
             $lang_el->setValue($CFG->lang);
         }
     }
     if ($user = $DB->get_record('user', array('id' => $userid))) {
         // remove description
         if (empty($user->description) && !empty($CFG->profilesforenrolledusersonly) && !$DB->record_exists('role_assignments', array('userid' => $userid))) {
             $mform->removeElement('description_editor');
         }
         // print picture
         $context = context_user::instance($user->id, MUST_EXIST);
         $fs = get_file_storage();
         $hasuploadedpicture = $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.png') || $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.jpg');
         if (!empty($user->picture) && $hasuploadedpicture) {
             $imagevalue = $OUTPUT->user_picture($user, array('courseid' => SITEID, 'size' => 64));
         } else {
             $imagevalue = get_string('none');
         }
         $imageelement = $mform->getElement('currentpicture');
         $imageelement->setValue($imagevalue);
         if ($mform->elementExists('deletepicture') && !$hasuploadedpicture) {
             $mform->removeElement('deletepicture');
         }
         /// disable fields that are locked by auth plugins
         $fields = get_user_fieldnames();
         $authplugin = get_auth_plugin($user->auth);
         foreach ($fields as $field) {
             if (!$mform->elementExists($field)) {
                 continue;
             }
             $configvariable = 'field_lock_' . $field;
             if (isset($authplugin->config->{$configvariable})) {
                 if ($authplugin->config->{$configvariable} === 'locked') {
                     $mform->hardFreeze($field);
                     $mform->setConstant($field, $user->{$field});
                 } else {
                     if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $user->{$field} != '') {
                         $mform->hardFreeze($field);
                         $mform->setConstant($field, $user->{$field});
                     }
                 }
             }
         }
         /// Next the customisable profile fields
         profile_definition_after_data($mform, $user->id);
     } else {
         profile_definition_after_data($mform, 0);
     }
 }
コード例 #3
0
 function definition_after_data()
 {
     global $CFG;
     $mform =& $this->_form;
     $userid = $mform->getElementValue('id');
     // if language does not exist, use site default lang
     if ($langsel = $mform->getElementValue('lang')) {
         $lang = reset($langsel);
         if (!file_exists($CFG->dataroot . '/lang/' . $lang) and !file_exists($CFG->dirroot . '/lang/' . $lang)) {
             $lang_el =& $mform->getElement('lang');
             $lang_el->setValue($CFG->lang);
         }
     }
     if ($user = get_record('user', 'id', $userid)) {
         // print picture
         if (!empty($CFG->gdversion)) {
             $image_el =& $mform->getElement('currentpicture');
             if ($user and $user->picture) {
                 $image_el->setValue(print_user_picture($user->id, SITEID, $user->picture, 64, true, false, '', true));
             } else {
                 $image_el->setValue(get_string('none'));
             }
         }
         /// disable fields that are locked by auth plugins
         $fields = get_user_fieldnames();
         $freezefields = array();
         $authplugin = get_auth_plugin($user->auth);
         foreach ($fields as $field) {
             if (!$mform->elementExists($field)) {
                 continue;
             }
             $configvariable = 'field_lock_' . $field;
             if (isset($authplugin->config->{$configvariable})) {
                 if ($authplugin->config->{$configvariable} === 'locked') {
                     $freezefields[] = $field;
                 } else {
                     if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $user->{$field} != '') {
                         $freezefields[] = $field;
                     }
                 }
             }
         }
         $mform->hardFreeze($freezefields);
     }
     /// Next the customisable profile fields
     profile_definition_after_data($mform);
 }
コード例 #4
0
ファイル: edit_form.php プロジェクト: educakanchay/campus
 /**
  * Extend the form definition after the data has been parsed.
  */
 public function definition_after_data()
 {
     global $CFG, $DB, $OUTPUT;
     $mform = $this->_form;
     $userid = $mform->getElementValue('id');
     if ($user = $DB->get_record('user', array('id' => $userid))) {
         // Remove description.
         if (empty($user->description) && !empty($CFG->profilesforenrolledusersonly) && !$DB->record_exists('role_assignments', array('userid' => $userid))) {
             $mform->removeElement('description_editor');
         }
         // Print picture.
         $context = context_user::instance($user->id, MUST_EXIST);
         $fs = get_file_storage();
         $hasuploadedpicture = $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.png') || $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.jpg');
         if (!empty($user->picture) && $hasuploadedpicture) {
             $imagevalue = $OUTPUT->user_picture($user, array('courseid' => SITEID, 'size' => 64));
         } else {
             $imagevalue = get_string('none');
         }
         $imageelement = $mform->getElement('currentpicture');
         $imageelement->setValue($imagevalue);
         if ($mform->elementExists('deletepicture') && !$hasuploadedpicture) {
             $mform->removeElement('deletepicture');
         }
         // Disable fields that are locked by auth plugins.
         $fields = get_user_fieldnames();
         $authplugin = get_auth_plugin($user->auth);
         $customfields = $authplugin->get_custom_user_profile_fields();
         $fields = array_merge($fields, $customfields);
         foreach ($fields as $field) {
             if ($field === 'description') {
                 // Hard coded hack for description field. See MDL-37704 for details.
                 $formfield = 'description_editor';
             } else {
                 $formfield = $field;
             }
             if (!$mform->elementExists($formfield)) {
                 continue;
             }
             $value = $mform->getElementValue($formfield);
             $configvariable = 'field_lock_' . $field;
             if (isset($authplugin->config->{$configvariable})) {
                 if ($authplugin->config->{$configvariable} === 'locked') {
                     $mform->hardFreeze($formfield);
                     $mform->setConstant($formfield, $value);
                 } else {
                     if ($authplugin->config->{$configvariable} === 'unlockedifempty' and $value != '') {
                         $mform->hardFreeze($formfield);
                         $mform->setConstant($formfield, $value);
                     }
                 }
             }
         }
         // Next the customisable profile fields.
         profile_definition_after_data($mform, $user->id);
     } else {
         profile_definition_after_data($mform, 0);
     }
 }
コード例 #5
0
ファイル: api.php プロジェクト: gabrielrosset/moodle
 /**
  * List the plans to review.
  *
  * The method returns values in this format:
  *
  * array(
  *     'plans' => array(
  *         (stdClass)(
  *             'plan' => (plan),
  *             'template' => (template),
  *             'owner' => (stdClass)
  *         )
  *     ),
  *     'count' => (int)
  * )
  *
  * @param int $skip The number of records to skip.
  * @param int $limit The number of results to return.
  * @param int $userid The user we're getting the plans to review for.
  * @return array Containing the keys 'count', and 'plans'. The 'plans' key contains an object
  *               which contains 'plan', 'template' and 'owner'.
  */
 public static function list_plans_to_review($skip = 0, $limit = 100, $userid = null)
 {
     global $DB, $USER;
     static::require_enabled();
     if ($userid === null) {
         $userid = $USER->id;
     }
     $planfields = plan::get_sql_fields('p', 'plan_');
     $tplfields = template::get_sql_fields('t', 'tpl_');
     $usercols = array('id') + get_user_fieldnames();
     $userfields = array();
     foreach ($usercols as $field) {
         $userfields[] = "u." . $field . " AS usr_" . $field;
     }
     $userfields = implode(',', $userfields);
     $select = "SELECT {$planfields}, {$tplfields}, {$userfields}";
     $countselect = "SELECT COUNT('x')";
     $sql = "  FROM {" . plan::TABLE . "} p\n                  JOIN {user} u\n                    ON u.id = p.userid\n             LEFT JOIN {" . template::TABLE . "} t\n                    ON t.id = p.templateid\n                 WHERE (p.status = :waitingforreview\n                    OR (p.status = :inreview AND p.reviewerid = :reviewerid))\n                   AND p.userid != :userid";
     $params = array('waitingforreview' => plan::STATUS_WAITING_FOR_REVIEW, 'inreview' => plan::STATUS_IN_REVIEW, 'reviewerid' => $userid, 'userid' => $userid);
     // Primary check to avoid the hard work of getting the users in which the user has permission.
     $count = $DB->count_records_sql($countselect . $sql, $params);
     if ($count < 1) {
         return array('count' => 0, 'plans' => array());
     }
     // TODO MDL-52243 Use core function.
     list($insql, $inparams) = self::filter_users_with_capability_on_user_context_sql('moodle/competency:planreview', $userid, SQL_PARAMS_NAMED);
     $sql .= " AND p.userid {$insql}";
     $params += $inparams;
     // Order by ID just to have some ordering in place.
     $ordersql = " ORDER BY p.id ASC";
     $plans = array();
     $records = $DB->get_recordset_sql($select . $sql . $ordersql, $params, $skip, $limit);
     foreach ($records as $record) {
         $plan = new plan(0, plan::extract_record($record, 'plan_'));
         $template = null;
         if ($plan->is_based_on_template()) {
             $template = new template(0, template::extract_record($record, 'tpl_'));
         }
         $plans[] = (object) array('plan' => $plan, 'template' => $template, 'owner' => persistent::extract_record($record, 'usr_'));
     }
     $records->close();
     return array('count' => $DB->count_records_sql($countselect . $sql, $params), 'plans' => $plans);
 }
コード例 #6
0
ファイル: lib.php プロジェクト: nadavkav/MoodleTAO
function mnet_get_user_fields()
{
    //fields that should be ignored and not able to map
    $ignorefields = array('AUTH', 'USERNAME', 'PASSWORD', 'MNETHOSTID', 'SECRET');
    //get a list of fields in the user table
    $userfields = get_user_fieldnames();
    //remove fields that we don't want.
    foreach ($ignorefields as $field) {
        unset($userfields[$field]);
    }
    //now get custom user profile fields
    $customuserfields = get_records('user_info_field', '', '', 'sortorder', 'shortname');
    if (!empty($customuserfields)) {
        foreach ($customuserfields as $field => $cf) {
            $userfields[strtoupper($field)] = $field;
        }
    }
    return $userfields;
}