id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
212,700 | moodle/moodle | enrol/locallib.php | course_enrolment_manager.remove_user_from_group | public function remove_user_from_group($user, $groupid) {
global $DB;
require_capability('moodle/course:managegroups', $this->context);
$group = $this->get_group($groupid);
if (!groups_remove_member_allowed($group, $user)) {
return false;
}
if (!$group) {
return false;
}
return groups_remove_member($group, $user);
} | php | public function remove_user_from_group($user, $groupid) {
global $DB;
require_capability('moodle/course:managegroups', $this->context);
$group = $this->get_group($groupid);
if (!groups_remove_member_allowed($group, $user)) {
return false;
}
if (!$group) {
return false;
}
return groups_remove_member($group, $user);
} | [
"public",
"function",
"remove_user_from_group",
"(",
"$",
"user",
",",
"$",
"groupid",
")",
"{",
"global",
"$",
"DB",
";",
"require_capability",
"(",
"'moodle/course:managegroups'",
",",
"$",
"this",
"->",
"context",
")",
";",
"$",
"group",
"=",
"$",
"this",
"->",
"get_group",
"(",
"$",
"groupid",
")",
";",
"if",
"(",
"!",
"groups_remove_member_allowed",
"(",
"$",
"group",
",",
"$",
"user",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"group",
")",
"{",
"return",
"false",
";",
"}",
"return",
"groups_remove_member",
"(",
"$",
"group",
",",
"$",
"user",
")",
";",
"}"
] | Removes a user from a group
@global moodle_database $DB
@param StdClass $user
@param int $groupid
@return bool | [
"Removes",
"a",
"user",
"from",
"a",
"group"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/locallib.php#L826-L837 |
212,701 | moodle/moodle | enrol/locallib.php | course_enrolment_manager.get_group | public function get_group($groupid) {
$groups = $this->get_all_groups();
if (!array_key_exists($groupid, $groups)) {
return false;
}
return $groups[$groupid];
} | php | public function get_group($groupid) {
$groups = $this->get_all_groups();
if (!array_key_exists($groupid, $groups)) {
return false;
}
return $groups[$groupid];
} | [
"public",
"function",
"get_group",
"(",
"$",
"groupid",
")",
"{",
"$",
"groups",
"=",
"$",
"this",
"->",
"get_all_groups",
"(",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"groupid",
",",
"$",
"groups",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"groups",
"[",
"$",
"groupid",
"]",
";",
"}"
] | Gets the requested group
@param int $groupid
@return stdClass|int | [
"Gets",
"the",
"requested",
"group"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/locallib.php#L845-L851 |
212,702 | moodle/moodle | enrol/locallib.php | course_enrolment_manager.edit_enrolment | public function edit_enrolment($userenrolment, $data) {
//Only allow editing if the user has the appropriate capability
//Already checked in /user/index.php but checking again in case this function is called from elsewhere
list($instance, $plugin) = $this->get_user_enrolment_components($userenrolment);
if ($instance && $plugin && $plugin->allow_manage($instance) && has_capability("enrol/$instance->enrol:manage", $this->context)) {
if (!isset($data->status)) {
$data->status = $userenrolment->status;
}
$plugin->update_user_enrol($instance, $userenrolment->userid, $data->status, $data->timestart, $data->timeend);
return true;
}
return false;
} | php | public function edit_enrolment($userenrolment, $data) {
//Only allow editing if the user has the appropriate capability
//Already checked in /user/index.php but checking again in case this function is called from elsewhere
list($instance, $plugin) = $this->get_user_enrolment_components($userenrolment);
if ($instance && $plugin && $plugin->allow_manage($instance) && has_capability("enrol/$instance->enrol:manage", $this->context)) {
if (!isset($data->status)) {
$data->status = $userenrolment->status;
}
$plugin->update_user_enrol($instance, $userenrolment->userid, $data->status, $data->timestart, $data->timeend);
return true;
}
return false;
} | [
"public",
"function",
"edit_enrolment",
"(",
"$",
"userenrolment",
",",
"$",
"data",
")",
"{",
"//Only allow editing if the user has the appropriate capability",
"//Already checked in /user/index.php but checking again in case this function is called from elsewhere",
"list",
"(",
"$",
"instance",
",",
"$",
"plugin",
")",
"=",
"$",
"this",
"->",
"get_user_enrolment_components",
"(",
"$",
"userenrolment",
")",
";",
"if",
"(",
"$",
"instance",
"&&",
"$",
"plugin",
"&&",
"$",
"plugin",
"->",
"allow_manage",
"(",
"$",
"instance",
")",
"&&",
"has_capability",
"(",
"\"enrol/$instance->enrol:manage\"",
",",
"$",
"this",
"->",
"context",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"->",
"status",
")",
")",
"{",
"$",
"data",
"->",
"status",
"=",
"$",
"userenrolment",
"->",
"status",
";",
"}",
"$",
"plugin",
"->",
"update_user_enrol",
"(",
"$",
"instance",
",",
"$",
"userenrolment",
"->",
"userid",
",",
"$",
"data",
"->",
"status",
",",
"$",
"data",
"->",
"timestart",
",",
"$",
"data",
"->",
"timeend",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Edits an enrolment
@param stdClass $userenrolment
@param stdClass $data
@return bool | [
"Edits",
"an",
"enrolment"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/locallib.php#L860-L872 |
212,703 | moodle/moodle | enrol/locallib.php | course_enrolment_manager.get_user_roles | public function get_user_roles($userid) {
$roles = array();
$ras = get_user_roles($this->context, $userid, true, 'c.contextlevel DESC, r.sortorder ASC');
$plugins = $this->get_enrolment_plugins(false);
foreach ($ras as $ra) {
if ($ra->contextid != $this->context->id) {
if (!array_key_exists($ra->roleid, $roles)) {
$roles[$ra->roleid] = null;
}
// higher ras, course always takes precedence
continue;
}
if (array_key_exists($ra->roleid, $roles) && $roles[$ra->roleid] === false) {
continue;
}
$changeable = true;
if ($ra->component) {
$changeable = false;
if (strpos($ra->component, 'enrol_') === 0) {
$plugin = substr($ra->component, 6);
if (isset($plugins[$plugin])) {
$changeable = !$plugins[$plugin]->roles_protected();
}
}
}
$roles[$ra->roleid] = $changeable;
}
return $roles;
} | php | public function get_user_roles($userid) {
$roles = array();
$ras = get_user_roles($this->context, $userid, true, 'c.contextlevel DESC, r.sortorder ASC');
$plugins = $this->get_enrolment_plugins(false);
foreach ($ras as $ra) {
if ($ra->contextid != $this->context->id) {
if (!array_key_exists($ra->roleid, $roles)) {
$roles[$ra->roleid] = null;
}
// higher ras, course always takes precedence
continue;
}
if (array_key_exists($ra->roleid, $roles) && $roles[$ra->roleid] === false) {
continue;
}
$changeable = true;
if ($ra->component) {
$changeable = false;
if (strpos($ra->component, 'enrol_') === 0) {
$plugin = substr($ra->component, 6);
if (isset($plugins[$plugin])) {
$changeable = !$plugins[$plugin]->roles_protected();
}
}
}
$roles[$ra->roleid] = $changeable;
}
return $roles;
} | [
"public",
"function",
"get_user_roles",
"(",
"$",
"userid",
")",
"{",
"$",
"roles",
"=",
"array",
"(",
")",
";",
"$",
"ras",
"=",
"get_user_roles",
"(",
"$",
"this",
"->",
"context",
",",
"$",
"userid",
",",
"true",
",",
"'c.contextlevel DESC, r.sortorder ASC'",
")",
";",
"$",
"plugins",
"=",
"$",
"this",
"->",
"get_enrolment_plugins",
"(",
"false",
")",
";",
"foreach",
"(",
"$",
"ras",
"as",
"$",
"ra",
")",
"{",
"if",
"(",
"$",
"ra",
"->",
"contextid",
"!=",
"$",
"this",
"->",
"context",
"->",
"id",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"ra",
"->",
"roleid",
",",
"$",
"roles",
")",
")",
"{",
"$",
"roles",
"[",
"$",
"ra",
"->",
"roleid",
"]",
"=",
"null",
";",
"}",
"// higher ras, course always takes precedence",
"continue",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"ra",
"->",
"roleid",
",",
"$",
"roles",
")",
"&&",
"$",
"roles",
"[",
"$",
"ra",
"->",
"roleid",
"]",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"$",
"changeable",
"=",
"true",
";",
"if",
"(",
"$",
"ra",
"->",
"component",
")",
"{",
"$",
"changeable",
"=",
"false",
";",
"if",
"(",
"strpos",
"(",
"$",
"ra",
"->",
"component",
",",
"'enrol_'",
")",
"===",
"0",
")",
"{",
"$",
"plugin",
"=",
"substr",
"(",
"$",
"ra",
"->",
"component",
",",
"6",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"plugins",
"[",
"$",
"plugin",
"]",
")",
")",
"{",
"$",
"changeable",
"=",
"!",
"$",
"plugins",
"[",
"$",
"plugin",
"]",
"->",
"roles_protected",
"(",
")",
";",
"}",
"}",
"}",
"$",
"roles",
"[",
"$",
"ra",
"->",
"roleid",
"]",
"=",
"$",
"changeable",
";",
"}",
"return",
"$",
"roles",
";",
"}"
] | Gets the roles assigned to this user that are applicable for this course.
@param int $userid
@return array | [
"Gets",
"the",
"roles",
"assigned",
"to",
"this",
"user",
"that",
"are",
"applicable",
"for",
"this",
"course",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/locallib.php#L888-L917 |
212,704 | moodle/moodle | enrol/locallib.php | course_enrolment_manager.get_user_enrolments | public function get_user_enrolments($userid) {
global $DB;
list($instancessql, $params, $filter) = $this->get_instance_sql();
$params['userid'] = $userid;
$userenrolments = $DB->get_records_select('user_enrolments', "enrolid $instancessql AND userid = :userid", $params);
$instances = $this->get_enrolment_instances();
$plugins = $this->get_enrolment_plugins(false);
$inames = $this->get_enrolment_instance_names();
foreach ($userenrolments as &$ue) {
$ue->enrolmentinstance = $instances[$ue->enrolid];
$ue->enrolmentplugin = $plugins[$ue->enrolmentinstance->enrol];
$ue->enrolmentinstancename = $inames[$ue->enrolmentinstance->id];
}
return $userenrolments;
} | php | public function get_user_enrolments($userid) {
global $DB;
list($instancessql, $params, $filter) = $this->get_instance_sql();
$params['userid'] = $userid;
$userenrolments = $DB->get_records_select('user_enrolments', "enrolid $instancessql AND userid = :userid", $params);
$instances = $this->get_enrolment_instances();
$plugins = $this->get_enrolment_plugins(false);
$inames = $this->get_enrolment_instance_names();
foreach ($userenrolments as &$ue) {
$ue->enrolmentinstance = $instances[$ue->enrolid];
$ue->enrolmentplugin = $plugins[$ue->enrolmentinstance->enrol];
$ue->enrolmentinstancename = $inames[$ue->enrolmentinstance->id];
}
return $userenrolments;
} | [
"public",
"function",
"get_user_enrolments",
"(",
"$",
"userid",
")",
"{",
"global",
"$",
"DB",
";",
"list",
"(",
"$",
"instancessql",
",",
"$",
"params",
",",
"$",
"filter",
")",
"=",
"$",
"this",
"->",
"get_instance_sql",
"(",
")",
";",
"$",
"params",
"[",
"'userid'",
"]",
"=",
"$",
"userid",
";",
"$",
"userenrolments",
"=",
"$",
"DB",
"->",
"get_records_select",
"(",
"'user_enrolments'",
",",
"\"enrolid $instancessql AND userid = :userid\"",
",",
"$",
"params",
")",
";",
"$",
"instances",
"=",
"$",
"this",
"->",
"get_enrolment_instances",
"(",
")",
";",
"$",
"plugins",
"=",
"$",
"this",
"->",
"get_enrolment_plugins",
"(",
"false",
")",
";",
"$",
"inames",
"=",
"$",
"this",
"->",
"get_enrolment_instance_names",
"(",
")",
";",
"foreach",
"(",
"$",
"userenrolments",
"as",
"&",
"$",
"ue",
")",
"{",
"$",
"ue",
"->",
"enrolmentinstance",
"=",
"$",
"instances",
"[",
"$",
"ue",
"->",
"enrolid",
"]",
";",
"$",
"ue",
"->",
"enrolmentplugin",
"=",
"$",
"plugins",
"[",
"$",
"ue",
"->",
"enrolmentinstance",
"->",
"enrol",
"]",
";",
"$",
"ue",
"->",
"enrolmentinstancename",
"=",
"$",
"inames",
"[",
"$",
"ue",
"->",
"enrolmentinstance",
"->",
"id",
"]",
";",
"}",
"return",
"$",
"userenrolments",
";",
"}"
] | Gets the enrolments this user has in the course - including all suspended plugins and instances.
@global moodle_database $DB
@param int $userid
@return array | [
"Gets",
"the",
"enrolments",
"this",
"user",
"has",
"in",
"the",
"course",
"-",
"including",
"all",
"suspended",
"plugins",
"and",
"instances",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/locallib.php#L926-L940 |
212,705 | moodle/moodle | enrol/locallib.php | course_enrolment_manager.get_url_params | public function get_url_params() {
$args = array(
'id' => $this->course->id
);
if (!empty($this->instancefilter)) {
$args['ifilter'] = $this->instancefilter;
}
if (!empty($this->rolefilter)) {
$args['role'] = $this->rolefilter;
}
if ($this->searchfilter !== '') {
$args['search'] = $this->searchfilter;
}
if (!empty($this->groupfilter)) {
$args['filtergroup'] = $this->groupfilter;
}
if ($this->statusfilter !== -1) {
$args['status'] = $this->statusfilter;
}
return $args;
} | php | public function get_url_params() {
$args = array(
'id' => $this->course->id
);
if (!empty($this->instancefilter)) {
$args['ifilter'] = $this->instancefilter;
}
if (!empty($this->rolefilter)) {
$args['role'] = $this->rolefilter;
}
if ($this->searchfilter !== '') {
$args['search'] = $this->searchfilter;
}
if (!empty($this->groupfilter)) {
$args['filtergroup'] = $this->groupfilter;
}
if ($this->statusfilter !== -1) {
$args['status'] = $this->statusfilter;
}
return $args;
} | [
"public",
"function",
"get_url_params",
"(",
")",
"{",
"$",
"args",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"course",
"->",
"id",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"instancefilter",
")",
")",
"{",
"$",
"args",
"[",
"'ifilter'",
"]",
"=",
"$",
"this",
"->",
"instancefilter",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"rolefilter",
")",
")",
"{",
"$",
"args",
"[",
"'role'",
"]",
"=",
"$",
"this",
"->",
"rolefilter",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"searchfilter",
"!==",
"''",
")",
"{",
"$",
"args",
"[",
"'search'",
"]",
"=",
"$",
"this",
"->",
"searchfilter",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"groupfilter",
")",
")",
"{",
"$",
"args",
"[",
"'filtergroup'",
"]",
"=",
"$",
"this",
"->",
"groupfilter",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"statusfilter",
"!==",
"-",
"1",
")",
"{",
"$",
"args",
"[",
"'status'",
"]",
"=",
"$",
"this",
"->",
"statusfilter",
";",
"}",
"return",
"$",
"args",
";",
"}"
] | Retursn an array of params that would go into the URL to return to this
exact page.
@return array | [
"Retursn",
"an",
"array",
"of",
"params",
"that",
"would",
"go",
"into",
"the",
"URL",
"to",
"return",
"to",
"this",
"exact",
"page",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/locallib.php#L958-L978 |
212,706 | moodle/moodle | enrol/locallib.php | course_enrolment_manager.get_other_users_for_display | public function get_other_users_for_display(core_enrol_renderer $renderer, moodle_url $pageurl, $sort, $direction, $page, $perpage) {
$userroles = $this->get_other_users($sort, $direction, $page, $perpage);
$roles = $this->get_all_roles();
$plugins = $this->get_enrolment_plugins(false);
$context = $this->get_context();
$now = time();
$extrafields = get_extra_user_fields($context);
$users = array();
foreach ($userroles as $userrole) {
$contextid = $userrole->contextid;
unset($userrole->contextid); // This would collide with user avatar.
if (!array_key_exists($userrole->id, $users)) {
$users[$userrole->id] = $this->prepare_user_for_display($userrole, $extrafields, $now);
}
$a = new stdClass;
$a->role = $roles[$userrole->roleid]->localname;
if ($contextid == $this->context->id) {
$changeable = true;
if ($userrole->component) {
$changeable = false;
if (strpos($userrole->component, 'enrol_') === 0) {
$plugin = substr($userrole->component, 6);
if (isset($plugins[$plugin])) {
$changeable = !$plugins[$plugin]->roles_protected();
}
}
}
$roletext = get_string('rolefromthiscourse', 'enrol', $a);
} else {
$changeable = false;
switch ($userrole->contextlevel) {
case CONTEXT_COURSE :
// Meta course
$roletext = get_string('rolefrommetacourse', 'enrol', $a);
break;
case CONTEXT_COURSECAT :
$roletext = get_string('rolefromcategory', 'enrol', $a);
break;
case CONTEXT_SYSTEM:
default:
$roletext = get_string('rolefromsystem', 'enrol', $a);
break;
}
}
if (!isset($users[$userrole->id]['roles'])) {
$users[$userrole->id]['roles'] = array();
}
$users[$userrole->id]['roles'][$userrole->roleid] = array(
'text' => $roletext,
'unchangeable' => !$changeable
);
}
return $users;
} | php | public function get_other_users_for_display(core_enrol_renderer $renderer, moodle_url $pageurl, $sort, $direction, $page, $perpage) {
$userroles = $this->get_other_users($sort, $direction, $page, $perpage);
$roles = $this->get_all_roles();
$plugins = $this->get_enrolment_plugins(false);
$context = $this->get_context();
$now = time();
$extrafields = get_extra_user_fields($context);
$users = array();
foreach ($userroles as $userrole) {
$contextid = $userrole->contextid;
unset($userrole->contextid); // This would collide with user avatar.
if (!array_key_exists($userrole->id, $users)) {
$users[$userrole->id] = $this->prepare_user_for_display($userrole, $extrafields, $now);
}
$a = new stdClass;
$a->role = $roles[$userrole->roleid]->localname;
if ($contextid == $this->context->id) {
$changeable = true;
if ($userrole->component) {
$changeable = false;
if (strpos($userrole->component, 'enrol_') === 0) {
$plugin = substr($userrole->component, 6);
if (isset($plugins[$plugin])) {
$changeable = !$plugins[$plugin]->roles_protected();
}
}
}
$roletext = get_string('rolefromthiscourse', 'enrol', $a);
} else {
$changeable = false;
switch ($userrole->contextlevel) {
case CONTEXT_COURSE :
// Meta course
$roletext = get_string('rolefrommetacourse', 'enrol', $a);
break;
case CONTEXT_COURSECAT :
$roletext = get_string('rolefromcategory', 'enrol', $a);
break;
case CONTEXT_SYSTEM:
default:
$roletext = get_string('rolefromsystem', 'enrol', $a);
break;
}
}
if (!isset($users[$userrole->id]['roles'])) {
$users[$userrole->id]['roles'] = array();
}
$users[$userrole->id]['roles'][$userrole->roleid] = array(
'text' => $roletext,
'unchangeable' => !$changeable
);
}
return $users;
} | [
"public",
"function",
"get_other_users_for_display",
"(",
"core_enrol_renderer",
"$",
"renderer",
",",
"moodle_url",
"$",
"pageurl",
",",
"$",
"sort",
",",
"$",
"direction",
",",
"$",
"page",
",",
"$",
"perpage",
")",
"{",
"$",
"userroles",
"=",
"$",
"this",
"->",
"get_other_users",
"(",
"$",
"sort",
",",
"$",
"direction",
",",
"$",
"page",
",",
"$",
"perpage",
")",
";",
"$",
"roles",
"=",
"$",
"this",
"->",
"get_all_roles",
"(",
")",
";",
"$",
"plugins",
"=",
"$",
"this",
"->",
"get_enrolment_plugins",
"(",
"false",
")",
";",
"$",
"context",
"=",
"$",
"this",
"->",
"get_context",
"(",
")",
";",
"$",
"now",
"=",
"time",
"(",
")",
";",
"$",
"extrafields",
"=",
"get_extra_user_fields",
"(",
"$",
"context",
")",
";",
"$",
"users",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"userroles",
"as",
"$",
"userrole",
")",
"{",
"$",
"contextid",
"=",
"$",
"userrole",
"->",
"contextid",
";",
"unset",
"(",
"$",
"userrole",
"->",
"contextid",
")",
";",
"// This would collide with user avatar.",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"userrole",
"->",
"id",
",",
"$",
"users",
")",
")",
"{",
"$",
"users",
"[",
"$",
"userrole",
"->",
"id",
"]",
"=",
"$",
"this",
"->",
"prepare_user_for_display",
"(",
"$",
"userrole",
",",
"$",
"extrafields",
",",
"$",
"now",
")",
";",
"}",
"$",
"a",
"=",
"new",
"stdClass",
";",
"$",
"a",
"->",
"role",
"=",
"$",
"roles",
"[",
"$",
"userrole",
"->",
"roleid",
"]",
"->",
"localname",
";",
"if",
"(",
"$",
"contextid",
"==",
"$",
"this",
"->",
"context",
"->",
"id",
")",
"{",
"$",
"changeable",
"=",
"true",
";",
"if",
"(",
"$",
"userrole",
"->",
"component",
")",
"{",
"$",
"changeable",
"=",
"false",
";",
"if",
"(",
"strpos",
"(",
"$",
"userrole",
"->",
"component",
",",
"'enrol_'",
")",
"===",
"0",
")",
"{",
"$",
"plugin",
"=",
"substr",
"(",
"$",
"userrole",
"->",
"component",
",",
"6",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"plugins",
"[",
"$",
"plugin",
"]",
")",
")",
"{",
"$",
"changeable",
"=",
"!",
"$",
"plugins",
"[",
"$",
"plugin",
"]",
"->",
"roles_protected",
"(",
")",
";",
"}",
"}",
"}",
"$",
"roletext",
"=",
"get_string",
"(",
"'rolefromthiscourse'",
",",
"'enrol'",
",",
"$",
"a",
")",
";",
"}",
"else",
"{",
"$",
"changeable",
"=",
"false",
";",
"switch",
"(",
"$",
"userrole",
"->",
"contextlevel",
")",
"{",
"case",
"CONTEXT_COURSE",
":",
"// Meta course",
"$",
"roletext",
"=",
"get_string",
"(",
"'rolefrommetacourse'",
",",
"'enrol'",
",",
"$",
"a",
")",
";",
"break",
";",
"case",
"CONTEXT_COURSECAT",
":",
"$",
"roletext",
"=",
"get_string",
"(",
"'rolefromcategory'",
",",
"'enrol'",
",",
"$",
"a",
")",
";",
"break",
";",
"case",
"CONTEXT_SYSTEM",
":",
"default",
":",
"$",
"roletext",
"=",
"get_string",
"(",
"'rolefromsystem'",
",",
"'enrol'",
",",
"$",
"a",
")",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"users",
"[",
"$",
"userrole",
"->",
"id",
"]",
"[",
"'roles'",
"]",
")",
")",
"{",
"$",
"users",
"[",
"$",
"userrole",
"->",
"id",
"]",
"[",
"'roles'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"users",
"[",
"$",
"userrole",
"->",
"id",
"]",
"[",
"'roles'",
"]",
"[",
"$",
"userrole",
"->",
"roleid",
"]",
"=",
"array",
"(",
"'text'",
"=>",
"$",
"roletext",
",",
"'unchangeable'",
"=>",
"!",
"$",
"changeable",
")",
";",
"}",
"return",
"$",
"users",
";",
"}"
] | Gets an array of other users in this course ready for display.
Other users are users who have been assigned or inherited roles within this
course but have not been enrolled.
@param core_enrol_renderer $renderer
@param moodle_url $pageurl
@param string $sort
@param string $direction ASC | DESC
@param int $page Starting from 0
@param int $perpage
@return array | [
"Gets",
"an",
"array",
"of",
"other",
"users",
"in",
"this",
"course",
"ready",
"for",
"display",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/locallib.php#L1012-L1068 |
212,707 | moodle/moodle | enrol/locallib.php | course_enrolment_manager.prepare_user_for_display | private function prepare_user_for_display($user, $extrafields, $now) {
$details = array(
'userid' => $user->id,
'courseid' => $this->get_course()->id,
'picture' => new user_picture($user),
'userfullnamedisplay' => fullname($user, has_capability('moodle/site:viewfullnames', $this->get_context())),
'lastaccess' => get_string('never'),
'lastcourseaccess' => get_string('never'),
);
foreach ($extrafields as $field) {
$details[$field] = $user->{$field};
}
// Last time user has accessed the site.
if (!empty($user->lastaccess)) {
$details['lastaccess'] = format_time($now - $user->lastaccess);
}
// Last time user has accessed the course.
if (!empty($user->lastcourseaccess)) {
$details['lastcourseaccess'] = format_time($now - $user->lastcourseaccess);
}
return $details;
} | php | private function prepare_user_for_display($user, $extrafields, $now) {
$details = array(
'userid' => $user->id,
'courseid' => $this->get_course()->id,
'picture' => new user_picture($user),
'userfullnamedisplay' => fullname($user, has_capability('moodle/site:viewfullnames', $this->get_context())),
'lastaccess' => get_string('never'),
'lastcourseaccess' => get_string('never'),
);
foreach ($extrafields as $field) {
$details[$field] = $user->{$field};
}
// Last time user has accessed the site.
if (!empty($user->lastaccess)) {
$details['lastaccess'] = format_time($now - $user->lastaccess);
}
// Last time user has accessed the course.
if (!empty($user->lastcourseaccess)) {
$details['lastcourseaccess'] = format_time($now - $user->lastcourseaccess);
}
return $details;
} | [
"private",
"function",
"prepare_user_for_display",
"(",
"$",
"user",
",",
"$",
"extrafields",
",",
"$",
"now",
")",
"{",
"$",
"details",
"=",
"array",
"(",
"'userid'",
"=>",
"$",
"user",
"->",
"id",
",",
"'courseid'",
"=>",
"$",
"this",
"->",
"get_course",
"(",
")",
"->",
"id",
",",
"'picture'",
"=>",
"new",
"user_picture",
"(",
"$",
"user",
")",
",",
"'userfullnamedisplay'",
"=>",
"fullname",
"(",
"$",
"user",
",",
"has_capability",
"(",
"'moodle/site:viewfullnames'",
",",
"$",
"this",
"->",
"get_context",
"(",
")",
")",
")",
",",
"'lastaccess'",
"=>",
"get_string",
"(",
"'never'",
")",
",",
"'lastcourseaccess'",
"=>",
"get_string",
"(",
"'never'",
")",
",",
")",
";",
"foreach",
"(",
"$",
"extrafields",
"as",
"$",
"field",
")",
"{",
"$",
"details",
"[",
"$",
"field",
"]",
"=",
"$",
"user",
"->",
"{",
"$",
"field",
"}",
";",
"}",
"// Last time user has accessed the site.",
"if",
"(",
"!",
"empty",
"(",
"$",
"user",
"->",
"lastaccess",
")",
")",
"{",
"$",
"details",
"[",
"'lastaccess'",
"]",
"=",
"format_time",
"(",
"$",
"now",
"-",
"$",
"user",
"->",
"lastaccess",
")",
";",
"}",
"// Last time user has accessed the course.",
"if",
"(",
"!",
"empty",
"(",
"$",
"user",
"->",
"lastcourseaccess",
")",
")",
"{",
"$",
"details",
"[",
"'lastcourseaccess'",
"]",
"=",
"format_time",
"(",
"$",
"now",
"-",
"$",
"user",
"->",
"lastcourseaccess",
")",
";",
"}",
"return",
"$",
"details",
";",
"}"
] | Prepare a user record for display
This function is called by both {@link get_users_for_display} and {@link get_other_users_for_display} to correctly
prepare user fields for display
Please note that this function does not check capability for moodle/coures:viewhiddenuserfields
@param object $user The user record
@param array $extrafields The list of fields as returned from get_extra_user_fields used to determine which
additional fields may be displayed
@param int $now The time used for lastaccess calculation
@return array The fields to be displayed including userid, courseid, picture, firstname, lastcourseaccess, lastaccess and any
additional fields from $extrafields | [
"Prepare",
"a",
"user",
"record",
"for",
"display"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/locallib.php#L1183-L1207 |
212,708 | moodle/moodle | enrol/locallib.php | course_enrolment_manager.get_filtered_enrolment_plugin | public function get_filtered_enrolment_plugin() {
$instances = $this->get_enrolment_instances();
$plugins = $this->get_enrolment_plugins(false);
if (empty($this->instancefilter) || !array_key_exists($this->instancefilter, $instances)) {
return false;
}
$instance = $instances[$this->instancefilter];
return $plugins[$instance->enrol];
} | php | public function get_filtered_enrolment_plugin() {
$instances = $this->get_enrolment_instances();
$plugins = $this->get_enrolment_plugins(false);
if (empty($this->instancefilter) || !array_key_exists($this->instancefilter, $instances)) {
return false;
}
$instance = $instances[$this->instancefilter];
return $plugins[$instance->enrol];
} | [
"public",
"function",
"get_filtered_enrolment_plugin",
"(",
")",
"{",
"$",
"instances",
"=",
"$",
"this",
"->",
"get_enrolment_instances",
"(",
")",
";",
"$",
"plugins",
"=",
"$",
"this",
"->",
"get_enrolment_plugins",
"(",
"false",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"instancefilter",
")",
"||",
"!",
"array_key_exists",
"(",
"$",
"this",
"->",
"instancefilter",
",",
"$",
"instances",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"instance",
"=",
"$",
"instances",
"[",
"$",
"this",
"->",
"instancefilter",
"]",
";",
"return",
"$",
"plugins",
"[",
"$",
"instance",
"->",
"enrol",
"]",
";",
"}"
] | Returns the enrolment plugin that the course manager was being filtered to.
If no filter was being applied then this function returns false.
@return enrol_plugin | [
"Returns",
"the",
"enrolment",
"plugin",
"that",
"the",
"course",
"manager",
"was",
"being",
"filtered",
"to",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/locallib.php#L1240-L1250 |
212,709 | moodle/moodle | enrol/locallib.php | course_enrolment_manager.get_users_enrolments | public function get_users_enrolments(array $userids) {
global $DB;
$instances = $this->get_enrolment_instances();
$plugins = $this->get_enrolment_plugins(false);
if (!empty($this->instancefilter)) {
$instancesql = ' = :instanceid';
$instanceparams = array('instanceid' => $this->instancefilter);
} else {
list($instancesql, $instanceparams) = $DB->get_in_or_equal(array_keys($instances), SQL_PARAMS_NAMED, 'instanceid0000');
}
$userfields = user_picture::fields('u');
list($idsql, $idparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, 'userid0000');
list($sort, $sortparams) = users_order_by_sql('u');
$sql = "SELECT ue.id AS ueid, ue.status, ue.enrolid, ue.userid, ue.timestart, ue.timeend, ue.modifierid, ue.timecreated, ue.timemodified, $userfields
FROM {user_enrolments} ue
LEFT JOIN {user} u ON u.id = ue.userid
WHERE ue.enrolid $instancesql AND
u.id $idsql
ORDER BY $sort";
$rs = $DB->get_recordset_sql($sql, $idparams + $instanceparams + $sortparams);
$users = array();
foreach ($rs as $ue) {
$user = user_picture::unalias($ue);
$ue->id = $ue->ueid;
unset($ue->ueid);
if (!array_key_exists($user->id, $users)) {
$user->enrolments = array();
$users[$user->id] = $user;
}
$ue->enrolmentinstance = $instances[$ue->enrolid];
$ue->enrolmentplugin = $plugins[$ue->enrolmentinstance->enrol];
$users[$user->id]->enrolments[$ue->id] = $ue;
}
$rs->close();
return $users;
} | php | public function get_users_enrolments(array $userids) {
global $DB;
$instances = $this->get_enrolment_instances();
$plugins = $this->get_enrolment_plugins(false);
if (!empty($this->instancefilter)) {
$instancesql = ' = :instanceid';
$instanceparams = array('instanceid' => $this->instancefilter);
} else {
list($instancesql, $instanceparams) = $DB->get_in_or_equal(array_keys($instances), SQL_PARAMS_NAMED, 'instanceid0000');
}
$userfields = user_picture::fields('u');
list($idsql, $idparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, 'userid0000');
list($sort, $sortparams) = users_order_by_sql('u');
$sql = "SELECT ue.id AS ueid, ue.status, ue.enrolid, ue.userid, ue.timestart, ue.timeend, ue.modifierid, ue.timecreated, ue.timemodified, $userfields
FROM {user_enrolments} ue
LEFT JOIN {user} u ON u.id = ue.userid
WHERE ue.enrolid $instancesql AND
u.id $idsql
ORDER BY $sort";
$rs = $DB->get_recordset_sql($sql, $idparams + $instanceparams + $sortparams);
$users = array();
foreach ($rs as $ue) {
$user = user_picture::unalias($ue);
$ue->id = $ue->ueid;
unset($ue->ueid);
if (!array_key_exists($user->id, $users)) {
$user->enrolments = array();
$users[$user->id] = $user;
}
$ue->enrolmentinstance = $instances[$ue->enrolid];
$ue->enrolmentplugin = $plugins[$ue->enrolmentinstance->enrol];
$users[$user->id]->enrolments[$ue->id] = $ue;
}
$rs->close();
return $users;
} | [
"public",
"function",
"get_users_enrolments",
"(",
"array",
"$",
"userids",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"instances",
"=",
"$",
"this",
"->",
"get_enrolment_instances",
"(",
")",
";",
"$",
"plugins",
"=",
"$",
"this",
"->",
"get_enrolment_plugins",
"(",
"false",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"instancefilter",
")",
")",
"{",
"$",
"instancesql",
"=",
"' = :instanceid'",
";",
"$",
"instanceparams",
"=",
"array",
"(",
"'instanceid'",
"=>",
"$",
"this",
"->",
"instancefilter",
")",
";",
"}",
"else",
"{",
"list",
"(",
"$",
"instancesql",
",",
"$",
"instanceparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"array_keys",
"(",
"$",
"instances",
")",
",",
"SQL_PARAMS_NAMED",
",",
"'instanceid0000'",
")",
";",
"}",
"$",
"userfields",
"=",
"user_picture",
"::",
"fields",
"(",
"'u'",
")",
";",
"list",
"(",
"$",
"idsql",
",",
"$",
"idparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"userids",
",",
"SQL_PARAMS_NAMED",
",",
"'userid0000'",
")",
";",
"list",
"(",
"$",
"sort",
",",
"$",
"sortparams",
")",
"=",
"users_order_by_sql",
"(",
"'u'",
")",
";",
"$",
"sql",
"=",
"\"SELECT ue.id AS ueid, ue.status, ue.enrolid, ue.userid, ue.timestart, ue.timeend, ue.modifierid, ue.timecreated, ue.timemodified, $userfields\n FROM {user_enrolments} ue\n LEFT JOIN {user} u ON u.id = ue.userid\n WHERE ue.enrolid $instancesql AND\n u.id $idsql\n ORDER BY $sort\"",
";",
"$",
"rs",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
",",
"$",
"idparams",
"+",
"$",
"instanceparams",
"+",
"$",
"sortparams",
")",
";",
"$",
"users",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"rs",
"as",
"$",
"ue",
")",
"{",
"$",
"user",
"=",
"user_picture",
"::",
"unalias",
"(",
"$",
"ue",
")",
";",
"$",
"ue",
"->",
"id",
"=",
"$",
"ue",
"->",
"ueid",
";",
"unset",
"(",
"$",
"ue",
"->",
"ueid",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"user",
"->",
"id",
",",
"$",
"users",
")",
")",
"{",
"$",
"user",
"->",
"enrolments",
"=",
"array",
"(",
")",
";",
"$",
"users",
"[",
"$",
"user",
"->",
"id",
"]",
"=",
"$",
"user",
";",
"}",
"$",
"ue",
"->",
"enrolmentinstance",
"=",
"$",
"instances",
"[",
"$",
"ue",
"->",
"enrolid",
"]",
";",
"$",
"ue",
"->",
"enrolmentplugin",
"=",
"$",
"plugins",
"[",
"$",
"ue",
"->",
"enrolmentinstance",
"->",
"enrol",
"]",
";",
"$",
"users",
"[",
"$",
"user",
"->",
"id",
"]",
"->",
"enrolments",
"[",
"$",
"ue",
"->",
"id",
"]",
"=",
"$",
"ue",
";",
"}",
"$",
"rs",
"->",
"close",
"(",
")",
";",
"return",
"$",
"users",
";",
"}"
] | Returns and array of users + enrolment details.
Given an array of user id's this function returns and array of user enrolments for those users
as well as enough user information to display the users name and picture for each enrolment.
@global moodle_database $DB
@param array $userids
@return array | [
"Returns",
"and",
"array",
"of",
"users",
"+",
"enrolment",
"details",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/locallib.php#L1262-L1303 |
212,710 | moodle/moodle | enrol/locallib.php | enrol_user_button.require_yui_module | public function require_yui_module($modules, $function, array $arguments = null, $galleryversion = null, $ondomready = false) {
if ($galleryversion != null) {
debugging('The galleryversion parameter to yui_module has been deprecated since Moodle 2.3.', DEBUG_DEVELOPER);
}
$js = new stdClass;
$js->modules = (array)$modules;
$js->function = $function;
$js->arguments = $arguments;
$js->ondomready = $ondomready;
$this->jsyuimodules[] = $js;
} | php | public function require_yui_module($modules, $function, array $arguments = null, $galleryversion = null, $ondomready = false) {
if ($galleryversion != null) {
debugging('The galleryversion parameter to yui_module has been deprecated since Moodle 2.3.', DEBUG_DEVELOPER);
}
$js = new stdClass;
$js->modules = (array)$modules;
$js->function = $function;
$js->arguments = $arguments;
$js->ondomready = $ondomready;
$this->jsyuimodules[] = $js;
} | [
"public",
"function",
"require_yui_module",
"(",
"$",
"modules",
",",
"$",
"function",
",",
"array",
"$",
"arguments",
"=",
"null",
",",
"$",
"galleryversion",
"=",
"null",
",",
"$",
"ondomready",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"galleryversion",
"!=",
"null",
")",
"{",
"debugging",
"(",
"'The galleryversion parameter to yui_module has been deprecated since Moodle 2.3.'",
",",
"DEBUG_DEVELOPER",
")",
";",
"}",
"$",
"js",
"=",
"new",
"stdClass",
";",
"$",
"js",
"->",
"modules",
"=",
"(",
"array",
")",
"$",
"modules",
";",
"$",
"js",
"->",
"function",
"=",
"$",
"function",
";",
"$",
"js",
"->",
"arguments",
"=",
"$",
"arguments",
";",
"$",
"js",
"->",
"ondomready",
"=",
"$",
"ondomready",
";",
"$",
"this",
"->",
"jsyuimodules",
"[",
"]",
"=",
"$",
"js",
";",
"}"
] | Adds a YUI module call that will be added to the page when the button is used.
@param string|array $modules One or more modules to require
@param string $function The JS function to call
@param array $arguments An array of arguments to pass to the function
@param string $galleryversion Deprecated: The gallery version to use
@param bool $ondomready If true the call is postponed until the DOM is finished loading | [
"Adds",
"a",
"YUI",
"module",
"call",
"that",
"will",
"be",
"added",
"to",
"the",
"page",
"when",
"the",
"button",
"is",
"used",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/locallib.php#L1357-L1368 |
212,711 | moodle/moodle | enrol/locallib.php | enrol_user_button.require_js_init_call | public function require_js_init_call($function, array $extraarguments = null, $ondomready = false, array $module = null) {
$js = new stdClass;
$js->function = $function;
$js->extraarguments = $extraarguments;
$js->ondomready = $ondomready;
$js->module = $module;
$this->jsinitcalls[] = $js;
} | php | public function require_js_init_call($function, array $extraarguments = null, $ondomready = false, array $module = null) {
$js = new stdClass;
$js->function = $function;
$js->extraarguments = $extraarguments;
$js->ondomready = $ondomready;
$js->module = $module;
$this->jsinitcalls[] = $js;
} | [
"public",
"function",
"require_js_init_call",
"(",
"$",
"function",
",",
"array",
"$",
"extraarguments",
"=",
"null",
",",
"$",
"ondomready",
"=",
"false",
",",
"array",
"$",
"module",
"=",
"null",
")",
"{",
"$",
"js",
"=",
"new",
"stdClass",
";",
"$",
"js",
"->",
"function",
"=",
"$",
"function",
";",
"$",
"js",
"->",
"extraarguments",
"=",
"$",
"extraarguments",
";",
"$",
"js",
"->",
"ondomready",
"=",
"$",
"ondomready",
";",
"$",
"js",
"->",
"module",
"=",
"$",
"module",
";",
"$",
"this",
"->",
"jsinitcalls",
"[",
"]",
"=",
"$",
"js",
";",
"}"
] | Adds a JS initialisation call to the page when the button is used.
@param string $function The function to call
@param array $extraarguments An array of arguments to pass to the function
@param bool $ondomready If true the call is postponed until the DOM is finished loading
@param array $module A module definition | [
"Adds",
"a",
"JS",
"initialisation",
"call",
"to",
"the",
"page",
"when",
"the",
"button",
"is",
"used",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/locallib.php#L1378-L1385 |
212,712 | moodle/moodle | enrol/locallib.php | enrol_user_button.strings_for_js | public function strings_for_js($identifiers, $component = 'moodle', $a = null) {
$string = new stdClass;
$string->identifiers = (array)$identifiers;
$string->component = $component;
$string->a = $a;
$this->jsstrings[] = $string;
} | php | public function strings_for_js($identifiers, $component = 'moodle', $a = null) {
$string = new stdClass;
$string->identifiers = (array)$identifiers;
$string->component = $component;
$string->a = $a;
$this->jsstrings[] = $string;
} | [
"public",
"function",
"strings_for_js",
"(",
"$",
"identifiers",
",",
"$",
"component",
"=",
"'moodle'",
",",
"$",
"a",
"=",
"null",
")",
"{",
"$",
"string",
"=",
"new",
"stdClass",
";",
"$",
"string",
"->",
"identifiers",
"=",
"(",
"array",
")",
"$",
"identifiers",
";",
"$",
"string",
"->",
"component",
"=",
"$",
"component",
";",
"$",
"string",
"->",
"a",
"=",
"$",
"a",
";",
"$",
"this",
"->",
"jsstrings",
"[",
"]",
"=",
"$",
"string",
";",
"}"
] | Requires strings for JS that will be loaded when the button is used.
@param type $identifiers
@param string $component
@param mixed $a | [
"Requires",
"strings",
"for",
"JS",
"that",
"will",
"be",
"loaded",
"when",
"the",
"button",
"is",
"used",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/locallib.php#L1394-L1400 |
212,713 | moodle/moodle | enrol/locallib.php | enrol_user_button.initialise_js | public function initialise_js(moodle_page $page) {
foreach ($this->jsyuimodules as $js) {
$page->requires->yui_module($js->modules, $js->function, $js->arguments, null, $js->ondomready);
}
foreach ($this->jsinitcalls as $js) {
$page->requires->js_init_call($js->function, $js->extraarguments, $js->ondomready, $js->module);
}
foreach ($this->jsstrings as $string) {
$page->requires->strings_for_js($string->identifiers, $string->component, $string->a);
}
} | php | public function initialise_js(moodle_page $page) {
foreach ($this->jsyuimodules as $js) {
$page->requires->yui_module($js->modules, $js->function, $js->arguments, null, $js->ondomready);
}
foreach ($this->jsinitcalls as $js) {
$page->requires->js_init_call($js->function, $js->extraarguments, $js->ondomready, $js->module);
}
foreach ($this->jsstrings as $string) {
$page->requires->strings_for_js($string->identifiers, $string->component, $string->a);
}
} | [
"public",
"function",
"initialise_js",
"(",
"moodle_page",
"$",
"page",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"jsyuimodules",
"as",
"$",
"js",
")",
"{",
"$",
"page",
"->",
"requires",
"->",
"yui_module",
"(",
"$",
"js",
"->",
"modules",
",",
"$",
"js",
"->",
"function",
",",
"$",
"js",
"->",
"arguments",
",",
"null",
",",
"$",
"js",
"->",
"ondomready",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"jsinitcalls",
"as",
"$",
"js",
")",
"{",
"$",
"page",
"->",
"requires",
"->",
"js_init_call",
"(",
"$",
"js",
"->",
"function",
",",
"$",
"js",
"->",
"extraarguments",
",",
"$",
"js",
"->",
"ondomready",
",",
"$",
"js",
"->",
"module",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"jsstrings",
"as",
"$",
"string",
")",
"{",
"$",
"page",
"->",
"requires",
"->",
"strings_for_js",
"(",
"$",
"string",
"->",
"identifiers",
",",
"$",
"string",
"->",
"component",
",",
"$",
"string",
"->",
"a",
")",
";",
"}",
"}"
] | Initialises the JS that is required by this button
@param moodle_page $page | [
"Initialises",
"the",
"JS",
"that",
"is",
"required",
"by",
"this",
"button"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/locallib.php#L1407-L1417 |
212,714 | moodle/moodle | grade/grading/form/rubric/edit_form.php | gradingform_rubric_editrubric.need_confirm_regrading | public function need_confirm_regrading($controller) {
$data = $this->get_data();
if (isset($data->rubric['regrade'])) {
// we have already displayed the confirmation on the previous step
return false;
}
if (!isset($data->saverubric) || !$data->saverubric) {
// we only need confirmation when button 'Save rubric' is pressed
return false;
}
if (!$controller->has_active_instances()) {
// nothing to re-grade, confirmation not needed
return false;
}
$changelevel = $controller->update_or_check_rubric($data);
if ($changelevel == 0) {
// no changes in the rubric, no confirmation needed
return false;
}
// freeze form elements and pass the values in hidden fields
// TODO MDL-29421 description_editor does not freeze the normal way, uncomment below when fixed
$form = $this->_form;
foreach (array('rubric', 'name'/*, 'description_editor'*/) as $fieldname) {
$el =& $form->getElement($fieldname);
$el->freeze();
$el->setPersistantFreeze(true);
if ($fieldname == 'rubric') {
$el->add_regrade_confirmation($changelevel);
}
}
// replace button text 'saverubric' and unfreeze 'Back to edit' button
$this->findButton('saverubric')->setValue(get_string('continue'));
$el =& $this->findButton('editrubric');
$el->setValue(get_string('backtoediting', 'gradingform_rubric'));
$el->unfreeze();
return true;
} | php | public function need_confirm_regrading($controller) {
$data = $this->get_data();
if (isset($data->rubric['regrade'])) {
// we have already displayed the confirmation on the previous step
return false;
}
if (!isset($data->saverubric) || !$data->saverubric) {
// we only need confirmation when button 'Save rubric' is pressed
return false;
}
if (!$controller->has_active_instances()) {
// nothing to re-grade, confirmation not needed
return false;
}
$changelevel = $controller->update_or_check_rubric($data);
if ($changelevel == 0) {
// no changes in the rubric, no confirmation needed
return false;
}
// freeze form elements and pass the values in hidden fields
// TODO MDL-29421 description_editor does not freeze the normal way, uncomment below when fixed
$form = $this->_form;
foreach (array('rubric', 'name'/*, 'description_editor'*/) as $fieldname) {
$el =& $form->getElement($fieldname);
$el->freeze();
$el->setPersistantFreeze(true);
if ($fieldname == 'rubric') {
$el->add_regrade_confirmation($changelevel);
}
}
// replace button text 'saverubric' and unfreeze 'Back to edit' button
$this->findButton('saverubric')->setValue(get_string('continue'));
$el =& $this->findButton('editrubric');
$el->setValue(get_string('backtoediting', 'gradingform_rubric'));
$el->unfreeze();
return true;
} | [
"public",
"function",
"need_confirm_regrading",
"(",
"$",
"controller",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"get_data",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"->",
"rubric",
"[",
"'regrade'",
"]",
")",
")",
"{",
"// we have already displayed the confirmation on the previous step",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"->",
"saverubric",
")",
"||",
"!",
"$",
"data",
"->",
"saverubric",
")",
"{",
"// we only need confirmation when button 'Save rubric' is pressed",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"controller",
"->",
"has_active_instances",
"(",
")",
")",
"{",
"// nothing to re-grade, confirmation not needed",
"return",
"false",
";",
"}",
"$",
"changelevel",
"=",
"$",
"controller",
"->",
"update_or_check_rubric",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"changelevel",
"==",
"0",
")",
"{",
"// no changes in the rubric, no confirmation needed",
"return",
"false",
";",
"}",
"// freeze form elements and pass the values in hidden fields",
"// TODO MDL-29421 description_editor does not freeze the normal way, uncomment below when fixed",
"$",
"form",
"=",
"$",
"this",
"->",
"_form",
";",
"foreach",
"(",
"array",
"(",
"'rubric'",
",",
"'name'",
"/*, 'description_editor'*/",
")",
"as",
"$",
"fieldname",
")",
"{",
"$",
"el",
"=",
"&",
"$",
"form",
"->",
"getElement",
"(",
"$",
"fieldname",
")",
";",
"$",
"el",
"->",
"freeze",
"(",
")",
";",
"$",
"el",
"->",
"setPersistantFreeze",
"(",
"true",
")",
";",
"if",
"(",
"$",
"fieldname",
"==",
"'rubric'",
")",
"{",
"$",
"el",
"->",
"add_regrade_confirmation",
"(",
"$",
"changelevel",
")",
";",
"}",
"}",
"// replace button text 'saverubric' and unfreeze 'Back to edit' button",
"$",
"this",
"->",
"findButton",
"(",
"'saverubric'",
")",
"->",
"setValue",
"(",
"get_string",
"(",
"'continue'",
")",
")",
";",
"$",
"el",
"=",
"&",
"$",
"this",
"->",
"findButton",
"(",
"'editrubric'",
")",
";",
"$",
"el",
"->",
"setValue",
"(",
"get_string",
"(",
"'backtoediting'",
",",
"'gradingform_rubric'",
")",
")",
";",
"$",
"el",
"->",
"unfreeze",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Check if there are changes in the rubric and it is needed to ask user whether to
mark the current grades for re-grading. User may confirm re-grading and continue,
return to editing or cancel the changes
@param gradingform_rubric_controller $controller | [
"Check",
"if",
"there",
"are",
"changes",
"in",
"the",
"rubric",
"and",
"it",
"is",
"needed",
"to",
"ask",
"user",
"whether",
"to",
"mark",
"the",
"current",
"grades",
"for",
"re",
"-",
"grading",
".",
"User",
"may",
"confirm",
"re",
"-",
"grading",
"and",
"continue",
"return",
"to",
"editing",
"or",
"cancel",
"the",
"changes"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/rubric/edit_form.php#L159-L198 |
212,715 | moodle/moodle | blocks/community/locallib.php | block_community_manager.block_community_add_course | public function block_community_add_course($course, $userid) {
global $DB;
$community = $this->block_community_get_course($course->url, $userid);
if (empty($community)) {
$community = new stdClass();
$community->userid = $userid;
$community->coursename = $course->name;
$community->coursedescription = $course->description;
$community->courseurl = $course->url;
$community->imageurl = $course->imageurl;
return $DB->insert_record('block_community', $community);
} else {
return false;
}
} | php | public function block_community_add_course($course, $userid) {
global $DB;
$community = $this->block_community_get_course($course->url, $userid);
if (empty($community)) {
$community = new stdClass();
$community->userid = $userid;
$community->coursename = $course->name;
$community->coursedescription = $course->description;
$community->courseurl = $course->url;
$community->imageurl = $course->imageurl;
return $DB->insert_record('block_community', $community);
} else {
return false;
}
} | [
"public",
"function",
"block_community_add_course",
"(",
"$",
"course",
",",
"$",
"userid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"community",
"=",
"$",
"this",
"->",
"block_community_get_course",
"(",
"$",
"course",
"->",
"url",
",",
"$",
"userid",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"community",
")",
")",
"{",
"$",
"community",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"community",
"->",
"userid",
"=",
"$",
"userid",
";",
"$",
"community",
"->",
"coursename",
"=",
"$",
"course",
"->",
"name",
";",
"$",
"community",
"->",
"coursedescription",
"=",
"$",
"course",
"->",
"description",
";",
"$",
"community",
"->",
"courseurl",
"=",
"$",
"course",
"->",
"url",
";",
"$",
"community",
"->",
"imageurl",
"=",
"$",
"course",
"->",
"imageurl",
";",
"return",
"$",
"DB",
"->",
"insert_record",
"(",
"'block_community'",
",",
"$",
"community",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Add a community course
@param object $course
@param integer $userid
@return id of course or false if already added | [
"Add",
"a",
"community",
"course"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/community/locallib.php#L36-L52 |
212,716 | moodle/moodle | theme/boost/classes/autoprefixer.php | autoprefixer.manipulateRuleValues | protected function manipulateRuleValues(array $rules) {
$finalrules = [];
foreach ($rules as $rule) {
$property = $rule->getRule();
$value = $rule->getValue();
if ($property === 'position' && $value === 'sticky') {
$newrule = clone $rule;
$newrule->setValue('-webkit-sticky');
$finalrules[] = $newrule;
} else if ($property === 'background-image' &&
$value instanceof CSSFunction &&
$value->getName() === 'linear-gradient') {
foreach (['-webkit-', '-o-'] as $prefix) {
$newfunction = clone $value;
$newfunction->setName($prefix . $value->getName());
$newrule = clone $rule;
$newrule->setValue($newfunction);
$finalrules[] = $newrule;
}
}
$finalrules[] = $rule;
}
return $finalrules;
} | php | protected function manipulateRuleValues(array $rules) {
$finalrules = [];
foreach ($rules as $rule) {
$property = $rule->getRule();
$value = $rule->getValue();
if ($property === 'position' && $value === 'sticky') {
$newrule = clone $rule;
$newrule->setValue('-webkit-sticky');
$finalrules[] = $newrule;
} else if ($property === 'background-image' &&
$value instanceof CSSFunction &&
$value->getName() === 'linear-gradient') {
foreach (['-webkit-', '-o-'] as $prefix) {
$newfunction = clone $value;
$newfunction->setName($prefix . $value->getName());
$newrule = clone $rule;
$newrule->setValue($newfunction);
$finalrules[] = $newrule;
}
}
$finalrules[] = $rule;
}
return $finalrules;
} | [
"protected",
"function",
"manipulateRuleValues",
"(",
"array",
"$",
"rules",
")",
"{",
"$",
"finalrules",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"rule",
")",
"{",
"$",
"property",
"=",
"$",
"rule",
"->",
"getRule",
"(",
")",
";",
"$",
"value",
"=",
"$",
"rule",
"->",
"getValue",
"(",
")",
";",
"if",
"(",
"$",
"property",
"===",
"'position'",
"&&",
"$",
"value",
"===",
"'sticky'",
")",
"{",
"$",
"newrule",
"=",
"clone",
"$",
"rule",
";",
"$",
"newrule",
"->",
"setValue",
"(",
"'-webkit-sticky'",
")",
";",
"$",
"finalrules",
"[",
"]",
"=",
"$",
"newrule",
";",
"}",
"else",
"if",
"(",
"$",
"property",
"===",
"'background-image'",
"&&",
"$",
"value",
"instanceof",
"CSSFunction",
"&&",
"$",
"value",
"->",
"getName",
"(",
")",
"===",
"'linear-gradient'",
")",
"{",
"foreach",
"(",
"[",
"'-webkit-'",
",",
"'-o-'",
"]",
"as",
"$",
"prefix",
")",
"{",
"$",
"newfunction",
"=",
"clone",
"$",
"value",
";",
"$",
"newfunction",
"->",
"setName",
"(",
"$",
"prefix",
".",
"$",
"value",
"->",
"getName",
"(",
")",
")",
";",
"$",
"newrule",
"=",
"clone",
"$",
"rule",
";",
"$",
"newrule",
"->",
"setValue",
"(",
"$",
"newfunction",
")",
";",
"$",
"finalrules",
"[",
"]",
"=",
"$",
"newrule",
";",
"}",
"}",
"$",
"finalrules",
"[",
"]",
"=",
"$",
"rule",
";",
"}",
"return",
"$",
"finalrules",
";",
"}"
] | Manipulate an array of rules to adapt their values.
@param array $rules The rules.
@return New array of rules. | [
"Manipulate",
"an",
"array",
"of",
"rules",
"to",
"adapt",
"their",
"values",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/theme/boost/classes/autoprefixer.php#L121-L150 |
212,717 | moodle/moodle | theme/boost/classes/autoprefixer.php | autoprefixer.processBlock | protected function processBlock($block) {
foreach ($block->getContents() as $node) {
if ($node instanceof AtRule) {
$name = $node->atRuleName();
if (isset(self::$atrules[$name])) {
foreach (self::$atrules[$name] as $prefix) {
$newname = $prefix . $name;
$newnode = clone $node;
if ($node instanceof KeyFrame) {
$newnode->setVendorKeyFrame($newname);
$block->insert($newnode, $node);
} else {
debugging('Unhandled atRule prefixing.', DEBUG_DEVELOPER);
}
}
}
}
if ($node instanceof CSSList) {
$this->processBlock($node);
} else if ($node instanceof RuleSet) {
$this->processDeclaration($node, $block);
}
}
} | php | protected function processBlock($block) {
foreach ($block->getContents() as $node) {
if ($node instanceof AtRule) {
$name = $node->atRuleName();
if (isset(self::$atrules[$name])) {
foreach (self::$atrules[$name] as $prefix) {
$newname = $prefix . $name;
$newnode = clone $node;
if ($node instanceof KeyFrame) {
$newnode->setVendorKeyFrame($newname);
$block->insert($newnode, $node);
} else {
debugging('Unhandled atRule prefixing.', DEBUG_DEVELOPER);
}
}
}
}
if ($node instanceof CSSList) {
$this->processBlock($node);
} else if ($node instanceof RuleSet) {
$this->processDeclaration($node, $block);
}
}
} | [
"protected",
"function",
"processBlock",
"(",
"$",
"block",
")",
"{",
"foreach",
"(",
"$",
"block",
"->",
"getContents",
"(",
")",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"AtRule",
")",
"{",
"$",
"name",
"=",
"$",
"node",
"->",
"atRuleName",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"atrules",
"[",
"$",
"name",
"]",
")",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"atrules",
"[",
"$",
"name",
"]",
"as",
"$",
"prefix",
")",
"{",
"$",
"newname",
"=",
"$",
"prefix",
".",
"$",
"name",
";",
"$",
"newnode",
"=",
"clone",
"$",
"node",
";",
"if",
"(",
"$",
"node",
"instanceof",
"KeyFrame",
")",
"{",
"$",
"newnode",
"->",
"setVendorKeyFrame",
"(",
"$",
"newname",
")",
";",
"$",
"block",
"->",
"insert",
"(",
"$",
"newnode",
",",
"$",
"node",
")",
";",
"}",
"else",
"{",
"debugging",
"(",
"'Unhandled atRule prefixing.'",
",",
"DEBUG_DEVELOPER",
")",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"$",
"node",
"instanceof",
"CSSList",
")",
"{",
"$",
"this",
"->",
"processBlock",
"(",
"$",
"node",
")",
";",
"}",
"else",
"if",
"(",
"$",
"node",
"instanceof",
"RuleSet",
")",
"{",
"$",
"this",
"->",
"processDeclaration",
"(",
"$",
"node",
",",
"$",
"block",
")",
";",
"}",
"}",
"}"
] | Process block.
@param object $block A block.
@param object $parent The parent of the block. | [
"Process",
"block",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/theme/boost/classes/autoprefixer.php#L165-L193 |
212,718 | moodle/moodle | theme/boost/classes/autoprefixer.php | autoprefixer.processDeclaration | protected function processDeclaration($node, $parent) {
$rules = [];
foreach ($node->getRules() as $key => $rule) {
$name = $rule->getRule();
$seen[$name] = true;
if (!isset(self::$rules[$name])) {
$rules[] = $rule;
continue;
}
foreach (self::$rules[$name] as $prefix) {
$newname = $prefix . $name;
if (isset($seen[$newname])) {
continue;
}
$newrule = clone $rule;
$newrule->setRule($newname);
$rules[] = $newrule;
}
$rules[] = $rule;
}
$node->setRules($this->manipulateRuleValues($rules));
if ($node instanceof DeclarationBlock) {
$selectors = $node->getSelectors();
foreach ($selectors as $key => $selector) {
$matches = [];
if (preg_match($this->pseudosregex, $selector->getSelector(), $matches)) {
$newnode = clone $node;
foreach (self::$pseudos[$matches[1]] as $newpseudo) {
$newselector = new Selector(str_replace($matches[1], $newpseudo, $selector->getSelector()));
$selectors[$key] = $newselector;
$newnode = clone $node;
$newnode->setSelectors($selectors);
$parent->insert($newnode, $node);
}
// We're only expecting one affected pseudo class per block.
break;
}
}
}
} | php | protected function processDeclaration($node, $parent) {
$rules = [];
foreach ($node->getRules() as $key => $rule) {
$name = $rule->getRule();
$seen[$name] = true;
if (!isset(self::$rules[$name])) {
$rules[] = $rule;
continue;
}
foreach (self::$rules[$name] as $prefix) {
$newname = $prefix . $name;
if (isset($seen[$newname])) {
continue;
}
$newrule = clone $rule;
$newrule->setRule($newname);
$rules[] = $newrule;
}
$rules[] = $rule;
}
$node->setRules($this->manipulateRuleValues($rules));
if ($node instanceof DeclarationBlock) {
$selectors = $node->getSelectors();
foreach ($selectors as $key => $selector) {
$matches = [];
if (preg_match($this->pseudosregex, $selector->getSelector(), $matches)) {
$newnode = clone $node;
foreach (self::$pseudos[$matches[1]] as $newpseudo) {
$newselector = new Selector(str_replace($matches[1], $newpseudo, $selector->getSelector()));
$selectors[$key] = $newselector;
$newnode = clone $node;
$newnode->setSelectors($selectors);
$parent->insert($newnode, $node);
}
// We're only expecting one affected pseudo class per block.
break;
}
}
}
} | [
"protected",
"function",
"processDeclaration",
"(",
"$",
"node",
",",
"$",
"parent",
")",
"{",
"$",
"rules",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"node",
"->",
"getRules",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"rule",
")",
"{",
"$",
"name",
"=",
"$",
"rule",
"->",
"getRule",
"(",
")",
";",
"$",
"seen",
"[",
"$",
"name",
"]",
"=",
"true",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"rules",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"rules",
"[",
"]",
"=",
"$",
"rule",
";",
"continue",
";",
"}",
"foreach",
"(",
"self",
"::",
"$",
"rules",
"[",
"$",
"name",
"]",
"as",
"$",
"prefix",
")",
"{",
"$",
"newname",
"=",
"$",
"prefix",
".",
"$",
"name",
";",
"if",
"(",
"isset",
"(",
"$",
"seen",
"[",
"$",
"newname",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"newrule",
"=",
"clone",
"$",
"rule",
";",
"$",
"newrule",
"->",
"setRule",
"(",
"$",
"newname",
")",
";",
"$",
"rules",
"[",
"]",
"=",
"$",
"newrule",
";",
"}",
"$",
"rules",
"[",
"]",
"=",
"$",
"rule",
";",
"}",
"$",
"node",
"->",
"setRules",
"(",
"$",
"this",
"->",
"manipulateRuleValues",
"(",
"$",
"rules",
")",
")",
";",
"if",
"(",
"$",
"node",
"instanceof",
"DeclarationBlock",
")",
"{",
"$",
"selectors",
"=",
"$",
"node",
"->",
"getSelectors",
"(",
")",
";",
"foreach",
"(",
"$",
"selectors",
"as",
"$",
"key",
"=>",
"$",
"selector",
")",
"{",
"$",
"matches",
"=",
"[",
"]",
";",
"if",
"(",
"preg_match",
"(",
"$",
"this",
"->",
"pseudosregex",
",",
"$",
"selector",
"->",
"getSelector",
"(",
")",
",",
"$",
"matches",
")",
")",
"{",
"$",
"newnode",
"=",
"clone",
"$",
"node",
";",
"foreach",
"(",
"self",
"::",
"$",
"pseudos",
"[",
"$",
"matches",
"[",
"1",
"]",
"]",
"as",
"$",
"newpseudo",
")",
"{",
"$",
"newselector",
"=",
"new",
"Selector",
"(",
"str_replace",
"(",
"$",
"matches",
"[",
"1",
"]",
",",
"$",
"newpseudo",
",",
"$",
"selector",
"->",
"getSelector",
"(",
")",
")",
")",
";",
"$",
"selectors",
"[",
"$",
"key",
"]",
"=",
"$",
"newselector",
";",
"$",
"newnode",
"=",
"clone",
"$",
"node",
";",
"$",
"newnode",
"->",
"setSelectors",
"(",
"$",
"selectors",
")",
";",
"$",
"parent",
"->",
"insert",
"(",
"$",
"newnode",
",",
"$",
"node",
")",
";",
"}",
"// We're only expecting one affected pseudo class per block.",
"break",
";",
"}",
"}",
"}",
"}"
] | Process declaration.
@param object $node The declaration block.
@param object $parent The parent. | [
"Process",
"declaration",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/theme/boost/classes/autoprefixer.php#L201-L249 |
212,719 | moodle/moodle | enrol/renderer.php | core_enrol_renderer.render_enrol_user_button | protected function render_enrol_user_button(enrol_user_button $button) {
$attributes = array('type' => 'submit',
'value' => $button->label,
'disabled' => $button->disabled ? 'disabled' : null,
'title' => $button->tooltip,
'class' => 'btn btn-secondary my-1');
if ($button->actions) {
$id = html_writer::random_id('single_button');
$attributes['id'] = $id;
foreach ($button->actions as $action) {
$this->add_action_handler($action, $id);
}
}
$button->initialise_js($this->page);
// first the input element
$output = html_writer::empty_tag('input', $attributes);
// then hidden fields
$params = $button->url->params();
if ($button->method === 'post') {
$params['sesskey'] = sesskey();
}
foreach ($params as $var => $val) {
$output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $var, 'value' => $val));
}
// then div wrapper for xhtml strictness
$output = html_writer::tag('div', $output);
// now the form itself around it
if ($button->method === 'get') {
$url = $button->url->out_omit_querystring(true); // url without params, the anchor part allowed
} else {
$url = $button->url->out_omit_querystring(); // url without params, the anchor part not allowed
}
if ($url === '') {
$url = '#'; // there has to be always some action
}
$attributes = array('method' => $button->method,
'action' => $url,
'id' => $button->formid);
$output = html_writer::tag('form', $output, $attributes);
// and finally one more wrapper with class
return html_writer::tag('div', $output, array('class' => $button->class));
} | php | protected function render_enrol_user_button(enrol_user_button $button) {
$attributes = array('type' => 'submit',
'value' => $button->label,
'disabled' => $button->disabled ? 'disabled' : null,
'title' => $button->tooltip,
'class' => 'btn btn-secondary my-1');
if ($button->actions) {
$id = html_writer::random_id('single_button');
$attributes['id'] = $id;
foreach ($button->actions as $action) {
$this->add_action_handler($action, $id);
}
}
$button->initialise_js($this->page);
// first the input element
$output = html_writer::empty_tag('input', $attributes);
// then hidden fields
$params = $button->url->params();
if ($button->method === 'post') {
$params['sesskey'] = sesskey();
}
foreach ($params as $var => $val) {
$output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $var, 'value' => $val));
}
// then div wrapper for xhtml strictness
$output = html_writer::tag('div', $output);
// now the form itself around it
if ($button->method === 'get') {
$url = $button->url->out_omit_querystring(true); // url without params, the anchor part allowed
} else {
$url = $button->url->out_omit_querystring(); // url without params, the anchor part not allowed
}
if ($url === '') {
$url = '#'; // there has to be always some action
}
$attributes = array('method' => $button->method,
'action' => $url,
'id' => $button->formid);
$output = html_writer::tag('form', $output, $attributes);
// and finally one more wrapper with class
return html_writer::tag('div', $output, array('class' => $button->class));
} | [
"protected",
"function",
"render_enrol_user_button",
"(",
"enrol_user_button",
"$",
"button",
")",
"{",
"$",
"attributes",
"=",
"array",
"(",
"'type'",
"=>",
"'submit'",
",",
"'value'",
"=>",
"$",
"button",
"->",
"label",
",",
"'disabled'",
"=>",
"$",
"button",
"->",
"disabled",
"?",
"'disabled'",
":",
"null",
",",
"'title'",
"=>",
"$",
"button",
"->",
"tooltip",
",",
"'class'",
"=>",
"'btn btn-secondary my-1'",
")",
";",
"if",
"(",
"$",
"button",
"->",
"actions",
")",
"{",
"$",
"id",
"=",
"html_writer",
"::",
"random_id",
"(",
"'single_button'",
")",
";",
"$",
"attributes",
"[",
"'id'",
"]",
"=",
"$",
"id",
";",
"foreach",
"(",
"$",
"button",
"->",
"actions",
"as",
"$",
"action",
")",
"{",
"$",
"this",
"->",
"add_action_handler",
"(",
"$",
"action",
",",
"$",
"id",
")",
";",
"}",
"}",
"$",
"button",
"->",
"initialise_js",
"(",
"$",
"this",
"->",
"page",
")",
";",
"// first the input element",
"$",
"output",
"=",
"html_writer",
"::",
"empty_tag",
"(",
"'input'",
",",
"$",
"attributes",
")",
";",
"// then hidden fields",
"$",
"params",
"=",
"$",
"button",
"->",
"url",
"->",
"params",
"(",
")",
";",
"if",
"(",
"$",
"button",
"->",
"method",
"===",
"'post'",
")",
"{",
"$",
"params",
"[",
"'sesskey'",
"]",
"=",
"sesskey",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"params",
"as",
"$",
"var",
"=>",
"$",
"val",
")",
"{",
"$",
"output",
".=",
"html_writer",
"::",
"empty_tag",
"(",
"'input'",
",",
"array",
"(",
"'type'",
"=>",
"'hidden'",
",",
"'name'",
"=>",
"$",
"var",
",",
"'value'",
"=>",
"$",
"val",
")",
")",
";",
"}",
"// then div wrapper for xhtml strictness",
"$",
"output",
"=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"$",
"output",
")",
";",
"// now the form itself around it",
"if",
"(",
"$",
"button",
"->",
"method",
"===",
"'get'",
")",
"{",
"$",
"url",
"=",
"$",
"button",
"->",
"url",
"->",
"out_omit_querystring",
"(",
"true",
")",
";",
"// url without params, the anchor part allowed",
"}",
"else",
"{",
"$",
"url",
"=",
"$",
"button",
"->",
"url",
"->",
"out_omit_querystring",
"(",
")",
";",
"// url without params, the anchor part not allowed",
"}",
"if",
"(",
"$",
"url",
"===",
"''",
")",
"{",
"$",
"url",
"=",
"'#'",
";",
"// there has to be always some action",
"}",
"$",
"attributes",
"=",
"array",
"(",
"'method'",
"=>",
"$",
"button",
"->",
"method",
",",
"'action'",
"=>",
"$",
"url",
",",
"'id'",
"=>",
"$",
"button",
"->",
"formid",
")",
";",
"$",
"output",
"=",
"html_writer",
"::",
"tag",
"(",
"'form'",
",",
"$",
"output",
",",
"$",
"attributes",
")",
";",
"// and finally one more wrapper with class",
"return",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"$",
"output",
",",
"array",
"(",
"'class'",
"=>",
"$",
"button",
"->",
"class",
")",
")",
";",
"}"
] | Renderers the enrol_user_button.
@param enrol_user_button $button
@return string XHTML | [
"Renderers",
"the",
"enrol_user_button",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/renderer.php#L39-L86 |
212,720 | moodle/moodle | enrol/renderer.php | core_enrol_renderer.render_course_enrolment_other_users_table | protected function render_course_enrolment_other_users_table(course_enrolment_other_users_table $table) {
$table->initialise_javascript();
$content = '';
$searchbutton = $table->get_user_search_button();
if ($searchbutton) {
$content .= $this->output->render($searchbutton);
}
$content .= html_writer::tag('div', get_string('otheruserdesc', 'enrol'), array('class'=>'otherusersdesc'));
$content .= $this->output->render($table->get_paging_bar());
$content .= html_writer::table($table);
$content .= $this->output->render($table->get_paging_bar());
$searchbutton = $table->get_user_search_button();
if ($searchbutton) {
$content .= $this->output->render($searchbutton);
}
return $content;
} | php | protected function render_course_enrolment_other_users_table(course_enrolment_other_users_table $table) {
$table->initialise_javascript();
$content = '';
$searchbutton = $table->get_user_search_button();
if ($searchbutton) {
$content .= $this->output->render($searchbutton);
}
$content .= html_writer::tag('div', get_string('otheruserdesc', 'enrol'), array('class'=>'otherusersdesc'));
$content .= $this->output->render($table->get_paging_bar());
$content .= html_writer::table($table);
$content .= $this->output->render($table->get_paging_bar());
$searchbutton = $table->get_user_search_button();
if ($searchbutton) {
$content .= $this->output->render($searchbutton);
}
return $content;
} | [
"protected",
"function",
"render_course_enrolment_other_users_table",
"(",
"course_enrolment_other_users_table",
"$",
"table",
")",
"{",
"$",
"table",
"->",
"initialise_javascript",
"(",
")",
";",
"$",
"content",
"=",
"''",
";",
"$",
"searchbutton",
"=",
"$",
"table",
"->",
"get_user_search_button",
"(",
")",
";",
"if",
"(",
"$",
"searchbutton",
")",
"{",
"$",
"content",
".=",
"$",
"this",
"->",
"output",
"->",
"render",
"(",
"$",
"searchbutton",
")",
";",
"}",
"$",
"content",
".=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"get_string",
"(",
"'otheruserdesc'",
",",
"'enrol'",
")",
",",
"array",
"(",
"'class'",
"=>",
"'otherusersdesc'",
")",
")",
";",
"$",
"content",
".=",
"$",
"this",
"->",
"output",
"->",
"render",
"(",
"$",
"table",
"->",
"get_paging_bar",
"(",
")",
")",
";",
"$",
"content",
".=",
"html_writer",
"::",
"table",
"(",
"$",
"table",
")",
";",
"$",
"content",
".=",
"$",
"this",
"->",
"output",
"->",
"render",
"(",
"$",
"table",
"->",
"get_paging_bar",
"(",
")",
")",
";",
"$",
"searchbutton",
"=",
"$",
"table",
"->",
"get_user_search_button",
"(",
")",
";",
"if",
"(",
"$",
"searchbutton",
")",
"{",
"$",
"content",
".=",
"$",
"this",
"->",
"output",
"->",
"render",
"(",
"$",
"searchbutton",
")",
";",
"}",
"return",
"$",
"content",
";",
"}"
] | Renders a course enrolment table
@param course_enrolment_table $table
@return string | [
"Renders",
"a",
"course",
"enrolment",
"table"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/renderer.php#L94-L112 |
212,721 | moodle/moodle | enrol/renderer.php | core_enrol_renderer.user_roles_and_actions | public function user_roles_and_actions($userid, $roles, $assignableroles, $canassign, $pageurl) {
// Get list of roles.
$rolesoutput = '';
foreach ($roles as $roleid=>$role) {
if ($canassign and (is_siteadmin() or isset($assignableroles[$roleid])) and !$role['unchangeable']) {
$strunassign = get_string('unassignarole', 'role', $role['text']);
$icon = $this->output->pix_icon('t/delete', $strunassign);
$url = new moodle_url($pageurl, array('action'=>'unassign', 'roleid'=>$roleid, 'user'=>$userid));
$rolesoutput .= html_writer::tag('div', $role['text'] . html_writer::link($url, $icon, array('class'=>'unassignrolelink', 'rel'=>$roleid, 'title'=>$strunassign)), array('class'=>'role role_'.$roleid));
} else {
$rolesoutput .= html_writer::tag('div', $role['text'], array('class'=>'role unchangeable', 'rel'=>$roleid));
}
}
$output = '';
if (!empty($assignableroles) && $canassign) {
$roleids = array_keys($roles);
$hasallroles = true;
foreach (array_keys($assignableroles) as $key) {
if (!in_array($key, $roleids)) {
$hasallroles = false;
break;
}
}
if (!$hasallroles) {
$url = new moodle_url($pageurl, array('action' => 'assign', 'user' => $userid));
$roleicon = $this->output->pix_icon('i/assignroles', get_string('assignroles', 'role'));
$link = html_writer::link($url, $roleicon, array('class' => 'assignrolelink'));
$output = html_writer::tag('div', $link, array('class'=>'addrole'));
}
}
$output .= html_writer::tag('div', $rolesoutput, array('class'=>'roles'));
return $output;
} | php | public function user_roles_and_actions($userid, $roles, $assignableroles, $canassign, $pageurl) {
// Get list of roles.
$rolesoutput = '';
foreach ($roles as $roleid=>$role) {
if ($canassign and (is_siteadmin() or isset($assignableroles[$roleid])) and !$role['unchangeable']) {
$strunassign = get_string('unassignarole', 'role', $role['text']);
$icon = $this->output->pix_icon('t/delete', $strunassign);
$url = new moodle_url($pageurl, array('action'=>'unassign', 'roleid'=>$roleid, 'user'=>$userid));
$rolesoutput .= html_writer::tag('div', $role['text'] . html_writer::link($url, $icon, array('class'=>'unassignrolelink', 'rel'=>$roleid, 'title'=>$strunassign)), array('class'=>'role role_'.$roleid));
} else {
$rolesoutput .= html_writer::tag('div', $role['text'], array('class'=>'role unchangeable', 'rel'=>$roleid));
}
}
$output = '';
if (!empty($assignableroles) && $canassign) {
$roleids = array_keys($roles);
$hasallroles = true;
foreach (array_keys($assignableroles) as $key) {
if (!in_array($key, $roleids)) {
$hasallroles = false;
break;
}
}
if (!$hasallroles) {
$url = new moodle_url($pageurl, array('action' => 'assign', 'user' => $userid));
$roleicon = $this->output->pix_icon('i/assignroles', get_string('assignroles', 'role'));
$link = html_writer::link($url, $roleicon, array('class' => 'assignrolelink'));
$output = html_writer::tag('div', $link, array('class'=>'addrole'));
}
}
$output .= html_writer::tag('div', $rolesoutput, array('class'=>'roles'));
return $output;
} | [
"public",
"function",
"user_roles_and_actions",
"(",
"$",
"userid",
",",
"$",
"roles",
",",
"$",
"assignableroles",
",",
"$",
"canassign",
",",
"$",
"pageurl",
")",
"{",
"// Get list of roles.",
"$",
"rolesoutput",
"=",
"''",
";",
"foreach",
"(",
"$",
"roles",
"as",
"$",
"roleid",
"=>",
"$",
"role",
")",
"{",
"if",
"(",
"$",
"canassign",
"and",
"(",
"is_siteadmin",
"(",
")",
"or",
"isset",
"(",
"$",
"assignableroles",
"[",
"$",
"roleid",
"]",
")",
")",
"and",
"!",
"$",
"role",
"[",
"'unchangeable'",
"]",
")",
"{",
"$",
"strunassign",
"=",
"get_string",
"(",
"'unassignarole'",
",",
"'role'",
",",
"$",
"role",
"[",
"'text'",
"]",
")",
";",
"$",
"icon",
"=",
"$",
"this",
"->",
"output",
"->",
"pix_icon",
"(",
"'t/delete'",
",",
"$",
"strunassign",
")",
";",
"$",
"url",
"=",
"new",
"moodle_url",
"(",
"$",
"pageurl",
",",
"array",
"(",
"'action'",
"=>",
"'unassign'",
",",
"'roleid'",
"=>",
"$",
"roleid",
",",
"'user'",
"=>",
"$",
"userid",
")",
")",
";",
"$",
"rolesoutput",
".=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"$",
"role",
"[",
"'text'",
"]",
".",
"html_writer",
"::",
"link",
"(",
"$",
"url",
",",
"$",
"icon",
",",
"array",
"(",
"'class'",
"=>",
"'unassignrolelink'",
",",
"'rel'",
"=>",
"$",
"roleid",
",",
"'title'",
"=>",
"$",
"strunassign",
")",
")",
",",
"array",
"(",
"'class'",
"=>",
"'role role_'",
".",
"$",
"roleid",
")",
")",
";",
"}",
"else",
"{",
"$",
"rolesoutput",
".=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"$",
"role",
"[",
"'text'",
"]",
",",
"array",
"(",
"'class'",
"=>",
"'role unchangeable'",
",",
"'rel'",
"=>",
"$",
"roleid",
")",
")",
";",
"}",
"}",
"$",
"output",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"assignableroles",
")",
"&&",
"$",
"canassign",
")",
"{",
"$",
"roleids",
"=",
"array_keys",
"(",
"$",
"roles",
")",
";",
"$",
"hasallroles",
"=",
"true",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"assignableroles",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"$",
"roleids",
")",
")",
"{",
"$",
"hasallroles",
"=",
"false",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"hasallroles",
")",
"{",
"$",
"url",
"=",
"new",
"moodle_url",
"(",
"$",
"pageurl",
",",
"array",
"(",
"'action'",
"=>",
"'assign'",
",",
"'user'",
"=>",
"$",
"userid",
")",
")",
";",
"$",
"roleicon",
"=",
"$",
"this",
"->",
"output",
"->",
"pix_icon",
"(",
"'i/assignroles'",
",",
"get_string",
"(",
"'assignroles'",
",",
"'role'",
")",
")",
";",
"$",
"link",
"=",
"html_writer",
"::",
"link",
"(",
"$",
"url",
",",
"$",
"roleicon",
",",
"array",
"(",
"'class'",
"=>",
"'assignrolelink'",
")",
")",
";",
"$",
"output",
"=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"$",
"link",
",",
"array",
"(",
"'class'",
"=>",
"'addrole'",
")",
")",
";",
"}",
"}",
"$",
"output",
".=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"$",
"rolesoutput",
",",
"array",
"(",
"'class'",
"=>",
"'roles'",
")",
")",
";",
"return",
"$",
"output",
";",
"}"
] | Generates HTML to display the users roles and any available actions
@param int $userid
@param array $roles
@param array $assignableroles
@param moodle_url $pageurl
@return string | [
"Generates",
"HTML",
"to",
"display",
"the",
"users",
"roles",
"and",
"any",
"available",
"actions"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/renderer.php#L123-L156 |
212,722 | moodle/moodle | enrol/renderer.php | core_enrol_renderer.user_groups_and_actions | public function user_groups_and_actions($userid, $groups, $allgroups, $canmanagegroups, $pageurl) {
$groupicon = $this->output->pix_icon('i/group', get_string('addgroup', 'group'));
$groupoutput = '';
foreach($groups as $groupid=>$name) {
if ($canmanagegroups and groups_remove_member_allowed($groupid, $userid)) {
$icon = $this->output->pix_icon('t/delete', get_string('removefromgroup', 'group', $name));
$url = new moodle_url($pageurl, array('action'=>'removemember', 'group'=>$groupid, 'user'=>$userid));
$groupoutput .= html_writer::tag('div', $name . html_writer::link($url, $icon), array('class'=>'group', 'rel'=>$groupid));
} else {
$groupoutput .= html_writer::tag('div', $name, array('class'=>'group', 'rel'=>$groupid));
}
}
$output = '';
if ($canmanagegroups && (count($groups) < count($allgroups))) {
$url = new moodle_url($pageurl, array('action'=>'addmember', 'user'=>$userid));
$output .= html_writer::tag('div', html_writer::link($url, $groupicon), array('class'=>'addgroup'));
}
$output = $output.html_writer::tag('div', $groupoutput, array('class'=>'groups'));
return $output;
} | php | public function user_groups_and_actions($userid, $groups, $allgroups, $canmanagegroups, $pageurl) {
$groupicon = $this->output->pix_icon('i/group', get_string('addgroup', 'group'));
$groupoutput = '';
foreach($groups as $groupid=>$name) {
if ($canmanagegroups and groups_remove_member_allowed($groupid, $userid)) {
$icon = $this->output->pix_icon('t/delete', get_string('removefromgroup', 'group', $name));
$url = new moodle_url($pageurl, array('action'=>'removemember', 'group'=>$groupid, 'user'=>$userid));
$groupoutput .= html_writer::tag('div', $name . html_writer::link($url, $icon), array('class'=>'group', 'rel'=>$groupid));
} else {
$groupoutput .= html_writer::tag('div', $name, array('class'=>'group', 'rel'=>$groupid));
}
}
$output = '';
if ($canmanagegroups && (count($groups) < count($allgroups))) {
$url = new moodle_url($pageurl, array('action'=>'addmember', 'user'=>$userid));
$output .= html_writer::tag('div', html_writer::link($url, $groupicon), array('class'=>'addgroup'));
}
$output = $output.html_writer::tag('div', $groupoutput, array('class'=>'groups'));
return $output;
} | [
"public",
"function",
"user_groups_and_actions",
"(",
"$",
"userid",
",",
"$",
"groups",
",",
"$",
"allgroups",
",",
"$",
"canmanagegroups",
",",
"$",
"pageurl",
")",
"{",
"$",
"groupicon",
"=",
"$",
"this",
"->",
"output",
"->",
"pix_icon",
"(",
"'i/group'",
",",
"get_string",
"(",
"'addgroup'",
",",
"'group'",
")",
")",
";",
"$",
"groupoutput",
"=",
"''",
";",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"groupid",
"=>",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"canmanagegroups",
"and",
"groups_remove_member_allowed",
"(",
"$",
"groupid",
",",
"$",
"userid",
")",
")",
"{",
"$",
"icon",
"=",
"$",
"this",
"->",
"output",
"->",
"pix_icon",
"(",
"'t/delete'",
",",
"get_string",
"(",
"'removefromgroup'",
",",
"'group'",
",",
"$",
"name",
")",
")",
";",
"$",
"url",
"=",
"new",
"moodle_url",
"(",
"$",
"pageurl",
",",
"array",
"(",
"'action'",
"=>",
"'removemember'",
",",
"'group'",
"=>",
"$",
"groupid",
",",
"'user'",
"=>",
"$",
"userid",
")",
")",
";",
"$",
"groupoutput",
".=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"$",
"name",
".",
"html_writer",
"::",
"link",
"(",
"$",
"url",
",",
"$",
"icon",
")",
",",
"array",
"(",
"'class'",
"=>",
"'group'",
",",
"'rel'",
"=>",
"$",
"groupid",
")",
")",
";",
"}",
"else",
"{",
"$",
"groupoutput",
".=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"$",
"name",
",",
"array",
"(",
"'class'",
"=>",
"'group'",
",",
"'rel'",
"=>",
"$",
"groupid",
")",
")",
";",
"}",
"}",
"$",
"output",
"=",
"''",
";",
"if",
"(",
"$",
"canmanagegroups",
"&&",
"(",
"count",
"(",
"$",
"groups",
")",
"<",
"count",
"(",
"$",
"allgroups",
")",
")",
")",
"{",
"$",
"url",
"=",
"new",
"moodle_url",
"(",
"$",
"pageurl",
",",
"array",
"(",
"'action'",
"=>",
"'addmember'",
",",
"'user'",
"=>",
"$",
"userid",
")",
")",
";",
"$",
"output",
".=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"html_writer",
"::",
"link",
"(",
"$",
"url",
",",
"$",
"groupicon",
")",
",",
"array",
"(",
"'class'",
"=>",
"'addgroup'",
")",
")",
";",
"}",
"$",
"output",
"=",
"$",
"output",
".",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"$",
"groupoutput",
",",
"array",
"(",
"'class'",
"=>",
"'groups'",
")",
")",
";",
"return",
"$",
"output",
";",
"}"
] | Generates the HTML to view the users groups and available group actions
@param int $userid
@param array $groups
@param array $allgroups
@param bool $canmanagegroups
@param moodle_url $pageurl
@return string | [
"Generates",
"the",
"HTML",
"to",
"view",
"the",
"users",
"groups",
"and",
"available",
"group",
"actions"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/renderer.php#L168-L188 |
212,723 | moodle/moodle | enrol/renderer.php | core_enrol_renderer.user_enrolments_and_actions | public function user_enrolments_and_actions($enrolments) {
$output = '';
foreach ($enrolments as $ue) {
$enrolmentoutput = $ue['text'].' '.$ue['period'];
if ($ue['dimmed']) {
$enrolmentoutput = html_writer::tag('span', $enrolmentoutput, array('class'=>'dimmed_text'));
} else {
$enrolmentoutput = html_writer::tag('span', $enrolmentoutput);
}
foreach ($ue['actions'] as $action) {
$enrolmentoutput .= $this->render($action);
}
$output .= html_writer::tag('div', $enrolmentoutput, array('class'=>'enrolment'));
}
return $output;
} | php | public function user_enrolments_and_actions($enrolments) {
$output = '';
foreach ($enrolments as $ue) {
$enrolmentoutput = $ue['text'].' '.$ue['period'];
if ($ue['dimmed']) {
$enrolmentoutput = html_writer::tag('span', $enrolmentoutput, array('class'=>'dimmed_text'));
} else {
$enrolmentoutput = html_writer::tag('span', $enrolmentoutput);
}
foreach ($ue['actions'] as $action) {
$enrolmentoutput .= $this->render($action);
}
$output .= html_writer::tag('div', $enrolmentoutput, array('class'=>'enrolment'));
}
return $output;
} | [
"public",
"function",
"user_enrolments_and_actions",
"(",
"$",
"enrolments",
")",
"{",
"$",
"output",
"=",
"''",
";",
"foreach",
"(",
"$",
"enrolments",
"as",
"$",
"ue",
")",
"{",
"$",
"enrolmentoutput",
"=",
"$",
"ue",
"[",
"'text'",
"]",
".",
"' '",
".",
"$",
"ue",
"[",
"'period'",
"]",
";",
"if",
"(",
"$",
"ue",
"[",
"'dimmed'",
"]",
")",
"{",
"$",
"enrolmentoutput",
"=",
"html_writer",
"::",
"tag",
"(",
"'span'",
",",
"$",
"enrolmentoutput",
",",
"array",
"(",
"'class'",
"=>",
"'dimmed_text'",
")",
")",
";",
"}",
"else",
"{",
"$",
"enrolmentoutput",
"=",
"html_writer",
"::",
"tag",
"(",
"'span'",
",",
"$",
"enrolmentoutput",
")",
";",
"}",
"foreach",
"(",
"$",
"ue",
"[",
"'actions'",
"]",
"as",
"$",
"action",
")",
"{",
"$",
"enrolmentoutput",
".=",
"$",
"this",
"->",
"render",
"(",
"$",
"action",
")",
";",
"}",
"$",
"output",
".=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"$",
"enrolmentoutput",
",",
"array",
"(",
"'class'",
"=>",
"'enrolment'",
")",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | Generates the HTML for the given enrolments + available actions
@param int $userid
@param array $enrolments
@param moodle_url $pageurl
@return string | [
"Generates",
"the",
"HTML",
"for",
"the",
"given",
"enrolments",
"+",
"available",
"actions"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/renderer.php#L198-L213 |
212,724 | moodle/moodle | enrol/renderer.php | core_enrol_renderer.render_user_enrolment_action | protected function render_user_enrolment_action(user_enrolment_action $icon) {
return html_writer::link($icon->get_url(), $this->output->render($icon->get_icon()), $icon->get_attributes());
} | php | protected function render_user_enrolment_action(user_enrolment_action $icon) {
return html_writer::link($icon->get_url(), $this->output->render($icon->get_icon()), $icon->get_attributes());
} | [
"protected",
"function",
"render_user_enrolment_action",
"(",
"user_enrolment_action",
"$",
"icon",
")",
"{",
"return",
"html_writer",
"::",
"link",
"(",
"$",
"icon",
"->",
"get_url",
"(",
")",
",",
"$",
"this",
"->",
"output",
"->",
"render",
"(",
"$",
"icon",
"->",
"get_icon",
"(",
")",
")",
",",
"$",
"icon",
"->",
"get_attributes",
"(",
")",
")",
";",
"}"
] | Renders a user enrolment action
@param user_enrolment_action $icon
@return string | [
"Renders",
"a",
"user",
"enrolment",
"action"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/renderer.php#L220-L222 |
212,725 | moodle/moodle | enrol/renderer.php | course_enrolment_table.set_fields | public function set_fields($fields, $output) {
$this->fields = $fields;
$this->head = array();
$this->colclasses = array();
$this->align = array();
$url = $this->manager->get_moodlepage()->url;
if (!empty($this->bulkoperations)) {
// If there are bulk operations add a column for checkboxes.
$this->head[] = '';
$this->colclasses[] = 'field col_bulkops';
}
foreach ($fields as $name => $label) {
$newlabel = '';
if (is_array($label)) {
$bits = array();
foreach ($label as $n => $l) {
if ($l === false) {
continue;
}
if (!in_array($n, self::$sortablefields)) {
$bits[] = $l;
} else {
$sorturl = new moodle_url($url, array(self::SORTVAR => $n, self::SORTDIRECTIONVAR => $this->get_field_sort_direction($n)));
$link = html_writer::link($sorturl, $fields[$name][$n]);
if ($this->sort == $n) {
$link .= $this->get_direction_icon($output, $n);
}
$bits[] = html_writer::tag('span', $link, array('class'=>'subheading_'.$n));
}
}
$newlabel = join(' / ', $bits);
} else {
if (!in_array($name, self::$sortablefields)) {
$newlabel = $label;
} else {
$sorturl = new moodle_url($url, array(self::SORTVAR => $name, self::SORTDIRECTIONVAR => $this->get_field_sort_direction($name)));
$newlabel = html_writer::link($sorturl, $fields[$name]);
if ($this->sort == $name) {
$newlabel .= $this->get_direction_icon($output, $name);
}
}
}
$this->head[] = $newlabel;
$this->colclasses[] = 'field col_'.$name;
}
} | php | public function set_fields($fields, $output) {
$this->fields = $fields;
$this->head = array();
$this->colclasses = array();
$this->align = array();
$url = $this->manager->get_moodlepage()->url;
if (!empty($this->bulkoperations)) {
// If there are bulk operations add a column for checkboxes.
$this->head[] = '';
$this->colclasses[] = 'field col_bulkops';
}
foreach ($fields as $name => $label) {
$newlabel = '';
if (is_array($label)) {
$bits = array();
foreach ($label as $n => $l) {
if ($l === false) {
continue;
}
if (!in_array($n, self::$sortablefields)) {
$bits[] = $l;
} else {
$sorturl = new moodle_url($url, array(self::SORTVAR => $n, self::SORTDIRECTIONVAR => $this->get_field_sort_direction($n)));
$link = html_writer::link($sorturl, $fields[$name][$n]);
if ($this->sort == $n) {
$link .= $this->get_direction_icon($output, $n);
}
$bits[] = html_writer::tag('span', $link, array('class'=>'subheading_'.$n));
}
}
$newlabel = join(' / ', $bits);
} else {
if (!in_array($name, self::$sortablefields)) {
$newlabel = $label;
} else {
$sorturl = new moodle_url($url, array(self::SORTVAR => $name, self::SORTDIRECTIONVAR => $this->get_field_sort_direction($name)));
$newlabel = html_writer::link($sorturl, $fields[$name]);
if ($this->sort == $name) {
$newlabel .= $this->get_direction_icon($output, $name);
}
}
}
$this->head[] = $newlabel;
$this->colclasses[] = 'field col_'.$name;
}
} | [
"public",
"function",
"set_fields",
"(",
"$",
"fields",
",",
"$",
"output",
")",
"{",
"$",
"this",
"->",
"fields",
"=",
"$",
"fields",
";",
"$",
"this",
"->",
"head",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"colclasses",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"align",
"=",
"array",
"(",
")",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"manager",
"->",
"get_moodlepage",
"(",
")",
"->",
"url",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"bulkoperations",
")",
")",
"{",
"// If there are bulk operations add a column for checkboxes.",
"$",
"this",
"->",
"head",
"[",
"]",
"=",
"''",
";",
"$",
"this",
"->",
"colclasses",
"[",
"]",
"=",
"'field col_bulkops'",
";",
"}",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"name",
"=>",
"$",
"label",
")",
"{",
"$",
"newlabel",
"=",
"''",
";",
"if",
"(",
"is_array",
"(",
"$",
"label",
")",
")",
"{",
"$",
"bits",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"label",
"as",
"$",
"n",
"=>",
"$",
"l",
")",
"{",
"if",
"(",
"$",
"l",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"n",
",",
"self",
"::",
"$",
"sortablefields",
")",
")",
"{",
"$",
"bits",
"[",
"]",
"=",
"$",
"l",
";",
"}",
"else",
"{",
"$",
"sorturl",
"=",
"new",
"moodle_url",
"(",
"$",
"url",
",",
"array",
"(",
"self",
"::",
"SORTVAR",
"=>",
"$",
"n",
",",
"self",
"::",
"SORTDIRECTIONVAR",
"=>",
"$",
"this",
"->",
"get_field_sort_direction",
"(",
"$",
"n",
")",
")",
")",
";",
"$",
"link",
"=",
"html_writer",
"::",
"link",
"(",
"$",
"sorturl",
",",
"$",
"fields",
"[",
"$",
"name",
"]",
"[",
"$",
"n",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"sort",
"==",
"$",
"n",
")",
"{",
"$",
"link",
".=",
"$",
"this",
"->",
"get_direction_icon",
"(",
"$",
"output",
",",
"$",
"n",
")",
";",
"}",
"$",
"bits",
"[",
"]",
"=",
"html_writer",
"::",
"tag",
"(",
"'span'",
",",
"$",
"link",
",",
"array",
"(",
"'class'",
"=>",
"'subheading_'",
".",
"$",
"n",
")",
")",
";",
"}",
"}",
"$",
"newlabel",
"=",
"join",
"(",
"' / '",
",",
"$",
"bits",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"name",
",",
"self",
"::",
"$",
"sortablefields",
")",
")",
"{",
"$",
"newlabel",
"=",
"$",
"label",
";",
"}",
"else",
"{",
"$",
"sorturl",
"=",
"new",
"moodle_url",
"(",
"$",
"url",
",",
"array",
"(",
"self",
"::",
"SORTVAR",
"=>",
"$",
"name",
",",
"self",
"::",
"SORTDIRECTIONVAR",
"=>",
"$",
"this",
"->",
"get_field_sort_direction",
"(",
"$",
"name",
")",
")",
")",
";",
"$",
"newlabel",
"=",
"html_writer",
"::",
"link",
"(",
"$",
"sorturl",
",",
"$",
"fields",
"[",
"$",
"name",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"sort",
"==",
"$",
"name",
")",
"{",
"$",
"newlabel",
".=",
"$",
"this",
"->",
"get_direction_icon",
"(",
"$",
"output",
",",
"$",
"name",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"head",
"[",
"]",
"=",
"$",
"newlabel",
";",
"$",
"this",
"->",
"colclasses",
"[",
"]",
"=",
"'field col_'",
".",
"$",
"name",
";",
"}",
"}"
] | Sets the fields for this table. These get added to the tables head as well.
You can also use a multi dimensional array for this to have multiple fields
in a single column
@param array $fields An array of fields to set
@param string $output | [
"Sets",
"the",
"fields",
"for",
"this",
"table",
".",
"These",
"get",
"added",
"to",
"the",
"tables",
"head",
"as",
"well",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/renderer.php#L425-L473 |
212,726 | moodle/moodle | enrol/renderer.php | course_enrolment_table.set_total_users | public function set_total_users($totalusers) {
$this->totalusers = $totalusers;
$this->pages = ceil($this->totalusers / $this->perpage);
if ($this->page > $this->pages) {
$this->page = $this->pages;
}
} | php | public function set_total_users($totalusers) {
$this->totalusers = $totalusers;
$this->pages = ceil($this->totalusers / $this->perpage);
if ($this->page > $this->pages) {
$this->page = $this->pages;
}
} | [
"public",
"function",
"set_total_users",
"(",
"$",
"totalusers",
")",
"{",
"$",
"this",
"->",
"totalusers",
"=",
"$",
"totalusers",
";",
"$",
"this",
"->",
"pages",
"=",
"ceil",
"(",
"$",
"this",
"->",
"totalusers",
"/",
"$",
"this",
"->",
"perpage",
")",
";",
"if",
"(",
"$",
"this",
"->",
"page",
">",
"$",
"this",
"->",
"pages",
")",
"{",
"$",
"this",
"->",
"page",
"=",
"$",
"this",
"->",
"pages",
";",
"}",
"}"
] | Sets the total number of users
@param int $totalusers | [
"Sets",
"the",
"total",
"number",
"of",
"users"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/renderer.php#L479-L485 |
212,727 | moodle/moodle | enrol/renderer.php | course_enrolment_table.set_users | public function set_users(array $users) {
$this->users = $users;
$hasbulkops = !empty($this->bulkoperations);
foreach ($users as $userid=>$user) {
$user = (array)$user;
$row = new html_table_row();
$row->attributes = array('class' => 'userinforow');
$row->id = 'user_'.$userid;
$row->cells = array();
if ($hasbulkops) {
// Add a checkbox into the first column.
$input = html_writer::empty_tag('input', array('type' => 'checkbox', 'name' => 'bulkuser[]', 'value' => $userid));
$row->cells[] = new html_table_cell($input);
}
foreach ($this->fields as $field => $label) {
if (is_array($label)) {
$bits = array();
foreach (array_keys($label) as $subfield) {
if (array_key_exists($subfield, $user)) {
$bits[] = html_writer::tag('div', $user[$subfield], array('class'=>'subfield subfield_'.$subfield));
}
}
if (empty($bits)) {
$bits[] = ' ';
}
$row->cells[] = new html_table_cell(join(' ', $bits));
} else {
if (!array_key_exists($field, $user)) {
$user[$field] = ' ';
}
$row->cells[] = new html_table_cell($user[$field]);
}
}
$this->data[] = $row;
}
} | php | public function set_users(array $users) {
$this->users = $users;
$hasbulkops = !empty($this->bulkoperations);
foreach ($users as $userid=>$user) {
$user = (array)$user;
$row = new html_table_row();
$row->attributes = array('class' => 'userinforow');
$row->id = 'user_'.$userid;
$row->cells = array();
if ($hasbulkops) {
// Add a checkbox into the first column.
$input = html_writer::empty_tag('input', array('type' => 'checkbox', 'name' => 'bulkuser[]', 'value' => $userid));
$row->cells[] = new html_table_cell($input);
}
foreach ($this->fields as $field => $label) {
if (is_array($label)) {
$bits = array();
foreach (array_keys($label) as $subfield) {
if (array_key_exists($subfield, $user)) {
$bits[] = html_writer::tag('div', $user[$subfield], array('class'=>'subfield subfield_'.$subfield));
}
}
if (empty($bits)) {
$bits[] = ' ';
}
$row->cells[] = new html_table_cell(join(' ', $bits));
} else {
if (!array_key_exists($field, $user)) {
$user[$field] = ' ';
}
$row->cells[] = new html_table_cell($user[$field]);
}
}
$this->data[] = $row;
}
} | [
"public",
"function",
"set_users",
"(",
"array",
"$",
"users",
")",
"{",
"$",
"this",
"->",
"users",
"=",
"$",
"users",
";",
"$",
"hasbulkops",
"=",
"!",
"empty",
"(",
"$",
"this",
"->",
"bulkoperations",
")",
";",
"foreach",
"(",
"$",
"users",
"as",
"$",
"userid",
"=>",
"$",
"user",
")",
"{",
"$",
"user",
"=",
"(",
"array",
")",
"$",
"user",
";",
"$",
"row",
"=",
"new",
"html_table_row",
"(",
")",
";",
"$",
"row",
"->",
"attributes",
"=",
"array",
"(",
"'class'",
"=>",
"'userinforow'",
")",
";",
"$",
"row",
"->",
"id",
"=",
"'user_'",
".",
"$",
"userid",
";",
"$",
"row",
"->",
"cells",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"hasbulkops",
")",
"{",
"// Add a checkbox into the first column.",
"$",
"input",
"=",
"html_writer",
"::",
"empty_tag",
"(",
"'input'",
",",
"array",
"(",
"'type'",
"=>",
"'checkbox'",
",",
"'name'",
"=>",
"'bulkuser[]'",
",",
"'value'",
"=>",
"$",
"userid",
")",
")",
";",
"$",
"row",
"->",
"cells",
"[",
"]",
"=",
"new",
"html_table_cell",
"(",
"$",
"input",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"as",
"$",
"field",
"=>",
"$",
"label",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"label",
")",
")",
"{",
"$",
"bits",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"label",
")",
"as",
"$",
"subfield",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"subfield",
",",
"$",
"user",
")",
")",
"{",
"$",
"bits",
"[",
"]",
"=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"$",
"user",
"[",
"$",
"subfield",
"]",
",",
"array",
"(",
"'class'",
"=>",
"'subfield subfield_'",
".",
"$",
"subfield",
")",
")",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"bits",
")",
")",
"{",
"$",
"bits",
"[",
"]",
"=",
"' '",
";",
"}",
"$",
"row",
"->",
"cells",
"[",
"]",
"=",
"new",
"html_table_cell",
"(",
"join",
"(",
"' '",
",",
"$",
"bits",
")",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"field",
",",
"$",
"user",
")",
")",
"{",
"$",
"user",
"[",
"$",
"field",
"]",
"=",
"' '",
";",
"}",
"$",
"row",
"->",
"cells",
"[",
"]",
"=",
"new",
"html_table_cell",
"(",
"$",
"user",
"[",
"$",
"field",
"]",
")",
";",
"}",
"}",
"$",
"this",
"->",
"data",
"[",
"]",
"=",
"$",
"row",
";",
"}",
"}"
] | Sets the users for this table
@param array $users
@return void | [
"Sets",
"the",
"users",
"for",
"this",
"table"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/renderer.php#L492-L527 |
212,728 | moodle/moodle | enrol/renderer.php | course_enrolment_table.get_paging_bar | public function get_paging_bar() {
if ($this->pagingbar == null) {
$this->pagingbar = new paging_bar($this->totalusers, $this->page, $this->perpage, $this->manager->get_moodlepage()->url, self::PAGEVAR);
}
return $this->pagingbar;
} | php | public function get_paging_bar() {
if ($this->pagingbar == null) {
$this->pagingbar = new paging_bar($this->totalusers, $this->page, $this->perpage, $this->manager->get_moodlepage()->url, self::PAGEVAR);
}
return $this->pagingbar;
} | [
"public",
"function",
"get_paging_bar",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"pagingbar",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"pagingbar",
"=",
"new",
"paging_bar",
"(",
"$",
"this",
"->",
"totalusers",
",",
"$",
"this",
"->",
"page",
",",
"$",
"this",
"->",
"perpage",
",",
"$",
"this",
"->",
"manager",
"->",
"get_moodlepage",
"(",
")",
"->",
"url",
",",
"self",
"::",
"PAGEVAR",
")",
";",
"}",
"return",
"$",
"this",
"->",
"pagingbar",
";",
"}"
] | Gets the paging bar instance for this table
@return paging_bar | [
"Gets",
"the",
"paging",
"bar",
"instance",
"for",
"this",
"table"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/renderer.php#L554-L559 |
212,729 | moodle/moodle | enrol/renderer.php | course_enrolment_table.get_direction_icon | protected function get_direction_icon($output, $field) {
$direction = self::DEFAULTSORTDIRECTION;
if ($this->sort == $field) {
$direction = $this->sortdirection;
}
if ($direction === 'ASC') {
return $output->pix_icon('t/sort_asc', get_string('sort'));
} else {
return $output->pix_icon('t/sort_desc', get_string('sort'));
}
} | php | protected function get_direction_icon($output, $field) {
$direction = self::DEFAULTSORTDIRECTION;
if ($this->sort == $field) {
$direction = $this->sortdirection;
}
if ($direction === 'ASC') {
return $output->pix_icon('t/sort_asc', get_string('sort'));
} else {
return $output->pix_icon('t/sort_desc', get_string('sort'));
}
} | [
"protected",
"function",
"get_direction_icon",
"(",
"$",
"output",
",",
"$",
"field",
")",
"{",
"$",
"direction",
"=",
"self",
"::",
"DEFAULTSORTDIRECTION",
";",
"if",
"(",
"$",
"this",
"->",
"sort",
"==",
"$",
"field",
")",
"{",
"$",
"direction",
"=",
"$",
"this",
"->",
"sortdirection",
";",
"}",
"if",
"(",
"$",
"direction",
"===",
"'ASC'",
")",
"{",
"return",
"$",
"output",
"->",
"pix_icon",
"(",
"'t/sort_asc'",
",",
"get_string",
"(",
"'sort'",
")",
")",
";",
"}",
"else",
"{",
"return",
"$",
"output",
"->",
"pix_icon",
"(",
"'t/sort_desc'",
",",
"get_string",
"(",
"'sort'",
")",
")",
";",
"}",
"}"
] | Gets the direction icon for the sortable field within this table
@param core_renderer $output
@param string $field
@return string | [
"Gets",
"the",
"direction",
"icon",
"for",
"the",
"sortable",
"field",
"within",
"this",
"table"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/renderer.php#L568-L578 |
212,730 | moodle/moodle | enrol/renderer.php | course_enrolment_table.get_url_params | public function get_url_params() {
return array(
self::PAGEVAR => $this->page,
self::PERPAGEVAR => $this->perpage,
self::SORTVAR => $this->sort,
self::SORTDIRECTIONVAR => $this->sortdirection
);
} | php | public function get_url_params() {
return array(
self::PAGEVAR => $this->page,
self::PERPAGEVAR => $this->perpage,
self::SORTVAR => $this->sort,
self::SORTDIRECTIONVAR => $this->sortdirection
);
} | [
"public",
"function",
"get_url_params",
"(",
")",
"{",
"return",
"array",
"(",
"self",
"::",
"PAGEVAR",
"=>",
"$",
"this",
"->",
"page",
",",
"self",
"::",
"PERPAGEVAR",
"=>",
"$",
"this",
"->",
"perpage",
",",
"self",
"::",
"SORTVAR",
"=>",
"$",
"this",
"->",
"sort",
",",
"self",
"::",
"SORTDIRECTIONVAR",
"=>",
"$",
"this",
"->",
"sortdirection",
")",
";",
"}"
] | Gets the params that will need to be added to the url in order to return to this page.
@return array | [
"Gets",
"the",
"params",
"that",
"will",
"need",
"to",
"be",
"added",
"to",
"the",
"url",
"in",
"order",
"to",
"return",
"to",
"this",
"page",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/renderer.php#L585-L592 |
212,731 | moodle/moodle | enrol/renderer.php | course_enrolment_other_users_table.get_user_search_button | public function get_user_search_button() {
static $count = 0;
if (!has_capability('moodle/role:assign', $this->manager->get_context())) {
return false;
}
$count++;
$url = new moodle_url('/admin/roles/assign.php', array('contextid'=>$this->manager->get_context()->id, 'sesskey'=>sesskey()));
$control = new single_button($url, get_string('assignroles', 'role'), 'get');
$control->class = 'singlebutton assignuserrole instance'.$count;
if ($count == 1) {
$this->manager->get_moodlepage()->requires->strings_for_js(array(
'ajaxoneuserfound',
'ajaxxusersfound',
'ajaxxmoreusersfound',
'ajaxnext25',
'enrol',
'enrolmentoptions',
'enrolusers',
'enrolxusers',
'errajaxfailedenrol',
'errajaxsearch',
'foundxcohorts',
'none',
'usersearch',
'unlimitedduration',
'startdatetoday',
'durationdays',
'enrolperiod'), 'enrol');
$this->manager->get_moodlepage()->requires->string_for_js('assignrole', 'role');
$modules = array('moodle-enrol-otherusersmanager', 'moodle-enrol-otherusersmanager-skin');
$function = 'M.enrol.otherusersmanager.init';
$arguments = array(
'courseId'=> $this->manager->get_course()->id,
'ajaxUrl' => '/enrol/ajax.php',
'url' => $this->manager->get_moodlepage()->url->out(false));
$this->manager->get_moodlepage()->requires->yui_module($modules, $function, array($arguments));
}
return $control;
} | php | public function get_user_search_button() {
static $count = 0;
if (!has_capability('moodle/role:assign', $this->manager->get_context())) {
return false;
}
$count++;
$url = new moodle_url('/admin/roles/assign.php', array('contextid'=>$this->manager->get_context()->id, 'sesskey'=>sesskey()));
$control = new single_button($url, get_string('assignroles', 'role'), 'get');
$control->class = 'singlebutton assignuserrole instance'.$count;
if ($count == 1) {
$this->manager->get_moodlepage()->requires->strings_for_js(array(
'ajaxoneuserfound',
'ajaxxusersfound',
'ajaxxmoreusersfound',
'ajaxnext25',
'enrol',
'enrolmentoptions',
'enrolusers',
'enrolxusers',
'errajaxfailedenrol',
'errajaxsearch',
'foundxcohorts',
'none',
'usersearch',
'unlimitedduration',
'startdatetoday',
'durationdays',
'enrolperiod'), 'enrol');
$this->manager->get_moodlepage()->requires->string_for_js('assignrole', 'role');
$modules = array('moodle-enrol-otherusersmanager', 'moodle-enrol-otherusersmanager-skin');
$function = 'M.enrol.otherusersmanager.init';
$arguments = array(
'courseId'=> $this->manager->get_course()->id,
'ajaxUrl' => '/enrol/ajax.php',
'url' => $this->manager->get_moodlepage()->url->out(false));
$this->manager->get_moodlepage()->requires->yui_module($modules, $function, array($arguments));
}
return $control;
} | [
"public",
"function",
"get_user_search_button",
"(",
")",
"{",
"static",
"$",
"count",
"=",
"0",
";",
"if",
"(",
"!",
"has_capability",
"(",
"'moodle/role:assign'",
",",
"$",
"this",
"->",
"manager",
"->",
"get_context",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"count",
"++",
";",
"$",
"url",
"=",
"new",
"moodle_url",
"(",
"'/admin/roles/assign.php'",
",",
"array",
"(",
"'contextid'",
"=>",
"$",
"this",
"->",
"manager",
"->",
"get_context",
"(",
")",
"->",
"id",
",",
"'sesskey'",
"=>",
"sesskey",
"(",
")",
")",
")",
";",
"$",
"control",
"=",
"new",
"single_button",
"(",
"$",
"url",
",",
"get_string",
"(",
"'assignroles'",
",",
"'role'",
")",
",",
"'get'",
")",
";",
"$",
"control",
"->",
"class",
"=",
"'singlebutton assignuserrole instance'",
".",
"$",
"count",
";",
"if",
"(",
"$",
"count",
"==",
"1",
")",
"{",
"$",
"this",
"->",
"manager",
"->",
"get_moodlepage",
"(",
")",
"->",
"requires",
"->",
"strings_for_js",
"(",
"array",
"(",
"'ajaxoneuserfound'",
",",
"'ajaxxusersfound'",
",",
"'ajaxxmoreusersfound'",
",",
"'ajaxnext25'",
",",
"'enrol'",
",",
"'enrolmentoptions'",
",",
"'enrolusers'",
",",
"'enrolxusers'",
",",
"'errajaxfailedenrol'",
",",
"'errajaxsearch'",
",",
"'foundxcohorts'",
",",
"'none'",
",",
"'usersearch'",
",",
"'unlimitedduration'",
",",
"'startdatetoday'",
",",
"'durationdays'",
",",
"'enrolperiod'",
")",
",",
"'enrol'",
")",
";",
"$",
"this",
"->",
"manager",
"->",
"get_moodlepage",
"(",
")",
"->",
"requires",
"->",
"string_for_js",
"(",
"'assignrole'",
",",
"'role'",
")",
";",
"$",
"modules",
"=",
"array",
"(",
"'moodle-enrol-otherusersmanager'",
",",
"'moodle-enrol-otherusersmanager-skin'",
")",
";",
"$",
"function",
"=",
"'M.enrol.otherusersmanager.init'",
";",
"$",
"arguments",
"=",
"array",
"(",
"'courseId'",
"=>",
"$",
"this",
"->",
"manager",
"->",
"get_course",
"(",
")",
"->",
"id",
",",
"'ajaxUrl'",
"=>",
"'/enrol/ajax.php'",
",",
"'url'",
"=>",
"$",
"this",
"->",
"manager",
"->",
"get_moodlepage",
"(",
")",
"->",
"url",
"->",
"out",
"(",
"false",
")",
")",
";",
"$",
"this",
"->",
"manager",
"->",
"get_moodlepage",
"(",
")",
"->",
"requires",
"->",
"yui_module",
"(",
"$",
"modules",
",",
"$",
"function",
",",
"array",
"(",
"$",
"arguments",
")",
")",
";",
"}",
"return",
"$",
"control",
";",
"}"
] | Gets a button to search users and assign them roles in the course.
@staticvar int $count
@param int $page
@return single_button | [
"Gets",
"a",
"button",
"to",
"search",
"users",
"and",
"assign",
"them",
"roles",
"in",
"the",
"course",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/renderer.php#L671-L710 |
212,732 | moodle/moodle | backup/cc/validator.php | cc_validate_type.validate | public function validate($element) {
$this->last_error = null;
$celement = realpath($element);
$cvalidator = realpath($this->location.DIRECTORY_SEPARATOR.$this->type);
$result = (empty($celement) || empty($cvalidator));
if (!$result) {
$xml_error = new libxml_errors_mgr();
$doc = new DOMDocument();
$doc->validateOnParse = false;
$result = $doc->load($celement, LIBXML_NONET) &&
$doc->schemaValidate($cvalidator);
}
return $result;
} | php | public function validate($element) {
$this->last_error = null;
$celement = realpath($element);
$cvalidator = realpath($this->location.DIRECTORY_SEPARATOR.$this->type);
$result = (empty($celement) || empty($cvalidator));
if (!$result) {
$xml_error = new libxml_errors_mgr();
$doc = new DOMDocument();
$doc->validateOnParse = false;
$result = $doc->load($celement, LIBXML_NONET) &&
$doc->schemaValidate($cvalidator);
}
return $result;
} | [
"public",
"function",
"validate",
"(",
"$",
"element",
")",
"{",
"$",
"this",
"->",
"last_error",
"=",
"null",
";",
"$",
"celement",
"=",
"realpath",
"(",
"$",
"element",
")",
";",
"$",
"cvalidator",
"=",
"realpath",
"(",
"$",
"this",
"->",
"location",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"type",
")",
";",
"$",
"result",
"=",
"(",
"empty",
"(",
"$",
"celement",
")",
"||",
"empty",
"(",
"$",
"cvalidator",
")",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"$",
"xml_error",
"=",
"new",
"libxml_errors_mgr",
"(",
")",
";",
"$",
"doc",
"=",
"new",
"DOMDocument",
"(",
")",
";",
"$",
"doc",
"->",
"validateOnParse",
"=",
"false",
";",
"$",
"result",
"=",
"$",
"doc",
"->",
"load",
"(",
"$",
"celement",
",",
"LIBXML_NONET",
")",
"&&",
"$",
"doc",
"->",
"schemaValidate",
"(",
"$",
"cvalidator",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Validates the item
@param string $element - File path for the xml
@return boolean | [
"Validates",
"the",
"item"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/cc/validator.php#L212-L225 |
212,733 | moodle/moodle | lib/horde/framework/Horde/Mime/Headers/ContentParam/ContentType.php | Horde_Mime_Headers_ContentParam_ContentType.create | public static function create()
{
$ob = new stdClass;
$ob->value = self::DEFAULT_CONTENT_TYPE;
return new self(null, $ob);
} | php | public static function create()
{
$ob = new stdClass;
$ob->value = self::DEFAULT_CONTENT_TYPE;
return new self(null, $ob);
} | [
"public",
"static",
"function",
"create",
"(",
")",
"{",
"$",
"ob",
"=",
"new",
"stdClass",
";",
"$",
"ob",
"->",
"value",
"=",
"self",
"::",
"DEFAULT_CONTENT_TYPE",
";",
"return",
"new",
"self",
"(",
"null",
",",
"$",
"ob",
")",
";",
"}"
] | Creates a default Content-Type header, conforming to the MIME
specification as detailed in RFC 2045.
@return Horde_Mime_Headers_ContentParam_ContentType Content-Type
header object. | [
"Creates",
"a",
"default",
"Content",
"-",
"Type",
"header",
"conforming",
"to",
"the",
"MIME",
"specification",
"as",
"detailed",
"in",
"RFC",
"2045",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Headers/ContentParam/ContentType.php#L42-L48 |
212,734 | moodle/moodle | mod/glossary/classes/entry_query_builder.php | mod_glossary_entry_query_builder.add_field | public function add_field($field, $table, $alias = null) {
$field = self::resolve_field($field, $table);
if (!empty($alias)) {
$field .= ' AS ' . $alias;
}
$this->fields[] = $field;
} | php | public function add_field($field, $table, $alias = null) {
$field = self::resolve_field($field, $table);
if (!empty($alias)) {
$field .= ' AS ' . $alias;
}
$this->fields[] = $field;
} | [
"public",
"function",
"add_field",
"(",
"$",
"field",
",",
"$",
"table",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"$",
"field",
"=",
"self",
"::",
"resolve_field",
"(",
"$",
"field",
",",
"$",
"table",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"alias",
")",
")",
"{",
"$",
"field",
".=",
"' AS '",
".",
"$",
"alias",
";",
"}",
"$",
"this",
"->",
"fields",
"[",
"]",
"=",
"$",
"field",
";",
"}"
] | Add a field to select.
@param string $field The field, or *.
@param string $table The table name, without the prefix 'glossary_'.
@param string $alias An alias for the field. | [
"Add",
"a",
"field",
"to",
"select",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/entry_query_builder.php#L106-L112 |
212,735 | moodle/moodle | mod/glossary/classes/entry_query_builder.php | mod_glossary_entry_query_builder.build_query | protected function build_query($count = false) {
$sql = 'SELECT ';
if ($count) {
$sql .= 'COUNT(\'x\') ';
} else {
$sql .= implode(', ', $this->fields) . ' ';
}
$sql .= $this->from . ' ';
$sql .= implode(' ', $this->joins) . ' ';
if (!empty($this->where)) {
$sql .= 'WHERE (' . implode(') AND (', $this->where) . ') ';
}
if (!$count && !empty($this->order)) {
$sql .= 'ORDER BY ' . implode(', ', $this->order);
}
return $sql;
} | php | protected function build_query($count = false) {
$sql = 'SELECT ';
if ($count) {
$sql .= 'COUNT(\'x\') ';
} else {
$sql .= implode(', ', $this->fields) . ' ';
}
$sql .= $this->from . ' ';
$sql .= implode(' ', $this->joins) . ' ';
if (!empty($this->where)) {
$sql .= 'WHERE (' . implode(') AND (', $this->where) . ') ';
}
if (!$count && !empty($this->order)) {
$sql .= 'ORDER BY ' . implode(', ', $this->order);
}
return $sql;
} | [
"protected",
"function",
"build_query",
"(",
"$",
"count",
"=",
"false",
")",
"{",
"$",
"sql",
"=",
"'SELECT '",
";",
"if",
"(",
"$",
"count",
")",
"{",
"$",
"sql",
".=",
"'COUNT(\\'x\\') '",
";",
"}",
"else",
"{",
"$",
"sql",
".=",
"implode",
"(",
"', '",
",",
"$",
"this",
"->",
"fields",
")",
".",
"' '",
";",
"}",
"$",
"sql",
".=",
"$",
"this",
"->",
"from",
".",
"' '",
";",
"$",
"sql",
".=",
"implode",
"(",
"' '",
",",
"$",
"this",
"->",
"joins",
")",
".",
"' '",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"where",
")",
")",
"{",
"$",
"sql",
".=",
"'WHERE ('",
".",
"implode",
"(",
"') AND ('",
",",
"$",
"this",
"->",
"where",
")",
".",
"') '",
";",
"}",
"if",
"(",
"!",
"$",
"count",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"order",
")",
")",
"{",
"$",
"sql",
".=",
"'ORDER BY '",
".",
"implode",
"(",
"', '",
",",
"$",
"this",
"->",
"order",
")",
";",
"}",
"return",
"$",
"sql",
";",
"}"
] | Internal method to build the query.
@param bool $count Query to count?
@return string The SQL statement. | [
"Internal",
"method",
"to",
"build",
"the",
"query",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/entry_query_builder.php#L129-L150 |
212,736 | moodle/moodle | mod/glossary/classes/entry_query_builder.php | mod_glossary_entry_query_builder.filter_by_letter | protected function filter_by_letter($letter, $finalfield) {
global $DB;
$letter = core_text::strtoupper($letter);
$len = core_text::strlen($letter);
$sql = $DB->sql_substr(sprintf('upper(%s)', $finalfield), 1, $len);
$this->where[] = "$sql = :letter";
$this->params['letter'] = $letter;
} | php | protected function filter_by_letter($letter, $finalfield) {
global $DB;
$letter = core_text::strtoupper($letter);
$len = core_text::strlen($letter);
$sql = $DB->sql_substr(sprintf('upper(%s)', $finalfield), 1, $len);
$this->where[] = "$sql = :letter";
$this->params['letter'] = $letter;
} | [
"protected",
"function",
"filter_by_letter",
"(",
"$",
"letter",
",",
"$",
"finalfield",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"letter",
"=",
"core_text",
"::",
"strtoupper",
"(",
"$",
"letter",
")",
";",
"$",
"len",
"=",
"core_text",
"::",
"strlen",
"(",
"$",
"letter",
")",
";",
"$",
"sql",
"=",
"$",
"DB",
"->",
"sql_substr",
"(",
"sprintf",
"(",
"'upper(%s)'",
",",
"$",
"finalfield",
")",
",",
"1",
",",
"$",
"len",
")",
";",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"\"$sql = :letter\"",
";",
"$",
"this",
"->",
"params",
"[",
"'letter'",
"]",
"=",
"$",
"letter",
";",
"}"
] | Filter a field using a letter.
@param string $letter The letter.
@param string $finalfield The SQL statement representing the field. | [
"Filter",
"a",
"field",
"using",
"a",
"letter",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/entry_query_builder.php#L168-L177 |
212,737 | moodle/moodle | mod/glossary/classes/entry_query_builder.php | mod_glossary_entry_query_builder.filter_by_non_letter | protected function filter_by_non_letter($finalfield) {
global $DB;
$alphabet = explode(',', get_string('alphabet', 'langconfig'));
list($nia, $aparams) = $DB->get_in_or_equal($alphabet, SQL_PARAMS_NAMED, 'nonletter', false);
$sql = $DB->sql_substr(sprintf('upper(%s)', $finalfield), 1, 1);
$this->where[] = "$sql $nia";
$this->params = array_merge($this->params, $aparams);
} | php | protected function filter_by_non_letter($finalfield) {
global $DB;
$alphabet = explode(',', get_string('alphabet', 'langconfig'));
list($nia, $aparams) = $DB->get_in_or_equal($alphabet, SQL_PARAMS_NAMED, 'nonletter', false);
$sql = $DB->sql_substr(sprintf('upper(%s)', $finalfield), 1, 1);
$this->where[] = "$sql $nia";
$this->params = array_merge($this->params, $aparams);
} | [
"protected",
"function",
"filter_by_non_letter",
"(",
"$",
"finalfield",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"alphabet",
"=",
"explode",
"(",
"','",
",",
"get_string",
"(",
"'alphabet'",
",",
"'langconfig'",
")",
")",
";",
"list",
"(",
"$",
"nia",
",",
"$",
"aparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"alphabet",
",",
"SQL_PARAMS_NAMED",
",",
"'nonletter'",
",",
"false",
")",
";",
"$",
"sql",
"=",
"$",
"DB",
"->",
"sql_substr",
"(",
"sprintf",
"(",
"'upper(%s)'",
",",
"$",
"finalfield",
")",
",",
"1",
",",
"1",
")",
";",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"\"$sql $nia\"",
";",
"$",
"this",
"->",
"params",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"params",
",",
"$",
"aparams",
")",
";",
"}"
] | Filter a field by special characters.
@param string $finalfield The SQL statement representing the field. | [
"Filter",
"a",
"field",
"by",
"special",
"characters",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/entry_query_builder.php#L184-L194 |
212,738 | moodle/moodle | mod/glossary/classes/entry_query_builder.php | mod_glossary_entry_query_builder.filter_by_author_letter | public function filter_by_author_letter($letter, $firstnamefirst = false) {
$field = self::get_fullname_field($firstnamefirst);
$this->filter_by_letter($letter, $field);
} | php | public function filter_by_author_letter($letter, $firstnamefirst = false) {
$field = self::get_fullname_field($firstnamefirst);
$this->filter_by_letter($letter, $field);
} | [
"public",
"function",
"filter_by_author_letter",
"(",
"$",
"letter",
",",
"$",
"firstnamefirst",
"=",
"false",
")",
"{",
"$",
"field",
"=",
"self",
"::",
"get_fullname_field",
"(",
"$",
"firstnamefirst",
")",
";",
"$",
"this",
"->",
"filter_by_letter",
"(",
"$",
"letter",
",",
"$",
"field",
")",
";",
"}"
] | Filter the author by letter.
@param string $letter The letter.
@param bool $firstnamefirst Whether or not the firstname is first in the author's name. | [
"Filter",
"the",
"author",
"by",
"letter",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/entry_query_builder.php#L202-L205 |
212,739 | moodle/moodle | mod/glossary/classes/entry_query_builder.php | mod_glossary_entry_query_builder.filter_by_author_non_letter | public function filter_by_author_non_letter($firstnamefirst = false) {
$field = self::get_fullname_field($firstnamefirst);
$this->filter_by_non_letter($field);
} | php | public function filter_by_author_non_letter($firstnamefirst = false) {
$field = self::get_fullname_field($firstnamefirst);
$this->filter_by_non_letter($field);
} | [
"public",
"function",
"filter_by_author_non_letter",
"(",
"$",
"firstnamefirst",
"=",
"false",
")",
"{",
"$",
"field",
"=",
"self",
"::",
"get_fullname_field",
"(",
"$",
"firstnamefirst",
")",
";",
"$",
"this",
"->",
"filter_by_non_letter",
"(",
"$",
"field",
")",
";",
"}"
] | Filter the author by special characters.
@param bool $firstnamefirst Whether or not the firstname is first in the author's name. | [
"Filter",
"the",
"author",
"by",
"special",
"characters",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/entry_query_builder.php#L212-L215 |
212,740 | moodle/moodle | mod/glossary/classes/entry_query_builder.php | mod_glossary_entry_query_builder.filter_by_non_approved | public function filter_by_non_approved($constant, $userid = null) {
global $USER;
if (!$userid) {
$userid = $USER->id;
}
if ($constant === self::NON_APPROVED_ALL) {
// Nothing to do.
} else if ($constant === self::NON_APPROVED_SELF) {
$this->where[] = sprintf('%s != 0 OR %s = :toapproveuserid',
self::resolve_field('approved', 'entries'), self::resolve_field('userid', 'entries'));
$this->params['toapproveuserid'] = $USER->id;
} else if ($constant === self::NON_APPROVED_NONE) {
$this->where[] = sprintf('%s != 0', self::resolve_field('approved', 'entries'));
} else if ($constant === self::NON_APPROVED_ONLY) {
$this->where[] = sprintf('%s = 0', self::resolve_field('approved', 'entries'));
} else {
throw new coding_exception('Invalid constant');
}
} | php | public function filter_by_non_approved($constant, $userid = null) {
global $USER;
if (!$userid) {
$userid = $USER->id;
}
if ($constant === self::NON_APPROVED_ALL) {
// Nothing to do.
} else if ($constant === self::NON_APPROVED_SELF) {
$this->where[] = sprintf('%s != 0 OR %s = :toapproveuserid',
self::resolve_field('approved', 'entries'), self::resolve_field('userid', 'entries'));
$this->params['toapproveuserid'] = $USER->id;
} else if ($constant === self::NON_APPROVED_NONE) {
$this->where[] = sprintf('%s != 0', self::resolve_field('approved', 'entries'));
} else if ($constant === self::NON_APPROVED_ONLY) {
$this->where[] = sprintf('%s = 0', self::resolve_field('approved', 'entries'));
} else {
throw new coding_exception('Invalid constant');
}
} | [
"public",
"function",
"filter_by_non_approved",
"(",
"$",
"constant",
",",
"$",
"userid",
"=",
"null",
")",
"{",
"global",
"$",
"USER",
";",
"if",
"(",
"!",
"$",
"userid",
")",
"{",
"$",
"userid",
"=",
"$",
"USER",
"->",
"id",
";",
"}",
"if",
"(",
"$",
"constant",
"===",
"self",
"::",
"NON_APPROVED_ALL",
")",
"{",
"// Nothing to do.",
"}",
"else",
"if",
"(",
"$",
"constant",
"===",
"self",
"::",
"NON_APPROVED_SELF",
")",
"{",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"sprintf",
"(",
"'%s != 0 OR %s = :toapproveuserid'",
",",
"self",
"::",
"resolve_field",
"(",
"'approved'",
",",
"'entries'",
")",
",",
"self",
"::",
"resolve_field",
"(",
"'userid'",
",",
"'entries'",
")",
")",
";",
"$",
"this",
"->",
"params",
"[",
"'toapproveuserid'",
"]",
"=",
"$",
"USER",
"->",
"id",
";",
"}",
"else",
"if",
"(",
"$",
"constant",
"===",
"self",
"::",
"NON_APPROVED_NONE",
")",
"{",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"sprintf",
"(",
"'%s != 0'",
",",
"self",
"::",
"resolve_field",
"(",
"'approved'",
",",
"'entries'",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"constant",
"===",
"self",
"::",
"NON_APPROVED_ONLY",
")",
"{",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"sprintf",
"(",
"'%s = 0'",
",",
"self",
"::",
"resolve_field",
"(",
"'approved'",
",",
"'entries'",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Invalid constant'",
")",
";",
"}",
"}"
] | Filter non approved entries.
@param string $constant One of the NON_APPROVED_* constants.
@param int $userid The user ID when relevant, otherwise current user. | [
"Filter",
"non",
"approved",
"entries",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/entry_query_builder.php#L241-L264 |
212,741 | moodle/moodle | mod/glossary/classes/entry_query_builder.php | mod_glossary_entry_query_builder.filter_by_term | public function filter_by_term($term) {
$this->where[] = sprintf("(%s = :filterterma OR %s = :filtertermb)",
self::resolve_field('concept', 'entries'),
self::resolve_field('alias', 'alias'));
$this->params['filterterma'] = $term;
$this->params['filtertermb'] = $term;
} | php | public function filter_by_term($term) {
$this->where[] = sprintf("(%s = :filterterma OR %s = :filtertermb)",
self::resolve_field('concept', 'entries'),
self::resolve_field('alias', 'alias'));
$this->params['filterterma'] = $term;
$this->params['filtertermb'] = $term;
} | [
"public",
"function",
"filter_by_term",
"(",
"$",
"term",
")",
"{",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"sprintf",
"(",
"\"(%s = :filterterma OR %s = :filtertermb)\"",
",",
"self",
"::",
"resolve_field",
"(",
"'concept'",
",",
"'entries'",
")",
",",
"self",
"::",
"resolve_field",
"(",
"'alias'",
",",
"'alias'",
")",
")",
";",
"$",
"this",
"->",
"params",
"[",
"'filterterma'",
"]",
"=",
"$",
"term",
";",
"$",
"this",
"->",
"params",
"[",
"'filtertermb'",
"]",
"=",
"$",
"term",
";",
"}"
] | Filter by concept or alias.
This requires the alias table to be joined in the query. See {@link self::join_alias()}.
@param string $term What the concept or aliases should be. | [
"Filter",
"by",
"concept",
"or",
"alias",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/entry_query_builder.php#L273-L279 |
212,742 | moodle/moodle | mod/glossary/classes/entry_query_builder.php | mod_glossary_entry_query_builder.get_fullname_field | public static function get_fullname_field($firstnamefirst = false) {
global $DB;
if ($firstnamefirst) {
return $DB->sql_fullname(self::resolve_field('firstname', 'user'), self::resolve_field('lastname', 'user'));
}
return $DB->sql_fullname(self::resolve_field('lastname', 'user'), self::resolve_field('firstname', 'user'));
} | php | public static function get_fullname_field($firstnamefirst = false) {
global $DB;
if ($firstnamefirst) {
return $DB->sql_fullname(self::resolve_field('firstname', 'user'), self::resolve_field('lastname', 'user'));
}
return $DB->sql_fullname(self::resolve_field('lastname', 'user'), self::resolve_field('firstname', 'user'));
} | [
"public",
"static",
"function",
"get_fullname_field",
"(",
"$",
"firstnamefirst",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"firstnamefirst",
")",
"{",
"return",
"$",
"DB",
"->",
"sql_fullname",
"(",
"self",
"::",
"resolve_field",
"(",
"'firstname'",
",",
"'user'",
")",
",",
"self",
"::",
"resolve_field",
"(",
"'lastname'",
",",
"'user'",
")",
")",
";",
"}",
"return",
"$",
"DB",
"->",
"sql_fullname",
"(",
"self",
"::",
"resolve_field",
"(",
"'lastname'",
",",
"'user'",
")",
",",
"self",
"::",
"resolve_field",
"(",
"'firstname'",
",",
"'user'",
")",
")",
";",
"}"
] | Convenience method to get get the SQL statement for the full name.
@param bool $firstnamefirst Whether or not the firstname is first in the author's name.
@return string The SQL statement. | [
"Convenience",
"method",
"to",
"get",
"get",
"the",
"SQL",
"statement",
"for",
"the",
"full",
"name",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/entry_query_builder.php#L287-L293 |
212,743 | moodle/moodle | mod/glossary/classes/entry_query_builder.php | mod_glossary_entry_query_builder.get_records | public function get_records() {
global $DB;
return $DB->get_records_sql($this->build_query(), $this->params, $this->limitfrom, $this->limitnum);
} | php | public function get_records() {
global $DB;
return $DB->get_records_sql($this->build_query(), $this->params, $this->limitfrom, $this->limitnum);
} | [
"public",
"function",
"get_records",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"return",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"this",
"->",
"build_query",
"(",
")",
",",
"$",
"this",
"->",
"params",
",",
"$",
"this",
"->",
"limitfrom",
",",
"$",
"this",
"->",
"limitnum",
")",
";",
"}"
] | Get the records.
@return array | [
"Get",
"the",
"records",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/entry_query_builder.php#L300-L303 |
212,744 | moodle/moodle | mod/glossary/classes/entry_query_builder.php | mod_glossary_entry_query_builder.get_recordset | public function get_recordset() {
global $DB;
return $DB->get_recordset_sql($this->build_query(), $this->params, $this->limitfrom, $this->limitnum);
} | php | public function get_recordset() {
global $DB;
return $DB->get_recordset_sql($this->build_query(), $this->params, $this->limitfrom, $this->limitnum);
} | [
"public",
"function",
"get_recordset",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"return",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"this",
"->",
"build_query",
"(",
")",
",",
"$",
"this",
"->",
"params",
",",
"$",
"this",
"->",
"limitfrom",
",",
"$",
"this",
"->",
"limitnum",
")",
";",
"}"
] | Get the recordset.
@return moodle_recordset | [
"Get",
"the",
"recordset",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/entry_query_builder.php#L310-L313 |
212,745 | moodle/moodle | mod/glossary/classes/entry_query_builder.php | mod_glossary_entry_query_builder.join_alias | public function join_alias() {
$this->joins[] = sprintf('LEFT JOIN {glossary_alias} %s ON %s = %s',
self::ALIAS_ALIAS, self::resolve_field('id', 'entries'), self::resolve_field('entryid', 'alias'));
} | php | public function join_alias() {
$this->joins[] = sprintf('LEFT JOIN {glossary_alias} %s ON %s = %s',
self::ALIAS_ALIAS, self::resolve_field('id', 'entries'), self::resolve_field('entryid', 'alias'));
} | [
"public",
"function",
"join_alias",
"(",
")",
"{",
"$",
"this",
"->",
"joins",
"[",
"]",
"=",
"sprintf",
"(",
"'LEFT JOIN {glossary_alias} %s ON %s = %s'",
",",
"self",
"::",
"ALIAS_ALIAS",
",",
"self",
"::",
"resolve_field",
"(",
"'id'",
",",
"'entries'",
")",
",",
"self",
"::",
"resolve_field",
"(",
"'entryid'",
",",
"'alias'",
")",
")",
";",
"}"
] | Join the alias table.
Note that this may cause the same entry to be returned more than once. You might want
to add a distinct on the entry id.
@return void | [
"Join",
"the",
"alias",
"table",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/entry_query_builder.php#L335-L338 |
212,746 | moodle/moodle | mod/glossary/classes/entry_query_builder.php | mod_glossary_entry_query_builder.join_category | public function join_category($categoryid) {
if ($categoryid === GLOSSARY_SHOW_ALL_CATEGORIES) {
$this->joins[] = sprintf('JOIN {glossary_entries_categories} %s ON %s = %s',
self::ALIAS_ENTRIES_CATEGORIES, self::resolve_field('id', 'entries'),
self::resolve_field('entryid', 'entries_categories'));
$this->joins[] = sprintf('JOIN {glossary_categories} %s ON %s = %s',
self::ALIAS_CATEGORIES, self::resolve_field('id', 'categories'),
self::resolve_field('categoryid', 'entries_categories'));
} else if ($categoryid === GLOSSARY_SHOW_NOT_CATEGORISED) {
$this->joins[] = sprintf('LEFT JOIN {glossary_entries_categories} %s ON %s = %s',
self::ALIAS_ENTRIES_CATEGORIES, self::resolve_field('id', 'entries'),
self::resolve_field('entryid', 'entries_categories'));
} else {
$this->joins[] = sprintf('JOIN {glossary_entries_categories} %s ON %s = %s AND %s = :joincategoryid',
self::ALIAS_ENTRIES_CATEGORIES, self::resolve_field('id', 'entries'),
self::resolve_field('entryid', 'entries_categories'),
self::resolve_field('categoryid', 'entries_categories'));
$this->params['joincategoryid'] = $categoryid;
}
} | php | public function join_category($categoryid) {
if ($categoryid === GLOSSARY_SHOW_ALL_CATEGORIES) {
$this->joins[] = sprintf('JOIN {glossary_entries_categories} %s ON %s = %s',
self::ALIAS_ENTRIES_CATEGORIES, self::resolve_field('id', 'entries'),
self::resolve_field('entryid', 'entries_categories'));
$this->joins[] = sprintf('JOIN {glossary_categories} %s ON %s = %s',
self::ALIAS_CATEGORIES, self::resolve_field('id', 'categories'),
self::resolve_field('categoryid', 'entries_categories'));
} else if ($categoryid === GLOSSARY_SHOW_NOT_CATEGORISED) {
$this->joins[] = sprintf('LEFT JOIN {glossary_entries_categories} %s ON %s = %s',
self::ALIAS_ENTRIES_CATEGORIES, self::resolve_field('id', 'entries'),
self::resolve_field('entryid', 'entries_categories'));
} else {
$this->joins[] = sprintf('JOIN {glossary_entries_categories} %s ON %s = %s AND %s = :joincategoryid',
self::ALIAS_ENTRIES_CATEGORIES, self::resolve_field('id', 'entries'),
self::resolve_field('entryid', 'entries_categories'),
self::resolve_field('categoryid', 'entries_categories'));
$this->params['joincategoryid'] = $categoryid;
}
} | [
"public",
"function",
"join_category",
"(",
"$",
"categoryid",
")",
"{",
"if",
"(",
"$",
"categoryid",
"===",
"GLOSSARY_SHOW_ALL_CATEGORIES",
")",
"{",
"$",
"this",
"->",
"joins",
"[",
"]",
"=",
"sprintf",
"(",
"'JOIN {glossary_entries_categories} %s ON %s = %s'",
",",
"self",
"::",
"ALIAS_ENTRIES_CATEGORIES",
",",
"self",
"::",
"resolve_field",
"(",
"'id'",
",",
"'entries'",
")",
",",
"self",
"::",
"resolve_field",
"(",
"'entryid'",
",",
"'entries_categories'",
")",
")",
";",
"$",
"this",
"->",
"joins",
"[",
"]",
"=",
"sprintf",
"(",
"'JOIN {glossary_categories} %s ON %s = %s'",
",",
"self",
"::",
"ALIAS_CATEGORIES",
",",
"self",
"::",
"resolve_field",
"(",
"'id'",
",",
"'categories'",
")",
",",
"self",
"::",
"resolve_field",
"(",
"'categoryid'",
",",
"'entries_categories'",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"categoryid",
"===",
"GLOSSARY_SHOW_NOT_CATEGORISED",
")",
"{",
"$",
"this",
"->",
"joins",
"[",
"]",
"=",
"sprintf",
"(",
"'LEFT JOIN {glossary_entries_categories} %s ON %s = %s'",
",",
"self",
"::",
"ALIAS_ENTRIES_CATEGORIES",
",",
"self",
"::",
"resolve_field",
"(",
"'id'",
",",
"'entries'",
")",
",",
"self",
"::",
"resolve_field",
"(",
"'entryid'",
",",
"'entries_categories'",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"joins",
"[",
"]",
"=",
"sprintf",
"(",
"'JOIN {glossary_entries_categories} %s ON %s = %s AND %s = :joincategoryid'",
",",
"self",
"::",
"ALIAS_ENTRIES_CATEGORIES",
",",
"self",
"::",
"resolve_field",
"(",
"'id'",
",",
"'entries'",
")",
",",
"self",
"::",
"resolve_field",
"(",
"'entryid'",
",",
"'entries_categories'",
")",
",",
"self",
"::",
"resolve_field",
"(",
"'categoryid'",
",",
"'entries_categories'",
")",
")",
";",
"$",
"this",
"->",
"params",
"[",
"'joincategoryid'",
"]",
"=",
"$",
"categoryid",
";",
"}",
"}"
] | Join on the category tables.
Depending on the category passed the joins will be different. This is due to the display
logic that assumes that when displaying all categories the non categorised entries should
not be returned, etc...
@param int $categoryid The category ID, or GLOSSARY_SHOW_* constant. | [
"Join",
"on",
"the",
"category",
"tables",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/entry_query_builder.php#L349-L373 |
212,747 | moodle/moodle | mod/glossary/classes/entry_query_builder.php | mod_glossary_entry_query_builder.join_user | public function join_user($strict = false) {
$join = $strict ? 'JOIN' : 'LEFT JOIN';
$this->joins[] = sprintf("$join {user} %s ON %s = %s",
self::ALIAS_USER, self::resolve_field('id', 'user'), self::resolve_field('userid', 'entries'));
} | php | public function join_user($strict = false) {
$join = $strict ? 'JOIN' : 'LEFT JOIN';
$this->joins[] = sprintf("$join {user} %s ON %s = %s",
self::ALIAS_USER, self::resolve_field('id', 'user'), self::resolve_field('userid', 'entries'));
} | [
"public",
"function",
"join_user",
"(",
"$",
"strict",
"=",
"false",
")",
"{",
"$",
"join",
"=",
"$",
"strict",
"?",
"'JOIN'",
":",
"'LEFT JOIN'",
";",
"$",
"this",
"->",
"joins",
"[",
"]",
"=",
"sprintf",
"(",
"\"$join {user} %s ON %s = %s\"",
",",
"self",
"::",
"ALIAS_USER",
",",
"self",
"::",
"resolve_field",
"(",
"'id'",
",",
"'user'",
")",
",",
"self",
"::",
"resolve_field",
"(",
"'userid'",
",",
"'entries'",
")",
")",
";",
"}"
] | Join the user table.
@param bool $strict When strict uses a JOIN rather than a LEFT JOIN. | [
"Join",
"the",
"user",
"table",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/entry_query_builder.php#L380-L384 |
212,748 | moodle/moodle | mod/glossary/classes/entry_query_builder.php | mod_glossary_entry_query_builder.order_by_author | public function order_by_author($firstnamefirst = false, $direction = '') {
$field = self::get_fullname_field($firstnamefirst);
$direction = self::normalize_direction($direction);
$this->order[] = $field . ' ' . $direction;
} | php | public function order_by_author($firstnamefirst = false, $direction = '') {
$field = self::get_fullname_field($firstnamefirst);
$direction = self::normalize_direction($direction);
$this->order[] = $field . ' ' . $direction;
} | [
"public",
"function",
"order_by_author",
"(",
"$",
"firstnamefirst",
"=",
"false",
",",
"$",
"direction",
"=",
"''",
")",
"{",
"$",
"field",
"=",
"self",
"::",
"get_fullname_field",
"(",
"$",
"firstnamefirst",
")",
";",
"$",
"direction",
"=",
"self",
"::",
"normalize_direction",
"(",
"$",
"direction",
")",
";",
"$",
"this",
"->",
"order",
"[",
"]",
"=",
"$",
"field",
".",
"' '",
".",
"$",
"direction",
";",
"}"
] | Order by author name.
@param bool $firstnamefirst Whether or not the firstname is first in the author's name.
@param string $direction ASC, or DESC. | [
"Order",
"by",
"author",
"name",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/entry_query_builder.php#L430-L434 |
212,749 | moodle/moodle | mod/glossary/classes/entry_query_builder.php | mod_glossary_entry_query_builder.resolve_field | protected static function resolve_field($field, $table) {
$prefix = constant(__CLASS__ . '::ALIAS_' . core_text::strtoupper($table));
return sprintf('%s.%s', $prefix, $field);
} | php | protected static function resolve_field($field, $table) {
$prefix = constant(__CLASS__ . '::ALIAS_' . core_text::strtoupper($table));
return sprintf('%s.%s', $prefix, $field);
} | [
"protected",
"static",
"function",
"resolve_field",
"(",
"$",
"field",
",",
"$",
"table",
")",
"{",
"$",
"prefix",
"=",
"constant",
"(",
"__CLASS__",
".",
"'::ALIAS_'",
".",
"core_text",
"::",
"strtoupper",
"(",
"$",
"table",
")",
")",
";",
"return",
"sprintf",
"(",
"'%s.%s'",
",",
"$",
"prefix",
",",
"$",
"field",
")",
";",
"}"
] | Convenience method to transform a field into SQL statement.
@param string $field The field, or *.
@param string $table The table name, without the prefix 'glossary_'.
@return string SQL statement. | [
"Convenience",
"method",
"to",
"transform",
"a",
"field",
"into",
"SQL",
"statement",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/entry_query_builder.php#L443-L446 |
212,750 | moodle/moodle | mod/glossary/classes/entry_query_builder.php | mod_glossary_entry_query_builder.where | public function where($field, $table, $value) {
static $i = 0;
$sql = self::resolve_field($field, $table) . ' ';
if ($value === null) {
$sql .= 'IS NULL';
} else {
$param = 'where' . $i++;
$sql .= " = :$param";
$this->params[$param] = $value;
}
$this->where[] = $sql;
} | php | public function where($field, $table, $value) {
static $i = 0;
$sql = self::resolve_field($field, $table) . ' ';
if ($value === null) {
$sql .= 'IS NULL';
} else {
$param = 'where' . $i++;
$sql .= " = :$param";
$this->params[$param] = $value;
}
$this->where[] = $sql;
} | [
"public",
"function",
"where",
"(",
"$",
"field",
",",
"$",
"table",
",",
"$",
"value",
")",
"{",
"static",
"$",
"i",
"=",
"0",
";",
"$",
"sql",
"=",
"self",
"::",
"resolve_field",
"(",
"$",
"field",
",",
"$",
"table",
")",
".",
"' '",
";",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"$",
"sql",
".=",
"'IS NULL'",
";",
"}",
"else",
"{",
"$",
"param",
"=",
"'where'",
".",
"$",
"i",
"++",
";",
"$",
"sql",
".=",
"\" = :$param\"",
";",
"$",
"this",
"->",
"params",
"[",
"$",
"param",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"$",
"sql",
";",
"}"
] | Simple where conditions.
@param string $field The field, or *.
@param string $table The table name, without the prefix 'glossary_'.
@param mixed $value The value to be equal to. | [
"Simple",
"where",
"conditions",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/entry_query_builder.php#L455-L469 |
212,751 | moodle/moodle | blocks/section_links/renderer.php | block_section_links_renderer.render_section_links | public function render_section_links(stdClass $course, array $sections, $jumptosection = false) {
$html = html_writer::start_tag('ol', array('class' => 'inline-list'));
foreach ($sections as $section) {
$attributes = array();
if (!$section->visible) {
$attributes['class'] = 'dimmed';
}
$html .= html_writer::start_tag('li');
$sectiontext = $section->section;
if ($section->highlight) {
$sectiontext = html_writer::tag('strong', $sectiontext);
}
$html .= html_writer::link(course_get_url($course, $section->section), $sectiontext, $attributes);
$html .= html_writer::end_tag('li').' ';
}
$html .= html_writer::end_tag('ol');
if ($jumptosection && isset($sections[$jumptosection])) {
if ($course->format == 'weeks') {
$linktext = new lang_string('jumptocurrentweek', 'block_section_links');
} else if ($course->format == 'topics') {
$linktext = new lang_string('jumptocurrenttopic', 'block_section_links');
}
$attributes = array();
if (!$sections[$jumptosection]->visible) {
$attributes['class'] = 'dimmed';
}
$html .= html_writer::link(course_get_url($course, $jumptosection), $linktext, $attributes);
}
return $html;
} | php | public function render_section_links(stdClass $course, array $sections, $jumptosection = false) {
$html = html_writer::start_tag('ol', array('class' => 'inline-list'));
foreach ($sections as $section) {
$attributes = array();
if (!$section->visible) {
$attributes['class'] = 'dimmed';
}
$html .= html_writer::start_tag('li');
$sectiontext = $section->section;
if ($section->highlight) {
$sectiontext = html_writer::tag('strong', $sectiontext);
}
$html .= html_writer::link(course_get_url($course, $section->section), $sectiontext, $attributes);
$html .= html_writer::end_tag('li').' ';
}
$html .= html_writer::end_tag('ol');
if ($jumptosection && isset($sections[$jumptosection])) {
if ($course->format == 'weeks') {
$linktext = new lang_string('jumptocurrentweek', 'block_section_links');
} else if ($course->format == 'topics') {
$linktext = new lang_string('jumptocurrenttopic', 'block_section_links');
}
$attributes = array();
if (!$sections[$jumptosection]->visible) {
$attributes['class'] = 'dimmed';
}
$html .= html_writer::link(course_get_url($course, $jumptosection), $linktext, $attributes);
}
return $html;
} | [
"public",
"function",
"render_section_links",
"(",
"stdClass",
"$",
"course",
",",
"array",
"$",
"sections",
",",
"$",
"jumptosection",
"=",
"false",
")",
"{",
"$",
"html",
"=",
"html_writer",
"::",
"start_tag",
"(",
"'ol'",
",",
"array",
"(",
"'class'",
"=>",
"'inline-list'",
")",
")",
";",
"foreach",
"(",
"$",
"sections",
"as",
"$",
"section",
")",
"{",
"$",
"attributes",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"section",
"->",
"visible",
")",
"{",
"$",
"attributes",
"[",
"'class'",
"]",
"=",
"'dimmed'",
";",
"}",
"$",
"html",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'li'",
")",
";",
"$",
"sectiontext",
"=",
"$",
"section",
"->",
"section",
";",
"if",
"(",
"$",
"section",
"->",
"highlight",
")",
"{",
"$",
"sectiontext",
"=",
"html_writer",
"::",
"tag",
"(",
"'strong'",
",",
"$",
"sectiontext",
")",
";",
"}",
"$",
"html",
".=",
"html_writer",
"::",
"link",
"(",
"course_get_url",
"(",
"$",
"course",
",",
"$",
"section",
"->",
"section",
")",
",",
"$",
"sectiontext",
",",
"$",
"attributes",
")",
";",
"$",
"html",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'li'",
")",
".",
"' '",
";",
"}",
"$",
"html",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'ol'",
")",
";",
"if",
"(",
"$",
"jumptosection",
"&&",
"isset",
"(",
"$",
"sections",
"[",
"$",
"jumptosection",
"]",
")",
")",
"{",
"if",
"(",
"$",
"course",
"->",
"format",
"==",
"'weeks'",
")",
"{",
"$",
"linktext",
"=",
"new",
"lang_string",
"(",
"'jumptocurrentweek'",
",",
"'block_section_links'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"course",
"->",
"format",
"==",
"'topics'",
")",
"{",
"$",
"linktext",
"=",
"new",
"lang_string",
"(",
"'jumptocurrenttopic'",
",",
"'block_section_links'",
")",
";",
"}",
"$",
"attributes",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"sections",
"[",
"$",
"jumptosection",
"]",
"->",
"visible",
")",
"{",
"$",
"attributes",
"[",
"'class'",
"]",
"=",
"'dimmed'",
";",
"}",
"$",
"html",
".=",
"html_writer",
"::",
"link",
"(",
"course_get_url",
"(",
"$",
"course",
",",
"$",
"jumptosection",
")",
",",
"$",
"linktext",
",",
"$",
"attributes",
")",
";",
"}",
"return",
"$",
"html",
";",
"}"
] | Render a series of section links.
@param stdClass $course The course we are rendering for.
@param array $sections An array of section objects to render.
@param bool|int The section to provide a jump to link for.
@return string The HTML to display. | [
"Render",
"a",
"series",
"of",
"section",
"links",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/section_links/renderer.php#L43-L75 |
212,752 | moodle/moodle | mod/forum/classes/subscriptions.php | subscriptions.is_subscribed | public static function is_subscribed($userid, $forum, $discussionid = null, $cm = null) {
// If forum is force subscribed and has allowforcesubscribe, then user is subscribed.
if (self::is_forcesubscribed($forum)) {
if (!$cm) {
$cm = get_fast_modinfo($forum->course)->instances['forum'][$forum->id];
}
if (has_capability('mod/forum:allowforcesubscribe', \context_module::instance($cm->id), $userid)) {
return true;
}
}
if ($discussionid === null) {
return self::is_subscribed_to_forum($userid, $forum);
}
$subscriptions = self::fetch_discussion_subscription($forum->id, $userid);
// Check whether there is a record for this discussion subscription.
if (isset($subscriptions[$discussionid])) {
return ($subscriptions[$discussionid] != self::FORUM_DISCUSSION_UNSUBSCRIBED);
}
return self::is_subscribed_to_forum($userid, $forum);
} | php | public static function is_subscribed($userid, $forum, $discussionid = null, $cm = null) {
// If forum is force subscribed and has allowforcesubscribe, then user is subscribed.
if (self::is_forcesubscribed($forum)) {
if (!$cm) {
$cm = get_fast_modinfo($forum->course)->instances['forum'][$forum->id];
}
if (has_capability('mod/forum:allowforcesubscribe', \context_module::instance($cm->id), $userid)) {
return true;
}
}
if ($discussionid === null) {
return self::is_subscribed_to_forum($userid, $forum);
}
$subscriptions = self::fetch_discussion_subscription($forum->id, $userid);
// Check whether there is a record for this discussion subscription.
if (isset($subscriptions[$discussionid])) {
return ($subscriptions[$discussionid] != self::FORUM_DISCUSSION_UNSUBSCRIBED);
}
return self::is_subscribed_to_forum($userid, $forum);
} | [
"public",
"static",
"function",
"is_subscribed",
"(",
"$",
"userid",
",",
"$",
"forum",
",",
"$",
"discussionid",
"=",
"null",
",",
"$",
"cm",
"=",
"null",
")",
"{",
"// If forum is force subscribed and has allowforcesubscribe, then user is subscribed.",
"if",
"(",
"self",
"::",
"is_forcesubscribed",
"(",
"$",
"forum",
")",
")",
"{",
"if",
"(",
"!",
"$",
"cm",
")",
"{",
"$",
"cm",
"=",
"get_fast_modinfo",
"(",
"$",
"forum",
"->",
"course",
")",
"->",
"instances",
"[",
"'forum'",
"]",
"[",
"$",
"forum",
"->",
"id",
"]",
";",
"}",
"if",
"(",
"has_capability",
"(",
"'mod/forum:allowforcesubscribe'",
",",
"\\",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
",",
"$",
"userid",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"if",
"(",
"$",
"discussionid",
"===",
"null",
")",
"{",
"return",
"self",
"::",
"is_subscribed_to_forum",
"(",
"$",
"userid",
",",
"$",
"forum",
")",
";",
"}",
"$",
"subscriptions",
"=",
"self",
"::",
"fetch_discussion_subscription",
"(",
"$",
"forum",
"->",
"id",
",",
"$",
"userid",
")",
";",
"// Check whether there is a record for this discussion subscription.",
"if",
"(",
"isset",
"(",
"$",
"subscriptions",
"[",
"$",
"discussionid",
"]",
")",
")",
"{",
"return",
"(",
"$",
"subscriptions",
"[",
"$",
"discussionid",
"]",
"!=",
"self",
"::",
"FORUM_DISCUSSION_UNSUBSCRIBED",
")",
";",
"}",
"return",
"self",
"::",
"is_subscribed_to_forum",
"(",
"$",
"userid",
",",
"$",
"forum",
")",
";",
"}"
] | Whether a user is subscribed to this forum, or a discussion within
the forum.
If a discussion is specified, then report whether the user is
subscribed to posts to this particular discussion, taking into
account the forum preference.
If it is not specified then only the forum preference is considered.
@param int $userid The user ID
@param \stdClass $forum The record of the forum to test
@param int $discussionid The ID of the discussion to check
@param $cm The coursemodule record. If not supplied, this will be calculated using get_fast_modinfo instead.
@return boolean | [
"Whether",
"a",
"user",
"is",
"subscribed",
"to",
"this",
"forum",
"or",
"a",
"discussion",
"within",
"the",
"forum",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/subscriptions.php#L103-L126 |
212,753 | moodle/moodle | mod/forum/classes/subscriptions.php | subscriptions.is_subscribable | public static function is_subscribable($forum) {
return (isloggedin() && !isguestuser() &&
!\mod_forum\subscriptions::is_forcesubscribed($forum) &&
!\mod_forum\subscriptions::subscription_disabled($forum));
} | php | public static function is_subscribable($forum) {
return (isloggedin() && !isguestuser() &&
!\mod_forum\subscriptions::is_forcesubscribed($forum) &&
!\mod_forum\subscriptions::subscription_disabled($forum));
} | [
"public",
"static",
"function",
"is_subscribable",
"(",
"$",
"forum",
")",
"{",
"return",
"(",
"isloggedin",
"(",
")",
"&&",
"!",
"isguestuser",
"(",
")",
"&&",
"!",
"\\",
"mod_forum",
"\\",
"subscriptions",
"::",
"is_forcesubscribed",
"(",
"$",
"forum",
")",
"&&",
"!",
"\\",
"mod_forum",
"\\",
"subscriptions",
"::",
"subscription_disabled",
"(",
"$",
"forum",
")",
")",
";",
"}"
] | Helper to determine whether the specified forum can be subscribed to.
@param \stdClass $forum The record of the forum to test
@return bool | [
"Helper",
"to",
"determine",
"whether",
"the",
"specified",
"forum",
"can",
"be",
"subscribed",
"to",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/subscriptions.php#L166-L170 |
212,754 | moodle/moodle | mod/forum/classes/subscriptions.php | subscriptions.get_unsubscribable_forums | public static function get_unsubscribable_forums() {
global $USER, $DB;
// Get courses that $USER is enrolled in and can see.
$courses = enrol_get_my_courses();
if (empty($courses)) {
return array();
}
$courseids = array();
foreach($courses as $course) {
$courseids[] = $course->id;
}
list($coursesql, $courseparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED, 'c');
// Get all forums from the user's courses that they are subscribed to and which are not set to forced.
// It is possible for users to be subscribed to a forum in subscription disallowed mode so they must be listed
// here so that that can be unsubscribed from.
$sql = "SELECT f.id, cm.id as cm, cm.visible, f.course
FROM {forum} f
JOIN {course_modules} cm ON cm.instance = f.id
JOIN {modules} m ON m.name = :modulename AND m.id = cm.module
LEFT JOIN {forum_subscriptions} fs ON (fs.forum = f.id AND fs.userid = :userid)
WHERE f.forcesubscribe <> :forcesubscribe
AND fs.id IS NOT NULL
AND cm.course
$coursesql";
$params = array_merge($courseparams, array(
'modulename'=>'forum',
'userid' => $USER->id,
'forcesubscribe' => FORUM_FORCESUBSCRIBE,
));
$forums = $DB->get_recordset_sql($sql, $params);
$unsubscribableforums = array();
foreach($forums as $forum) {
if (empty($forum->visible)) {
// The forum is hidden - check if the user can view the forum.
$context = \context_module::instance($forum->cm);
if (!has_capability('moodle/course:viewhiddenactivities', $context)) {
// The user can't see the hidden forum to cannot unsubscribe.
continue;
}
}
$unsubscribableforums[] = $forum;
}
$forums->close();
return $unsubscribableforums;
} | php | public static function get_unsubscribable_forums() {
global $USER, $DB;
// Get courses that $USER is enrolled in and can see.
$courses = enrol_get_my_courses();
if (empty($courses)) {
return array();
}
$courseids = array();
foreach($courses as $course) {
$courseids[] = $course->id;
}
list($coursesql, $courseparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED, 'c');
// Get all forums from the user's courses that they are subscribed to and which are not set to forced.
// It is possible for users to be subscribed to a forum in subscription disallowed mode so they must be listed
// here so that that can be unsubscribed from.
$sql = "SELECT f.id, cm.id as cm, cm.visible, f.course
FROM {forum} f
JOIN {course_modules} cm ON cm.instance = f.id
JOIN {modules} m ON m.name = :modulename AND m.id = cm.module
LEFT JOIN {forum_subscriptions} fs ON (fs.forum = f.id AND fs.userid = :userid)
WHERE f.forcesubscribe <> :forcesubscribe
AND fs.id IS NOT NULL
AND cm.course
$coursesql";
$params = array_merge($courseparams, array(
'modulename'=>'forum',
'userid' => $USER->id,
'forcesubscribe' => FORUM_FORCESUBSCRIBE,
));
$forums = $DB->get_recordset_sql($sql, $params);
$unsubscribableforums = array();
foreach($forums as $forum) {
if (empty($forum->visible)) {
// The forum is hidden - check if the user can view the forum.
$context = \context_module::instance($forum->cm);
if (!has_capability('moodle/course:viewhiddenactivities', $context)) {
// The user can't see the hidden forum to cannot unsubscribe.
continue;
}
}
$unsubscribableforums[] = $forum;
}
$forums->close();
return $unsubscribableforums;
} | [
"public",
"static",
"function",
"get_unsubscribable_forums",
"(",
")",
"{",
"global",
"$",
"USER",
",",
"$",
"DB",
";",
"// Get courses that $USER is enrolled in and can see.",
"$",
"courses",
"=",
"enrol_get_my_courses",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"courses",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"courseids",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"courses",
"as",
"$",
"course",
")",
"{",
"$",
"courseids",
"[",
"]",
"=",
"$",
"course",
"->",
"id",
";",
"}",
"list",
"(",
"$",
"coursesql",
",",
"$",
"courseparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"courseids",
",",
"SQL_PARAMS_NAMED",
",",
"'c'",
")",
";",
"// Get all forums from the user's courses that they are subscribed to and which are not set to forced.",
"// It is possible for users to be subscribed to a forum in subscription disallowed mode so they must be listed",
"// here so that that can be unsubscribed from.",
"$",
"sql",
"=",
"\"SELECT f.id, cm.id as cm, cm.visible, f.course\n FROM {forum} f\n JOIN {course_modules} cm ON cm.instance = f.id\n JOIN {modules} m ON m.name = :modulename AND m.id = cm.module\n LEFT JOIN {forum_subscriptions} fs ON (fs.forum = f.id AND fs.userid = :userid)\n WHERE f.forcesubscribe <> :forcesubscribe\n AND fs.id IS NOT NULL\n AND cm.course\n $coursesql\"",
";",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"courseparams",
",",
"array",
"(",
"'modulename'",
"=>",
"'forum'",
",",
"'userid'",
"=>",
"$",
"USER",
"->",
"id",
",",
"'forcesubscribe'",
"=>",
"FORUM_FORCESUBSCRIBE",
",",
")",
")",
";",
"$",
"forums",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"$",
"unsubscribableforums",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"forums",
"as",
"$",
"forum",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"forum",
"->",
"visible",
")",
")",
"{",
"// The forum is hidden - check if the user can view the forum.",
"$",
"context",
"=",
"\\",
"context_module",
"::",
"instance",
"(",
"$",
"forum",
"->",
"cm",
")",
";",
"if",
"(",
"!",
"has_capability",
"(",
"'moodle/course:viewhiddenactivities'",
",",
"$",
"context",
")",
")",
"{",
"// The user can't see the hidden forum to cannot unsubscribe.",
"continue",
";",
"}",
"}",
"$",
"unsubscribableforums",
"[",
"]",
"=",
"$",
"forum",
";",
"}",
"$",
"forums",
"->",
"close",
"(",
")",
";",
"return",
"$",
"unsubscribableforums",
";",
"}"
] | Returns an array of forums that the current user is subscribed to and is allowed to unsubscribe from
@return array An array of unsubscribable forums | [
"Returns",
"an",
"array",
"of",
"forums",
"that",
"the",
"current",
"user",
"is",
"subscribed",
"to",
"and",
"is",
"allowed",
"to",
"unsubscribe",
"from"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/subscriptions.php#L201-L251 |
212,755 | moodle/moodle | mod/forum/classes/subscriptions.php | subscriptions.get_potential_subscribers | public static function get_potential_subscribers($context, $groupid, $fields, $sort = '') {
global $DB;
// Only active enrolled users or everybody on the frontpage.
list($esql, $params) = get_enrolled_sql($context, 'mod/forum:allowforcesubscribe', $groupid, true);
if (!$sort) {
list($sort, $sortparams) = users_order_by_sql('u');
$params = array_merge($params, $sortparams);
}
$sql = "SELECT $fields
FROM {user} u
JOIN ($esql) je ON je.id = u.id
ORDER BY $sort";
return $DB->get_records_sql($sql, $params);
} | php | public static function get_potential_subscribers($context, $groupid, $fields, $sort = '') {
global $DB;
// Only active enrolled users or everybody on the frontpage.
list($esql, $params) = get_enrolled_sql($context, 'mod/forum:allowforcesubscribe', $groupid, true);
if (!$sort) {
list($sort, $sortparams) = users_order_by_sql('u');
$params = array_merge($params, $sortparams);
}
$sql = "SELECT $fields
FROM {user} u
JOIN ($esql) je ON je.id = u.id
ORDER BY $sort";
return $DB->get_records_sql($sql, $params);
} | [
"public",
"static",
"function",
"get_potential_subscribers",
"(",
"$",
"context",
",",
"$",
"groupid",
",",
"$",
"fields",
",",
"$",
"sort",
"=",
"''",
")",
"{",
"global",
"$",
"DB",
";",
"// Only active enrolled users or everybody on the frontpage.",
"list",
"(",
"$",
"esql",
",",
"$",
"params",
")",
"=",
"get_enrolled_sql",
"(",
"$",
"context",
",",
"'mod/forum:allowforcesubscribe'",
",",
"$",
"groupid",
",",
"true",
")",
";",
"if",
"(",
"!",
"$",
"sort",
")",
"{",
"list",
"(",
"$",
"sort",
",",
"$",
"sortparams",
")",
"=",
"users_order_by_sql",
"(",
"'u'",
")",
";",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"params",
",",
"$",
"sortparams",
")",
";",
"}",
"$",
"sql",
"=",
"\"SELECT $fields\n FROM {user} u\n JOIN ($esql) je ON je.id = u.id\n ORDER BY $sort\"",
";",
"return",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] | Get the list of potential subscribers to a forum.
@param context_module $context the forum context.
@param integer $groupid the id of a group, or 0 for all groups.
@param string $fields the list of fields to return for each user. As for get_users_by_capability.
@param string $sort sort order. As for get_users_by_capability.
@return array list of users. | [
"Get",
"the",
"list",
"of",
"potential",
"subscribers",
"to",
"a",
"forum",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/subscriptions.php#L262-L278 |
212,756 | moodle/moodle | mod/forum/classes/subscriptions.php | subscriptions.fetch_subscription_cache | public static function fetch_subscription_cache($forumid, $userid) {
if (isset(self::$forumcache[$userid]) && isset(self::$forumcache[$userid][$forumid])) {
return self::$forumcache[$userid][$forumid];
}
self::fill_subscription_cache($forumid, $userid);
if (!isset(self::$forumcache[$userid]) || !isset(self::$forumcache[$userid][$forumid])) {
return false;
}
return self::$forumcache[$userid][$forumid];
} | php | public static function fetch_subscription_cache($forumid, $userid) {
if (isset(self::$forumcache[$userid]) && isset(self::$forumcache[$userid][$forumid])) {
return self::$forumcache[$userid][$forumid];
}
self::fill_subscription_cache($forumid, $userid);
if (!isset(self::$forumcache[$userid]) || !isset(self::$forumcache[$userid][$forumid])) {
return false;
}
return self::$forumcache[$userid][$forumid];
} | [
"public",
"static",
"function",
"fetch_subscription_cache",
"(",
"$",
"forumid",
",",
"$",
"userid",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"forumcache",
"[",
"$",
"userid",
"]",
")",
"&&",
"isset",
"(",
"self",
"::",
"$",
"forumcache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forumid",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"forumcache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forumid",
"]",
";",
"}",
"self",
"::",
"fill_subscription_cache",
"(",
"$",
"forumid",
",",
"$",
"userid",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"forumcache",
"[",
"$",
"userid",
"]",
")",
"||",
"!",
"isset",
"(",
"self",
"::",
"$",
"forumcache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forumid",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"self",
"::",
"$",
"forumcache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forumid",
"]",
";",
"}"
] | Fetch the forum subscription data for the specified userid and forum.
@param int $forumid The forum to retrieve a cache for
@param int $userid The user ID
@return boolean | [
"Fetch",
"the",
"forum",
"subscription",
"data",
"for",
"the",
"specified",
"userid",
"and",
"forum",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/subscriptions.php#L287-L298 |
212,757 | moodle/moodle | mod/forum/classes/subscriptions.php | subscriptions.fill_subscription_cache | public static function fill_subscription_cache($forumid, $userid = null) {
global $DB;
if (!isset(self::$fetchedforums[$forumid])) {
// This forum has not been fetched as a whole.
if (isset($userid)) {
if (!isset(self::$forumcache[$userid])) {
self::$forumcache[$userid] = array();
}
if (!isset(self::$forumcache[$userid][$forumid])) {
if ($DB->record_exists('forum_subscriptions', array(
'userid' => $userid,
'forum' => $forumid,
))) {
self::$forumcache[$userid][$forumid] = true;
} else {
self::$forumcache[$userid][$forumid] = false;
}
}
} else {
$subscriptions = $DB->get_recordset('forum_subscriptions', array(
'forum' => $forumid,
), '', 'id, userid');
foreach ($subscriptions as $id => $data) {
if (!isset(self::$forumcache[$data->userid])) {
self::$forumcache[$data->userid] = array();
}
self::$forumcache[$data->userid][$forumid] = true;
}
self::$fetchedforums[$forumid] = true;
$subscriptions->close();
}
}
} | php | public static function fill_subscription_cache($forumid, $userid = null) {
global $DB;
if (!isset(self::$fetchedforums[$forumid])) {
// This forum has not been fetched as a whole.
if (isset($userid)) {
if (!isset(self::$forumcache[$userid])) {
self::$forumcache[$userid] = array();
}
if (!isset(self::$forumcache[$userid][$forumid])) {
if ($DB->record_exists('forum_subscriptions', array(
'userid' => $userid,
'forum' => $forumid,
))) {
self::$forumcache[$userid][$forumid] = true;
} else {
self::$forumcache[$userid][$forumid] = false;
}
}
} else {
$subscriptions = $DB->get_recordset('forum_subscriptions', array(
'forum' => $forumid,
), '', 'id, userid');
foreach ($subscriptions as $id => $data) {
if (!isset(self::$forumcache[$data->userid])) {
self::$forumcache[$data->userid] = array();
}
self::$forumcache[$data->userid][$forumid] = true;
}
self::$fetchedforums[$forumid] = true;
$subscriptions->close();
}
}
} | [
"public",
"static",
"function",
"fill_subscription_cache",
"(",
"$",
"forumid",
",",
"$",
"userid",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"fetchedforums",
"[",
"$",
"forumid",
"]",
")",
")",
"{",
"// This forum has not been fetched as a whole.",
"if",
"(",
"isset",
"(",
"$",
"userid",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"forumcache",
"[",
"$",
"userid",
"]",
")",
")",
"{",
"self",
"::",
"$",
"forumcache",
"[",
"$",
"userid",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"forumcache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forumid",
"]",
")",
")",
"{",
"if",
"(",
"$",
"DB",
"->",
"record_exists",
"(",
"'forum_subscriptions'",
",",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
",",
"'forum'",
"=>",
"$",
"forumid",
",",
")",
")",
")",
"{",
"self",
"::",
"$",
"forumcache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forumid",
"]",
"=",
"true",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"forumcache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forumid",
"]",
"=",
"false",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"subscriptions",
"=",
"$",
"DB",
"->",
"get_recordset",
"(",
"'forum_subscriptions'",
",",
"array",
"(",
"'forum'",
"=>",
"$",
"forumid",
",",
")",
",",
"''",
",",
"'id, userid'",
")",
";",
"foreach",
"(",
"$",
"subscriptions",
"as",
"$",
"id",
"=>",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"forumcache",
"[",
"$",
"data",
"->",
"userid",
"]",
")",
")",
"{",
"self",
"::",
"$",
"forumcache",
"[",
"$",
"data",
"->",
"userid",
"]",
"=",
"array",
"(",
")",
";",
"}",
"self",
"::",
"$",
"forumcache",
"[",
"$",
"data",
"->",
"userid",
"]",
"[",
"$",
"forumid",
"]",
"=",
"true",
";",
"}",
"self",
"::",
"$",
"fetchedforums",
"[",
"$",
"forumid",
"]",
"=",
"true",
";",
"$",
"subscriptions",
"->",
"close",
"(",
")",
";",
"}",
"}",
"}"
] | Fill the forum subscription data for the specified userid and forum.
If the userid is not specified, then all subscription data for that forum is fetched in a single query and used
for subsequent lookups without requiring further database queries.
@param int $forumid The forum to retrieve a cache for
@param int $userid The user ID
@return void | [
"Fill",
"the",
"forum",
"subscription",
"data",
"for",
"the",
"specified",
"userid",
"and",
"forum",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/subscriptions.php#L310-L344 |
212,758 | moodle/moodle | mod/forum/classes/subscriptions.php | subscriptions.fill_subscription_cache_for_course | public static function fill_subscription_cache_for_course($courseid, $userid) {
global $DB;
if (!isset(self::$forumcache[$userid])) {
self::$forumcache[$userid] = array();
}
$sql = "SELECT
f.id AS forumid,
s.id AS subscriptionid
FROM {forum} f
LEFT JOIN {forum_subscriptions} s ON (s.forum = f.id AND s.userid = :userid)
WHERE f.course = :course
AND f.forcesubscribe <> :subscriptionforced";
$subscriptions = $DB->get_recordset_sql($sql, array(
'course' => $courseid,
'userid' => $userid,
'subscriptionforced' => FORUM_FORCESUBSCRIBE,
));
foreach ($subscriptions as $id => $data) {
self::$forumcache[$userid][$id] = !empty($data->subscriptionid);
}
$subscriptions->close();
} | php | public static function fill_subscription_cache_for_course($courseid, $userid) {
global $DB;
if (!isset(self::$forumcache[$userid])) {
self::$forumcache[$userid] = array();
}
$sql = "SELECT
f.id AS forumid,
s.id AS subscriptionid
FROM {forum} f
LEFT JOIN {forum_subscriptions} s ON (s.forum = f.id AND s.userid = :userid)
WHERE f.course = :course
AND f.forcesubscribe <> :subscriptionforced";
$subscriptions = $DB->get_recordset_sql($sql, array(
'course' => $courseid,
'userid' => $userid,
'subscriptionforced' => FORUM_FORCESUBSCRIBE,
));
foreach ($subscriptions as $id => $data) {
self::$forumcache[$userid][$id] = !empty($data->subscriptionid);
}
$subscriptions->close();
} | [
"public",
"static",
"function",
"fill_subscription_cache_for_course",
"(",
"$",
"courseid",
",",
"$",
"userid",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"forumcache",
"[",
"$",
"userid",
"]",
")",
")",
"{",
"self",
"::",
"$",
"forumcache",
"[",
"$",
"userid",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"sql",
"=",
"\"SELECT\n f.id AS forumid,\n s.id AS subscriptionid\n FROM {forum} f\n LEFT JOIN {forum_subscriptions} s ON (s.forum = f.id AND s.userid = :userid)\n WHERE f.course = :course\n AND f.forcesubscribe <> :subscriptionforced\"",
";",
"$",
"subscriptions",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
",",
"array",
"(",
"'course'",
"=>",
"$",
"courseid",
",",
"'userid'",
"=>",
"$",
"userid",
",",
"'subscriptionforced'",
"=>",
"FORUM_FORCESUBSCRIBE",
",",
")",
")",
";",
"foreach",
"(",
"$",
"subscriptions",
"as",
"$",
"id",
"=>",
"$",
"data",
")",
"{",
"self",
"::",
"$",
"forumcache",
"[",
"$",
"userid",
"]",
"[",
"$",
"id",
"]",
"=",
"!",
"empty",
"(",
"$",
"data",
"->",
"subscriptionid",
")",
";",
"}",
"$",
"subscriptions",
"->",
"close",
"(",
")",
";",
"}"
] | Fill the forum subscription data for all forums that the specified userid can subscribe to in the specified course.
@param int $courseid The course to retrieve a cache for
@param int $userid The user ID
@return void | [
"Fill",
"the",
"forum",
"subscription",
"data",
"for",
"all",
"forums",
"that",
"the",
"specified",
"userid",
"can",
"subscribe",
"to",
"in",
"the",
"specified",
"course",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/subscriptions.php#L353-L378 |
212,759 | moodle/moodle | mod/forum/classes/subscriptions.php | subscriptions.fetch_subscribed_users | public static function fetch_subscribed_users($forum, $groupid = 0, $context = null, $fields = null,
$includediscussionsubscriptions = false) {
global $CFG, $DB;
if (empty($fields)) {
$allnames = get_all_user_name_fields(true, 'u');
$fields ="u.id,
u.username,
$allnames,
u.maildisplay,
u.mailformat,
u.maildigest,
u.imagealt,
u.email,
u.emailstop,
u.city,
u.country,
u.lastaccess,
u.lastlogin,
u.picture,
u.timezone,
u.theme,
u.lang,
u.trackforums,
u.mnethostid";
}
// Retrieve the forum context if it wasn't specified.
$context = forum_get_context($forum->id, $context);
if (self::is_forcesubscribed($forum)) {
$results = \mod_forum\subscriptions::get_potential_subscribers($context, $groupid, $fields, "u.email ASC");
} else {
// Only active enrolled users or everybody on the frontpage.
list($esql, $params) = get_enrolled_sql($context, '', $groupid, true);
$params['forumid'] = $forum->id;
if ($includediscussionsubscriptions) {
$params['sforumid'] = $forum->id;
$params['dsforumid'] = $forum->id;
$params['unsubscribed'] = self::FORUM_DISCUSSION_UNSUBSCRIBED;
$sql = "SELECT $fields
FROM (
SELECT userid FROM {forum_subscriptions} s
WHERE
s.forum = :sforumid
UNION
SELECT userid FROM {forum_discussion_subs} ds
WHERE
ds.forum = :dsforumid AND ds.preference <> :unsubscribed
) subscriptions
JOIN {user} u ON u.id = subscriptions.userid
JOIN ($esql) je ON je.id = u.id
ORDER BY u.email ASC";
} else {
$sql = "SELECT $fields
FROM {user} u
JOIN ($esql) je ON je.id = u.id
JOIN {forum_subscriptions} s ON s.userid = u.id
WHERE
s.forum = :forumid
ORDER BY u.email ASC";
}
$results = $DB->get_records_sql($sql, $params);
}
// Guest user should never be subscribed to a forum.
unset($results[$CFG->siteguest]);
// Apply the activity module availability resetrictions.
$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course);
$modinfo = get_fast_modinfo($forum->course);
$info = new \core_availability\info_module($modinfo->get_cm($cm->id));
$results = $info->filter_user_list($results);
return $results;
} | php | public static function fetch_subscribed_users($forum, $groupid = 0, $context = null, $fields = null,
$includediscussionsubscriptions = false) {
global $CFG, $DB;
if (empty($fields)) {
$allnames = get_all_user_name_fields(true, 'u');
$fields ="u.id,
u.username,
$allnames,
u.maildisplay,
u.mailformat,
u.maildigest,
u.imagealt,
u.email,
u.emailstop,
u.city,
u.country,
u.lastaccess,
u.lastlogin,
u.picture,
u.timezone,
u.theme,
u.lang,
u.trackforums,
u.mnethostid";
}
// Retrieve the forum context if it wasn't specified.
$context = forum_get_context($forum->id, $context);
if (self::is_forcesubscribed($forum)) {
$results = \mod_forum\subscriptions::get_potential_subscribers($context, $groupid, $fields, "u.email ASC");
} else {
// Only active enrolled users or everybody on the frontpage.
list($esql, $params) = get_enrolled_sql($context, '', $groupid, true);
$params['forumid'] = $forum->id;
if ($includediscussionsubscriptions) {
$params['sforumid'] = $forum->id;
$params['dsforumid'] = $forum->id;
$params['unsubscribed'] = self::FORUM_DISCUSSION_UNSUBSCRIBED;
$sql = "SELECT $fields
FROM (
SELECT userid FROM {forum_subscriptions} s
WHERE
s.forum = :sforumid
UNION
SELECT userid FROM {forum_discussion_subs} ds
WHERE
ds.forum = :dsforumid AND ds.preference <> :unsubscribed
) subscriptions
JOIN {user} u ON u.id = subscriptions.userid
JOIN ($esql) je ON je.id = u.id
ORDER BY u.email ASC";
} else {
$sql = "SELECT $fields
FROM {user} u
JOIN ($esql) je ON je.id = u.id
JOIN {forum_subscriptions} s ON s.userid = u.id
WHERE
s.forum = :forumid
ORDER BY u.email ASC";
}
$results = $DB->get_records_sql($sql, $params);
}
// Guest user should never be subscribed to a forum.
unset($results[$CFG->siteguest]);
// Apply the activity module availability resetrictions.
$cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course);
$modinfo = get_fast_modinfo($forum->course);
$info = new \core_availability\info_module($modinfo->get_cm($cm->id));
$results = $info->filter_user_list($results);
return $results;
} | [
"public",
"static",
"function",
"fetch_subscribed_users",
"(",
"$",
"forum",
",",
"$",
"groupid",
"=",
"0",
",",
"$",
"context",
"=",
"null",
",",
"$",
"fields",
"=",
"null",
",",
"$",
"includediscussionsubscriptions",
"=",
"false",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"if",
"(",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"allnames",
"=",
"get_all_user_name_fields",
"(",
"true",
",",
"'u'",
")",
";",
"$",
"fields",
"=",
"\"u.id,\n u.username,\n $allnames,\n u.maildisplay,\n u.mailformat,\n u.maildigest,\n u.imagealt,\n u.email,\n u.emailstop,\n u.city,\n u.country,\n u.lastaccess,\n u.lastlogin,\n u.picture,\n u.timezone,\n u.theme,\n u.lang,\n u.trackforums,\n u.mnethostid\"",
";",
"}",
"// Retrieve the forum context if it wasn't specified.",
"$",
"context",
"=",
"forum_get_context",
"(",
"$",
"forum",
"->",
"id",
",",
"$",
"context",
")",
";",
"if",
"(",
"self",
"::",
"is_forcesubscribed",
"(",
"$",
"forum",
")",
")",
"{",
"$",
"results",
"=",
"\\",
"mod_forum",
"\\",
"subscriptions",
"::",
"get_potential_subscribers",
"(",
"$",
"context",
",",
"$",
"groupid",
",",
"$",
"fields",
",",
"\"u.email ASC\"",
")",
";",
"}",
"else",
"{",
"// Only active enrolled users or everybody on the frontpage.",
"list",
"(",
"$",
"esql",
",",
"$",
"params",
")",
"=",
"get_enrolled_sql",
"(",
"$",
"context",
",",
"''",
",",
"$",
"groupid",
",",
"true",
")",
";",
"$",
"params",
"[",
"'forumid'",
"]",
"=",
"$",
"forum",
"->",
"id",
";",
"if",
"(",
"$",
"includediscussionsubscriptions",
")",
"{",
"$",
"params",
"[",
"'sforumid'",
"]",
"=",
"$",
"forum",
"->",
"id",
";",
"$",
"params",
"[",
"'dsforumid'",
"]",
"=",
"$",
"forum",
"->",
"id",
";",
"$",
"params",
"[",
"'unsubscribed'",
"]",
"=",
"self",
"::",
"FORUM_DISCUSSION_UNSUBSCRIBED",
";",
"$",
"sql",
"=",
"\"SELECT $fields\n FROM (\n SELECT userid FROM {forum_subscriptions} s\n WHERE\n s.forum = :sforumid\n UNION\n SELECT userid FROM {forum_discussion_subs} ds\n WHERE\n ds.forum = :dsforumid AND ds.preference <> :unsubscribed\n ) subscriptions\n JOIN {user} u ON u.id = subscriptions.userid\n JOIN ($esql) je ON je.id = u.id\n ORDER BY u.email ASC\"",
";",
"}",
"else",
"{",
"$",
"sql",
"=",
"\"SELECT $fields\n FROM {user} u\n JOIN ($esql) je ON je.id = u.id\n JOIN {forum_subscriptions} s ON s.userid = u.id\n WHERE\n s.forum = :forumid\n ORDER BY u.email ASC\"",
";",
"}",
"$",
"results",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}",
"// Guest user should never be subscribed to a forum.",
"unset",
"(",
"$",
"results",
"[",
"$",
"CFG",
"->",
"siteguest",
"]",
")",
";",
"// Apply the activity module availability resetrictions.",
"$",
"cm",
"=",
"get_coursemodule_from_instance",
"(",
"'forum'",
",",
"$",
"forum",
"->",
"id",
",",
"$",
"forum",
"->",
"course",
")",
";",
"$",
"modinfo",
"=",
"get_fast_modinfo",
"(",
"$",
"forum",
"->",
"course",
")",
";",
"$",
"info",
"=",
"new",
"\\",
"core_availability",
"\\",
"info_module",
"(",
"$",
"modinfo",
"->",
"get_cm",
"(",
"$",
"cm",
"->",
"id",
")",
")",
";",
"$",
"results",
"=",
"$",
"info",
"->",
"filter_user_list",
"(",
"$",
"results",
")",
";",
"return",
"$",
"results",
";",
"}"
] | Returns a list of user objects who are subscribed to this forum.
@param stdClass $forum The forum record.
@param int $groupid The group id if restricting subscriptions to a group of users, or 0 for all.
@param context_module $context the forum context, to save re-fetching it where possible.
@param string $fields requested user fields (with "u." table prefix).
@param boolean $includediscussionsubscriptions Whether to take discussion subscriptions and unsubscriptions into consideration.
@return array list of users. | [
"Returns",
"a",
"list",
"of",
"user",
"objects",
"who",
"are",
"subscribed",
"to",
"this",
"forum",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/subscriptions.php#L390-L469 |
212,760 | moodle/moodle | mod/forum/classes/subscriptions.php | subscriptions.fetch_discussion_subscription | public static function fetch_discussion_subscription($forumid, $userid = null) {
self::fill_discussion_subscription_cache($forumid, $userid);
if (!isset(self::$forumdiscussioncache[$userid]) || !isset(self::$forumdiscussioncache[$userid][$forumid])) {
return array();
}
return self::$forumdiscussioncache[$userid][$forumid];
} | php | public static function fetch_discussion_subscription($forumid, $userid = null) {
self::fill_discussion_subscription_cache($forumid, $userid);
if (!isset(self::$forumdiscussioncache[$userid]) || !isset(self::$forumdiscussioncache[$userid][$forumid])) {
return array();
}
return self::$forumdiscussioncache[$userid][$forumid];
} | [
"public",
"static",
"function",
"fetch_discussion_subscription",
"(",
"$",
"forumid",
",",
"$",
"userid",
"=",
"null",
")",
"{",
"self",
"::",
"fill_discussion_subscription_cache",
"(",
"$",
"forumid",
",",
"$",
"userid",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
")",
"||",
"!",
"isset",
"(",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forumid",
"]",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"return",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forumid",
"]",
";",
"}"
] | Retrieve the discussion subscription data for the specified userid and forum.
This is returned as an array of discussions for that forum which contain the preference in a stdClass.
@param int $forumid The forum to retrieve a cache for
@param int $userid The user ID
@return array of stdClass objects with one per discussion in the forum. | [
"Retrieve",
"the",
"discussion",
"subscription",
"data",
"for",
"the",
"specified",
"userid",
"and",
"forum",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/subscriptions.php#L480-L488 |
212,761 | moodle/moodle | mod/forum/classes/subscriptions.php | subscriptions.fill_discussion_subscription_cache | public static function fill_discussion_subscription_cache($forumid, $userid = null) {
global $DB;
if (!isset(self::$discussionfetchedforums[$forumid])) {
// This forum hasn't been fetched as a whole yet.
if (isset($userid)) {
if (!isset(self::$forumdiscussioncache[$userid])) {
self::$forumdiscussioncache[$userid] = array();
}
if (!isset(self::$forumdiscussioncache[$userid][$forumid])) {
$subscriptions = $DB->get_recordset('forum_discussion_subs', array(
'userid' => $userid,
'forum' => $forumid,
), null, 'id, discussion, preference');
foreach ($subscriptions as $id => $data) {
self::add_to_discussion_cache($forumid, $userid, $data->discussion, $data->preference);
}
$subscriptions->close();
}
} else {
$subscriptions = $DB->get_recordset('forum_discussion_subs', array(
'forum' => $forumid,
), null, 'id, userid, discussion, preference');
foreach ($subscriptions as $id => $data) {
self::add_to_discussion_cache($forumid, $data->userid, $data->discussion, $data->preference);
}
self::$discussionfetchedforums[$forumid] = true;
$subscriptions->close();
}
}
} | php | public static function fill_discussion_subscription_cache($forumid, $userid = null) {
global $DB;
if (!isset(self::$discussionfetchedforums[$forumid])) {
// This forum hasn't been fetched as a whole yet.
if (isset($userid)) {
if (!isset(self::$forumdiscussioncache[$userid])) {
self::$forumdiscussioncache[$userid] = array();
}
if (!isset(self::$forumdiscussioncache[$userid][$forumid])) {
$subscriptions = $DB->get_recordset('forum_discussion_subs', array(
'userid' => $userid,
'forum' => $forumid,
), null, 'id, discussion, preference');
foreach ($subscriptions as $id => $data) {
self::add_to_discussion_cache($forumid, $userid, $data->discussion, $data->preference);
}
$subscriptions->close();
}
} else {
$subscriptions = $DB->get_recordset('forum_discussion_subs', array(
'forum' => $forumid,
), null, 'id, userid, discussion, preference');
foreach ($subscriptions as $id => $data) {
self::add_to_discussion_cache($forumid, $data->userid, $data->discussion, $data->preference);
}
self::$discussionfetchedforums[$forumid] = true;
$subscriptions->close();
}
}
} | [
"public",
"static",
"function",
"fill_discussion_subscription_cache",
"(",
"$",
"forumid",
",",
"$",
"userid",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"discussionfetchedforums",
"[",
"$",
"forumid",
"]",
")",
")",
"{",
"// This forum hasn't been fetched as a whole yet.",
"if",
"(",
"isset",
"(",
"$",
"userid",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
")",
")",
"{",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forumid",
"]",
")",
")",
"{",
"$",
"subscriptions",
"=",
"$",
"DB",
"->",
"get_recordset",
"(",
"'forum_discussion_subs'",
",",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
",",
"'forum'",
"=>",
"$",
"forumid",
",",
")",
",",
"null",
",",
"'id, discussion, preference'",
")",
";",
"foreach",
"(",
"$",
"subscriptions",
"as",
"$",
"id",
"=>",
"$",
"data",
")",
"{",
"self",
"::",
"add_to_discussion_cache",
"(",
"$",
"forumid",
",",
"$",
"userid",
",",
"$",
"data",
"->",
"discussion",
",",
"$",
"data",
"->",
"preference",
")",
";",
"}",
"$",
"subscriptions",
"->",
"close",
"(",
")",
";",
"}",
"}",
"else",
"{",
"$",
"subscriptions",
"=",
"$",
"DB",
"->",
"get_recordset",
"(",
"'forum_discussion_subs'",
",",
"array",
"(",
"'forum'",
"=>",
"$",
"forumid",
",",
")",
",",
"null",
",",
"'id, userid, discussion, preference'",
")",
";",
"foreach",
"(",
"$",
"subscriptions",
"as",
"$",
"id",
"=>",
"$",
"data",
")",
"{",
"self",
"::",
"add_to_discussion_cache",
"(",
"$",
"forumid",
",",
"$",
"data",
"->",
"userid",
",",
"$",
"data",
"->",
"discussion",
",",
"$",
"data",
"->",
"preference",
")",
";",
"}",
"self",
"::",
"$",
"discussionfetchedforums",
"[",
"$",
"forumid",
"]",
"=",
"true",
";",
"$",
"subscriptions",
"->",
"close",
"(",
")",
";",
"}",
"}",
"}"
] | Fill the discussion subscription data for the specified userid and forum.
If the userid is not specified, then all discussion subscription data for that forum is fetched in a single query
and used for subsequent lookups without requiring further database queries.
@param int $forumid The forum to retrieve a cache for
@param int $userid The user ID
@return void | [
"Fill",
"the",
"discussion",
"subscription",
"data",
"for",
"the",
"specified",
"userid",
"and",
"forum",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/subscriptions.php#L500-L531 |
212,762 | moodle/moodle | mod/forum/classes/subscriptions.php | subscriptions.add_to_discussion_cache | protected static function add_to_discussion_cache($forumid, $userid, $discussion, $preference) {
if (!isset(self::$forumdiscussioncache[$userid])) {
self::$forumdiscussioncache[$userid] = array();
}
if (!isset(self::$forumdiscussioncache[$userid][$forumid])) {
self::$forumdiscussioncache[$userid][$forumid] = array();
}
self::$forumdiscussioncache[$userid][$forumid][$discussion] = $preference;
} | php | protected static function add_to_discussion_cache($forumid, $userid, $discussion, $preference) {
if (!isset(self::$forumdiscussioncache[$userid])) {
self::$forumdiscussioncache[$userid] = array();
}
if (!isset(self::$forumdiscussioncache[$userid][$forumid])) {
self::$forumdiscussioncache[$userid][$forumid] = array();
}
self::$forumdiscussioncache[$userid][$forumid][$discussion] = $preference;
} | [
"protected",
"static",
"function",
"add_to_discussion_cache",
"(",
"$",
"forumid",
",",
"$",
"userid",
",",
"$",
"discussion",
",",
"$",
"preference",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
")",
")",
"{",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forumid",
"]",
")",
")",
"{",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forumid",
"]",
"=",
"array",
"(",
")",
";",
"}",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forumid",
"]",
"[",
"$",
"discussion",
"]",
"=",
"$",
"preference",
";",
"}"
] | Add the specified discussion and user preference to the discussion
subscription cache.
@param int $forumid The ID of the forum that this preference belongs to
@param int $userid The ID of the user that this preference belongs to
@param int $discussion The ID of the discussion that this preference relates to
@param int $preference The preference to store | [
"Add",
"the",
"specified",
"discussion",
"and",
"user",
"preference",
"to",
"the",
"discussion",
"subscription",
"cache",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/subscriptions.php#L542-L552 |
212,763 | moodle/moodle | mod/forum/classes/subscriptions.php | subscriptions.subscribe_user | public static function subscribe_user($userid, $forum, $context = null, $userrequest = false) {
global $DB;
if (self::is_subscribed($userid, $forum)) {
return true;
}
$sub = new \stdClass();
$sub->userid = $userid;
$sub->forum = $forum->id;
$result = $DB->insert_record("forum_subscriptions", $sub);
if ($userrequest) {
$discussionsubscriptions = $DB->get_recordset('forum_discussion_subs', array('userid' => $userid, 'forum' => $forum->id));
$DB->delete_records_select('forum_discussion_subs',
'userid = :userid AND forum = :forumid AND preference <> :preference', array(
'userid' => $userid,
'forumid' => $forum->id,
'preference' => self::FORUM_DISCUSSION_UNSUBSCRIBED,
));
// Reset the subscription caches for this forum.
// We know that the there were previously entries and there aren't any more.
if (isset(self::$forumdiscussioncache[$userid]) && isset(self::$forumdiscussioncache[$userid][$forum->id])) {
foreach (self::$forumdiscussioncache[$userid][$forum->id] as $discussionid => $preference) {
if ($preference != self::FORUM_DISCUSSION_UNSUBSCRIBED) {
unset(self::$forumdiscussioncache[$userid][$forum->id][$discussionid]);
}
}
}
}
// Reset the cache for this forum.
self::$forumcache[$userid][$forum->id] = true;
$context = forum_get_context($forum->id, $context);
$params = array(
'context' => $context,
'objectid' => $result,
'relateduserid' => $userid,
'other' => array('forumid' => $forum->id),
);
$event = event\subscription_created::create($params);
if ($userrequest && $discussionsubscriptions) {
foreach ($discussionsubscriptions as $subscription) {
$event->add_record_snapshot('forum_discussion_subs', $subscription);
}
$discussionsubscriptions->close();
}
$event->trigger();
return $result;
} | php | public static function subscribe_user($userid, $forum, $context = null, $userrequest = false) {
global $DB;
if (self::is_subscribed($userid, $forum)) {
return true;
}
$sub = new \stdClass();
$sub->userid = $userid;
$sub->forum = $forum->id;
$result = $DB->insert_record("forum_subscriptions", $sub);
if ($userrequest) {
$discussionsubscriptions = $DB->get_recordset('forum_discussion_subs', array('userid' => $userid, 'forum' => $forum->id));
$DB->delete_records_select('forum_discussion_subs',
'userid = :userid AND forum = :forumid AND preference <> :preference', array(
'userid' => $userid,
'forumid' => $forum->id,
'preference' => self::FORUM_DISCUSSION_UNSUBSCRIBED,
));
// Reset the subscription caches for this forum.
// We know that the there were previously entries and there aren't any more.
if (isset(self::$forumdiscussioncache[$userid]) && isset(self::$forumdiscussioncache[$userid][$forum->id])) {
foreach (self::$forumdiscussioncache[$userid][$forum->id] as $discussionid => $preference) {
if ($preference != self::FORUM_DISCUSSION_UNSUBSCRIBED) {
unset(self::$forumdiscussioncache[$userid][$forum->id][$discussionid]);
}
}
}
}
// Reset the cache for this forum.
self::$forumcache[$userid][$forum->id] = true;
$context = forum_get_context($forum->id, $context);
$params = array(
'context' => $context,
'objectid' => $result,
'relateduserid' => $userid,
'other' => array('forumid' => $forum->id),
);
$event = event\subscription_created::create($params);
if ($userrequest && $discussionsubscriptions) {
foreach ($discussionsubscriptions as $subscription) {
$event->add_record_snapshot('forum_discussion_subs', $subscription);
}
$discussionsubscriptions->close();
}
$event->trigger();
return $result;
} | [
"public",
"static",
"function",
"subscribe_user",
"(",
"$",
"userid",
",",
"$",
"forum",
",",
"$",
"context",
"=",
"null",
",",
"$",
"userrequest",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"self",
"::",
"is_subscribed",
"(",
"$",
"userid",
",",
"$",
"forum",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"sub",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"sub",
"->",
"userid",
"=",
"$",
"userid",
";",
"$",
"sub",
"->",
"forum",
"=",
"$",
"forum",
"->",
"id",
";",
"$",
"result",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"\"forum_subscriptions\"",
",",
"$",
"sub",
")",
";",
"if",
"(",
"$",
"userrequest",
")",
"{",
"$",
"discussionsubscriptions",
"=",
"$",
"DB",
"->",
"get_recordset",
"(",
"'forum_discussion_subs'",
",",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
",",
"'forum'",
"=>",
"$",
"forum",
"->",
"id",
")",
")",
";",
"$",
"DB",
"->",
"delete_records_select",
"(",
"'forum_discussion_subs'",
",",
"'userid = :userid AND forum = :forumid AND preference <> :preference'",
",",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
",",
"'forumid'",
"=>",
"$",
"forum",
"->",
"id",
",",
"'preference'",
"=>",
"self",
"::",
"FORUM_DISCUSSION_UNSUBSCRIBED",
",",
")",
")",
";",
"// Reset the subscription caches for this forum.",
"// We know that the there were previously entries and there aren't any more.",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
")",
"&&",
"isset",
"(",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forum",
"->",
"id",
"]",
")",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forum",
"->",
"id",
"]",
"as",
"$",
"discussionid",
"=>",
"$",
"preference",
")",
"{",
"if",
"(",
"$",
"preference",
"!=",
"self",
"::",
"FORUM_DISCUSSION_UNSUBSCRIBED",
")",
"{",
"unset",
"(",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forum",
"->",
"id",
"]",
"[",
"$",
"discussionid",
"]",
")",
";",
"}",
"}",
"}",
"}",
"// Reset the cache for this forum.",
"self",
"::",
"$",
"forumcache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forum",
"->",
"id",
"]",
"=",
"true",
";",
"$",
"context",
"=",
"forum_get_context",
"(",
"$",
"forum",
"->",
"id",
",",
"$",
"context",
")",
";",
"$",
"params",
"=",
"array",
"(",
"'context'",
"=>",
"$",
"context",
",",
"'objectid'",
"=>",
"$",
"result",
",",
"'relateduserid'",
"=>",
"$",
"userid",
",",
"'other'",
"=>",
"array",
"(",
"'forumid'",
"=>",
"$",
"forum",
"->",
"id",
")",
",",
")",
";",
"$",
"event",
"=",
"event",
"\\",
"subscription_created",
"::",
"create",
"(",
"$",
"params",
")",
";",
"if",
"(",
"$",
"userrequest",
"&&",
"$",
"discussionsubscriptions",
")",
"{",
"foreach",
"(",
"$",
"discussionsubscriptions",
"as",
"$",
"subscription",
")",
"{",
"$",
"event",
"->",
"add_record_snapshot",
"(",
"'forum_discussion_subs'",
",",
"$",
"subscription",
")",
";",
"}",
"$",
"discussionsubscriptions",
"->",
"close",
"(",
")",
";",
"}",
"$",
"event",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Adds user to the subscriber list.
@param int $userid The ID of the user to subscribe
@param \stdClass $forum The forum record for this forum.
@param \context_module|null $context Module context, may be omitted if not known or if called for the current
module set in page.
@param boolean $userrequest Whether the user requested this change themselves. This has an effect on whether
discussion subscriptions are removed too.
@return bool|int Returns true if the user is already subscribed, or the forum_subscriptions ID if the user was
successfully subscribed. | [
"Adds",
"user",
"to",
"the",
"subscriber",
"list",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/subscriptions.php#L588-L642 |
212,764 | moodle/moodle | mod/forum/classes/subscriptions.php | subscriptions.unsubscribe_user | public static function unsubscribe_user($userid, $forum, $context = null, $userrequest = false) {
global $DB;
$sqlparams = array(
'userid' => $userid,
'forum' => $forum->id,
);
$DB->delete_records('forum_digests', $sqlparams);
if ($forumsubscription = $DB->get_record('forum_subscriptions', $sqlparams)) {
$DB->delete_records('forum_subscriptions', array('id' => $forumsubscription->id));
if ($userrequest) {
$discussionsubscriptions = $DB->get_recordset('forum_discussion_subs', $sqlparams);
$DB->delete_records('forum_discussion_subs',
array('userid' => $userid, 'forum' => $forum->id, 'preference' => self::FORUM_DISCUSSION_UNSUBSCRIBED));
// We know that the there were previously entries and there aren't any more.
if (isset(self::$forumdiscussioncache[$userid]) && isset(self::$forumdiscussioncache[$userid][$forum->id])) {
self::$forumdiscussioncache[$userid][$forum->id] = array();
}
}
// Reset the cache for this forum.
self::$forumcache[$userid][$forum->id] = false;
$context = forum_get_context($forum->id, $context);
$params = array(
'context' => $context,
'objectid' => $forumsubscription->id,
'relateduserid' => $userid,
'other' => array('forumid' => $forum->id),
);
$event = event\subscription_deleted::create($params);
$event->add_record_snapshot('forum_subscriptions', $forumsubscription);
if ($userrequest && $discussionsubscriptions) {
foreach ($discussionsubscriptions as $subscription) {
$event->add_record_snapshot('forum_discussion_subs', $subscription);
}
$discussionsubscriptions->close();
}
$event->trigger();
}
return true;
} | php | public static function unsubscribe_user($userid, $forum, $context = null, $userrequest = false) {
global $DB;
$sqlparams = array(
'userid' => $userid,
'forum' => $forum->id,
);
$DB->delete_records('forum_digests', $sqlparams);
if ($forumsubscription = $DB->get_record('forum_subscriptions', $sqlparams)) {
$DB->delete_records('forum_subscriptions', array('id' => $forumsubscription->id));
if ($userrequest) {
$discussionsubscriptions = $DB->get_recordset('forum_discussion_subs', $sqlparams);
$DB->delete_records('forum_discussion_subs',
array('userid' => $userid, 'forum' => $forum->id, 'preference' => self::FORUM_DISCUSSION_UNSUBSCRIBED));
// We know that the there were previously entries and there aren't any more.
if (isset(self::$forumdiscussioncache[$userid]) && isset(self::$forumdiscussioncache[$userid][$forum->id])) {
self::$forumdiscussioncache[$userid][$forum->id] = array();
}
}
// Reset the cache for this forum.
self::$forumcache[$userid][$forum->id] = false;
$context = forum_get_context($forum->id, $context);
$params = array(
'context' => $context,
'objectid' => $forumsubscription->id,
'relateduserid' => $userid,
'other' => array('forumid' => $forum->id),
);
$event = event\subscription_deleted::create($params);
$event->add_record_snapshot('forum_subscriptions', $forumsubscription);
if ($userrequest && $discussionsubscriptions) {
foreach ($discussionsubscriptions as $subscription) {
$event->add_record_snapshot('forum_discussion_subs', $subscription);
}
$discussionsubscriptions->close();
}
$event->trigger();
}
return true;
} | [
"public",
"static",
"function",
"unsubscribe_user",
"(",
"$",
"userid",
",",
"$",
"forum",
",",
"$",
"context",
"=",
"null",
",",
"$",
"userrequest",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"sqlparams",
"=",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
",",
"'forum'",
"=>",
"$",
"forum",
"->",
"id",
",",
")",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"'forum_digests'",
",",
"$",
"sqlparams",
")",
";",
"if",
"(",
"$",
"forumsubscription",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'forum_subscriptions'",
",",
"$",
"sqlparams",
")",
")",
"{",
"$",
"DB",
"->",
"delete_records",
"(",
"'forum_subscriptions'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"forumsubscription",
"->",
"id",
")",
")",
";",
"if",
"(",
"$",
"userrequest",
")",
"{",
"$",
"discussionsubscriptions",
"=",
"$",
"DB",
"->",
"get_recordset",
"(",
"'forum_discussion_subs'",
",",
"$",
"sqlparams",
")",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"'forum_discussion_subs'",
",",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
",",
"'forum'",
"=>",
"$",
"forum",
"->",
"id",
",",
"'preference'",
"=>",
"self",
"::",
"FORUM_DISCUSSION_UNSUBSCRIBED",
")",
")",
";",
"// We know that the there were previously entries and there aren't any more.",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
")",
"&&",
"isset",
"(",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forum",
"->",
"id",
"]",
")",
")",
"{",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forum",
"->",
"id",
"]",
"=",
"array",
"(",
")",
";",
"}",
"}",
"// Reset the cache for this forum.",
"self",
"::",
"$",
"forumcache",
"[",
"$",
"userid",
"]",
"[",
"$",
"forum",
"->",
"id",
"]",
"=",
"false",
";",
"$",
"context",
"=",
"forum_get_context",
"(",
"$",
"forum",
"->",
"id",
",",
"$",
"context",
")",
";",
"$",
"params",
"=",
"array",
"(",
"'context'",
"=>",
"$",
"context",
",",
"'objectid'",
"=>",
"$",
"forumsubscription",
"->",
"id",
",",
"'relateduserid'",
"=>",
"$",
"userid",
",",
"'other'",
"=>",
"array",
"(",
"'forumid'",
"=>",
"$",
"forum",
"->",
"id",
")",
",",
")",
";",
"$",
"event",
"=",
"event",
"\\",
"subscription_deleted",
"::",
"create",
"(",
"$",
"params",
")",
";",
"$",
"event",
"->",
"add_record_snapshot",
"(",
"'forum_subscriptions'",
",",
"$",
"forumsubscription",
")",
";",
"if",
"(",
"$",
"userrequest",
"&&",
"$",
"discussionsubscriptions",
")",
"{",
"foreach",
"(",
"$",
"discussionsubscriptions",
"as",
"$",
"subscription",
")",
"{",
"$",
"event",
"->",
"add_record_snapshot",
"(",
"'forum_discussion_subs'",
",",
"$",
"subscription",
")",
";",
"}",
"$",
"discussionsubscriptions",
"->",
"close",
"(",
")",
";",
"}",
"$",
"event",
"->",
"trigger",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Removes user from the subscriber list
@param int $userid The ID of the user to unsubscribe
@param \stdClass $forum The forum record for this forum.
@param \context_module|null $context Module context, may be omitted if not known or if called for the current
module set in page.
@param boolean $userrequest Whether the user requested this change themselves. This has an effect on whether
discussion subscriptions are removed too.
@return boolean Always returns true. | [
"Removes",
"user",
"from",
"the",
"subscriber",
"list"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/subscriptions.php#L655-L701 |
212,765 | moodle/moodle | mod/forum/classes/subscriptions.php | subscriptions.subscribe_user_to_discussion | public static function subscribe_user_to_discussion($userid, $discussion, $context = null) {
global $DB;
// First check whether the user is subscribed to the discussion already.
$subscription = $DB->get_record('forum_discussion_subs', array('userid' => $userid, 'discussion' => $discussion->id));
if ($subscription) {
if ($subscription->preference != self::FORUM_DISCUSSION_UNSUBSCRIBED) {
// The user is already subscribed to the discussion. Ignore.
return false;
}
}
// No discussion-level subscription. Check for a forum level subscription.
if ($DB->record_exists('forum_subscriptions', array('userid' => $userid, 'forum' => $discussion->forum))) {
if ($subscription && $subscription->preference == self::FORUM_DISCUSSION_UNSUBSCRIBED) {
// The user is subscribed to the forum, but unsubscribed from the discussion, delete the discussion preference.
$DB->delete_records('forum_discussion_subs', array('id' => $subscription->id));
unset(self::$forumdiscussioncache[$userid][$discussion->forum][$discussion->id]);
} else {
// The user is already subscribed to the forum. Ignore.
return false;
}
} else {
if ($subscription) {
$subscription->preference = time();
$DB->update_record('forum_discussion_subs', $subscription);
} else {
$subscription = new \stdClass();
$subscription->userid = $userid;
$subscription->forum = $discussion->forum;
$subscription->discussion = $discussion->id;
$subscription->preference = time();
$subscription->id = $DB->insert_record('forum_discussion_subs', $subscription);
self::$forumdiscussioncache[$userid][$discussion->forum][$discussion->id] = $subscription->preference;
}
}
$context = forum_get_context($discussion->forum, $context);
$params = array(
'context' => $context,
'objectid' => $subscription->id,
'relateduserid' => $userid,
'other' => array(
'forumid' => $discussion->forum,
'discussion' => $discussion->id,
),
);
$event = event\discussion_subscription_created::create($params);
$event->trigger();
return true;
} | php | public static function subscribe_user_to_discussion($userid, $discussion, $context = null) {
global $DB;
// First check whether the user is subscribed to the discussion already.
$subscription = $DB->get_record('forum_discussion_subs', array('userid' => $userid, 'discussion' => $discussion->id));
if ($subscription) {
if ($subscription->preference != self::FORUM_DISCUSSION_UNSUBSCRIBED) {
// The user is already subscribed to the discussion. Ignore.
return false;
}
}
// No discussion-level subscription. Check for a forum level subscription.
if ($DB->record_exists('forum_subscriptions', array('userid' => $userid, 'forum' => $discussion->forum))) {
if ($subscription && $subscription->preference == self::FORUM_DISCUSSION_UNSUBSCRIBED) {
// The user is subscribed to the forum, but unsubscribed from the discussion, delete the discussion preference.
$DB->delete_records('forum_discussion_subs', array('id' => $subscription->id));
unset(self::$forumdiscussioncache[$userid][$discussion->forum][$discussion->id]);
} else {
// The user is already subscribed to the forum. Ignore.
return false;
}
} else {
if ($subscription) {
$subscription->preference = time();
$DB->update_record('forum_discussion_subs', $subscription);
} else {
$subscription = new \stdClass();
$subscription->userid = $userid;
$subscription->forum = $discussion->forum;
$subscription->discussion = $discussion->id;
$subscription->preference = time();
$subscription->id = $DB->insert_record('forum_discussion_subs', $subscription);
self::$forumdiscussioncache[$userid][$discussion->forum][$discussion->id] = $subscription->preference;
}
}
$context = forum_get_context($discussion->forum, $context);
$params = array(
'context' => $context,
'objectid' => $subscription->id,
'relateduserid' => $userid,
'other' => array(
'forumid' => $discussion->forum,
'discussion' => $discussion->id,
),
);
$event = event\discussion_subscription_created::create($params);
$event->trigger();
return true;
} | [
"public",
"static",
"function",
"subscribe_user_to_discussion",
"(",
"$",
"userid",
",",
"$",
"discussion",
",",
"$",
"context",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"// First check whether the user is subscribed to the discussion already.",
"$",
"subscription",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'forum_discussion_subs'",
",",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
",",
"'discussion'",
"=>",
"$",
"discussion",
"->",
"id",
")",
")",
";",
"if",
"(",
"$",
"subscription",
")",
"{",
"if",
"(",
"$",
"subscription",
"->",
"preference",
"!=",
"self",
"::",
"FORUM_DISCUSSION_UNSUBSCRIBED",
")",
"{",
"// The user is already subscribed to the discussion. Ignore.",
"return",
"false",
";",
"}",
"}",
"// No discussion-level subscription. Check for a forum level subscription.",
"if",
"(",
"$",
"DB",
"->",
"record_exists",
"(",
"'forum_subscriptions'",
",",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
",",
"'forum'",
"=>",
"$",
"discussion",
"->",
"forum",
")",
")",
")",
"{",
"if",
"(",
"$",
"subscription",
"&&",
"$",
"subscription",
"->",
"preference",
"==",
"self",
"::",
"FORUM_DISCUSSION_UNSUBSCRIBED",
")",
"{",
"// The user is subscribed to the forum, but unsubscribed from the discussion, delete the discussion preference.",
"$",
"DB",
"->",
"delete_records",
"(",
"'forum_discussion_subs'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"subscription",
"->",
"id",
")",
")",
";",
"unset",
"(",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
"[",
"$",
"discussion",
"->",
"forum",
"]",
"[",
"$",
"discussion",
"->",
"id",
"]",
")",
";",
"}",
"else",
"{",
"// The user is already subscribed to the forum. Ignore.",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"subscription",
")",
"{",
"$",
"subscription",
"->",
"preference",
"=",
"time",
"(",
")",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'forum_discussion_subs'",
",",
"$",
"subscription",
")",
";",
"}",
"else",
"{",
"$",
"subscription",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"subscription",
"->",
"userid",
"=",
"$",
"userid",
";",
"$",
"subscription",
"->",
"forum",
"=",
"$",
"discussion",
"->",
"forum",
";",
"$",
"subscription",
"->",
"discussion",
"=",
"$",
"discussion",
"->",
"id",
";",
"$",
"subscription",
"->",
"preference",
"=",
"time",
"(",
")",
";",
"$",
"subscription",
"->",
"id",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"'forum_discussion_subs'",
",",
"$",
"subscription",
")",
";",
"self",
"::",
"$",
"forumdiscussioncache",
"[",
"$",
"userid",
"]",
"[",
"$",
"discussion",
"->",
"forum",
"]",
"[",
"$",
"discussion",
"->",
"id",
"]",
"=",
"$",
"subscription",
"->",
"preference",
";",
"}",
"}",
"$",
"context",
"=",
"forum_get_context",
"(",
"$",
"discussion",
"->",
"forum",
",",
"$",
"context",
")",
";",
"$",
"params",
"=",
"array",
"(",
"'context'",
"=>",
"$",
"context",
",",
"'objectid'",
"=>",
"$",
"subscription",
"->",
"id",
",",
"'relateduserid'",
"=>",
"$",
"userid",
",",
"'other'",
"=>",
"array",
"(",
"'forumid'",
"=>",
"$",
"discussion",
"->",
"forum",
",",
"'discussion'",
"=>",
"$",
"discussion",
"->",
"id",
",",
")",
",",
")",
";",
"$",
"event",
"=",
"event",
"\\",
"discussion_subscription_created",
"::",
"create",
"(",
"$",
"params",
")",
";",
"$",
"event",
"->",
"trigger",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Subscribes the user to the specified discussion.
@param int $userid The userid of the user being subscribed
@param \stdClass $discussion The discussion to subscribe to
@param \context_module|null $context Module context, may be omitted if not known or if called for the current
module set in page.
@return boolean Whether a change was made | [
"Subscribes",
"the",
"user",
"to",
"the",
"specified",
"discussion",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/subscriptions.php#L712-L764 |
212,766 | moodle/moodle | mod/forum/classes/subscriptions.php | subscriptions.get_user_default_subscription | public static function get_user_default_subscription($forum, $context, $cm, ?int $discussionid) {
global $USER;
$manageactivities = has_capability('moodle/course:manageactivities', $context);
if (\mod_forum\subscriptions::subscription_disabled($forum) && !$manageactivities) {
// User does not have permission to subscribe to this discussion at all.
$discussionsubscribe = false;
} else if (\mod_forum\subscriptions::is_forcesubscribed($forum)) {
// User does not have permission to unsubscribe from this discussion at all.
$discussionsubscribe = true;
} else {
if (isset($discussion) && \mod_forum\subscriptions::is_subscribed($USER->id, $forum, $discussionid, $cm)) {
// User is subscribed to the discussion - continue the subscription.
$discussionsubscribe = true;
} else if (!isset($discussionid) && \mod_forum\subscriptions::is_subscribed($USER->id, $forum, null, $cm)) {
// Starting a new discussion, and the user is subscribed to the forum - subscribe to the discussion.
$discussionsubscribe = true;
} else {
// User is not subscribed to either forum or discussion. Follow user preference.
$discussionsubscribe = $USER->autosubscribe ?? false;
}
}
return $discussionsubscribe;
} | php | public static function get_user_default_subscription($forum, $context, $cm, ?int $discussionid) {
global $USER;
$manageactivities = has_capability('moodle/course:manageactivities', $context);
if (\mod_forum\subscriptions::subscription_disabled($forum) && !$manageactivities) {
// User does not have permission to subscribe to this discussion at all.
$discussionsubscribe = false;
} else if (\mod_forum\subscriptions::is_forcesubscribed($forum)) {
// User does not have permission to unsubscribe from this discussion at all.
$discussionsubscribe = true;
} else {
if (isset($discussion) && \mod_forum\subscriptions::is_subscribed($USER->id, $forum, $discussionid, $cm)) {
// User is subscribed to the discussion - continue the subscription.
$discussionsubscribe = true;
} else if (!isset($discussionid) && \mod_forum\subscriptions::is_subscribed($USER->id, $forum, null, $cm)) {
// Starting a new discussion, and the user is subscribed to the forum - subscribe to the discussion.
$discussionsubscribe = true;
} else {
// User is not subscribed to either forum or discussion. Follow user preference.
$discussionsubscribe = $USER->autosubscribe ?? false;
}
}
return $discussionsubscribe;
} | [
"public",
"static",
"function",
"get_user_default_subscription",
"(",
"$",
"forum",
",",
"$",
"context",
",",
"$",
"cm",
",",
"?",
"int",
"$",
"discussionid",
")",
"{",
"global",
"$",
"USER",
";",
"$",
"manageactivities",
"=",
"has_capability",
"(",
"'moodle/course:manageactivities'",
",",
"$",
"context",
")",
";",
"if",
"(",
"\\",
"mod_forum",
"\\",
"subscriptions",
"::",
"subscription_disabled",
"(",
"$",
"forum",
")",
"&&",
"!",
"$",
"manageactivities",
")",
"{",
"// User does not have permission to subscribe to this discussion at all.",
"$",
"discussionsubscribe",
"=",
"false",
";",
"}",
"else",
"if",
"(",
"\\",
"mod_forum",
"\\",
"subscriptions",
"::",
"is_forcesubscribed",
"(",
"$",
"forum",
")",
")",
"{",
"// User does not have permission to unsubscribe from this discussion at all.",
"$",
"discussionsubscribe",
"=",
"true",
";",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"discussion",
")",
"&&",
"\\",
"mod_forum",
"\\",
"subscriptions",
"::",
"is_subscribed",
"(",
"$",
"USER",
"->",
"id",
",",
"$",
"forum",
",",
"$",
"discussionid",
",",
"$",
"cm",
")",
")",
"{",
"// User is subscribed to the discussion - continue the subscription.",
"$",
"discussionsubscribe",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"!",
"isset",
"(",
"$",
"discussionid",
")",
"&&",
"\\",
"mod_forum",
"\\",
"subscriptions",
"::",
"is_subscribed",
"(",
"$",
"USER",
"->",
"id",
",",
"$",
"forum",
",",
"null",
",",
"$",
"cm",
")",
")",
"{",
"// Starting a new discussion, and the user is subscribed to the forum - subscribe to the discussion.",
"$",
"discussionsubscribe",
"=",
"true",
";",
"}",
"else",
"{",
"// User is not subscribed to either forum or discussion. Follow user preference.",
"$",
"discussionsubscribe",
"=",
"$",
"USER",
"->",
"autosubscribe",
"??",
"false",
";",
"}",
"}",
"return",
"$",
"discussionsubscribe",
";",
"}"
] | Gets the default subscription value for the logged in user.
@param \stdClass $forum The forum record
@param \context $context The course context
@param \cm_info $cm cm_info
@param int|null $discussionid The discussion we are checking against
@return bool Default subscription
@throws coding_exception | [
"Gets",
"the",
"default",
"subscription",
"value",
"for",
"the",
"logged",
"in",
"user",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/subscriptions.php#L838-L861 |
212,767 | moodle/moodle | lib/form/autocomplete.php | MoodleQuickForm_autocomplete.optionExists | function optionExists($value) {
foreach ($this->_options as $option) {
if (isset($option['attr']['value']) && ($option['attr']['value'] == $value)) {
return true;
}
}
return false;
} | php | function optionExists($value) {
foreach ($this->_options as $option) {
if (isset($option['attr']['value']) && ($option['attr']['value'] == $value)) {
return true;
}
}
return false;
} | [
"function",
"optionExists",
"(",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_options",
"as",
"$",
"option",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"option",
"[",
"'attr'",
"]",
"[",
"'value'",
"]",
")",
"&&",
"(",
"$",
"option",
"[",
"'attr'",
"]",
"[",
"'value'",
"]",
"==",
"$",
"value",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Search the current list of options to see if there are any options with this value.
@param string $value to search
@return boolean | [
"Search",
"the",
"current",
"list",
"of",
"options",
"to",
"see",
"if",
"there",
"are",
"any",
"options",
"with",
"this",
"value",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/autocomplete.php#L160-L167 |
212,768 | moodle/moodle | course/format/weeks/lib.php | format_weeks.get_default_section_name | public function get_default_section_name($section) {
if ($section->section == 0) {
// Return the general section.
return get_string('section0name', 'format_weeks');
} else {
$dates = $this->get_section_dates($section);
// We subtract 24 hours for display purposes.
$dates->end = ($dates->end - 86400);
$dateformat = get_string('strftimedateshort');
$weekday = userdate($dates->start, $dateformat);
$endweekday = userdate($dates->end, $dateformat);
return $weekday.' - '.$endweekday;
}
} | php | public function get_default_section_name($section) {
if ($section->section == 0) {
// Return the general section.
return get_string('section0name', 'format_weeks');
} else {
$dates = $this->get_section_dates($section);
// We subtract 24 hours for display purposes.
$dates->end = ($dates->end - 86400);
$dateformat = get_string('strftimedateshort');
$weekday = userdate($dates->start, $dateformat);
$endweekday = userdate($dates->end, $dateformat);
return $weekday.' - '.$endweekday;
}
} | [
"public",
"function",
"get_default_section_name",
"(",
"$",
"section",
")",
"{",
"if",
"(",
"$",
"section",
"->",
"section",
"==",
"0",
")",
"{",
"// Return the general section.",
"return",
"get_string",
"(",
"'section0name'",
",",
"'format_weeks'",
")",
";",
"}",
"else",
"{",
"$",
"dates",
"=",
"$",
"this",
"->",
"get_section_dates",
"(",
"$",
"section",
")",
";",
"// We subtract 24 hours for display purposes.",
"$",
"dates",
"->",
"end",
"=",
"(",
"$",
"dates",
"->",
"end",
"-",
"86400",
")",
";",
"$",
"dateformat",
"=",
"get_string",
"(",
"'strftimedateshort'",
")",
";",
"$",
"weekday",
"=",
"userdate",
"(",
"$",
"dates",
"->",
"start",
",",
"$",
"dateformat",
")",
";",
"$",
"endweekday",
"=",
"userdate",
"(",
"$",
"dates",
"->",
"end",
",",
"$",
"dateformat",
")",
";",
"return",
"$",
"weekday",
".",
"' - '",
".",
"$",
"endweekday",
";",
"}",
"}"
] | Returns the default section name for the weekly course format.
If the section number is 0, it will use the string with key = section0name from the course format's lang file.
Otherwise, the default format of "[start date] - [end date]" will be returned.
@param stdClass $section Section object from database or just field course_sections section
@return string The default value for the section name. | [
"Returns",
"the",
"default",
"section",
"name",
"for",
"the",
"weekly",
"course",
"format",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/weeks/lib.php#L72-L87 |
212,769 | moodle/moodle | course/format/weeks/lib.php | format_weeks.get_section_dates | public function get_section_dates($section, $startdate = false) {
if ($startdate === false) {
$course = $this->get_course();
$startdate = $course->startdate;
}
if (is_object($section)) {
$sectionnum = $section->section;
} else {
$sectionnum = $section;
}
$oneweekseconds = 604800;
// Hack alert. We add 2 hours to avoid possible DST problems. (e.g. we go into daylight
// savings and the date changes.
$startdate = $startdate + 7200;
$dates = new stdClass();
$dates->start = $startdate + ($oneweekseconds * ($sectionnum - 1));
$dates->end = $dates->start + $oneweekseconds;
return $dates;
} | php | public function get_section_dates($section, $startdate = false) {
if ($startdate === false) {
$course = $this->get_course();
$startdate = $course->startdate;
}
if (is_object($section)) {
$sectionnum = $section->section;
} else {
$sectionnum = $section;
}
$oneweekseconds = 604800;
// Hack alert. We add 2 hours to avoid possible DST problems. (e.g. we go into daylight
// savings and the date changes.
$startdate = $startdate + 7200;
$dates = new stdClass();
$dates->start = $startdate + ($oneweekseconds * ($sectionnum - 1));
$dates->end = $dates->start + $oneweekseconds;
return $dates;
} | [
"public",
"function",
"get_section_dates",
"(",
"$",
"section",
",",
"$",
"startdate",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"startdate",
"===",
"false",
")",
"{",
"$",
"course",
"=",
"$",
"this",
"->",
"get_course",
"(",
")",
";",
"$",
"startdate",
"=",
"$",
"course",
"->",
"startdate",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"section",
")",
")",
"{",
"$",
"sectionnum",
"=",
"$",
"section",
"->",
"section",
";",
"}",
"else",
"{",
"$",
"sectionnum",
"=",
"$",
"section",
";",
"}",
"$",
"oneweekseconds",
"=",
"604800",
";",
"// Hack alert. We add 2 hours to avoid possible DST problems. (e.g. we go into daylight",
"// savings and the date changes.",
"$",
"startdate",
"=",
"$",
"startdate",
"+",
"7200",
";",
"$",
"dates",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"dates",
"->",
"start",
"=",
"$",
"startdate",
"+",
"(",
"$",
"oneweekseconds",
"*",
"(",
"$",
"sectionnum",
"-",
"1",
")",
")",
";",
"$",
"dates",
"->",
"end",
"=",
"$",
"dates",
"->",
"start",
"+",
"$",
"oneweekseconds",
";",
"return",
"$",
"dates",
";",
"}"
] | Return the start and end date of the passed section
@param int|stdClass|section_info $section section to get the dates for
@param int $startdate Force course start date, useful when the course is not yet created
@return stdClass property start for startdate, property end for enddate | [
"Return",
"the",
"start",
"and",
"end",
"date",
"of",
"the",
"passed",
"section"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/weeks/lib.php#L365-L387 |
212,770 | moodle/moodle | course/format/weeks/lib.php | format_weeks.is_section_current | public function is_section_current($section) {
if (is_object($section)) {
$sectionnum = $section->section;
} else {
$sectionnum = $section;
}
if ($sectionnum < 1) {
return false;
}
$timenow = time();
$dates = $this->get_section_dates($section);
return (($timenow >= $dates->start) && ($timenow < $dates->end));
} | php | public function is_section_current($section) {
if (is_object($section)) {
$sectionnum = $section->section;
} else {
$sectionnum = $section;
}
if ($sectionnum < 1) {
return false;
}
$timenow = time();
$dates = $this->get_section_dates($section);
return (($timenow >= $dates->start) && ($timenow < $dates->end));
} | [
"public",
"function",
"is_section_current",
"(",
"$",
"section",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"section",
")",
")",
"{",
"$",
"sectionnum",
"=",
"$",
"section",
"->",
"section",
";",
"}",
"else",
"{",
"$",
"sectionnum",
"=",
"$",
"section",
";",
"}",
"if",
"(",
"$",
"sectionnum",
"<",
"1",
")",
"{",
"return",
"false",
";",
"}",
"$",
"timenow",
"=",
"time",
"(",
")",
";",
"$",
"dates",
"=",
"$",
"this",
"->",
"get_section_dates",
"(",
"$",
"section",
")",
";",
"return",
"(",
"(",
"$",
"timenow",
">=",
"$",
"dates",
"->",
"start",
")",
"&&",
"(",
"$",
"timenow",
"<",
"$",
"dates",
"->",
"end",
")",
")",
";",
"}"
] | Returns true if the specified week is current
@param int|stdClass|section_info $section
@return bool | [
"Returns",
"true",
"if",
"the",
"specified",
"week",
"is",
"current"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/weeks/lib.php#L395-L407 |
212,771 | moodle/moodle | course/format/weeks/lib.php | format_weeks.get_default_course_enddate | public function get_default_course_enddate($mform, $fieldnames = array()) {
if (empty($fieldnames['startdate'])) {
$fieldnames['startdate'] = 'startdate';
}
if (empty($fieldnames['numsections'])) {
$fieldnames['numsections'] = 'numsections';
}
$startdate = $this->get_form_start_date($mform, $fieldnames);
if ($mform->elementExists($fieldnames['numsections'])) {
$numsections = $mform->getElementValue($fieldnames['numsections']);
$numsections = $mform->getElement($fieldnames['numsections'])->exportValue($numsections);
} else if ($this->get_courseid()) {
// For existing courses get the number of sections.
$numsections = $this->get_last_section_number();
} else {
// Fallback to the default value for new courses.
$numsections = get_config('moodlecourse', $fieldnames['numsections']);
}
// Final week's last day.
$dates = $this->get_section_dates(intval($numsections), $startdate);
return $dates->end;
} | php | public function get_default_course_enddate($mform, $fieldnames = array()) {
if (empty($fieldnames['startdate'])) {
$fieldnames['startdate'] = 'startdate';
}
if (empty($fieldnames['numsections'])) {
$fieldnames['numsections'] = 'numsections';
}
$startdate = $this->get_form_start_date($mform, $fieldnames);
if ($mform->elementExists($fieldnames['numsections'])) {
$numsections = $mform->getElementValue($fieldnames['numsections']);
$numsections = $mform->getElement($fieldnames['numsections'])->exportValue($numsections);
} else if ($this->get_courseid()) {
// For existing courses get the number of sections.
$numsections = $this->get_last_section_number();
} else {
// Fallback to the default value for new courses.
$numsections = get_config('moodlecourse', $fieldnames['numsections']);
}
// Final week's last day.
$dates = $this->get_section_dates(intval($numsections), $startdate);
return $dates->end;
} | [
"public",
"function",
"get_default_course_enddate",
"(",
"$",
"mform",
",",
"$",
"fieldnames",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"fieldnames",
"[",
"'startdate'",
"]",
")",
")",
"{",
"$",
"fieldnames",
"[",
"'startdate'",
"]",
"=",
"'startdate'",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"fieldnames",
"[",
"'numsections'",
"]",
")",
")",
"{",
"$",
"fieldnames",
"[",
"'numsections'",
"]",
"=",
"'numsections'",
";",
"}",
"$",
"startdate",
"=",
"$",
"this",
"->",
"get_form_start_date",
"(",
"$",
"mform",
",",
"$",
"fieldnames",
")",
";",
"if",
"(",
"$",
"mform",
"->",
"elementExists",
"(",
"$",
"fieldnames",
"[",
"'numsections'",
"]",
")",
")",
"{",
"$",
"numsections",
"=",
"$",
"mform",
"->",
"getElementValue",
"(",
"$",
"fieldnames",
"[",
"'numsections'",
"]",
")",
";",
"$",
"numsections",
"=",
"$",
"mform",
"->",
"getElement",
"(",
"$",
"fieldnames",
"[",
"'numsections'",
"]",
")",
"->",
"exportValue",
"(",
"$",
"numsections",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"get_courseid",
"(",
")",
")",
"{",
"// For existing courses get the number of sections.",
"$",
"numsections",
"=",
"$",
"this",
"->",
"get_last_section_number",
"(",
")",
";",
"}",
"else",
"{",
"// Fallback to the default value for new courses.",
"$",
"numsections",
"=",
"get_config",
"(",
"'moodlecourse'",
",",
"$",
"fieldnames",
"[",
"'numsections'",
"]",
")",
";",
"}",
"// Final week's last day.",
"$",
"dates",
"=",
"$",
"this",
"->",
"get_section_dates",
"(",
"intval",
"(",
"$",
"numsections",
")",
",",
"$",
"startdate",
")",
";",
"return",
"$",
"dates",
"->",
"end",
";",
"}"
] | Returns the default end date for weeks course format.
@param moodleform $mform
@param array $fieldnames The form - field names mapping.
@return int | [
"Returns",
"the",
"default",
"end",
"date",
"for",
"weeks",
"course",
"format",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/weeks/lib.php#L450-L475 |
212,772 | moodle/moodle | course/format/weeks/lib.php | format_weeks.update_end_date | public static function update_end_date($courseid) {
global $DB, $COURSE;
// Use one DB query to retrieve necessary fields in course, value for automaticenddate and number of the last
// section. This query will also validate that the course is indeed in 'weeks' format.
$insql = "SELECT c.id, c.format, c.startdate, c.enddate, MAX(s.section) AS lastsection
FROM {course} c
JOIN {course_sections} s
ON s.course = c.id
WHERE c.format = :format
AND c.id = :courseid
GROUP BY c.id, c.format, c.startdate, c.enddate";
$sql = "SELECT co.id, co.format, co.startdate, co.enddate, co.lastsection, fo.value AS automaticenddate
FROM ($insql) co
LEFT JOIN {course_format_options} fo
ON fo.courseid = co.id
AND fo.format = co.format
AND fo.name = :optionname
AND fo.sectionid = 0";
$course = $DB->get_record_sql($sql,
['optionname' => 'automaticenddate', 'format' => 'weeks', 'courseid' => $courseid]);
if (!$course) {
// Looks like it is a course in a different format, nothing to do here.
return;
}
// Create an instance of this class and mock the course object.
$format = new format_weeks('weeks', $courseid);
$format->course = $course;
// If automaticenddate is not specified take the default value.
if (!isset($course->automaticenddate)) {
$defaults = $format->course_format_options();
$course->automaticenddate = $defaults['automaticenddate']['default'];
}
// Check that the course format for setting an automatic date is set.
if (!empty($course->automaticenddate)) {
// Get the final week's last day.
$dates = $format->get_section_dates((int)$course->lastsection);
// Set the course end date.
if ($course->enddate != $dates->end) {
$DB->set_field('course', 'enddate', $dates->end, array('id' => $course->id));
if (isset($COURSE->id) && $COURSE->id == $courseid) {
$COURSE->enddate = $dates->end;
}
}
}
} | php | public static function update_end_date($courseid) {
global $DB, $COURSE;
// Use one DB query to retrieve necessary fields in course, value for automaticenddate and number of the last
// section. This query will also validate that the course is indeed in 'weeks' format.
$insql = "SELECT c.id, c.format, c.startdate, c.enddate, MAX(s.section) AS lastsection
FROM {course} c
JOIN {course_sections} s
ON s.course = c.id
WHERE c.format = :format
AND c.id = :courseid
GROUP BY c.id, c.format, c.startdate, c.enddate";
$sql = "SELECT co.id, co.format, co.startdate, co.enddate, co.lastsection, fo.value AS automaticenddate
FROM ($insql) co
LEFT JOIN {course_format_options} fo
ON fo.courseid = co.id
AND fo.format = co.format
AND fo.name = :optionname
AND fo.sectionid = 0";
$course = $DB->get_record_sql($sql,
['optionname' => 'automaticenddate', 'format' => 'weeks', 'courseid' => $courseid]);
if (!$course) {
// Looks like it is a course in a different format, nothing to do here.
return;
}
// Create an instance of this class and mock the course object.
$format = new format_weeks('weeks', $courseid);
$format->course = $course;
// If automaticenddate is not specified take the default value.
if (!isset($course->automaticenddate)) {
$defaults = $format->course_format_options();
$course->automaticenddate = $defaults['automaticenddate']['default'];
}
// Check that the course format for setting an automatic date is set.
if (!empty($course->automaticenddate)) {
// Get the final week's last day.
$dates = $format->get_section_dates((int)$course->lastsection);
// Set the course end date.
if ($course->enddate != $dates->end) {
$DB->set_field('course', 'enddate', $dates->end, array('id' => $course->id));
if (isset($COURSE->id) && $COURSE->id == $courseid) {
$COURSE->enddate = $dates->end;
}
}
}
} | [
"public",
"static",
"function",
"update_end_date",
"(",
"$",
"courseid",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"COURSE",
";",
"// Use one DB query to retrieve necessary fields in course, value for automaticenddate and number of the last",
"// section. This query will also validate that the course is indeed in 'weeks' format.",
"$",
"insql",
"=",
"\"SELECT c.id, c.format, c.startdate, c.enddate, MAX(s.section) AS lastsection\n FROM {course} c\n JOIN {course_sections} s\n ON s.course = c.id\n WHERE c.format = :format\n AND c.id = :courseid\n GROUP BY c.id, c.format, c.startdate, c.enddate\"",
";",
"$",
"sql",
"=",
"\"SELECT co.id, co.format, co.startdate, co.enddate, co.lastsection, fo.value AS automaticenddate\n FROM ($insql) co\n LEFT JOIN {course_format_options} fo\n ON fo.courseid = co.id\n AND fo.format = co.format\n AND fo.name = :optionname\n AND fo.sectionid = 0\"",
";",
"$",
"course",
"=",
"$",
"DB",
"->",
"get_record_sql",
"(",
"$",
"sql",
",",
"[",
"'optionname'",
"=>",
"'automaticenddate'",
",",
"'format'",
"=>",
"'weeks'",
",",
"'courseid'",
"=>",
"$",
"courseid",
"]",
")",
";",
"if",
"(",
"!",
"$",
"course",
")",
"{",
"// Looks like it is a course in a different format, nothing to do here.",
"return",
";",
"}",
"// Create an instance of this class and mock the course object.",
"$",
"format",
"=",
"new",
"format_weeks",
"(",
"'weeks'",
",",
"$",
"courseid",
")",
";",
"$",
"format",
"->",
"course",
"=",
"$",
"course",
";",
"// If automaticenddate is not specified take the default value.",
"if",
"(",
"!",
"isset",
"(",
"$",
"course",
"->",
"automaticenddate",
")",
")",
"{",
"$",
"defaults",
"=",
"$",
"format",
"->",
"course_format_options",
"(",
")",
";",
"$",
"course",
"->",
"automaticenddate",
"=",
"$",
"defaults",
"[",
"'automaticenddate'",
"]",
"[",
"'default'",
"]",
";",
"}",
"// Check that the course format for setting an automatic date is set.",
"if",
"(",
"!",
"empty",
"(",
"$",
"course",
"->",
"automaticenddate",
")",
")",
"{",
"// Get the final week's last day.",
"$",
"dates",
"=",
"$",
"format",
"->",
"get_section_dates",
"(",
"(",
"int",
")",
"$",
"course",
"->",
"lastsection",
")",
";",
"// Set the course end date.",
"if",
"(",
"$",
"course",
"->",
"enddate",
"!=",
"$",
"dates",
"->",
"end",
")",
"{",
"$",
"DB",
"->",
"set_field",
"(",
"'course'",
",",
"'enddate'",
",",
"$",
"dates",
"->",
"end",
",",
"array",
"(",
"'id'",
"=>",
"$",
"course",
"->",
"id",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"COURSE",
"->",
"id",
")",
"&&",
"$",
"COURSE",
"->",
"id",
"==",
"$",
"courseid",
")",
"{",
"$",
"COURSE",
"->",
"enddate",
"=",
"$",
"dates",
"->",
"end",
";",
"}",
"}",
"}",
"}"
] | Updates the end date for a course in weeks format if option automaticenddate is set.
This method is called from event observers and it can not use any modinfo or format caches because
events are triggered before the caches are reset.
@param int $courseid | [
"Updates",
"the",
"end",
"date",
"for",
"a",
"course",
"in",
"weeks",
"format",
"if",
"option",
"automaticenddate",
"is",
"set",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/weeks/lib.php#L517-L567 |
212,773 | moodle/moodle | mod/folder/classes/external.php | mod_folder_external.get_folders_by_courses | public static function get_folders_by_courses($courseids = array()) {
$warnings = array();
$returnedfolders = array();
$params = array(
'courseids' => $courseids,
);
$params = self::validate_parameters(self::get_folders_by_courses_parameters(), $params);
$mycourses = array();
if (empty($params['courseids'])) {
$mycourses = enrol_get_my_courses();
$params['courseids'] = array_keys($mycourses);
}
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
// Get the folders in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
$folders = get_all_instances_in_courses("folder", $courses);
foreach ($folders as $folder) {
$context = context_module::instance($folder->coursemodule);
// Entry to return.
$folder->name = external_format_string($folder->name, $context->id);
list($folder->intro, $folder->introformat) = external_format_text($folder->intro,
$folder->introformat, $context->id, 'mod_folder', 'intro', null);
$folder->introfiles = external_util::get_area_files($context->id, 'mod_folder', 'intro', false, false);
$returnedfolders[] = $folder;
}
}
$result = array(
'folders' => $returnedfolders,
'warnings' => $warnings
);
return $result;
} | php | public static function get_folders_by_courses($courseids = array()) {
$warnings = array();
$returnedfolders = array();
$params = array(
'courseids' => $courseids,
);
$params = self::validate_parameters(self::get_folders_by_courses_parameters(), $params);
$mycourses = array();
if (empty($params['courseids'])) {
$mycourses = enrol_get_my_courses();
$params['courseids'] = array_keys($mycourses);
}
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
// Get the folders in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
$folders = get_all_instances_in_courses("folder", $courses);
foreach ($folders as $folder) {
$context = context_module::instance($folder->coursemodule);
// Entry to return.
$folder->name = external_format_string($folder->name, $context->id);
list($folder->intro, $folder->introformat) = external_format_text($folder->intro,
$folder->introformat, $context->id, 'mod_folder', 'intro', null);
$folder->introfiles = external_util::get_area_files($context->id, 'mod_folder', 'intro', false, false);
$returnedfolders[] = $folder;
}
}
$result = array(
'folders' => $returnedfolders,
'warnings' => $warnings
);
return $result;
} | [
"public",
"static",
"function",
"get_folders_by_courses",
"(",
"$",
"courseids",
"=",
"array",
"(",
")",
")",
"{",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"$",
"returnedfolders",
"=",
"array",
"(",
")",
";",
"$",
"params",
"=",
"array",
"(",
"'courseids'",
"=>",
"$",
"courseids",
",",
")",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_folders_by_courses_parameters",
"(",
")",
",",
"$",
"params",
")",
";",
"$",
"mycourses",
"=",
"array",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"'courseids'",
"]",
")",
")",
"{",
"$",
"mycourses",
"=",
"enrol_get_my_courses",
"(",
")",
";",
"$",
"params",
"[",
"'courseids'",
"]",
"=",
"array_keys",
"(",
"$",
"mycourses",
")",
";",
"}",
"// Ensure there are courseids to loop through.",
"if",
"(",
"!",
"empty",
"(",
"$",
"params",
"[",
"'courseids'",
"]",
")",
")",
"{",
"list",
"(",
"$",
"courses",
",",
"$",
"warnings",
")",
"=",
"external_util",
"::",
"validate_courses",
"(",
"$",
"params",
"[",
"'courseids'",
"]",
",",
"$",
"mycourses",
")",
";",
"// Get the folders in this course, this function checks users visibility permissions.",
"// We can avoid then additional validate_context calls.",
"$",
"folders",
"=",
"get_all_instances_in_courses",
"(",
"\"folder\"",
",",
"$",
"courses",
")",
";",
"foreach",
"(",
"$",
"folders",
"as",
"$",
"folder",
")",
"{",
"$",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"folder",
"->",
"coursemodule",
")",
";",
"// Entry to return.",
"$",
"folder",
"->",
"name",
"=",
"external_format_string",
"(",
"$",
"folder",
"->",
"name",
",",
"$",
"context",
"->",
"id",
")",
";",
"list",
"(",
"$",
"folder",
"->",
"intro",
",",
"$",
"folder",
"->",
"introformat",
")",
"=",
"external_format_text",
"(",
"$",
"folder",
"->",
"intro",
",",
"$",
"folder",
"->",
"introformat",
",",
"$",
"context",
"->",
"id",
",",
"'mod_folder'",
",",
"'intro'",
",",
"null",
")",
";",
"$",
"folder",
"->",
"introfiles",
"=",
"external_util",
"::",
"get_area_files",
"(",
"$",
"context",
"->",
"id",
",",
"'mod_folder'",
",",
"'intro'",
",",
"false",
",",
"false",
")",
";",
"$",
"returnedfolders",
"[",
"]",
"=",
"$",
"folder",
";",
"}",
"}",
"$",
"result",
"=",
"array",
"(",
"'folders'",
"=>",
"$",
"returnedfolders",
",",
"'warnings'",
"=>",
"$",
"warnings",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Returns a list of folders in a provided list of courses.
If no list is provided all folders that the user can view will be returned.
@param array $courseids course ids
@return array of warnings and folders
@since Moodle 3.3 | [
"Returns",
"a",
"list",
"of",
"folders",
"in",
"a",
"provided",
"list",
"of",
"courses",
".",
"If",
"no",
"list",
"is",
"provided",
"all",
"folders",
"that",
"the",
"user",
"can",
"view",
"will",
"be",
"returned",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/folder/classes/external.php#L131-L173 |
212,774 | moodle/moodle | mod/folder/classes/external.php | mod_folder_external.get_folders_by_courses_returns | public static function get_folders_by_courses_returns() {
return new external_single_structure(
array(
'folders' => new external_multiple_structure(
new external_single_structure(
array(
'id' => new external_value(PARAM_INT, 'Module id'),
'coursemodule' => new external_value(PARAM_INT, 'Course module id'),
'course' => new external_value(PARAM_INT, 'Course id'),
'name' => new external_value(PARAM_RAW, 'Page name'),
'intro' => new external_value(PARAM_RAW, 'Summary'),
'introformat' => new external_format_value('intro', 'Summary format'),
'introfiles' => new external_files('Files in the introduction text'),
'revision' => new external_value(PARAM_INT, 'Incremented when after each file changes, to avoid cache'),
'timemodified' => new external_value(PARAM_INT, 'Last time the folder was modified'),
'display' => new external_value(PARAM_INT, 'Display type of folder contents on a separate page or inline'),
'showexpanded' => new external_value(PARAM_INT, '1 = expanded, 0 = collapsed for sub-folders'),
'showdownloadfolder' => new external_value(PARAM_INT, 'Whether to show the download folder button'),
'section' => new external_value(PARAM_INT, 'Course section id'),
'visible' => new external_value(PARAM_INT, 'Module visibility'),
'groupmode' => new external_value(PARAM_INT, 'Group mode'),
'groupingid' => new external_value(PARAM_INT, 'Grouping id'),
)
)
),
'warnings' => new external_warnings(),
)
);
} | php | public static function get_folders_by_courses_returns() {
return new external_single_structure(
array(
'folders' => new external_multiple_structure(
new external_single_structure(
array(
'id' => new external_value(PARAM_INT, 'Module id'),
'coursemodule' => new external_value(PARAM_INT, 'Course module id'),
'course' => new external_value(PARAM_INT, 'Course id'),
'name' => new external_value(PARAM_RAW, 'Page name'),
'intro' => new external_value(PARAM_RAW, 'Summary'),
'introformat' => new external_format_value('intro', 'Summary format'),
'introfiles' => new external_files('Files in the introduction text'),
'revision' => new external_value(PARAM_INT, 'Incremented when after each file changes, to avoid cache'),
'timemodified' => new external_value(PARAM_INT, 'Last time the folder was modified'),
'display' => new external_value(PARAM_INT, 'Display type of folder contents on a separate page or inline'),
'showexpanded' => new external_value(PARAM_INT, '1 = expanded, 0 = collapsed for sub-folders'),
'showdownloadfolder' => new external_value(PARAM_INT, 'Whether to show the download folder button'),
'section' => new external_value(PARAM_INT, 'Course section id'),
'visible' => new external_value(PARAM_INT, 'Module visibility'),
'groupmode' => new external_value(PARAM_INT, 'Group mode'),
'groupingid' => new external_value(PARAM_INT, 'Grouping id'),
)
)
),
'warnings' => new external_warnings(),
)
);
} | [
"public",
"static",
"function",
"get_folders_by_courses_returns",
"(",
")",
"{",
"return",
"new",
"external_single_structure",
"(",
"array",
"(",
"'folders'",
"=>",
"new",
"external_multiple_structure",
"(",
"new",
"external_single_structure",
"(",
"array",
"(",
"'id'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Module id'",
")",
",",
"'coursemodule'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Course module id'",
")",
",",
"'course'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Course id'",
")",
",",
"'name'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'Page name'",
")",
",",
"'intro'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'Summary'",
")",
",",
"'introformat'",
"=>",
"new",
"external_format_value",
"(",
"'intro'",
",",
"'Summary format'",
")",
",",
"'introfiles'",
"=>",
"new",
"external_files",
"(",
"'Files in the introduction text'",
")",
",",
"'revision'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Incremented when after each file changes, to avoid cache'",
")",
",",
"'timemodified'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Last time the folder was modified'",
")",
",",
"'display'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Display type of folder contents on a separate page or inline'",
")",
",",
"'showexpanded'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'1 = expanded, 0 = collapsed for sub-folders'",
")",
",",
"'showdownloadfolder'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Whether to show the download folder button'",
")",
",",
"'section'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Course section id'",
")",
",",
"'visible'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Module visibility'",
")",
",",
"'groupmode'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Group mode'",
")",
",",
"'groupingid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Grouping id'",
")",
",",
")",
")",
")",
",",
"'warnings'",
"=>",
"new",
"external_warnings",
"(",
")",
",",
")",
")",
";",
"}"
] | Describes the get_folders_by_courses return value.
@return external_single_structure
@since Moodle 3.3 | [
"Describes",
"the",
"get_folders_by_courses",
"return",
"value",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/folder/classes/external.php#L181-L209 |
212,775 | moodle/moodle | admin/tool/policy/classes/output/page_viewdoc.php | page_viewdoc.prepare_policy | protected function prepare_policy($policyid, $versionid) {
if ($versionid) {
$this->policy = api::get_policy_version($versionid);
} else {
$this->policy = array_reduce(api::list_current_versions(), function ($carry, $current) use ($policyid) {
if ($current->policyid == $policyid) {
return $current;
}
return $carry;
});
}
if (empty($this->policy)) {
throw new \moodle_exception('errorpolicyversionnotfound', 'tool_policy');
}
} | php | protected function prepare_policy($policyid, $versionid) {
if ($versionid) {
$this->policy = api::get_policy_version($versionid);
} else {
$this->policy = array_reduce(api::list_current_versions(), function ($carry, $current) use ($policyid) {
if ($current->policyid == $policyid) {
return $current;
}
return $carry;
});
}
if (empty($this->policy)) {
throw new \moodle_exception('errorpolicyversionnotfound', 'tool_policy');
}
} | [
"protected",
"function",
"prepare_policy",
"(",
"$",
"policyid",
",",
"$",
"versionid",
")",
"{",
"if",
"(",
"$",
"versionid",
")",
"{",
"$",
"this",
"->",
"policy",
"=",
"api",
"::",
"get_policy_version",
"(",
"$",
"versionid",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"policy",
"=",
"array_reduce",
"(",
"api",
"::",
"list_current_versions",
"(",
")",
",",
"function",
"(",
"$",
"carry",
",",
"$",
"current",
")",
"use",
"(",
"$",
"policyid",
")",
"{",
"if",
"(",
"$",
"current",
"->",
"policyid",
"==",
"$",
"policyid",
")",
"{",
"return",
"$",
"current",
";",
"}",
"return",
"$",
"carry",
";",
"}",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"policy",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorpolicyversionnotfound'",
",",
"'tool_policy'",
")",
";",
"}",
"}"
] | Loads the policy version to display on the page.
@param int $policyid The policy id for this page.
@param int $versionid The version id to show. Empty tries to load the current one. | [
"Loads",
"the",
"policy",
"version",
"to",
"display",
"on",
"the",
"page",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/output/page_viewdoc.php#L87-L104 |
212,776 | moodle/moodle | completion/criteria/completion_criteria_activity.php | completion_criteria_activity.get_mod_name | public static function get_mod_name($type) {
static $types;
if (!is_array($types)) {
global $DB;
$types = $DB->get_records('modules');
}
return $types[$type]->name;
} | php | public static function get_mod_name($type) {
static $types;
if (!is_array($types)) {
global $DB;
$types = $DB->get_records('modules');
}
return $types[$type]->name;
} | [
"public",
"static",
"function",
"get_mod_name",
"(",
"$",
"type",
")",
"{",
"static",
"$",
"types",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"types",
")",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"types",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'modules'",
")",
";",
"}",
"return",
"$",
"types",
"[",
"$",
"type",
"]",
"->",
"name",
";",
"}"
] | Get module instance module type
@param int $type Module type id
@return string | [
"Get",
"module",
"instance",
"module",
"type"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/criteria/completion_criteria_activity.php#L108-L117 |
212,777 | moodle/moodle | completion/criteria/completion_criteria_activity.php | completion_criteria_activity.cron | public function cron() {
global $DB;
// Get all users who meet this criteria
$sql = '
SELECT DISTINCT
c.id AS course,
cr.id AS criteriaid,
ra.userid AS userid,
mc.timemodified AS timecompleted
FROM
{course_completion_criteria} cr
INNER JOIN
{course} c
ON cr.course = c.id
INNER JOIN
{context} con
ON con.instanceid = c.id
INNER JOIN
{role_assignments} ra
ON ra.contextid = con.id
INNER JOIN
{course_modules_completion} mc
ON mc.coursemoduleid = cr.moduleinstance
AND mc.userid = ra.userid
LEFT JOIN
{course_completion_crit_compl} cc
ON cc.criteriaid = cr.id
AND cc.userid = ra.userid
WHERE
cr.criteriatype = '.COMPLETION_CRITERIA_TYPE_ACTIVITY.'
AND con.contextlevel = '.CONTEXT_COURSE.'
AND c.enablecompletion = 1
AND cc.id IS NULL
AND (
mc.completionstate = '.COMPLETION_COMPLETE.'
OR mc.completionstate = '.COMPLETION_COMPLETE_PASS.'
OR mc.completionstate = '.COMPLETION_COMPLETE_FAIL.'
)
';
// Loop through completions, and mark as complete
$rs = $DB->get_recordset_sql($sql);
foreach ($rs as $record) {
$completion = new completion_criteria_completion((array) $record, DATA_OBJECT_FETCH_BY_KEY);
$completion->mark_complete($record->timecompleted);
}
$rs->close();
} | php | public function cron() {
global $DB;
// Get all users who meet this criteria
$sql = '
SELECT DISTINCT
c.id AS course,
cr.id AS criteriaid,
ra.userid AS userid,
mc.timemodified AS timecompleted
FROM
{course_completion_criteria} cr
INNER JOIN
{course} c
ON cr.course = c.id
INNER JOIN
{context} con
ON con.instanceid = c.id
INNER JOIN
{role_assignments} ra
ON ra.contextid = con.id
INNER JOIN
{course_modules_completion} mc
ON mc.coursemoduleid = cr.moduleinstance
AND mc.userid = ra.userid
LEFT JOIN
{course_completion_crit_compl} cc
ON cc.criteriaid = cr.id
AND cc.userid = ra.userid
WHERE
cr.criteriatype = '.COMPLETION_CRITERIA_TYPE_ACTIVITY.'
AND con.contextlevel = '.CONTEXT_COURSE.'
AND c.enablecompletion = 1
AND cc.id IS NULL
AND (
mc.completionstate = '.COMPLETION_COMPLETE.'
OR mc.completionstate = '.COMPLETION_COMPLETE_PASS.'
OR mc.completionstate = '.COMPLETION_COMPLETE_FAIL.'
)
';
// Loop through completions, and mark as complete
$rs = $DB->get_recordset_sql($sql);
foreach ($rs as $record) {
$completion = new completion_criteria_completion((array) $record, DATA_OBJECT_FETCH_BY_KEY);
$completion->mark_complete($record->timecompleted);
}
$rs->close();
} | [
"public",
"function",
"cron",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"// Get all users who meet this criteria",
"$",
"sql",
"=",
"'\n SELECT DISTINCT\n c.id AS course,\n cr.id AS criteriaid,\n ra.userid AS userid,\n mc.timemodified AS timecompleted\n FROM\n {course_completion_criteria} cr\n INNER JOIN\n {course} c\n ON cr.course = c.id\n INNER JOIN\n {context} con\n ON con.instanceid = c.id\n INNER JOIN\n {role_assignments} ra\n ON ra.contextid = con.id\n INNER JOIN\n {course_modules_completion} mc\n ON mc.coursemoduleid = cr.moduleinstance\n AND mc.userid = ra.userid\n LEFT JOIN\n {course_completion_crit_compl} cc\n ON cc.criteriaid = cr.id\n AND cc.userid = ra.userid\n WHERE\n cr.criteriatype = '",
".",
"COMPLETION_CRITERIA_TYPE_ACTIVITY",
".",
"'\n AND con.contextlevel = '",
".",
"CONTEXT_COURSE",
".",
"'\n AND c.enablecompletion = 1\n AND cc.id IS NULL\n AND (\n mc.completionstate = '",
".",
"COMPLETION_COMPLETE",
".",
"'\n OR mc.completionstate = '",
".",
"COMPLETION_COMPLETE_PASS",
".",
"'\n OR mc.completionstate = '",
".",
"COMPLETION_COMPLETE_FAIL",
".",
"'\n )\n '",
";",
"// Loop through completions, and mark as complete",
"$",
"rs",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
")",
";",
"foreach",
"(",
"$",
"rs",
"as",
"$",
"record",
")",
"{",
"$",
"completion",
"=",
"new",
"completion_criteria_completion",
"(",
"(",
"array",
")",
"$",
"record",
",",
"DATA_OBJECT_FETCH_BY_KEY",
")",
";",
"$",
"completion",
"->",
"mark_complete",
"(",
"$",
"record",
"->",
"timecompleted",
")",
";",
"}",
"$",
"rs",
"->",
"close",
"(",
")",
";",
"}"
] | Find users who have completed this criteria and mark them accordingly | [
"Find",
"users",
"who",
"have",
"completed",
"this",
"criteria",
"and",
"mark",
"them",
"accordingly"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/criteria/completion_criteria_activity.php#L205-L253 |
212,778 | moodle/moodle | admin/tool/lp/classes/form/framework_autocomplete.php | framework_autocomplete.setValue | public function setValue($value) {
global $DB;
$values = (array) $value;
$ids = array();
foreach ($values as $onevalue) {
if (!empty($onevalue) && (!$this->optionExists($onevalue)) &&
($onevalue !== '_qf__force_multiselect_submission')) {
array_push($ids, $onevalue);
}
}
if (empty($ids)) {
return $this->setSelected(array());
}
// Logic here is simulating API.
$toselect = array();
list($insql, $inparams) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED, 'param');
$frameworks = competency_framework::get_records_select("id $insql", $inparams, 'shortname');
foreach ($frameworks as $framework) {
if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'),
$framework->get_context())) {
continue;
} else if ($this->onlyvisible && !$framework->get('visible')) {
continue;
}
$this->addOption($framework->get('shortname') . ' ' . $framework->get('idnumber'), $framework->get('id'));
array_push($toselect, $framework->get('id'));
}
return $this->setSelected($toselect);
} | php | public function setValue($value) {
global $DB;
$values = (array) $value;
$ids = array();
foreach ($values as $onevalue) {
if (!empty($onevalue) && (!$this->optionExists($onevalue)) &&
($onevalue !== '_qf__force_multiselect_submission')) {
array_push($ids, $onevalue);
}
}
if (empty($ids)) {
return $this->setSelected(array());
}
// Logic here is simulating API.
$toselect = array();
list($insql, $inparams) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED, 'param');
$frameworks = competency_framework::get_records_select("id $insql", $inparams, 'shortname');
foreach ($frameworks as $framework) {
if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'),
$framework->get_context())) {
continue;
} else if ($this->onlyvisible && !$framework->get('visible')) {
continue;
}
$this->addOption($framework->get('shortname') . ' ' . $framework->get('idnumber'), $framework->get('id'));
array_push($toselect, $framework->get('id'));
}
return $this->setSelected($toselect);
} | [
"public",
"function",
"setValue",
"(",
"$",
"value",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"values",
"=",
"(",
"array",
")",
"$",
"value",
";",
"$",
"ids",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"onevalue",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"onevalue",
")",
"&&",
"(",
"!",
"$",
"this",
"->",
"optionExists",
"(",
"$",
"onevalue",
")",
")",
"&&",
"(",
"$",
"onevalue",
"!==",
"'_qf__force_multiselect_submission'",
")",
")",
"{",
"array_push",
"(",
"$",
"ids",
",",
"$",
"onevalue",
")",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"ids",
")",
")",
"{",
"return",
"$",
"this",
"->",
"setSelected",
"(",
"array",
"(",
")",
")",
";",
"}",
"// Logic here is simulating API.",
"$",
"toselect",
"=",
"array",
"(",
")",
";",
"list",
"(",
"$",
"insql",
",",
"$",
"inparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"ids",
",",
"SQL_PARAMS_NAMED",
",",
"'param'",
")",
";",
"$",
"frameworks",
"=",
"competency_framework",
"::",
"get_records_select",
"(",
"\"id $insql\"",
",",
"$",
"inparams",
",",
"'shortname'",
")",
";",
"foreach",
"(",
"$",
"frameworks",
"as",
"$",
"framework",
")",
"{",
"if",
"(",
"!",
"has_any_capability",
"(",
"array",
"(",
"'moodle/competency:competencyview'",
",",
"'moodle/competency:competencymanage'",
")",
",",
"$",
"framework",
"->",
"get_context",
"(",
")",
")",
")",
"{",
"continue",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"onlyvisible",
"&&",
"!",
"$",
"framework",
"->",
"get",
"(",
"'visible'",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"addOption",
"(",
"$",
"framework",
"->",
"get",
"(",
"'shortname'",
")",
".",
"' '",
".",
"$",
"framework",
"->",
"get",
"(",
"'idnumber'",
")",
",",
"$",
"framework",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"array_push",
"(",
"$",
"toselect",
",",
"$",
"framework",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setSelected",
"(",
"$",
"toselect",
")",
";",
"}"
] | Set the value of this element.
@param string|array $value The value to set.
@return boolean | [
"Set",
"the",
"value",
"of",
"this",
"element",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/form/framework_autocomplete.php#L88-L120 |
212,779 | moodle/moodle | competency/classes/user_competency_course.php | user_competency_course.create_relation | public static function create_relation($userid, $competencyid, $courseid) {
$data = new \stdClass();
$data->userid = $userid;
$data->competencyid = $competencyid;
$data->courseid = $courseid;
$relation = new user_competency_course(0, $data);
return $relation;
} | php | public static function create_relation($userid, $competencyid, $courseid) {
$data = new \stdClass();
$data->userid = $userid;
$data->competencyid = $competencyid;
$data->courseid = $courseid;
$relation = new user_competency_course(0, $data);
return $relation;
} | [
"public",
"static",
"function",
"create_relation",
"(",
"$",
"userid",
",",
"$",
"competencyid",
",",
"$",
"courseid",
")",
"{",
"$",
"data",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"data",
"->",
"userid",
"=",
"$",
"userid",
";",
"$",
"data",
"->",
"competencyid",
"=",
"$",
"competencyid",
";",
"$",
"data",
"->",
"courseid",
"=",
"$",
"courseid",
";",
"$",
"relation",
"=",
"new",
"user_competency_course",
"(",
"0",
",",
"$",
"data",
")",
";",
"return",
"$",
"relation",
";",
"}"
] | Create a new user_competency_course object.
Note, this is intended to be used to create a blank relation, for instance when
the record was not found in the database. This does not save the model.
@param int $userid The user ID.
@param int $competencyid The competency ID.
@param int $courseid The course ID.
@return \core_competency\user_competency_course | [
"Create",
"a",
"new",
"user_competency_course",
"object",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_competency_course.php#L100-L108 |
212,780 | moodle/moodle | competency/classes/user_competency_course.php | user_competency_course.validate_proficiency | protected function validate_proficiency($value) {
$grade = $this->get('grade');
if ($grade !== null && $value === null) {
// We must set a proficiency when we set a grade.
return new lang_string('invaliddata', 'error');
} else if ($grade === null && $value !== null) {
// We must not set a proficiency when we don't set a grade.
return new lang_string('invaliddata', 'error');
}
return true;
} | php | protected function validate_proficiency($value) {
$grade = $this->get('grade');
if ($grade !== null && $value === null) {
// We must set a proficiency when we set a grade.
return new lang_string('invaliddata', 'error');
} else if ($grade === null && $value !== null) {
// We must not set a proficiency when we don't set a grade.
return new lang_string('invaliddata', 'error');
}
return true;
} | [
"protected",
"function",
"validate_proficiency",
"(",
"$",
"value",
")",
"{",
"$",
"grade",
"=",
"$",
"this",
"->",
"get",
"(",
"'grade'",
")",
";",
"if",
"(",
"$",
"grade",
"!==",
"null",
"&&",
"$",
"value",
"===",
"null",
")",
"{",
"// We must set a proficiency when we set a grade.",
"return",
"new",
"lang_string",
"(",
"'invaliddata'",
",",
"'error'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"grade",
"===",
"null",
"&&",
"$",
"value",
"!==",
"null",
")",
"{",
"// We must not set a proficiency when we don't set a grade.",
"return",
"new",
"lang_string",
"(",
"'invaliddata'",
",",
"'error'",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Validate the proficiency.
@param int $value The value.
@return true|lang_string | [
"Validate",
"the",
"proficiency",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_competency_course.php#L160-L173 |
212,781 | moodle/moodle | competency/classes/user_competency_course.php | user_competency_course.count_proficient_competencies | public static function count_proficient_competencies($courseid, $userid) {
global $DB;
$sql = 'SELECT COUNT(comp.id)
FROM {' . self::TABLE . '} usercoursecomp
JOIN {' . course_competency::TABLE . '} cc
ON usercoursecomp.competencyid = cc.competencyid AND cc.courseid = usercoursecomp.courseid
JOIN {' . competency::TABLE . '} comp
ON usercoursecomp.competencyid = comp.id
WHERE usercoursecomp.courseid = ? AND usercoursecomp.userid = ? AND usercoursecomp.proficiency = ?';
$params = array($courseid, $userid, true);
$results = $DB->count_records_sql($sql, $params);
return $results;
} | php | public static function count_proficient_competencies($courseid, $userid) {
global $DB;
$sql = 'SELECT COUNT(comp.id)
FROM {' . self::TABLE . '} usercoursecomp
JOIN {' . course_competency::TABLE . '} cc
ON usercoursecomp.competencyid = cc.competencyid AND cc.courseid = usercoursecomp.courseid
JOIN {' . competency::TABLE . '} comp
ON usercoursecomp.competencyid = comp.id
WHERE usercoursecomp.courseid = ? AND usercoursecomp.userid = ? AND usercoursecomp.proficiency = ?';
$params = array($courseid, $userid, true);
$results = $DB->count_records_sql($sql, $params);
return $results;
} | [
"public",
"static",
"function",
"count_proficient_competencies",
"(",
"$",
"courseid",
",",
"$",
"userid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"sql",
"=",
"'SELECT COUNT(comp.id)\n FROM {'",
".",
"self",
"::",
"TABLE",
".",
"'} usercoursecomp\n JOIN {'",
".",
"course_competency",
"::",
"TABLE",
".",
"'} cc\n ON usercoursecomp.competencyid = cc.competencyid AND cc.courseid = usercoursecomp.courseid\n JOIN {'",
".",
"competency",
"::",
"TABLE",
".",
"'} comp\n ON usercoursecomp.competencyid = comp.id\n WHERE usercoursecomp.courseid = ? AND usercoursecomp.userid = ? AND usercoursecomp.proficiency = ?'",
";",
"$",
"params",
"=",
"array",
"(",
"$",
"courseid",
",",
"$",
"userid",
",",
"true",
")",
";",
"$",
"results",
"=",
"$",
"DB",
"->",
"count_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"return",
"$",
"results",
";",
"}"
] | Count the proficient competencies in this course for one user.
@param int $courseid The course id
@param int $userid The user id
@return int | [
"Count",
"the",
"proficient",
"competencies",
"in",
"this",
"course",
"for",
"one",
"user",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_competency_course.php#L241-L256 |
212,782 | moodle/moodle | competency/classes/user_competency_course.php | user_competency_course.get_least_proficient_competencies_for_course | public static function get_least_proficient_competencies_for_course($courseid, $skip = 0, $limit = 0) {
global $DB;
$fields = competency::get_sql_fields('c', 'c_');
$params = array('courseid' => $courseid);
$sql = 'SELECT ' . $fields . '
FROM (SELECT cc.competencyid, SUM(COALESCE(ucc.proficiency, 0)) AS timesproficient
FROM {' . course_competency::TABLE . '} cc
LEFT JOIN {' . self::TABLE . '} ucc
ON ucc.competencyid = cc.competencyid
AND ucc.courseid = cc.courseid
WHERE cc.courseid = :courseid
GROUP BY cc.competencyid
) p
JOIN {' . competency::TABLE . '} c
ON c.id = p.competencyid
ORDER BY p.timesproficient ASC, c.id DESC';
$results = $DB->get_records_sql($sql, $params, $skip, $limit);
$comps = array();
foreach ($results as $r) {
$c = competency::extract_record($r, 'c_');
$comps[] = new competency(0, $c);
}
return $comps;
} | php | public static function get_least_proficient_competencies_for_course($courseid, $skip = 0, $limit = 0) {
global $DB;
$fields = competency::get_sql_fields('c', 'c_');
$params = array('courseid' => $courseid);
$sql = 'SELECT ' . $fields . '
FROM (SELECT cc.competencyid, SUM(COALESCE(ucc.proficiency, 0)) AS timesproficient
FROM {' . course_competency::TABLE . '} cc
LEFT JOIN {' . self::TABLE . '} ucc
ON ucc.competencyid = cc.competencyid
AND ucc.courseid = cc.courseid
WHERE cc.courseid = :courseid
GROUP BY cc.competencyid
) p
JOIN {' . competency::TABLE . '} c
ON c.id = p.competencyid
ORDER BY p.timesproficient ASC, c.id DESC';
$results = $DB->get_records_sql($sql, $params, $skip, $limit);
$comps = array();
foreach ($results as $r) {
$c = competency::extract_record($r, 'c_');
$comps[] = new competency(0, $c);
}
return $comps;
} | [
"public",
"static",
"function",
"get_least_proficient_competencies_for_course",
"(",
"$",
"courseid",
",",
"$",
"skip",
"=",
"0",
",",
"$",
"limit",
"=",
"0",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"fields",
"=",
"competency",
"::",
"get_sql_fields",
"(",
"'c'",
",",
"'c_'",
")",
";",
"$",
"params",
"=",
"array",
"(",
"'courseid'",
"=>",
"$",
"courseid",
")",
";",
"$",
"sql",
"=",
"'SELECT '",
".",
"$",
"fields",
".",
"'\n FROM (SELECT cc.competencyid, SUM(COALESCE(ucc.proficiency, 0)) AS timesproficient\n FROM {'",
".",
"course_competency",
"::",
"TABLE",
".",
"'} cc\n LEFT JOIN {'",
".",
"self",
"::",
"TABLE",
".",
"'} ucc\n ON ucc.competencyid = cc.competencyid\n AND ucc.courseid = cc.courseid\n WHERE cc.courseid = :courseid\n GROUP BY cc.competencyid\n ) p\n JOIN {'",
".",
"competency",
"::",
"TABLE",
".",
"'} c\n ON c.id = p.competencyid\n ORDER BY p.timesproficient ASC, c.id DESC'",
";",
"$",
"results",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
",",
"$",
"skip",
",",
"$",
"limit",
")",
";",
"$",
"comps",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"results",
"as",
"$",
"r",
")",
"{",
"$",
"c",
"=",
"competency",
"::",
"extract_record",
"(",
"$",
"r",
",",
"'c_'",
")",
";",
"$",
"comps",
"[",
"]",
"=",
"new",
"competency",
"(",
"0",
",",
"$",
"c",
")",
";",
"}",
"return",
"$",
"comps",
";",
"}"
] | Get the list of competencies that were completed the least times in a course.
@param int $courseid
@param int $skip The number of competencies to skip
@param int $limit The max number of competencies to return
@return competency[] | [
"Get",
"the",
"list",
"of",
"competencies",
"that",
"were",
"completed",
"the",
"least",
"times",
"in",
"a",
"course",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/user_competency_course.php#L266-L292 |
212,783 | moodle/moodle | admin/tool/monitor/classes/subscription.php | subscription.get_instance_name | public function get_instance_name() {
if ($this->plugin === 'core') {
$string = get_string('allevents', 'tool_monitor');
} else {
if ($this->cmid == 0) {
$string = get_string('allmodules', 'tool_monitor');
} else {
$cms = get_fast_modinfo($this->courseid);
$cms = $cms->get_cms();
if (isset($cms[$this->cmid])) {
$string = $cms[$this->cmid]->get_formatted_name(); // Instance name.
} else {
// Something is wrong, instance is not present anymore.
$string = get_string('invalidmodule', 'tool_monitor');
}
}
}
return $string;
} | php | public function get_instance_name() {
if ($this->plugin === 'core') {
$string = get_string('allevents', 'tool_monitor');
} else {
if ($this->cmid == 0) {
$string = get_string('allmodules', 'tool_monitor');
} else {
$cms = get_fast_modinfo($this->courseid);
$cms = $cms->get_cms();
if (isset($cms[$this->cmid])) {
$string = $cms[$this->cmid]->get_formatted_name(); // Instance name.
} else {
// Something is wrong, instance is not present anymore.
$string = get_string('invalidmodule', 'tool_monitor');
}
}
}
return $string;
} | [
"public",
"function",
"get_instance_name",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"plugin",
"===",
"'core'",
")",
"{",
"$",
"string",
"=",
"get_string",
"(",
"'allevents'",
",",
"'tool_monitor'",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"cmid",
"==",
"0",
")",
"{",
"$",
"string",
"=",
"get_string",
"(",
"'allmodules'",
",",
"'tool_monitor'",
")",
";",
"}",
"else",
"{",
"$",
"cms",
"=",
"get_fast_modinfo",
"(",
"$",
"this",
"->",
"courseid",
")",
";",
"$",
"cms",
"=",
"$",
"cms",
"->",
"get_cms",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"cms",
"[",
"$",
"this",
"->",
"cmid",
"]",
")",
")",
"{",
"$",
"string",
"=",
"$",
"cms",
"[",
"$",
"this",
"->",
"cmid",
"]",
"->",
"get_formatted_name",
"(",
")",
";",
"// Instance name.",
"}",
"else",
"{",
"// Something is wrong, instance is not present anymore.",
"$",
"string",
"=",
"get_string",
"(",
"'invalidmodule'",
",",
"'tool_monitor'",
")",
";",
"}",
"}",
"}",
"return",
"$",
"string",
";",
"}"
] | Get a human readable name for instances associated with this subscription.
@return string
@throws \coding_exception | [
"Get",
"a",
"human",
"readable",
"name",
"for",
"instances",
"associated",
"with",
"this",
"subscription",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/subscription.php#L84-L103 |
212,784 | moodle/moodle | admin/tool/monitor/classes/subscription.php | subscription.get_filters_description | public function get_filters_description() {
$a = new \stdClass();
$a->freq = $this->frequency;
$mins = $this->timewindow / MINSECS; // Convert seconds to minutes.
$a->mins = $mins;
return get_string('freqdesc', 'tool_monitor', $a);
} | php | public function get_filters_description() {
$a = new \stdClass();
$a->freq = $this->frequency;
$mins = $this->timewindow / MINSECS; // Convert seconds to minutes.
$a->mins = $mins;
return get_string('freqdesc', 'tool_monitor', $a);
} | [
"public",
"function",
"get_filters_description",
"(",
")",
"{",
"$",
"a",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"a",
"->",
"freq",
"=",
"$",
"this",
"->",
"frequency",
";",
"$",
"mins",
"=",
"$",
"this",
"->",
"timewindow",
"/",
"MINSECS",
";",
"// Convert seconds to minutes.",
"$",
"a",
"->",
"mins",
"=",
"$",
"mins",
";",
"return",
"get_string",
"(",
"'freqdesc'",
",",
"'tool_monitor'",
",",
"$",
"a",
")",
";",
"}"
] | Get filter description.
@return string | [
"Get",
"filter",
"description",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/subscription.php#L124-L130 |
212,785 | moodle/moodle | admin/tool/monitor/classes/subscription.php | subscription.get_plugin_name | public function get_plugin_name() {
if ($this->plugin === 'core') {
$string = get_string('core', 'tool_monitor');
} else if (get_string_manager()->string_exists('pluginname', $this->plugin)) {
$string = get_string('pluginname', $this->plugin);
} else {
$string = $this->plugin;
}
return $string;
} | php | public function get_plugin_name() {
if ($this->plugin === 'core') {
$string = get_string('core', 'tool_monitor');
} else if (get_string_manager()->string_exists('pluginname', $this->plugin)) {
$string = get_string('pluginname', $this->plugin);
} else {
$string = $this->plugin;
}
return $string;
} | [
"public",
"function",
"get_plugin_name",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"plugin",
"===",
"'core'",
")",
"{",
"$",
"string",
"=",
"get_string",
"(",
"'core'",
",",
"'tool_monitor'",
")",
";",
"}",
"else",
"if",
"(",
"get_string_manager",
"(",
")",
"->",
"string_exists",
"(",
"'pluginname'",
",",
"$",
"this",
"->",
"plugin",
")",
")",
"{",
"$",
"string",
"=",
"get_string",
"(",
"'pluginname'",
",",
"$",
"this",
"->",
"plugin",
")",
";",
"}",
"else",
"{",
"$",
"string",
"=",
"$",
"this",
"->",
"plugin",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Get name of the plugin associated with this rule
@return string Plugin name. | [
"Get",
"name",
"of",
"the",
"plugin",
"associated",
"with",
"this",
"rule"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/subscription.php#L157-L166 |
212,786 | moodle/moodle | admin/tool/monitor/classes/subscription.php | subscription.get_course_name | public function get_course_name(\context $context) {
$courseid = $this->courseid;
if (empty($courseid)) {
return get_string('site');
} else {
try {
$course = get_course($courseid);
return format_string($course->fullname, true, array('context' => $context));
} catch (\dml_exception $e) {
return '-';
}
}
} | php | public function get_course_name(\context $context) {
$courseid = $this->courseid;
if (empty($courseid)) {
return get_string('site');
} else {
try {
$course = get_course($courseid);
return format_string($course->fullname, true, array('context' => $context));
} catch (\dml_exception $e) {
return '-';
}
}
} | [
"public",
"function",
"get_course_name",
"(",
"\\",
"context",
"$",
"context",
")",
"{",
"$",
"courseid",
"=",
"$",
"this",
"->",
"courseid",
";",
"if",
"(",
"empty",
"(",
"$",
"courseid",
")",
")",
"{",
"return",
"get_string",
"(",
"'site'",
")",
";",
"}",
"else",
"{",
"try",
"{",
"$",
"course",
"=",
"get_course",
"(",
"$",
"courseid",
")",
";",
"return",
"format_string",
"(",
"$",
"course",
"->",
"fullname",
",",
"true",
",",
"array",
"(",
"'context'",
"=>",
"$",
"context",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"dml_exception",
"$",
"e",
")",
"{",
"return",
"'-'",
";",
"}",
"}",
"}"
] | Get properly formatted name of the course associated.
@param \context $context context where this name would be displayed.
@return string Formatted name of the rule. | [
"Get",
"properly",
"formatted",
"name",
"of",
"the",
"course",
"associated",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/subscription.php#L174-L186 |
212,787 | moodle/moodle | admin/tool/monitor/classes/subscription.php | subscription.can_manage_rule | public function can_manage_rule() {
$courseid = $this->rulecourseid;
$context = empty($courseid) ? \context_system::instance() : \context_course::instance($courseid);
return has_capability('tool/monitor:managerules', $context);
} | php | public function can_manage_rule() {
$courseid = $this->rulecourseid;
$context = empty($courseid) ? \context_system::instance() : \context_course::instance($courseid);
return has_capability('tool/monitor:managerules', $context);
} | [
"public",
"function",
"can_manage_rule",
"(",
")",
"{",
"$",
"courseid",
"=",
"$",
"this",
"->",
"rulecourseid",
";",
"$",
"context",
"=",
"empty",
"(",
"$",
"courseid",
")",
"?",
"\\",
"context_system",
"::",
"instance",
"(",
")",
":",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"courseid",
")",
";",
"return",
"has_capability",
"(",
"'tool/monitor:managerules'",
",",
"$",
"context",
")",
";",
"}"
] | Can the current user manage the rule associate with this subscription?
@return bool true if the current user can manage this rule, else false. | [
"Can",
"the",
"current",
"user",
"manage",
"the",
"rule",
"associate",
"with",
"this",
"subscription?"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/subscription.php#L193-L197 |
212,788 | moodle/moodle | privacy/classes/local/request/userlist.php | userlist.add_from_sql | public function add_from_sql(string $fieldname, string $sql, array $params) : userlist {
global $DB;
// Able to guess a field name.
$wrapper = "
SELECT DISTINCT u.id
FROM {user} u
JOIN ({$sql}) target ON u.id = target.{$fieldname}";
$users = $DB->get_records_sql($wrapper, $params);
$this->add_userids(array_keys($users));
return $this;
} | php | public function add_from_sql(string $fieldname, string $sql, array $params) : userlist {
global $DB;
// Able to guess a field name.
$wrapper = "
SELECT DISTINCT u.id
FROM {user} u
JOIN ({$sql}) target ON u.id = target.{$fieldname}";
$users = $DB->get_records_sql($wrapper, $params);
$this->add_userids(array_keys($users));
return $this;
} | [
"public",
"function",
"add_from_sql",
"(",
"string",
"$",
"fieldname",
",",
"string",
"$",
"sql",
",",
"array",
"$",
"params",
")",
":",
"userlist",
"{",
"global",
"$",
"DB",
";",
"// Able to guess a field name.",
"$",
"wrapper",
"=",
"\"\n SELECT DISTINCT u.id\n FROM {user} u\n JOIN ({$sql}) target ON u.id = target.{$fieldname}\"",
";",
"$",
"users",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"wrapper",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"add_userids",
"(",
"array_keys",
"(",
"$",
"users",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add a set of users from SQL.
The SQL should only return a list of user IDs.
@param string $fieldname The name of the field which holds the user id
@param string $sql The SQL which will fetch the list of * user IDs
@param array $params The set of SQL parameters
@return $this | [
"Add",
"a",
"set",
"of",
"users",
"from",
"SQL",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/userlist.php#L47-L60 |
212,789 | moodle/moodle | privacy/classes/local/request/userlist.php | userlist.add_users | public function add_users(array $userids) : userlist {
global $DB;
if (!empty($userids)) {
list($useridsql, $useridparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
$sql = "SELECT DISTINCT u.id
FROM {user} u
WHERE u.id {$useridsql}";
$this->add_from_sql('id', $sql, $useridparams);
}
return $this;
} | php | public function add_users(array $userids) : userlist {
global $DB;
if (!empty($userids)) {
list($useridsql, $useridparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
$sql = "SELECT DISTINCT u.id
FROM {user} u
WHERE u.id {$useridsql}";
$this->add_from_sql('id', $sql, $useridparams);
}
return $this;
} | [
"public",
"function",
"add_users",
"(",
"array",
"$",
"userids",
")",
":",
"userlist",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"userids",
")",
")",
"{",
"list",
"(",
"$",
"useridsql",
",",
"$",
"useridparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"userids",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"sql",
"=",
"\"SELECT DISTINCT u.id\n FROM {user} u\n WHERE u.id {$useridsql}\"",
";",
"$",
"this",
"->",
"add_from_sql",
"(",
"'id'",
",",
"$",
"sql",
",",
"$",
"useridparams",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Adds the user users for given users.
@param int[] $userids
@return $this | [
"Adds",
"the",
"user",
"users",
"for",
"given",
"users",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/userlist.php#L80-L91 |
212,790 | moodle/moodle | mod/glossary/locallib.php | glossary_full_portfolio_caller.expected_time | public function expected_time() {
$filetime = portfolio_expected_time_file($this->multifiles);
$dbtime = portfolio_expected_time_db(count($this->exportdata['entries']));
return ($filetime > $dbtime) ? $filetime : $dbtime;
} | php | public function expected_time() {
$filetime = portfolio_expected_time_file($this->multifiles);
$dbtime = portfolio_expected_time_db(count($this->exportdata['entries']));
return ($filetime > $dbtime) ? $filetime : $dbtime;
} | [
"public",
"function",
"expected_time",
"(",
")",
"{",
"$",
"filetime",
"=",
"portfolio_expected_time_file",
"(",
"$",
"this",
"->",
"multifiles",
")",
";",
"$",
"dbtime",
"=",
"portfolio_expected_time_db",
"(",
"count",
"(",
"$",
"this",
"->",
"exportdata",
"[",
"'entries'",
"]",
")",
")",
";",
"return",
"(",
"$",
"filetime",
">",
"$",
"dbtime",
")",
"?",
"$",
"filetime",
":",
"$",
"dbtime",
";",
"}"
] | how long might we expect this export to take
@return constant one of PORTFOLIO_TIME_XX | [
"how",
"long",
"might",
"we",
"expect",
"this",
"export",
"to",
"take"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/locallib.php#L91-L95 |
212,791 | moodle/moodle | mod/glossary/locallib.php | glossary_entry_portfolio_caller.check_permissions | public function check_permissions() {
$context = context_module::instance($this->cm->id);
return has_capability('mod/glossary:exportentry', $context)
|| ($this->entry->userid == $this->user->id && has_capability('mod/glossary:exportownentry', $context));
} | php | public function check_permissions() {
$context = context_module::instance($this->cm->id);
return has_capability('mod/glossary:exportentry', $context)
|| ($this->entry->userid == $this->user->id && has_capability('mod/glossary:exportownentry', $context));
} | [
"public",
"function",
"check_permissions",
"(",
")",
"{",
"$",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"this",
"->",
"cm",
"->",
"id",
")",
";",
"return",
"has_capability",
"(",
"'mod/glossary:exportentry'",
",",
"$",
"context",
")",
"||",
"(",
"$",
"this",
"->",
"entry",
"->",
"userid",
"==",
"$",
"this",
"->",
"user",
"->",
"id",
"&&",
"has_capability",
"(",
"'mod/glossary:exportownentry'",
",",
"$",
"context",
")",
")",
";",
"}"
] | make sure that the current user is allowed to do this
@return boolean | [
"make",
"sure",
"that",
"the",
"current",
"user",
"is",
"allowed",
"to",
"do",
"this"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/locallib.php#L291-L295 |
212,792 | moodle/moodle | mod/glossary/locallib.php | glossary_entry_portfolio_caller.entry_content | public static function entry_content($course, $cm, $glossary, $entry, $aliases, $format) {
global $OUTPUT, $DB;
$entry = clone $entry;
$context = context_module::instance($cm->id);
$options = portfolio_format_text_options();
$options->trusted = $entry->definitiontrust;
$options->context = $context;
$output = '<table class="glossarypost dictionary" cellspacing="0">' . "\n";
$output .= '<tr valign="top">' . "\n";
$output .= '<td class="entry">' . "\n";
$output .= '<div class="concept">';
$output .= format_text($OUTPUT->heading($entry->concept, 3), FORMAT_MOODLE, $options);
$output .= '</div> ' . "\n";
$entry->definition = format_text($entry->definition, $entry->definitionformat, $options);
$output .= portfolio_rewrite_pluginfile_urls($entry->definition, $context->id, 'mod_glossary', 'entry', $entry->id, $format);
if (isset($entry->footer)) {
$output .= $entry->footer;
}
$output .= '</td></tr>' . "\n";
if (!empty($aliases)) {
$aliases = explode(',', $aliases->alias);
$output .= '<tr valign="top"><td class="entrylowersection">';
$key = (count($aliases) == 1) ? 'alias' : 'aliases';
$output .= get_string($key, 'glossary') . ': ';
foreach ($aliases as $alias) {
$output .= s($alias) . ',';
}
$output = substr($output, 0, -1);
$output .= '</td></tr>' . "\n";
}
if ($entry->sourceglossaryid == $cm->instance) {
if (!$maincm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) {
return '';
}
$filecontext = context_module::instance($maincm->id);
} else {
$filecontext = $context;
}
$fs = get_file_storage();
if ($files = $fs->get_area_files($filecontext->id, 'mod_glossary', 'attachment', $entry->id, "timemodified", false)) {
$output .= '<table border="0" width="100%"><tr><td>' . "\n";
foreach ($files as $file) {
$output .= $format->file_output($file);
}
$output .= '</td></tr></table>' . "\n";
}
$output .= '</table>' . "\n";
return $output;
} | php | public static function entry_content($course, $cm, $glossary, $entry, $aliases, $format) {
global $OUTPUT, $DB;
$entry = clone $entry;
$context = context_module::instance($cm->id);
$options = portfolio_format_text_options();
$options->trusted = $entry->definitiontrust;
$options->context = $context;
$output = '<table class="glossarypost dictionary" cellspacing="0">' . "\n";
$output .= '<tr valign="top">' . "\n";
$output .= '<td class="entry">' . "\n";
$output .= '<div class="concept">';
$output .= format_text($OUTPUT->heading($entry->concept, 3), FORMAT_MOODLE, $options);
$output .= '</div> ' . "\n";
$entry->definition = format_text($entry->definition, $entry->definitionformat, $options);
$output .= portfolio_rewrite_pluginfile_urls($entry->definition, $context->id, 'mod_glossary', 'entry', $entry->id, $format);
if (isset($entry->footer)) {
$output .= $entry->footer;
}
$output .= '</td></tr>' . "\n";
if (!empty($aliases)) {
$aliases = explode(',', $aliases->alias);
$output .= '<tr valign="top"><td class="entrylowersection">';
$key = (count($aliases) == 1) ? 'alias' : 'aliases';
$output .= get_string($key, 'glossary') . ': ';
foreach ($aliases as $alias) {
$output .= s($alias) . ',';
}
$output = substr($output, 0, -1);
$output .= '</td></tr>' . "\n";
}
if ($entry->sourceglossaryid == $cm->instance) {
if (!$maincm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) {
return '';
}
$filecontext = context_module::instance($maincm->id);
} else {
$filecontext = $context;
}
$fs = get_file_storage();
if ($files = $fs->get_area_files($filecontext->id, 'mod_glossary', 'attachment', $entry->id, "timemodified", false)) {
$output .= '<table border="0" width="100%"><tr><td>' . "\n";
foreach ($files as $file) {
$output .= $format->file_output($file);
}
$output .= '</td></tr></table>' . "\n";
}
$output .= '</table>' . "\n";
return $output;
} | [
"public",
"static",
"function",
"entry_content",
"(",
"$",
"course",
",",
"$",
"cm",
",",
"$",
"glossary",
",",
"$",
"entry",
",",
"$",
"aliases",
",",
"$",
"format",
")",
"{",
"global",
"$",
"OUTPUT",
",",
"$",
"DB",
";",
"$",
"entry",
"=",
"clone",
"$",
"entry",
";",
"$",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"$",
"options",
"=",
"portfolio_format_text_options",
"(",
")",
";",
"$",
"options",
"->",
"trusted",
"=",
"$",
"entry",
"->",
"definitiontrust",
";",
"$",
"options",
"->",
"context",
"=",
"$",
"context",
";",
"$",
"output",
"=",
"'<table class=\"glossarypost dictionary\" cellspacing=\"0\">'",
".",
"\"\\n\"",
";",
"$",
"output",
".=",
"'<tr valign=\"top\">'",
".",
"\"\\n\"",
";",
"$",
"output",
".=",
"'<td class=\"entry\">'",
".",
"\"\\n\"",
";",
"$",
"output",
".=",
"'<div class=\"concept\">'",
";",
"$",
"output",
".=",
"format_text",
"(",
"$",
"OUTPUT",
"->",
"heading",
"(",
"$",
"entry",
"->",
"concept",
",",
"3",
")",
",",
"FORMAT_MOODLE",
",",
"$",
"options",
")",
";",
"$",
"output",
".=",
"'</div> '",
".",
"\"\\n\"",
";",
"$",
"entry",
"->",
"definition",
"=",
"format_text",
"(",
"$",
"entry",
"->",
"definition",
",",
"$",
"entry",
"->",
"definitionformat",
",",
"$",
"options",
")",
";",
"$",
"output",
".=",
"portfolio_rewrite_pluginfile_urls",
"(",
"$",
"entry",
"->",
"definition",
",",
"$",
"context",
"->",
"id",
",",
"'mod_glossary'",
",",
"'entry'",
",",
"$",
"entry",
"->",
"id",
",",
"$",
"format",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"entry",
"->",
"footer",
")",
")",
"{",
"$",
"output",
".=",
"$",
"entry",
"->",
"footer",
";",
"}",
"$",
"output",
".=",
"'</td></tr>'",
".",
"\"\\n\"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"aliases",
")",
")",
"{",
"$",
"aliases",
"=",
"explode",
"(",
"','",
",",
"$",
"aliases",
"->",
"alias",
")",
";",
"$",
"output",
".=",
"'<tr valign=\"top\"><td class=\"entrylowersection\">'",
";",
"$",
"key",
"=",
"(",
"count",
"(",
"$",
"aliases",
")",
"==",
"1",
")",
"?",
"'alias'",
":",
"'aliases'",
";",
"$",
"output",
".=",
"get_string",
"(",
"$",
"key",
",",
"'glossary'",
")",
".",
"': '",
";",
"foreach",
"(",
"$",
"aliases",
"as",
"$",
"alias",
")",
"{",
"$",
"output",
".=",
"s",
"(",
"$",
"alias",
")",
".",
"','",
";",
"}",
"$",
"output",
"=",
"substr",
"(",
"$",
"output",
",",
"0",
",",
"-",
"1",
")",
";",
"$",
"output",
".=",
"'</td></tr>'",
".",
"\"\\n\"",
";",
"}",
"if",
"(",
"$",
"entry",
"->",
"sourceglossaryid",
"==",
"$",
"cm",
"->",
"instance",
")",
"{",
"if",
"(",
"!",
"$",
"maincm",
"=",
"get_coursemodule_from_instance",
"(",
"'glossary'",
",",
"$",
"entry",
"->",
"glossaryid",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"filecontext",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"maincm",
"->",
"id",
")",
";",
"}",
"else",
"{",
"$",
"filecontext",
"=",
"$",
"context",
";",
"}",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"if",
"(",
"$",
"files",
"=",
"$",
"fs",
"->",
"get_area_files",
"(",
"$",
"filecontext",
"->",
"id",
",",
"'mod_glossary'",
",",
"'attachment'",
",",
"$",
"entry",
"->",
"id",
",",
"\"timemodified\"",
",",
"false",
")",
")",
"{",
"$",
"output",
".=",
"'<table border=\"0\" width=\"100%\"><tr><td>'",
".",
"\"\\n\"",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"output",
".=",
"$",
"format",
"->",
"file_output",
"(",
"$",
"file",
")",
";",
"}",
"$",
"output",
".=",
"'</td></tr></table>'",
".",
"\"\\n\"",
";",
"}",
"$",
"output",
".=",
"'</table>'",
".",
"\"\\n\"",
";",
"return",
"$",
"output",
";",
"}"
] | helper function to get the html content of an entry
for both this class and the full glossary exporter
this is a very simplified version of the dictionary format output,
but with its 500 levels of indirection removed
and file rewriting handled by the portfolio export format.
@param stdclass $course
@param stdclass $cm
@param stdclass $glossary
@param stdclass $entry
@return string | [
"helper",
"function",
"to",
"get",
"the",
"html",
"content",
"of",
"an",
"entry",
"for",
"both",
"this",
"class",
"and",
"the",
"full",
"glossary",
"exporter",
"this",
"is",
"a",
"very",
"simplified",
"version",
"of",
"the",
"dictionary",
"format",
"output",
"but",
"with",
"its",
"500",
"levels",
"of",
"indirection",
"removed",
"and",
"file",
"rewriting",
"handled",
"by",
"the",
"portfolio",
"export",
"format",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/locallib.php#L395-L454 |
212,793 | moodle/moodle | lib/weblib.php | moodle_url.params | public function params(array $params = null) {
$params = (array)$params;
foreach ($params as $key => $value) {
if (is_int($key)) {
throw new coding_exception('Url parameters can not have numeric keys!');
}
if (!is_string($value)) {
if (is_array($value)) {
throw new coding_exception('Url parameters values can not be arrays!');
}
if (is_object($value) and !method_exists($value, '__toString')) {
throw new coding_exception('Url parameters values can not be objects, unless __toString() is defined!');
}
}
$this->params[$key] = (string)$value;
}
return $this->params;
} | php | public function params(array $params = null) {
$params = (array)$params;
foreach ($params as $key => $value) {
if (is_int($key)) {
throw new coding_exception('Url parameters can not have numeric keys!');
}
if (!is_string($value)) {
if (is_array($value)) {
throw new coding_exception('Url parameters values can not be arrays!');
}
if (is_object($value) and !method_exists($value, '__toString')) {
throw new coding_exception('Url parameters values can not be objects, unless __toString() is defined!');
}
}
$this->params[$key] = (string)$value;
}
return $this->params;
} | [
"public",
"function",
"params",
"(",
"array",
"$",
"params",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"(",
"array",
")",
"$",
"params",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Url parameters can not have numeric keys!'",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Url parameters values can not be arrays!'",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"and",
"!",
"method_exists",
"(",
"$",
"value",
",",
"'__toString'",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Url parameters values can not be objects, unless __toString() is defined!'",
")",
";",
"}",
"}",
"$",
"this",
"->",
"params",
"[",
"$",
"key",
"]",
"=",
"(",
"string",
")",
"$",
"value",
";",
"}",
"return",
"$",
"this",
"->",
"params",
";",
"}"
] | Add an array of params to the params for this url.
The added params override existing ones if they have the same name.
@param array $params Defaults to null. If null then returns all params.
@return array Array of Params for url.
@throws coding_exception | [
"Add",
"an",
"array",
"of",
"params",
"to",
"the",
"params",
"for",
"this",
"url",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/weblib.php#L396-L414 |
212,794 | moodle/moodle | lib/weblib.php | moodle_url.remove_params | public function remove_params($params = null) {
if (!is_array($params)) {
$params = func_get_args();
}
foreach ($params as $param) {
unset($this->params[$param]);
}
return $this->params;
} | php | public function remove_params($params = null) {
if (!is_array($params)) {
$params = func_get_args();
}
foreach ($params as $param) {
unset($this->params[$param]);
}
return $this->params;
} | [
"public",
"function",
"remove_params",
"(",
"$",
"params",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"params",
")",
")",
"{",
"$",
"params",
"=",
"func_get_args",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"params",
"[",
"$",
"param",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"params",
";",
"}"
] | Remove all params if no arguments passed.
Remove selected params if arguments are passed.
Can be called as either remove_params('param1', 'param2')
or remove_params(array('param1', 'param2')).
@param string[]|string $params,... either an array of param names, or 1..n string params to remove as args.
@return array url parameters | [
"Remove",
"all",
"params",
"if",
"no",
"arguments",
"passed",
".",
"Remove",
"selected",
"params",
"if",
"arguments",
"are",
"passed",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/weblib.php#L426-L434 |
212,795 | moodle/moodle | lib/weblib.php | moodle_url.param | public function param($paramname, $newvalue = '') {
if (func_num_args() > 1) {
// Set new value.
$this->params(array($paramname => $newvalue));
}
if (isset($this->params[$paramname])) {
return $this->params[$paramname];
} else {
return null;
}
} | php | public function param($paramname, $newvalue = '') {
if (func_num_args() > 1) {
// Set new value.
$this->params(array($paramname => $newvalue));
}
if (isset($this->params[$paramname])) {
return $this->params[$paramname];
} else {
return null;
}
} | [
"public",
"function",
"param",
"(",
"$",
"paramname",
",",
"$",
"newvalue",
"=",
"''",
")",
"{",
"if",
"(",
"func_num_args",
"(",
")",
">",
"1",
")",
"{",
"// Set new value.",
"$",
"this",
"->",
"params",
"(",
"array",
"(",
"$",
"paramname",
"=>",
"$",
"newvalue",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"params",
"[",
"$",
"paramname",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"params",
"[",
"$",
"paramname",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | Add a param to the params for this url.
The added param overrides existing one if they have the same name.
@param string $paramname name
@param string $newvalue Param value. If new value specified current value is overriden or parameter is added
@return mixed string parameter value, null if parameter does not exist | [
"Add",
"a",
"param",
"to",
"the",
"params",
"for",
"this",
"url",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/weblib.php#L457-L467 |
212,796 | moodle/moodle | lib/weblib.php | moodle_url.merge_overrideparams | protected function merge_overrideparams(array $overrideparams = null) {
$overrideparams = (array)$overrideparams;
$params = $this->params;
foreach ($overrideparams as $key => $value) {
if (is_int($key)) {
throw new coding_exception('Overridden parameters can not have numeric keys!');
}
if (is_array($value)) {
throw new coding_exception('Overridden parameters values can not be arrays!');
}
if (is_object($value) and !method_exists($value, '__toString')) {
throw new coding_exception('Overridden parameters values can not be objects, unless __toString() is defined!');
}
$params[$key] = (string)$value;
}
return $params;
} | php | protected function merge_overrideparams(array $overrideparams = null) {
$overrideparams = (array)$overrideparams;
$params = $this->params;
foreach ($overrideparams as $key => $value) {
if (is_int($key)) {
throw new coding_exception('Overridden parameters can not have numeric keys!');
}
if (is_array($value)) {
throw new coding_exception('Overridden parameters values can not be arrays!');
}
if (is_object($value) and !method_exists($value, '__toString')) {
throw new coding_exception('Overridden parameters values can not be objects, unless __toString() is defined!');
}
$params[$key] = (string)$value;
}
return $params;
} | [
"protected",
"function",
"merge_overrideparams",
"(",
"array",
"$",
"overrideparams",
"=",
"null",
")",
"{",
"$",
"overrideparams",
"=",
"(",
"array",
")",
"$",
"overrideparams",
";",
"$",
"params",
"=",
"$",
"this",
"->",
"params",
";",
"foreach",
"(",
"$",
"overrideparams",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Overridden parameters can not have numeric keys!'",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Overridden parameters values can not be arrays!'",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"and",
"!",
"method_exists",
"(",
"$",
"value",
",",
"'__toString'",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Overridden parameters values can not be objects, unless __toString() is defined!'",
")",
";",
"}",
"$",
"params",
"[",
"$",
"key",
"]",
"=",
"(",
"string",
")",
"$",
"value",
";",
"}",
"return",
"$",
"params",
";",
"}"
] | Merges parameters and validates them
@param array $overrideparams
@return array merged parameters
@throws coding_exception | [
"Merges",
"parameters",
"and",
"validates",
"them"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/weblib.php#L476-L492 |
212,797 | moodle/moodle | lib/weblib.php | moodle_url.get_query_string | public function get_query_string($escaped = true, array $overrideparams = null) {
$arr = array();
if ($overrideparams !== null) {
$params = $this->merge_overrideparams($overrideparams);
} else {
$params = $this->params;
}
foreach ($params as $key => $val) {
if (is_array($val)) {
foreach ($val as $index => $value) {
$arr[] = rawurlencode($key.'['.$index.']')."=".rawurlencode($value);
}
} else {
if (isset($val) && $val !== '') {
$arr[] = rawurlencode($key)."=".rawurlencode($val);
} else {
$arr[] = rawurlencode($key);
}
}
}
if ($escaped) {
return implode('&', $arr);
} else {
return implode('&', $arr);
}
} | php | public function get_query_string($escaped = true, array $overrideparams = null) {
$arr = array();
if ($overrideparams !== null) {
$params = $this->merge_overrideparams($overrideparams);
} else {
$params = $this->params;
}
foreach ($params as $key => $val) {
if (is_array($val)) {
foreach ($val as $index => $value) {
$arr[] = rawurlencode($key.'['.$index.']')."=".rawurlencode($value);
}
} else {
if (isset($val) && $val !== '') {
$arr[] = rawurlencode($key)."=".rawurlencode($val);
} else {
$arr[] = rawurlencode($key);
}
}
}
if ($escaped) {
return implode('&', $arr);
} else {
return implode('&', $arr);
}
} | [
"public",
"function",
"get_query_string",
"(",
"$",
"escaped",
"=",
"true",
",",
"array",
"$",
"overrideparams",
"=",
"null",
")",
"{",
"$",
"arr",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"overrideparams",
"!==",
"null",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"merge_overrideparams",
"(",
"$",
"overrideparams",
")",
";",
"}",
"else",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"params",
";",
"}",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"val",
")",
")",
"{",
"foreach",
"(",
"$",
"val",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"$",
"arr",
"[",
"]",
"=",
"rawurlencode",
"(",
"$",
"key",
".",
"'['",
".",
"$",
"index",
".",
"']'",
")",
".",
"\"=\"",
".",
"rawurlencode",
"(",
"$",
"value",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"val",
")",
"&&",
"$",
"val",
"!==",
"''",
")",
"{",
"$",
"arr",
"[",
"]",
"=",
"rawurlencode",
"(",
"$",
"key",
")",
".",
"\"=\"",
".",
"rawurlencode",
"(",
"$",
"val",
")",
";",
"}",
"else",
"{",
"$",
"arr",
"[",
"]",
"=",
"rawurlencode",
"(",
"$",
"key",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"escaped",
")",
"{",
"return",
"implode",
"(",
"'&'",
",",
"$",
"arr",
")",
";",
"}",
"else",
"{",
"return",
"implode",
"(",
"'&'",
",",
"$",
"arr",
")",
";",
"}",
"}"
] | Get the params as as a query string.
This method should not be used outside of this method.
@param bool $escaped Use & as params separator instead of plain &
@param array $overrideparams params to add to the output params, these
override existing ones with the same name.
@return string query string that can be added to a url. | [
"Get",
"the",
"params",
"as",
"as",
"a",
"query",
"string",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/weblib.php#L504-L529 |
212,798 | moodle/moodle | lib/weblib.php | moodle_url.out | public function out($escaped = true, array $overrideparams = null) {
global $CFG;
if (!is_bool($escaped)) {
debugging('Escape parameter must be of type boolean, '.gettype($escaped).' given instead.');
}
$url = $this;
// Allow url's to be rewritten by a plugin.
if (isset($CFG->urlrewriteclass) && !isset($CFG->upgraderunning)) {
$class = $CFG->urlrewriteclass;
$pluginurl = $class::url_rewrite($url);
if ($pluginurl instanceof moodle_url) {
$url = $pluginurl;
}
}
return $url->raw_out($escaped, $overrideparams);
} | php | public function out($escaped = true, array $overrideparams = null) {
global $CFG;
if (!is_bool($escaped)) {
debugging('Escape parameter must be of type boolean, '.gettype($escaped).' given instead.');
}
$url = $this;
// Allow url's to be rewritten by a plugin.
if (isset($CFG->urlrewriteclass) && !isset($CFG->upgraderunning)) {
$class = $CFG->urlrewriteclass;
$pluginurl = $class::url_rewrite($url);
if ($pluginurl instanceof moodle_url) {
$url = $pluginurl;
}
}
return $url->raw_out($escaped, $overrideparams);
} | [
"public",
"function",
"out",
"(",
"$",
"escaped",
"=",
"true",
",",
"array",
"$",
"overrideparams",
"=",
"null",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"!",
"is_bool",
"(",
"$",
"escaped",
")",
")",
"{",
"debugging",
"(",
"'Escape parameter must be of type boolean, '",
".",
"gettype",
"(",
"$",
"escaped",
")",
".",
"' given instead.'",
")",
";",
"}",
"$",
"url",
"=",
"$",
"this",
";",
"// Allow url's to be rewritten by a plugin.",
"if",
"(",
"isset",
"(",
"$",
"CFG",
"->",
"urlrewriteclass",
")",
"&&",
"!",
"isset",
"(",
"$",
"CFG",
"->",
"upgraderunning",
")",
")",
"{",
"$",
"class",
"=",
"$",
"CFG",
"->",
"urlrewriteclass",
";",
"$",
"pluginurl",
"=",
"$",
"class",
"::",
"url_rewrite",
"(",
"$",
"url",
")",
";",
"if",
"(",
"$",
"pluginurl",
"instanceof",
"moodle_url",
")",
"{",
"$",
"url",
"=",
"$",
"pluginurl",
";",
"}",
"}",
"return",
"$",
"url",
"->",
"raw_out",
"(",
"$",
"escaped",
",",
"$",
"overrideparams",
")",
";",
"}"
] | Output url.
If you use the returned URL in HTML code, you want the escaped ampersands. If you use
the returned URL in HTTP headers, you want $escaped=false.
@param bool $escaped Use & as params separator instead of plain &
@param array $overrideparams params to add to the output url, these override existing ones with the same name.
@return string Resulting URL | [
"Output",
"url",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/weblib.php#L550-L571 |
212,799 | moodle/moodle | lib/weblib.php | moodle_url.raw_out | public function raw_out($escaped = true, array $overrideparams = null) {
if (!is_bool($escaped)) {
debugging('Escape parameter must be of type boolean, '.gettype($escaped).' given instead.');
}
$uri = $this->out_omit_querystring().$this->slashargument;
$querystring = $this->get_query_string($escaped, $overrideparams);
if ($querystring !== '') {
$uri .= '?' . $querystring;
}
if (!is_null($this->anchor)) {
$uri .= '#'.$this->anchor;
}
return $uri;
} | php | public function raw_out($escaped = true, array $overrideparams = null) {
if (!is_bool($escaped)) {
debugging('Escape parameter must be of type boolean, '.gettype($escaped).' given instead.');
}
$uri = $this->out_omit_querystring().$this->slashargument;
$querystring = $this->get_query_string($escaped, $overrideparams);
if ($querystring !== '') {
$uri .= '?' . $querystring;
}
if (!is_null($this->anchor)) {
$uri .= '#'.$this->anchor;
}
return $uri;
} | [
"public",
"function",
"raw_out",
"(",
"$",
"escaped",
"=",
"true",
",",
"array",
"$",
"overrideparams",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_bool",
"(",
"$",
"escaped",
")",
")",
"{",
"debugging",
"(",
"'Escape parameter must be of type boolean, '",
".",
"gettype",
"(",
"$",
"escaped",
")",
".",
"' given instead.'",
")",
";",
"}",
"$",
"uri",
"=",
"$",
"this",
"->",
"out_omit_querystring",
"(",
")",
".",
"$",
"this",
"->",
"slashargument",
";",
"$",
"querystring",
"=",
"$",
"this",
"->",
"get_query_string",
"(",
"$",
"escaped",
",",
"$",
"overrideparams",
")",
";",
"if",
"(",
"$",
"querystring",
"!==",
"''",
")",
"{",
"$",
"uri",
".=",
"'?'",
".",
"$",
"querystring",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"anchor",
")",
")",
"{",
"$",
"uri",
".=",
"'#'",
".",
"$",
"this",
"->",
"anchor",
";",
"}",
"return",
"$",
"uri",
";",
"}"
] | Output url without any rewrites
This is identical in signature and use to out() but doesn't call the rewrite handler.
@param bool $escaped Use & as params separator instead of plain &
@param array $overrideparams params to add to the output url, these override existing ones with the same name.
@return string Resulting URL | [
"Output",
"url",
"without",
"any",
"rewrites"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/weblib.php#L582-L598 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.