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


PHP context_helper::preload_from_record方法代码示例

本文整理汇总了PHP中context_helper::preload_from_record方法的典型用法代码示例。如果您正苦于以下问题:PHP context_helper::preload_from_record方法的具体用法?PHP context_helper::preload_from_record怎么用?PHP context_helper::preload_from_record使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在context_helper的用法示例。


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

示例1: get_courses

    /**
     * Return all courses this rule applies to.
     *
     * @return array A list of courses.
     */
    public function get_courses()
    {
        global $CFG, $DB;
        if (isset($this->courses)) {
            return $this->courses;
        }
        require_once $CFG->libdir . '/coursecatlib.php';
        $coursecat = \coursecat::get($this->id);
        $courselist = $coursecat->get_courses(array('recursive' => true, 'idonly' => true));
        // Generate the SQL.
        list($sql, $params) = $DB->get_in_or_equal($courselist);
        $ctxlevel = \CONTEXT_COURSE;
        $preload = \context_helper::get_preload_record_columns_sql('ctx');
        $sql = <<<SQL
            SELECT c.*, {$preload}
            FROM {course} c
            INNER JOIN {context} ctx
                ON ctx.instanceid = c.id AND ctx.contextlevel = {$ctxlevel}
            WHERE c.id {$sql}
SQL;
        // Get the courses and preload contexts.
        $this->courses = $DB->get_records_sql($sql, $params);
        foreach ($this->courses as $course) {
            \context_helper::preload_from_record($course);
        }
        return $this->courses;
    }
开发者ID:unikent,项目名称:moodle-tool_cat,代码行数:32,代码来源:category.php

示例2: block_course_overview_get_child_shortnames

/**
 * Returns shortname of activities in course
 *
 * @param int $courseid id of course for which activity shortname is needed
 * @return string|bool list of child shortname
 */
function block_course_overview_get_child_shortnames($courseid)
{
    global $DB;
    $ctxselect = context_helper::get_preload_record_columns_sql('ctx');
    $sql = "SELECT c.id, c.shortname, {$ctxselect}\n            FROM {enrol} e\n            JOIN {course} c ON (c.id = e.customint1)\n            JOIN {context} ctx ON (ctx.instanceid = e.customint1)\n            WHERE e.courseid = :courseid AND e.enrol = :method AND ctx.contextlevel = :contextlevel ORDER BY e.sortorder";
    $params = array('method' => 'meta', 'courseid' => $courseid, 'contextlevel' => CONTEXT_COURSE);
    if ($results = $DB->get_records_sql($sql, $params)) {
        $shortnames = array();
        // Preload the context we will need it to format the category name shortly.
        foreach ($results as $res) {
            context_helper::preload_from_record($res);
            $context = context_course::instance($res->id);
            $shortnames[] = format_string($res->shortname, true, $context);
        }
        $total = count($shortnames);
        $suffix = '';
        if ($total > 10) {
            $shortnames = array_slice($shortnames, 0, 10);
            $diff = $total - count($shortnames);
            if ($diff > 1) {
                $suffix = get_string('shortnamesufixprural', 'block_course_overview', $diff);
            } else {
                $suffix = get_string('shortnamesufixsingular', 'block_course_overview', $diff);
            }
        }
        $shortnames = get_string('shortnameprefix', 'block_course_overview', implode('; ', $shortnames));
        $shortnames .= $suffix;
    }
    return isset($shortnames) ? $shortnames : false;
}
开发者ID:JP-Git,项目名称:moodle,代码行数:36,代码来源:locallib.php

示例3: definition

 function definition()
 {
     global $CFG, $DB;
     $mform = $this->_form;
     $course = $this->_customdata;
     $this->course = $course;
     $existing = $DB->get_records('enrol', array('enrol' => 'meta', 'courseid' => $course->id), '', 'customint1, id');
     // TODO: this has to be done via ajax or else it will fail very badly on large sites!
     $courses = array('' => get_string('choosedots'));
     list($select, $join) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
     $sql = "SELECT c.id, c.fullname, c.shortname, c.visible {$select} FROM {course} c {$join} ORDER BY c.sortorder ASC";
     $rs = $DB->get_recordset_sql($sql);
     foreach ($rs as $c) {
         if ($c->id == SITEID or $c->id == $course->id or isset($existing[$c->id])) {
             continue;
         }
         context_helper::preload_from_record($c);
         $coursecontext = context_course::instance($c->id);
         if (!$c->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
             continue;
         }
         if (!has_capability('enrol/meta:selectaslinked', $coursecontext)) {
             continue;
         }
         $courses[$c->id] = $coursecontext->get_context_name(false);
     }
     $rs->close();
     $mform->addElement('header', 'general', get_string('pluginname', 'enrol_meta'));
     $mform->addElement('select', 'link', get_string('linkedcourse', 'enrol_meta'), $courses);
     $mform->addRule('link', get_string('required'), 'required', null, 'client');
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
     $this->add_action_buttons(true, get_string('addinstance', 'enrol'));
     $this->set_data(array('id' => $course->id));
 }
开发者ID:Burick,项目名称:moodle,代码行数:35,代码来源:addinstance_form.php

示例4: definition

    public function definition()
    {
        global $CFG, $DB;
        $mform = $this->_form;
        $course = $this->_customdata['course'];
        $instance = $this->_customdata['instance'];
        $this->course = $course;
        $existing = array();
        if ($instance) {
            $existing = $DB->get_records('enrol_metaplus', array('enrolid' => $instance->id), '', 'courseid, id');
        }
        $courses = array();
        $select = context_helper::get_preload_record_columns_sql('ctx');
        $sql = <<<SQL
            SELECT c.id, c.fullname, c.shortname, c.visible, {$select}
            FROM {course} c
            LEFT JOIN {context} ctx
                ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)
SQL;
        $rs = $DB->get_recordset_sql($sql, array('contextlevel' => CONTEXT_COURSE));
        foreach ($rs as $c) {
            if ($c->id == SITEID || $c->id == $course->id) {
                continue;
            }
            context_helper::preload_from_record($c);
            $coursecontext = context_course::instance($c->id);
            if (!$c->visible && !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
                continue;
            }
            if (!has_capability('enrol/meta:selectaslinked', $coursecontext)) {
                continue;
            }
            $courses[$c->id] = $coursecontext->get_context_name(false);
        }
        $rs->close();
        $mform->addElement('header', 'general', get_string('pluginname', 'enrol_meta'));
        $mform->addElement('select', 'link', get_string('linkedcourse', 'enrol_metaplus'), $courses, array('multiple' => 'multiple', 'class' => 'chosen'));
        $mform->addRule('link', get_string('required'), 'required', null, 'server');
        // Add role sync list.
        $coursecontext = \context_course::instance($course->id);
        $roles = get_assignable_roles($coursecontext);
        $mform->addElement('select', 'roleexclusions', get_string('roleexclusions', 'enrol_metaplus'), $roles, array('multiple' => 'multiple'));
        $mform->addElement('hidden', 'id', null);
        $mform->setType('id', PARAM_INT);
        $mform->addElement('hidden', 'enrolid');
        $mform->setType('enrolid', PARAM_INT);
        $data = array('id' => $course->id);
        if ($instance) {
            $data['link'] = implode(',', array_keys($existing));
            $data['enrolid'] = $instance->id;
            $data['roleexclusions'] = $instance->customtext1;
            $this->add_action_buttons();
        } else {
            $this->add_add_buttons();
        }
        $this->set_data($data);
    }
开发者ID:unikent,项目名称:moodle-enrol_metaplus,代码行数:57,代码来源:addinstance_form.php

示例5: context_instance_preload

/**
 * Preloads context information from db record and strips the cached info.
 * The db request has to contain both the $join and $select from context_instance_preload_sql()
 *
 * @deprecated since 2.2
 * @param stdClass $rec
 * @return void (modifies $rec)
 */
function context_instance_preload(stdClass $rec)
{
    context_helper::preload_from_record($rec);
}
开发者ID:rolandovanegas,项目名称:moodle,代码行数:12,代码来源:accesslib.php

示例6: generate_user_settings

 /**
  * This function gets called by {@link settings_navigation::load_user_settings()} and actually works out
  * what can be shown/done
  *
  * @param int $courseid The current course' id
  * @param int $userid The user id to load for
  * @param string $gstitle The string to pass to get_string for the branch title
  * @return navigation_node|false
  */
 protected function generate_user_settings($courseid, $userid, $gstitle = 'usercurrentsettings')
 {
     global $DB, $CFG, $USER, $SITE;
     if ($courseid != $SITE->id) {
         if (!empty($this->page->course->id) && $this->page->course->id == $courseid) {
             $course = $this->page->course;
         } else {
             $select = context_helper::get_preload_record_columns_sql('ctx');
             $sql = "SELECT c.*, {$select}\n                          FROM {course} c\n                          JOIN {context} ctx ON c.id = ctx.instanceid\n                         WHERE c.id = :courseid AND ctx.contextlevel = :contextlevel";
             $params = array('courseid' => $courseid, 'contextlevel' => CONTEXT_COURSE);
             $course = $DB->get_record_sql($sql, $params, MUST_EXIST);
             context_helper::preload_from_record($course);
         }
     } else {
         $course = $SITE;
     }
     $coursecontext = context_course::instance($course->id);
     // Course context
     $systemcontext = context_system::instance();
     $currentuser = $USER->id == $userid;
     if ($currentuser) {
         $user = $USER;
         $usercontext = context_user::instance($user->id);
         // User context
     } else {
         $select = context_helper::get_preload_record_columns_sql('ctx');
         $sql = "SELECT u.*, {$select}\n                      FROM {user} u\n                      JOIN {context} ctx ON u.id = ctx.instanceid\n                     WHERE u.id = :userid AND ctx.contextlevel = :contextlevel";
         $params = array('userid' => $userid, 'contextlevel' => CONTEXT_USER);
         $user = $DB->get_record_sql($sql, $params, IGNORE_MISSING);
         if (!$user) {
             return false;
         }
         context_helper::preload_from_record($user);
         // Check that the user can view the profile
         $usercontext = context_user::instance($user->id);
         // User context
         $canviewuser = has_capability('moodle/user:viewdetails', $usercontext);
         if ($course->id == $SITE->id) {
             if ($CFG->forceloginforprofiles && !has_coursecontact_role($user->id) && !$canviewuser) {
                 // Reduce possibility of "browsing" userbase at site level
                 // Teachers can browse and be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
                 return false;
             }
         } else {
             $canviewusercourse = has_capability('moodle/user:viewdetails', $coursecontext);
             $userisenrolled = is_enrolled($coursecontext, $user->id, '', true);
             if (!$canviewusercourse && !$canviewuser || !$userisenrolled) {
                 return false;
             }
             $canaccessallgroups = has_capability('moodle/site:accessallgroups', $coursecontext);
             if (!$canaccessallgroups && groups_get_course_groupmode($course) == SEPARATEGROUPS && !$canviewuser) {
                 // If groups are in use, make sure we can see that group (MDL-45874). That does not apply to parents.
                 if ($courseid == $this->page->course->id) {
                     $mygroups = get_fast_modinfo($this->page->course)->groups;
                 } else {
                     $mygroups = groups_get_user_groups($courseid);
                 }
                 $usergroups = groups_get_user_groups($courseid, $userid);
                 if (!array_intersect_key($mygroups[0], $usergroups[0])) {
                     return false;
                 }
             }
         }
     }
     $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $this->page->context));
     $key = $gstitle;
     $prefurl = new moodle_url('/user/preferences.php');
     if ($gstitle != 'usercurrentsettings') {
         $key .= $userid;
         $prefurl->param('userid', $userid);
     }
     // Add a user setting branch.
     if ($gstitle == 'usercurrentsettings') {
         $dashboard = $this->add(get_string('myhome'), new moodle_url('/my/'), self::TYPE_CONTAINER, null, 'dashboard');
         // This should be set to false as we don't want to show this to the user. It's only for generating the correct
         // breadcrumb.
         $dashboard->display = false;
         if (get_home_page() == HOMEPAGE_MY) {
             $dashboard->mainnavonly = true;
         }
         $iscurrentuser = $user->id == $USER->id;
         $baseargs = array('id' => $user->id);
         if ($course->id != $SITE->id && !$iscurrentuser) {
             $baseargs['course'] = $course->id;
             $issitecourse = false;
         } else {
             // Load all categories and get the context for the system.
             $issitecourse = true;
         }
         // Add the user profile to the dashboard.
         $profilenode = $dashboard->add(get_string('profile'), new moodle_url('/user/profile.php', array('id' => $user->id)), self::TYPE_SETTING, null, 'myprofile');
//.........这里部分代码省略.........
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:navigationlib.php

示例7: build_table

 /**
  * Process the data returned by the query.
  *
  * @see self::compute_rank_start()
  * @return void
  */
 function build_table()
 {
     global $USER;
     $this->compute_rank_start();
     $rank = $this->startingrank;
     $lastlvl = $this->startinglevel;
     $lastxp = $this->startingxp;
     $offset = $this->startingoffset;
     $xptodiff = $this->startingxpdiff;
     if ($this->rawdata) {
         foreach ($this->rawdata as $row) {
             // Preload the context.
             context_helper::preload_from_record($row);
             // Show the real rank.
             if ($this->rankmode == block_xp_manager::RANK_ON) {
                 // If this row is different than the previous one.
                 if ($row->lvl != $lastlvl || $row->xp != $lastxp) {
                     $rank += $offset;
                     $offset = 1;
                     $lastlvl = $row->lvl;
                     $lastxp = $row->xp;
                 } else {
                     $offset++;
                 }
                 $row->rank = $rank;
                 // Show a "relative" rank, the difference between a student and another.
             } else {
                 if ($this->rankmode == block_xp_manager::RANK_REL) {
                     // There was no indication of what XP to diff with, let's take the first entry.
                     if ($xptodiff == -1 && $lastxp == -1) {
                         $xptodiff = $row->xp;
                     }
                     // The last row does not this one.
                     if ($row->xp != $lastxp) {
                         $rank = $row->xp - $xptodiff;
                         $lastxp = $row->xp;
                     }
                     $row->rank = $rank;
                 }
             }
             $classes = $this->userid == $row->userid ? 'highlight' : '';
             $formattedrow = $this->format_row($row);
             $this->add_data_keyed($formattedrow, $classes);
         }
     }
 }
开发者ID:antoniorodrigues,项目名称:redes-digitais,代码行数:52,代码来源:ladder_table.php

示例8: print_row

}
if ($user->aim && !isset($hiddenfields['aimid'])) {
    print_row(get_string('aimid') . ':', '<a href="aim:goim?screenname=' . urlencode($user->aim) . '">' . s($user->aim) . '</a>');
}
if ($user->msn && !isset($hiddenfields['msnid'])) {
    print_row(get_string('msnid') . ':', s($user->msn));
}
/// Print the Custom User Fields
profile_display_fields($user->id);
if (!isset($hiddenfields['mycourses'])) {
    if ($mycourses = enrol_get_all_users_courses($user->id, true, NULL, 'visible DESC,sortorder ASC')) {
        $shown = 0;
        $courselisting = '';
        foreach ($mycourses as $mycourse) {
            if ($mycourse->category) {
                context_helper::preload_from_record($mycourse);
                $ccontext = context_course::instance($mycourse->id);
                $class = '';
                if ($mycourse->visible == 0) {
                    if (!has_capability('moodle/course:viewhiddencourses', $ccontext)) {
                        continue;
                    }
                    $class = 'class="dimmed"';
                }
                $courselisting .= "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&amp;course={$mycourse->id}\" {$class} >" . $ccontext->get_context_name(false) . "</a>, ";
            }
            $shown++;
            if ($shown == 20) {
                $courselisting .= "...";
                break;
            }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:31,代码来源:profile.php

示例9: __construct

 /**
  * Creates an instance of the class from record
  *
  * @param stdClass $record except fields from course table it may contain
  *     field hassummary indicating that summary field is not empty.
  *     Also it is recommended to have context fields here ready for
  *     context preloading
  */
 public function __construct(stdClass $record)
 {
     context_helper::preload_from_record($record);
     $this->record = new stdClass();
     foreach ($record as $key => $value) {
         $this->record->{$key} = $value;
     }
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:16,代码来源:coursecatlib.php

示例10: coursetag_get_tagged_courses

/**
 * Get courses tagged with a tag
 *
 * @deprecated since 3.0
 * @package  core_tag
 * @category tag
 * @param int $tagid
 * @return array of course objects
 */
function coursetag_get_tagged_courses($tagid)
{
    debugging('Function coursetag_get_tagged_courses() is deprecated. Userid is no longer used for tagging courses.', DEBUG_DEVELOPER);
    global $DB;
    $courses = array();
    $ctxselect = context_helper::get_preload_record_columns_sql('ctx');
    $sql = "SELECT c.*, {$ctxselect}\n            FROM {course} c\n            JOIN {tag_instance} t ON t.itemid = c.id\n            JOIN {context} ctx ON ctx.instanceid = c.id\n            WHERE t.tagid = :tagid AND\n            t.itemtype = 'course' AND\n            ctx.contextlevel = :contextlevel\n            ORDER BY c.sortorder ASC";
    $params = array('tagid' => $tagid, 'contextlevel' => CONTEXT_COURSE);
    $rs = $DB->get_recordset_sql($sql, $params);
    foreach ($rs as $course) {
        context_helper::preload_from_record($course);
        if ($course->visible == 1 || has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
            $courses[$course->id] = $course;
        }
    }
    return $courses;
}
开发者ID:evltuma,项目名称:moodle,代码行数:26,代码来源:deprecatedlib.php

示例11: calendar_get_default_courses

/**
 * Returns the default courses to display on the calendar when there isn't a specific
 * course to display.
 *
 * @return array $courses Array of courses to display
 */
function calendar_get_default_courses()
{
    global $CFG, $DB;
    if (!isloggedin()) {
        return array();
    }
    $courses = array();
    if (!empty($CFG->calendar_adminseesall) && has_capability('moodle/calendar:manageentries', context_system::instance())) {
        list($select, $join) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
        $sql = "SELECT c.* {$select}\n                  FROM {course} c\n                  {$join}\n                  WHERE EXISTS (SELECT 1 FROM {event} e WHERE e.courseid = c.id)\n                  ";
        $courses = $DB->get_records_sql($sql, null, 0, 20);
        foreach ($courses as $course) {
            context_helper::preload_from_record($course);
        }
        return $courses;
    }
    $courses = enrol_get_my_courses();
    return $courses;
}
开发者ID:JP-Git,项目名称:moodle,代码行数:25,代码来源:lib.php

示例12: setValue

 /**
  * Set the value of this element. If values can be added or are unknown, we will
  * make sure they exist in the options array.
  * @param string|array $value The value to set.
  * @return boolean
  */
 public function setValue($value)
 {
     global $DB;
     $values = (array) $value;
     $coursestofetch = array();
     foreach ($values as $onevalue) {
         if (!$this->optionExists($onevalue) && $onevalue !== '_qf__force_multiselect_submission') {
             array_push($coursestofetch, $onevalue);
         }
     }
     if (empty($coursestofetch)) {
         return $this->setSelected(array());
     }
     // There is no API function to load a list of course from a list of ids.
     $ctxselect = context_helper::get_preload_record_columns_sql('ctx');
     $fields = array('c.id', 'c.category', 'c.sortorder', 'c.shortname', 'c.fullname', 'c.idnumber', 'c.startdate', 'c.visible', 'c.cacherev');
     list($whereclause, $params) = $DB->get_in_or_equal($coursestofetch, SQL_PARAMS_NAMED, 'id');
     $sql = "SELECT " . join(',', $fields) . ", {$ctxselect}\n                FROM {course} c\n                JOIN {context} ctx ON c.id = ctx.instanceid AND ctx.contextlevel = :contextcourse\n                WHERE c.id " . $whereclause . " ORDER BY c.sortorder";
     $list = $DB->get_records_sql($sql, array('contextcourse' => CONTEXT_COURSE) + $params);
     $coursestoselect = array();
     foreach ($list as $course) {
         context_helper::preload_from_record($course);
         // Make sure we can see the course.
         if (!$course->visible && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
             continue;
         }
         $label = get_course_display_name_for_list($course);
         $this->addOption($label, $course->id);
         array_push($coursestoselect, $course->id);
     }
     return $this->setSelected($coursestoselect);
 }
开发者ID:rushi963,项目名称:moodle,代码行数:38,代码来源:course.php

示例13: core_myprofile_navigation


//.........这里部分代码省略.........
        $tree->add_node($node);
    }
    if (isset($identityfields['department']) && $user->department) {
        $node = new core_user\output\myprofile\node('contact', 'department', get_string('department'), null, null, $user->institution);
        $tree->add_node($node);
    }
    if (isset($identityfields['idnumber']) && $user->idnumber) {
        $node = new core_user\output\myprofile\node('contact', 'idnumber', get_string('idnumber'), null, null, $user->institution);
        $tree->add_node($node);
    }
    if ($user->url && !isset($hiddenfields['webpage'])) {
        $url = $user->url;
        if (strpos($user->url, '://') === false) {
            $url = 'http://' . $url;
        }
        $webpageurl = new moodle_url($url);
        $node = new core_user\output\myprofile\node('contact', 'webpage', get_string('webpage'), null, null, html_writer::link($url, $webpageurl));
        $tree->add_node($node);
    }
    // Printing tagged interests. We want this only for full profile.
    if (!empty($CFG->usetags) && empty($course)) {
        if ($interests = tag_get_tags_csv('user', $user->id)) {
            $node = new core_user\output\myprofile\node('contact', 'interests', get_string('interests'), null, null, $interests);
            $tree->add_node($node);
        }
    }
    if (!isset($hiddenfields['mycourses'])) {
        $showallcourses = optional_param('showallcourses', 0, PARAM_INT);
        if ($mycourses = enrol_get_all_users_courses($user->id, true, null, 'visible DESC, sortorder ASC')) {
            $shown = 0;
            $courselisting = html_writer::start_tag('ul');
            foreach ($mycourses as $mycourse) {
                if ($mycourse->category) {
                    context_helper::preload_from_record($mycourse);
                    $ccontext = context_course::instance($mycourse->id);
                    if (!isset($course) || $mycourse->id != $course->id) {
                        $linkattributes = null;
                        if ($mycourse->visible == 0) {
                            if (!has_capability('moodle/course:viewhiddencourses', $ccontext)) {
                                continue;
                            }
                            $linkattributes['class'] = 'dimmed';
                        }
                        $params = array('id' => $user->id, 'course' => $mycourse->id);
                        if ($showallcourses) {
                            $params['showallcourses'] = 1;
                        }
                        $url = new moodle_url('/user/view.php', $params);
                        $courselisting .= html_writer::tag('li', html_writer::link($url, $ccontext->get_context_name(false), $linkattributes));
                    } else {
                        $courselisting .= html_writer::tag('li', $course->fullname);
                    }
                }
                $shown++;
                if (!$showallcourses && $shown == $CFG->navcourselimit) {
                    $url = null;
                    if (isset($course)) {
                        $url = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id, 'showallcourses' => 1));
                    } else {
                        $url = new moodle_url('/user/profile.php', array('id' => $user->id, 'showallcourses' => 1));
                    }
                    $courselisting .= html_writer::tag('li', html_writer::link($url, get_string('viewmore'), array('title' => get_string('viewmore'))));
                    break;
                }
            }
            $courselisting .= html_writer::end_tag('ul');
开发者ID:mike-grant,项目名称:moodle,代码行数:67,代码来源:myprofilelib.php

示例14: definition

 function definition()
 {
     global $CFG, $DB;
     $mform = $this->_form;
     $course = $this->_customdata['course'];
     $instance = $this->_customdata['instance'];
     $this->course = $course;
     if ($instance) {
         $where = 'WHERE c.id = :courseid';
         $params = array('courseid' => $instance->customint1);
         $existing = array();
     } else {
         $where = '';
         $params = array();
         $existing = $DB->get_records('enrol', array('enrol' => 'meta', 'courseid' => $course->id), '', 'customint1, id');
     }
     // TODO: this has to be done via ajax or else it will fail very badly on large sites!
     $courses = array('' => get_string('choosedots'));
     $select = ', ' . context_helper::get_preload_record_columns_sql('ctx');
     $join = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
     $plugin = enrol_get_plugin('meta');
     $sortorder = 'c.' . $plugin->get_config('coursesort', 'sortorder') . ' ASC';
     $sql = "SELECT c.id, c.fullname, c.shortname, c.visible {$select} FROM {course} c {$join} {$where} ORDER BY {$sortorder}";
     $rs = $DB->get_recordset_sql($sql, array('contextlevel' => CONTEXT_COURSE) + $params);
     foreach ($rs as $c) {
         if ($c->id == SITEID or $c->id == $course->id or isset($existing[$c->id])) {
             continue;
         }
         context_helper::preload_from_record($c);
         $coursecontext = context_course::instance($c->id);
         if (!$c->visible and !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
             continue;
         }
         if (!has_capability('enrol/meta:selectaslinked', $coursecontext)) {
             continue;
         }
         $courses[$c->id] = $coursecontext->get_context_name(false);
     }
     $rs->close();
     $groups = array(0 => get_string('none'));
     if (has_capability('moodle/course:managegroups', context_course::instance($course->id))) {
         $groups[ENROL_META_CREATE_GROUP] = get_string('creategroup', 'enrol_meta');
     }
     foreach (groups_get_all_groups($course->id) as $group) {
         $groups[$group->id] = format_string($group->name, true, array('context' => context_course::instance($course->id)));
     }
     $mform->addElement('header', 'general', get_string('pluginname', 'enrol_meta'));
     $mform->addElement('select', 'link', get_string('linkedcourse', 'enrol_meta'), $courses);
     $mform->addRule('link', get_string('required'), 'required', null, 'client');
     $mform->addElement('select', 'customint2', get_string('addgroup', 'enrol_meta'), $groups);
     $mform->addElement('hidden', 'id', null);
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'enrolid');
     $mform->setType('enrolid', PARAM_INT);
     $data = array('id' => $course->id);
     if ($instance) {
         $data['link'] = $instance->customint1;
         $data['enrolid'] = $instance->id;
         $data['customint2'] = $instance->customint2;
         $mform->freeze('link');
         $this->add_action_buttons();
     } else {
         $this->add_add_buttons();
     }
     $this->set_data($data);
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:66,代码来源:addinstance_form.php

示例15: update_users_used

 /**
      * Helper function to create list of user fullnames shown in log report.
      *
      * This will update $this->userfullnames array with userfullname,
      * which will be used to render logs in table.
      *
      * @since   Moodle 2.9
      * @return  void
 
     protected function update_users_used() {
         global $DB;
    $this->userfullnames = array();
         $userids = array();
    // For each event cache full username.
         // Get list of userids which will be shown in log report.
         foreach ($this->rawdata as $event) {
             $logextra = $event->get_logextra();
             if (!empty($event->userid) && empty($userids[$event->userid])) {
                 $userids[$event->userid] = $event->userid;
             }
             if (!empty($logextra['realuserid']) && empty($userids[$logextra['realuserid']])) {
                 $userids[$logextra['realuserid']] = $logextra['realuserid'];
             }
             if (!empty($event->relateduserid) && empty($userids[$event->relateduserid])) {
                 $userids[$event->relateduserid] = $event->relateduserid;
             }
         }
         // Get user fullname and put that in return list.
         if (!empty($userids)) {
             list($usql, $uparams) = $DB->get_in_or_equal($userids);
             $users = $DB->get_records_sql("SELECT id," . get_all_user_name_fields(true) . " FROM {user} WHERE id " . $usql,
                     $uparams);
             foreach ($users as $userid => $user) {
                 $this->userfullnames[$userid] = fullname($user);
                 unset($userids[$userid]);
             }
        // We fill the array with false values for the users that don't exist anymore
             // in the database so we don't need to query the db again later.
             foreach ($userids as $userid) {
                 $this->userfullnames[$userid] = false;
             }
         }
     }
 */
 protected function update_users_used()
 {
     global $SITE, $DB;
     $this->userfullnames = array();
     $this->courseshortnames = array($SITE->id => $SITE->shortname);
     $userids = array();
     $courseids = array();
     // For each event cache full username and course.
     // Get list of userids and courseids which will be shown in log report.
     foreach ($this->rawdata as $event) {
         $logextra = $event->get_logextra();
         if (!empty($event->userid) && empty($userids[$event->userid])) {
             $userids[$event->userid] = $event->userid;
         }
         if (!empty($logextra['realuserid']) && empty($userids[$logextra['realuserid']])) {
             $userids[$logextra['realuserid']] = $logextra['realuserid'];
         }
         if (!empty($event->relateduserid) && empty($userids[$event->relateduserid])) {
             $userids[$event->relateduserid] = $event->relateduserid;
         }
         if (!empty($event->courseid) && $event->courseid != $SITE->id && !in_array($event->courseid, $courseids)) {
             $courseids[] = $event->courseid;
         }
     }
     // Closing it just in case, we can not rewind moodle recordsets anyway.
     if ($this->rawdata instanceof \core\dml\recordset_walk || $this->rawdata instanceof moodle_recordset) {
         $this->rawdata->close();
     }
     // Get user fullname and put that in return list.
     if (!empty($userids)) {
         list($usql, $uparams) = $DB->get_in_or_equal($userids);
         $users = $DB->get_records_sql("SELECT id," . get_all_user_name_fields(true) . " FROM {user} WHERE id " . $usql, $uparams);
         foreach ($users as $userid => $user) {
             $this->userfullnames[$userid] = fullname($user);
             unset($userids[$userid]);
         }
         // We fill the array with false values for the users that don't exist anymore
         // in the database so we don't need to query the db again later.
         foreach ($userids as $userid) {
             $this->userfullnames[$userid] = false;
         }
     }
     // Get course shortname and put that in return list.
     if (!empty($courseids)) {
         // If all logs don't belong to site level then get course info.
         list($coursesql, $courseparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
         $ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
         $courseparams['contextlevel'] = CONTEXT_COURSE;
         $sql = "\n                SELECT\n                    c.id, c.shortname {$ccselect}\n                FROM\n                    {course} c\n                LEFT JOIN\n                    {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)\n                WHERE\n                    c.id " . $coursesql;
         // A response code other than 0 is a failure
         $courses = $DB->get_records_sql($sql, $courseparams);
         foreach ($courses as $courseid => $course) {
             $url = new moodle_url("/course/view.php", array('id' => $courseid));
             context_helper::preload_from_record($course);
             $context = context_course::instance($courseid, IGNORE_MISSING);
             // Method format_string() takes care of missing contexts.
//.........这里部分代码省略.........
开发者ID:posttechguy,项目名称:moodle-tbst2-report_log,代码行数:101,代码来源:table_log.php


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