本文整理汇总了PHP中context_helper::get_preload_record_columns_sql方法的典型用法代码示例。如果您正苦于以下问题:PHP context_helper::get_preload_record_columns_sql方法的具体用法?PHP context_helper::get_preload_record_columns_sql怎么用?PHP context_helper::get_preload_record_columns_sql使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类context_helper
的用法示例。
在下文中一共展示了context_helper::get_preload_record_columns_sql方法的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;
}
示例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;
}
示例3: 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);
}
示例4: get_courses_with_competency_and_user
/**
* Return the courses where both competency and user are.
*
* A user is considered being in a course when they are enrolled, the enrolment is valid,
* the enrolment instance is enabled, and the enrolment plugin is enabled..
*
* @param int $competencyid The competency ID.
* @param int $userid The user ID.
* @return array Indexed by course ID.
*/
public static function get_courses_with_competency_and_user($competencyid, $userid)
{
global $CFG, $DB;
if (!($plugins = explode(',', $CFG->enrol_plugins_enabled))) {
return array();
}
$ctxfields = \context_helper::get_preload_record_columns_sql('ctx');
list($plugins, $params) = $DB->get_in_or_equal($plugins, SQL_PARAMS_NAMED, 'ee');
$params['competencyid'] = $competencyid;
$params['userid'] = $userid;
$params['enabled'] = ENROL_INSTANCE_ENABLED;
$params['active'] = ENROL_USER_ACTIVE;
$params['contextlevel'] = CONTEXT_COURSE;
// Heavily based on enrol_get_shared_courses().
$sql = "SELECT c.*, {$ctxfields}\n FROM {course} c\n JOIN {" . static::TABLE . "} cc\n ON cc.courseid = c.id\n AND cc.competencyid = :competencyid\n JOIN (\n SELECT DISTINCT c.id\n FROM {enrol} e\n JOIN {user_enrolments} ue\n ON ue.enrolid = e.id\n AND ue.status = :active\n AND ue.userid = :userid\n JOIN {course} c\n ON c.id = e.courseid\n WHERE e.status = :enabled\n AND e.enrol {$plugins}\n ) ec ON ec.id = c.id\n LEFT JOIN {context} ctx\n ON ctx.instanceid = c.id\n AND ctx.contextlevel = :contextlevel\n ORDER BY c.id";
$courses = $DB->get_records_sql($sql, $params);
array_map('context_helper::preload_from_record', $courses);
return $courses;
}
示例5: 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'));
$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} ORDER BY " . $sortorder;
$rs = $DB->get_recordset_sql($sql, array('contextlevel' => CONTEXT_COURSE));
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));
}
示例6: 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;
}
示例7: 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())) {
$select = ', ' . context_helper::get_preload_record_columns_sql('ctx');
$join = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
$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, array('contextlevel' => CONTEXT_COURSE), 0, 20);
foreach ($courses as $course) {
context_helper::preload_from_record($course);
}
return $courses;
}
$courses = enrol_get_my_courses();
return $courses;
}
示例8: context_instance_preload_sql
/**
* Preloads context information together with instances.
* Use context_instance_preload() to strip the context info from the record and cache the context instance.
*
* @deprecated
* @param string $joinon for example 'u.id'
* @param string $contextlevel context level of instance in $joinon
* @param string $tablealias context table alias
* @return array with two values - select and join part
*/
function context_instance_preload_sql($joinon, $contextlevel, $tablealias)
{
$select = ", " . context_helper::get_preload_record_columns_sql($tablealias);
$join = "LEFT JOIN {context} {$tablealias} ON ({$tablealias}.instanceid = {$joinon} AND {$tablealias}.contextlevel = {$contextlevel})";
return array($select, $join);
}
示例9: 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);
}
示例10: __construct
/**
* Constructor.
*
* @param string $uniqueid Unique ID.
* @param int $courseid Course ID.
* @param int $groupid Group ID.
*/
public function __construct($uniqueid, $courseid, $groupid, array $options = array(), $userid = null)
{
global $PAGE, $USER;
parent::__construct($uniqueid);
if (isset($options['rankmode'])) {
$this->rankmode = $options['rankmode'];
}
if (isset($options['neighboursonly'])) {
$this->neighboursonly = $options['neighboursonly'];
}
if (isset($options['neighboursabove'])) {
$this->neighboursabove = $options['neighboursabove'];
}
if (isset($options['neighboursbelow'])) {
$this->neighboursbelow = $options['neighboursbelow'];
}
if (isset($options['identitymode'])) {
$this->identitymode = $options['identitymode'];
}
// The user ID we're viewing the ladder for.
if ($userid === null) {
$userid = $USER->id;
}
$this->userid = $userid;
// Block XP stuff.
$this->xpmanager = block_xp_manager::get($courseid);
$this->xpoutput = $PAGE->get_renderer('block_xp');
// Define columns, and headers.
$columns = array();
$headers = array();
if ($this->rankmode != block_xp_manager::RANK_OFF) {
$columns += array('rank');
if ($this->rankmode == block_xp_manager::RANK_REL) {
$headers += array(get_string('difference', 'block_xp'));
} else {
$headers += array(get_string('rank', 'block_xp'));
}
}
$columns = array_merge($columns, array('userpic', 'fullname', 'lvl', 'xp', 'progress'));
$headers = array_merge($headers, array('', get_string('fullname'), get_string('level', 'block_xp'), get_string('xp', 'block_xp'), get_string('progress', 'block_xp')));
$this->define_columns($columns);
$this->define_headers($headers);
// Define SQL.
$sqlfrom = '';
$sqlparams = array();
if ($groupid) {
$sqlfrom = '{block_xp} x
JOIN {groups_members} gm
ON gm.groupid = :groupid
AND gm.userid = x.userid
JOIN {user} u
ON x.userid = u.id';
$sqlparams = array('groupid' => $groupid);
} else {
$sqlfrom = '{block_xp} x JOIN {user} u ON x.userid = u.id';
}
$sqlfrom .= " JOIN {context} ctx\n ON ctx.instanceid = u.id\n AND ctx.contextlevel = :contextlevel";
$sqlparams += array('contextlevel' => CONTEXT_USER);
$this->sql = new stdClass();
$this->sql->fields = 'x.*, ' . user_picture::fields('u', null, 'userid') . ', ' . context_helper::get_preload_record_columns_sql('ctx');
$this->sql->from = $sqlfrom;
$this->sql->where = 'courseid = :courseid';
$this->sql->params = array_merge(array('courseid' => $courseid), $sqlparams);
// Define various table settings.
$this->sortable(false);
$this->no_sorting('userpic');
$this->no_sorting('progress');
$this->collapsible(false);
}
示例11: 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');
//.........这里部分代码省略.........
示例12: load_blocks
/**
* This method actually loads the blocks for our page from the database.
*
* @param boolean|null $includeinvisible
* null (default) - load hidden blocks if $this->page->user_is_editing();
* true - load hidden blocks.
* false - don't load hidden blocks.
*/
public function load_blocks($includeinvisible = null)
{
global $DB, $CFG;
if (!is_null($this->birecordsbyregion)) {
// Already done.
return;
}
if ($CFG->version < 2009050619) {
// Upgrade/install not complete. Don't try too show any blocks.
$this->birecordsbyregion = array();
return;
}
// Ensure we have been initialised.
if (is_null($this->defaultregion)) {
$this->page->initialise_theme_and_output();
// If there are still no block regions, then there are no blocks on this page.
if (empty($this->regions)) {
$this->birecordsbyregion = array();
return;
}
}
// Check if we need to load normal blocks
if ($this->fakeblocksonly) {
$this->birecordsbyregion = $this->prepare_per_region_arrays();
return;
}
if (is_null($includeinvisible)) {
$includeinvisible = $this->page->user_is_editing();
}
if ($includeinvisible) {
$visiblecheck = '';
} else {
$visiblecheck = 'AND (bp.visible = 1 OR bp.visible IS NULL)';
}
$context = $this->page->context;
$contexttest = 'bi.parentcontextid IN (:contextid2, :contextid3)';
$parentcontextparams = array();
$parentcontextids = $context->get_parent_context_ids();
if ($parentcontextids) {
list($parentcontexttest, $parentcontextparams) = $DB->get_in_or_equal($parentcontextids, SQL_PARAMS_NAMED, 'parentcontext');
$contexttest = "({$contexttest} OR (bi.showinsubcontexts = 1 AND bi.parentcontextid {$parentcontexttest}))";
}
$pagetypepatterns = matching_page_type_patterns($this->page->pagetype);
list($pagetypepatterntest, $pagetypepatternparams) = $DB->get_in_or_equal($pagetypepatterns, SQL_PARAMS_NAMED, 'pagetypepatterntest');
$ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
$ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = bi.id AND ctx.contextlevel = :contextlevel)";
$systemcontext = context_system::instance();
$params = array('contextlevel' => CONTEXT_BLOCK, 'subpage1' => $this->page->subpage, 'subpage2' => $this->page->subpage, 'contextid1' => $context->id, 'contextid2' => $context->id, 'contextid3' => $systemcontext->id, 'pagetype' => $this->page->pagetype);
if ($this->page->subpage === '') {
$params['subpage1'] = '';
$params['subpage2'] = '';
}
$sql = "SELECT\n bi.id,\n bp.id AS blockpositionid,\n bi.blockname,\n bi.parentcontextid,\n bi.showinsubcontexts,\n bi.pagetypepattern,\n bi.subpagepattern,\n bi.defaultregion,\n bi.defaultweight,\n COALESCE(bp.visible, 1) AS visible,\n COALESCE(bp.region, bi.defaultregion) AS region,\n COALESCE(bp.weight, bi.defaultweight) AS weight,\n bi.configdata\n {$ccselect}\n\n FROM {block_instances} bi\n JOIN {block} b ON bi.blockname = b.name\n LEFT JOIN {block_positions} bp ON bp.blockinstanceid = bi.id\n AND bp.contextid = :contextid1\n AND bp.pagetype = :pagetype\n AND bp.subpage = :subpage1\n {$ccjoin}\n\n WHERE\n {$contexttest}\n AND bi.pagetypepattern {$pagetypepatterntest}\n AND (bi.subpagepattern IS NULL OR bi.subpagepattern = :subpage2)\n {$visiblecheck}\n AND b.visible = 1\n\n ORDER BY\n COALESCE(bp.region, bi.defaultregion),\n COALESCE(bp.weight, bi.defaultweight),\n bi.id";
$blockinstances = $DB->get_recordset_sql($sql, $params + $parentcontextparams + $pagetypepatternparams);
$this->birecordsbyregion = $this->prepare_per_region_arrays();
$unknown = array();
foreach ($blockinstances as $bi) {
context_helper::preload_from_record($bi);
if ($this->is_known_region($bi->region)) {
$this->birecordsbyregion[$bi->region][] = $bi;
} else {
$unknown[] = $bi;
}
}
// Pages don't necessarily have a defaultregion. The one time this can
// happen is when there are no theme block regions, but the script itself
// has a block region in the main content area.
if (!empty($this->defaultregion)) {
$this->birecordsbyregion[$this->defaultregion] = array_merge($this->birecordsbyregion[$this->defaultregion], $unknown);
}
}
示例13: forum_get_courses_user_posted_in
/**
* Gets all of the courses where the provided user has posted in a forum.
*
* @global moodle_database $DB The database connection
* @param stdClass $user The user who's posts we are looking for
* @param bool $discussionsonly If true only look for discussions started by the user
* @param bool $includecontexts If set to trye contexts for the courses will be preloaded
* @param int $limitfrom The offset of records to return
* @param int $limitnum The number of records to return
* @return array An array of courses
*/
function forum_get_courses_user_posted_in($user, $discussionsonly = false, $includecontexts = true, $limitfrom = null, $limitnum = null)
{
global $DB;
// If we are only after discussions we need only look at the forum_discussions
// table and join to the userid there. If we are looking for posts then we need
// to join to the forum_posts table.
if (!$discussionsonly) {
$subquery = "(SELECT DISTINCT fd.course\n FROM {forum_discussions} fd\n JOIN {forum_posts} fp ON fp.discussion = fd.id\n WHERE fp.userid = :userid )";
} else {
$subquery = "(SELECT DISTINCT fd.course\n FROM {forum_discussions} fd\n WHERE fd.userid = :userid )";
}
$params = array('userid' => $user->id);
// Join to the context table so that we can preload contexts if required.
if ($includecontexts) {
$ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
$ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
$params['contextlevel'] = CONTEXT_COURSE;
} else {
$ctxselect = '';
$ctxjoin = '';
}
// Now we need to get all of the courses to search.
// All courses where the user has posted within a forum will be returned.
$sql = "SELECT c.* {$ctxselect}\n FROM {course} c\n {$ctxjoin}\n WHERE c.id IN ({$subquery})";
$courses = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum);
if ($includecontexts) {
array_map('context_helper::preload_from_record', $courses);
}
return $courses;
}
示例14: 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.
//.........这里部分代码省略.........
示例15: get_courses_search
/**
* A list of courses that match a search
*
* @global object
* @global object
* @param array $searchterms An array of search criteria
* @param string $sort A field and direction to sort by
* @param int $page The page number to get
* @param int $recordsperpage The number of records per page
* @param int $totalcount Passed in by reference.
* @param array $requiredcapabilities Extra list of capabilities used to filter courses
* @return object {@link $COURSE} records
*/
function get_courses_search($searchterms, $sort, $page, $recordsperpage, &$totalcount, $requiredcapabilities = array())
{
global $CFG, $DB;
if ($DB->sql_regex_supported()) {
$REGEXP = $DB->sql_regex(true);
$NOTREGEXP = $DB->sql_regex(false);
}
$searchcond = array();
$params = array();
$i = 0;
// Thanks Oracle for your non-ansi concat and type limits in coalesce. MDL-29912
if ($DB->get_dbfamily() == 'oracle') {
$concat = "(c.summary|| ' ' || c.fullname || ' ' || c.idnumber || ' ' || c.shortname)";
} else {
$concat = $DB->sql_concat("COALESCE(c.summary, '')", "' '", 'c.fullname', "' '", 'c.idnumber', "' '", 'c.shortname');
}
foreach ($searchterms as $searchterm) {
$i++;
$NOT = false;
/// Initially we aren't going to perform NOT LIKE searches, only MSSQL and Oracle
/// will use it to simulate the "-" operator with LIKE clause
/// Under Oracle and MSSQL, trim the + and - operators and perform
/// simpler LIKE (or NOT LIKE) queries
if (!$DB->sql_regex_supported()) {
if (substr($searchterm, 0, 1) == '-') {
$NOT = true;
}
$searchterm = trim($searchterm, '+-');
}
// TODO: +- may not work for non latin languages
if (substr($searchterm, 0, 1) == '+') {
$searchterm = trim($searchterm, '+-');
$searchterm = preg_quote($searchterm, '|');
$searchcond[] = "{$concat} {$REGEXP} :ss{$i}";
$params['ss' . $i] = "(^|[^a-zA-Z0-9]){$searchterm}([^a-zA-Z0-9]|\$)";
} else {
if (substr($searchterm, 0, 1) == "-") {
$searchterm = trim($searchterm, '+-');
$searchterm = preg_quote($searchterm, '|');
$searchcond[] = "{$concat} {$NOTREGEXP} :ss{$i}";
$params['ss' . $i] = "(^|[^a-zA-Z0-9]){$searchterm}([^a-zA-Z0-9]|\$)";
} else {
$searchcond[] = $DB->sql_like($concat, ":ss{$i}", false, true, $NOT);
$params['ss' . $i] = "%{$searchterm}%";
}
}
}
if (empty($searchcond)) {
$searchcond = array('1 = 1');
}
$searchcond = implode(" AND ", $searchcond);
$courses = array();
$c = 0;
// counts how many visible courses we've seen
// Tiki pagination
$limitfrom = $page * $recordsperpage;
$limitto = $limitfrom + $recordsperpage;
$ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
$ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
$params['contextlevel'] = CONTEXT_COURSE;
$sql = "SELECT c.* {$ccselect}\n FROM {course} c\n {$ccjoin}\n WHERE {$searchcond} AND c.id <> " . SITEID . "\n ORDER BY {$sort}";
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $course) {
// Preload contexts only for hidden courses or courses we need to return.
context_helper::preload_from_record($course);
$coursecontext = context_course::instance($course->id);
if (!$course->visible && !has_capability('moodle/course:viewhiddencourses', $coursecontext)) {
continue;
}
if (!empty($requiredcapabilities)) {
if (!has_all_capabilities($requiredcapabilities, $coursecontext)) {
continue;
}
}
// Don't exit this loop till the end
// we need to count all the visible courses
// to update $totalcount
if ($c >= $limitfrom && $c < $limitto) {
$courses[$course->id] = $course;
}
$c++;
}
$rs->close();
// our caller expects 2 bits of data - our return
// array, and an updated $totalcount
$totalcount = $c;
return $courses;
//.........这里部分代码省略.........