本文整理汇总了PHP中core_collator::asort_objects_by_property方法的典型用法代码示例。如果您正苦于以下问题:PHP core_collator::asort_objects_by_property方法的具体用法?PHP core_collator::asort_objects_by_property怎么用?PHP core_collator::asort_objects_by_property使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core_collator
的用法示例。
在下文中一共展示了core_collator::asort_objects_by_property方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filter
function filter($text, array $options = array())
{
$coursectx = $this->context->get_course_context(false);
if (!$coursectx) {
return $text;
}
$courseid = $coursectx->instanceid;
// Initialise/invalidate our trivial cache if dealing with a different course
if (!isset(self::$cachedcourseid) || self::$cachedcourseid !== (int) $courseid) {
self::$activitylist = null;
}
self::$cachedcourseid = (int) $courseid;
/// It may be cached
if (is_null(self::$activitylist)) {
self::$activitylist = array();
$modinfo = get_fast_modinfo($courseid);
if (!empty($modinfo->cms)) {
self::$activitylist = array();
// We will store all the created filters here.
// Create array of visible activities sorted by the name length (we are only interested in properties name and url).
$sortedactivities = array();
foreach ($modinfo->cms as $cm) {
// Exclude labels, hidden activities and activities for group members only.
if ($cm->visible and empty($cm->groupmembersonly) and $cm->has_view()) {
$sortedactivities[] = (object) array('name' => $cm->name, 'url' => $cm->url, 'id' => $cm->id, 'namelen' => strlen($cm->name));
}
}
core_collator::asort_objects_by_property($sortedactivities, 'namelen', SORT_NUMERIC);
foreach ($sortedactivities as $cm) {
$title = s(trim(strip_tags($cm->name)));
$currentname = trim($cm->name);
$entitisedname = s($currentname);
// Avoid empty or unlinkable activity names.
if (!empty($title)) {
$href_tag_begin = html_writer::start_tag('a', array('class' => 'autolink', 'title' => $title, 'href' => $cm->url));
self::$activitylist[$cm->id] = new filterobject($currentname, $href_tag_begin, '</a>', false, true);
if ($currentname != $entitisedname) {
// If name has some entity (& " < >) add that filter too. MDL-17545.
self::$activitylist[$cm->id . '-e'] = new filterobject($entitisedname, $href_tag_begin, '</a>', false, true);
}
}
}
}
}
$filterslist = array();
if (self::$activitylist) {
$cmid = $this->context->instanceid;
if ($this->context->contextlevel == CONTEXT_MODULE && isset(self::$activitylist[$cmid])) {
// remove filterobjects for the current module
$filterslist = array_values(array_diff_key(self::$activitylist, array($cmid => 1, $cmid . '-e' => 1)));
} else {
$filterslist = array_values(self::$activitylist);
}
}
if ($filterslist) {
return $text = filter_phrases($text, $filterslist);
} else {
return $text;
}
}
示例2: filter_set_global_state
//.........这里部分代码省略.........
if (strpos($filtername, 'filter/') === 0) {
//debugging("Old filtername '$filtername' parameter used in filter_set_global_state()", DEBUG_DEVELOPER);
$filtername = substr($filtername, 7);
} else {
if (strpos($filtername, '/') !== false) {
throw new coding_exception("Invalid filter name '{$filtername}' used in filter_set_global_state()");
}
}
$transaction = $DB->start_delegated_transaction();
$syscontext = context_system::instance();
$filters = $DB->get_records('filter_active', array('contextid' => $syscontext->id), 'sortorder ASC');
$on = array();
$off = array();
foreach ($filters as $f) {
if ($f->active == TEXTFILTER_DISABLED) {
$off[$f->filter] = $f;
} else {
$on[$f->filter] = $f;
}
}
// Update the state or add new record.
if (isset($on[$filtername])) {
$filter = $on[$filtername];
if ($filter->active != $state) {
add_to_config_log('filter_active', $filter->active, $state, $filtername);
$filter->active = $state;
$DB->update_record('filter_active', $filter);
if ($filter->active == TEXTFILTER_DISABLED) {
unset($on[$filtername]);
$off = array($filter->filter => $filter) + $off;
}
}
} else {
if (isset($off[$filtername])) {
$filter = $off[$filtername];
if ($filter->active != $state) {
add_to_config_log('filter_active', $filter->active, $state, $filtername);
$filter->active = $state;
$DB->update_record('filter_active', $filter);
if ($filter->active != TEXTFILTER_DISABLED) {
unset($off[$filtername]);
$on[$filter->filter] = $filter;
}
}
} else {
add_to_config_log('filter_active', '', $state, $filtername);
$filter = new stdClass();
$filter->filter = $filtername;
$filter->contextid = $syscontext->id;
$filter->active = $state;
$filter->sortorder = 99999;
$filter->id = $DB->insert_record('filter_active', $filter);
$filters[$filter->id] = $filter;
if ($state == TEXTFILTER_DISABLED) {
$off[$filter->filter] = $filter;
} else {
$on[$filter->filter] = $filter;
}
}
}
// Move only active.
if ($move != 0 and isset($on[$filter->filter])) {
$i = 1;
foreach ($on as $f) {
$f->newsortorder = $i;
$i++;
}
$filter->newsortorder = $filter->newsortorder + $move;
foreach ($on as $f) {
if ($f->id == $filter->id) {
continue;
}
if ($f->newsortorder == $filter->newsortorder) {
if ($move == 1) {
$f->newsortorder = $f->newsortorder - 1;
} else {
$f->newsortorder = $f->newsortorder + 1;
}
}
}
core_collator::asort_objects_by_property($on, 'newsortorder', core_collator::SORT_NUMERIC);
}
// Inactive are sorted by filter name.
core_collator::asort_objects_by_property($off, 'filter', core_collator::SORT_NATURAL);
// Update records if necessary.
$i = 1;
foreach ($on as $f) {
if ($f->sortorder != $i) {
$DB->set_field('filter_active', 'sortorder', $i, array('id' => $f->id));
}
$i++;
}
foreach ($off as $f) {
if ($f->sortorder != $i) {
$DB->set_field('filter_active', 'sortorder', $i, array('id' => $f->id));
}
$i++;
}
$transaction->allow_commit();
}
示例3: get_children
/**
* Returns the children associated with this category.
*
* @return part_of_admin_tree[]
*/
public function get_children()
{
// If we should sort and it hasn't already been sorted.
if ($this->sort && !$this->sorted) {
if ($this->sortsplit) {
$categories = array();
$pages = array();
foreach ($this->children as $child) {
if ($child instanceof admin_category) {
$categories[] = $child;
} else {
$pages[] = $child;
}
}
core_collator::asort_objects_by_property($categories, 'visiblename');
core_collator::asort_objects_by_property($pages, 'visiblename');
if (!$this->sortasc) {
$categories = array_reverse($categories);
$pages = array_reverse($pages);
}
$this->children = array_merge($pages, $categories);
} else {
core_collator::asort_objects_by_property($this->children, 'visiblename');
if (!$this->sortasc) {
$this->children = array_reverse($this->children);
}
}
$this->sorted = true;
}
return $this->children;
}
示例4: resort_courses
/**
* Resort the courses within this category by the given field.
*
* @param string $field One of fullname, shortname, idnumber or descending values of each (appended desc)
* @param bool $cleanup
* @return bool True for success.
* @throws coding_exception
*/
public function resort_courses($field, $cleanup = true)
{
global $DB;
$desc = false;
if (substr($field, -4) === "desc") {
$desc = true;
$field = substr($field, 0, -4);
// Remove "desc" from field name.
}
if ($field !== 'fullname' && $field !== 'shortname' && $field !== 'idnumber' && $field !== 'timecreated') {
// This is ultra important as we use $field in an SQL statement below this.
throw new coding_exception('Invalid field requested');
}
$ctxfields = context_helper::get_preload_record_columns_sql('ctx');
$sql = "SELECT c.id, c.sortorder, c.{$field}, {$ctxfields}\n FROM {course} c\n LEFT JOIN {context} ctx ON ctx.instanceid = c.id\n WHERE ctx.contextlevel = :ctxlevel AND\n c.category = :categoryid";
$params = array('ctxlevel' => CONTEXT_COURSE, 'categoryid' => $this->id);
$courses = $DB->get_records_sql($sql, $params);
if (count($courses) > 0) {
foreach ($courses as $courseid => $course) {
context_helper::preload_from_record($course);
if ($field === 'idnumber') {
$course->sortby = $course->idnumber;
} else {
// It'll require formatting.
$options = array('context' => context_course::instance($course->id));
// We format the string first so that it appears as the user would see it.
// This ensures the sorting makes sense to them. However it won't necessarily make
// sense to everyone if things like multilang filters are enabled.
// We then strip any tags as we don't want things such as image tags skewing the
// sort results.
$course->sortby = strip_tags(format_string($course->{$field}, true, $options));
}
// We set it back here rather than using references as there is a bug with using
// references in a foreach before passing as an arg by reference.
$courses[$courseid] = $course;
}
// Sort the courses.
core_collator::asort_objects_by_property($courses, 'sortby', core_collator::SORT_NATURAL);
if (!empty($desc)) {
$courses = array_reverse($courses);
}
$i = 1;
foreach ($courses as $course) {
$DB->set_field('course', 'sortorder', $this->sortorder + $i, array('id' => $course->id));
$i++;
}
if ($cleanup) {
// This should not be needed but we do it just to be safe.
fix_course_sortorder();
cache_helper::purge_by_event('changesincourse');
}
}
return true;
}
示例5: message_get_history
/**
* Retrieve the messages between two users
*
* @param object $user1 the current user
* @param object $user2 the other user
* @param int $limitnum the maximum number of messages to retrieve
* @param bool $viewingnewmessages are we currently viewing new messages?
*/
function message_get_history($user1, $user2, $limitnum=0, $viewingnewmessages=false) {
global $DB, $CFG;
$messages = array();
//we want messages sorted oldest to newest but if getting a subset of messages we need to sort
//desc to get the last $limitnum messages then flip the order in php
$sort = 'asc';
if ($limitnum>0) {
$sort = 'desc';
}
$notificationswhere = null;
//we have just moved new messages to read. If theyre here to see new messages dont hide notifications
if (!$viewingnewmessages && $CFG->messaginghidereadnotifications) {
$notificationswhere = 'AND notification=0';
}
//prevent notifications of your own actions appearing in your own message history
$ownnotificationwhere = ' AND NOT (useridfrom=? AND notification=1)';
$sql = "((useridto = ? AND useridfrom = ? AND timeusertodeleted = 0) OR
(useridto = ? AND useridfrom = ? AND timeuserfromdeleted = 0))";
if ($messages_read = $DB->get_records_select('message_read', $sql . $notificationswhere . $ownnotificationwhere,
array($user1->id, $user2->id, $user2->id, $user1->id, $user1->id),
"timecreated $sort", '*', 0, $limitnum)) {
foreach ($messages_read as $message) {
$messages[] = $message;
}
}
if ($messages_new = $DB->get_records_select('message', $sql . $ownnotificationwhere,
array($user1->id, $user2->id, $user2->id, $user1->id, $user1->id),
"timecreated $sort", '*', 0, $limitnum)) {
foreach ($messages_new as $message) {
$messages[] = $message;
}
}
$result = core_collator::asort_objects_by_property($messages, 'timecreated', core_collator::SORT_NUMERIC);
//if we only want the last $limitnum messages
$messagecount = count($messages);
if ($limitnum > 0 && $messagecount > $limitnum) {
$messages = array_slice($messages, $messagecount - $limitnum, $limitnum, true);
}
return $messages;
}
示例6: test_asort_objects_by_property
/**
* Tests the static asort_objects_by_method method.
*/
public function test_asort_objects_by_property()
{
$objects = array('b' => new string_test_class('ab'), 1 => new string_test_class('aa'), 0 => new string_test_class('cc'));
$result = core_collator::asort_objects_by_property($objects, 'publicname');
$this->assertSame(array(1, 'b', 0), array_keys($objects));
$this->assertSame(array('aa', 'ab', 'cc'), $this->get_ordered_names($objects, 'publicname'));
$this->assertTrue($result);
$objects = array('b' => new string_test_class('a20'), 1 => new string_test_class('a1'), 0 => new string_test_class('a100'));
$result = core_collator::asort_objects_by_property($objects, 'publicname', core_collator::SORT_NATURAL);
$this->assertSame(array(1, 'b', 0), array_keys($objects));
$this->assertSame(array('a1', 'a20', 'a100'), $this->get_ordered_names($objects, 'publicname'));
$this->assertTrue($result);
}
示例7: array
}
if ($swapcategory and $movecategory) {
$DB->set_field('course_categories', 'sortorder', $swapcategory->sortorder, array('id' => $movecategory->id));
$DB->set_field('course_categories', 'sortorder', $movecategory->sortorder, array('id' => $swapcategory->id));
cache_helper::purge_by_event('changesincoursecat');
add_to_log(SITEID, "category", "move", "editcategory.php?id=$movecategory->id", $movecategory->id);
}
// Finally reorder courses.
fix_course_sortorder();
}
if ($coursecat->id && $canmanage && $resort && confirm_sesskey()) {
// Resort the category.
if ($courses = get_courses($coursecat->id, '', 'c.id,c.fullname,c.sortorder')) {
core_collator::asort_objects_by_property($courses, 'fullname', core_collator::SORT_NATURAL);
$i = 1;
foreach ($courses as $course) {
$DB->set_field('course', 'sortorder', $coursecat->sortorder + $i, array('id' => $course->id));
$i++;
}
// This should not be needed but we do it just to be safe.
fix_course_sortorder();
cache_helper::purge_by_event('changesincourse');
}
}
if (!empty($moveto) && ($data = data_submitted()) && confirm_sesskey()) {
// Move a specified course to a new category.
// User must have category update in both cats to perform this.
require_capability('moodle/category:manage', $context);
示例8: workshop_print_recent_activity
//.........这里部分代码省略.........
} else {
// can see all submissions from all groups
$submissions[$activity->submissionid] = $s;
}
}
} while (0);
}
if ($activity->assessmentmodified > $timestart and empty($assessments[$activity->assessmentid])) {
$a = new stdclass();
$a->submissionid = $activity->submissionid;
$a->submissiontitle = $activity->submissiontitle;
$a->reviewerid = $activity->reviewerid;
$a->timemodified = $activity->assessmentmodified;
$a->cmid = $activity->cmid;
if ($activity->reviewerid == $USER->id || has_capability('mod/workshop:viewreviewernames', $context)) {
$a->reviewernamevisible = true;
} else {
$a->reviewernamevisible = false;
}
// the following do-while wrapper allows to break from deeply nested if-statements
do {
if ($a->reviewerid === $USER->id) {
// own assessments always visible
$assessments[$activity->assessmentid] = $a;
break;
}
if (has_capability('mod/workshop:viewallassessments', $context)) {
if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
if (isguestuser()) {
// shortcut - guest user does not belong into any group
break;
}
// this might be slow - show only submissions by users who share group with me in this cm
if (!$modinfo->get_groups($cm->groupingid)) {
break;
}
$reviewersgroups = groups_get_all_groups($course->id, $a->reviewerid, $cm->groupingid);
if (is_array($reviewersgroups)) {
$reviewersgroups = array_keys($reviewersgroups);
$intersect = array_intersect($reviewersgroups, $modinfo->get_groups($cm->groupingid));
if (empty($intersect)) {
break;
} else {
// can see all assessments and shares a group with the reviewer
$assessments[$activity->assessmentid] = $a;
break;
}
}
} else {
// can see all assessments from all groups
$assessments[$activity->assessmentid] = $a;
}
}
} while (0);
}
}
$rs->close();
$shown = false;
if (!empty($submissions)) {
$shown = true;
echo $OUTPUT->heading(get_string('recentsubmissions', 'workshop'), 3);
foreach ($submissions as $id => $submission) {
$link = new moodle_url('/mod/workshop/submission.php', array('id'=>$id, 'cmid'=>$submission->cmid));
if ($submission->authornamevisible) {
$author = $users[$submission->authorid];
} else {
$author = null;
}
print_recent_activity_note($submission->timemodified, $author, $submission->title, $link->out(), false, $viewfullnames);
}
}
if (!empty($assessments)) {
$shown = true;
echo $OUTPUT->heading(get_string('recentassessments', 'workshop'), 3);
core_collator::asort_objects_by_property($assessments, 'timemodified');
foreach ($assessments as $id => $assessment) {
$link = new moodle_url('/mod/workshop/assessment.php', array('asid' => $id));
if ($assessment->reviewernamevisible) {
$reviewer = $users[$assessment->reviewerid];
} else {
$reviewer = null;
}
print_recent_activity_note($assessment->timemodified, $reviewer, $assessment->submissiontitle, $link->out(), false, $viewfullnames);
}
}
if ($shown) {
return true;
}
return false;
}
示例9: message_get_recent_conversations
//.........这里部分代码省略.........
FROM {message_read} message
JOIN (
SELECT MAX(id) AS messageid,
matchedmessage.useridto,
matchedmessage.useridfrom
FROM {message_read} matchedmessage
INNER JOIN (
SELECT MAX(recentmessages.timecreated) timecreated,
recentmessages.useridfrom,
recentmessages.useridto
FROM {message_read} recentmessages
WHERE (
(recentmessages.useridfrom = :userid1 AND recentmessages.timeuserfromdeleted = 0) OR
(recentmessages.useridto = :userid2 AND recentmessages.timeusertodeleted = 0)
)
GROUP BY recentmessages.useridfrom, recentmessages.useridto
) recent ON matchedmessage.useridto = recent.useridto
AND matchedmessage.useridfrom = recent.useridfrom
AND matchedmessage.timecreated = recent.timecreated
WHERE (
(matchedmessage.useridfrom = :userid6 AND matchedmessage.timeuserfromdeleted = 0) OR
(matchedmessage.useridto = :userid7 AND matchedmessage.timeusertodeleted = 0)
)
GROUP BY matchedmessage.useridto, matchedmessage.useridfrom
) messagesubset ON messagesubset.messageid = message.id
JOIN {user} otheruser ON (message.useridfrom = :userid4 AND message.useridto = otheruser.id)
OR (message.useridto = :userid5 AND message.useridfrom = otheruser.id)
LEFT JOIN {message_contacts} contact ON contact.userid = :userid3 AND contact.contactid = otheruser.id
WHERE otheruser.deleted = 0 AND message.notification = 0
ORDER BY message.timecreated DESC";
$params = array(
'userid1' => $user->id,
'userid2' => $user->id,
'userid3' => $user->id,
'userid4' => $user->id,
'userid5' => $user->id,
'userid6' => $user->id,
'userid7' => $user->id
);
$read = $DB->get_records_sql($sql, $params, $limitfrom, $limitto);
// We want to get the messages that have not been read. These are stored in the 'message' table. It is the
// exact same query as the one above, except for the table we are querying. So, simply replace references to
// the 'message_read' table with the 'message' table.
$sql = str_replace('{message_read}', '{message}', $sql);
$unread = $DB->get_records_sql($sql, $params, $limitfrom, $limitto);
$unreadcountssql = 'SELECT useridfrom, count(*) as count
FROM {message}
WHERE useridto = :userid
AND timeusertodeleted = 0
AND notification = 0
GROUP BY useridfrom';
$unreadcounts = $DB->get_records_sql($unreadcountssql, array('userid' => $user->id));
// Union the 2 result sets together looking for the message with the most
// recent timecreated for each other user.
// $conversation->id (the array key) is the other user's ID.
$conversations = array();
$conversation_arrays = array($unread, $read);
foreach ($conversation_arrays as $conversation_array) {
foreach ($conversation_array as $conversation) {
// Only consider it unread if $user has unread messages.
if (isset($unreadcounts[$conversation->useridfrom])) {
$conversation->isread = 0;
$conversation->unreadcount = $unreadcounts[$conversation->useridfrom]->count;
} else {
$conversation->isread = 1;
}
if (!isset($conversations[$conversation->id])) {
$conversations[$conversation->id] = $conversation;
} else {
$current = $conversations[$conversation->id];
// We need to maintain the isread and unreadcount values from existing
// parts of the conversation if we're replacing it.
$conversation->isread = ($conversation->isread && $current->isread);
if (isset($current->unreadcount) && !isset($conversation->unreadcount)) {
$conversation->unreadcount = $current->unreadcount;
}
if ($current->timecreated < $conversation->timecreated) {
$conversations[$conversation->id] = $conversation;
} else if ($current->timecreated == $conversation->timecreated) {
if ($current->mid < $conversation->mid) {
$conversations[$conversation->id] = $conversation;
}
}
}
}
}
// Sort the conversations by $conversation->timecreated, newest to oldest
// There may be multiple conversations with the same timecreated
// The conversations array contains both read and unread messages (different tables) so sorting by ID won't work
$result = core_collator::asort_objects_by_property($conversations, 'timecreated', core_collator::SORT_NUMERIC);
$conversations = array_reverse($conversations);
return $conversations;
}
示例10: admin_settingpage
$settingspath = $path . '/settings.php';
if (file_exists($settingspath)) {
$settings = new admin_settingpage('cachestore_' . $plugin . '_settings', new lang_string('pluginname', 'cachestore_' . $plugin), 'moodle/site:config');
include $settingspath;
$ADMIN->add('cachestores', $settings);
}
}
}
// Add Calendar type settings.
if ($hassiteconfig) {
$ADMIN->add('modules', new admin_category('calendartype', new lang_string('calendartypes', 'calendar')));
$plugins = core_plugin_manager::instance()->get_plugins_of_type('calendartype');
core_collator::asort_objects_by_property($plugins, 'displayname');
foreach ($plugins as $plugin) {
/** @var \core\plugininfo\calendartype $plugin */
$plugin->load_settings($ADMIN, 'calendartype', $hassiteconfig);
}
}
/// Add all local plugins - must be always last!
if ($hassiteconfig) {
$ADMIN->add('modules', new admin_category('localplugins', new lang_string('localplugins')));
$ADMIN->add('localplugins', new admin_externalpage('managelocalplugins', new lang_string('localpluginsmanage'), $CFG->wwwroot . '/' . $CFG->admin . '/localplugins.php'));
}
// Extend settings for each local plugin. Note that their settings may be in any part of the
// settings tree and may be visible not only for administrators.
$plugins = core_plugin_manager::instance()->get_plugins_of_type('local');
core_collator::asort_objects_by_property($plugins, 'displayname');
foreach ($plugins as $plugin) {
/** @var \core\plugininfo\local $plugin */
$plugin->load_settings($ADMIN, null, $hassiteconfig);
}
示例11: get_module_metadata
//.........这里部分代码省略.........
continue;
}
$modlist[$course->id][$modname] = array();
// Create an object for a default representation of this module type in the activity chooser. It will be used
// if module does not implement callback get_shortcuts() and it will also be passed to the callback if it exists.
$defaultmodule = new stdClass();
$defaultmodule->title = $modnamestr;
$defaultmodule->name = $modname;
$defaultmodule->link = new moodle_url($urlbase, array('add' => $modname));
$defaultmodule->icon = $OUTPUT->pix_icon('icon', '', $defaultmodule->name, array('class' => 'icon'));
$sm = get_string_manager();
if ($sm->string_exists('modulename_help', $modname)) {
$defaultmodule->help = get_string('modulename_help', $modname);
if ($sm->string_exists('modulename_link', $modname)) {
// Link to further info in Moodle docs.
$link = get_string('modulename_link', $modname);
$linktext = get_string('morehelp');
$defaultmodule->help .= html_writer::tag('div', $OUTPUT->doc_link($link, $linktext, true), array('class' => 'helpdoclink'));
}
}
$defaultmodule->archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
// Legacy support for callback get_types() - do not use any more, use get_shortcuts() instead!
$typescallbackexists = component_callback_exists($modname, 'get_types');
// Each module can implement callback modulename_get_shortcuts() in its lib.php and return the list
// of elements to be added to activity chooser.
$items = component_callback($modname, 'get_shortcuts', array($defaultmodule), null);
if ($items !== null) {
foreach ($items as $item) {
// Add all items to the return array. All items must have different links, use them as a key in the return array.
if (!isset($item->archetype)) {
$item->archetype = $defaultmodule->archetype;
}
if (!isset($item->icon)) {
$item->icon = $defaultmodule->icon;
}
// If plugin returned the only one item with the same link as default item - cache it as $modname,
// otherwise append the link url to the module name.
$item->name = count($items) == 1 && $item->link->out() === $defaultmodule->link->out() ? $modname : $modname . ':' . $item->link;
// If the module provides the helptext property, append it to the help text to match the look and feel
// of the default course modules.
if (isset($item->help) && isset($item->helplink)) {
$linktext = get_string('morehelp');
$item->help .= html_writer::tag('div', $OUTPUT->doc_link($item->helplink, $linktext, true), array('class' => 'helpdoclink'));
}
$modlist[$course->id][$modname][$item->name] = $item;
}
$return += $modlist[$course->id][$modname];
if ($typescallbackexists) {
debugging('Both callbacks get_shortcuts() and get_types() are found in module ' . $modname . '. Callback get_types() will be completely ignored', DEBUG_DEVELOPER);
}
// If get_shortcuts() callback is defined, the default module action is not added.
// It is a responsibility of the callback to add it to the return value unless it is not needed.
continue;
}
if ($typescallbackexists) {
debugging('Callback get_types() is found in module ' . $modname . ', this functionality is deprecated, ' . 'please use callback get_shortcuts() instead', DEBUG_DEVELOPER);
}
$types = component_callback($modname, 'get_types', array(), MOD_SUBTYPE_NO_CHILDREN);
if ($types !== MOD_SUBTYPE_NO_CHILDREN) {
// Legacy support for deprecated callback get_types(). To be removed in Moodle 3.5. TODO MDL-53697.
if (is_array($types) && count($types) > 0) {
$grouptitle = $modnamestr;
$icon = $OUTPUT->pix_icon('icon', '', $modname, array('class' => 'icon'));
foreach ($types as $type) {
if ($type->typestr === '--') {
continue;
}
if (strpos($type->typestr, '--') === 0) {
$grouptitle = str_replace('--', '', $type->typestr);
continue;
}
// Set the Sub Type metadata.
$subtype = new stdClass();
$subtype->title = get_string('activitytypetitle', '', (object) ['activity' => $grouptitle, 'type' => $type->typestr]);
$subtype->type = str_replace('&', '&', $type->type);
$typename = preg_replace('/.*type=/', '', $subtype->type);
$subtype->archetype = $type->modclass;
if (!empty($type->help)) {
$subtype->help = $type->help;
} else {
if (get_string_manager()->string_exists('help' . $subtype->name, $modname)) {
$subtype->help = get_string('help' . $subtype->name, $modname);
}
}
$subtype->link = new moodle_url($urlbase, array('add' => $modname, 'type' => $typename));
$subtype->name = $modname . ':' . $subtype->link;
$subtype->icon = $icon;
$modlist[$course->id][$modname][$subtype->name] = $subtype;
}
$return += $modlist[$course->id][$modname];
}
} else {
// Neither get_shortcuts() nor get_types() callbacks found, use the default item for the activity chooser.
$modlist[$course->id][$modname][$modname] = $defaultmodule;
$return[$modname] = $defaultmodule;
}
}
core_collator::asort_objects_by_property($return, 'title');
return $return;
}
示例12: get_addable_blocks
/**
* The list of block types that may be added to this page.
*
* @return array block name => record from block table.
*/
public function get_addable_blocks()
{
$this->check_is_loaded();
if (!is_null($this->addableblocks)) {
return $this->addableblocks;
}
// Lazy load.
$this->addableblocks = array();
$allblocks = blocks_get_record();
if (empty($allblocks)) {
return $this->addableblocks;
}
$unaddableblocks = self::get_undeletable_block_types();
$requiredbythemeblocks = self::get_required_by_theme_block_types();
$pageformat = $this->page->pagetype;
foreach ($allblocks as $block) {
if (!($bi = block_instance($block->name))) {
continue;
}
if ($block->visible && !in_array($block->name, $unaddableblocks) && !in_array($block->name, $requiredbythemeblocks) && ($bi->instance_allow_multiple() || !$this->is_block_present($block->name)) && blocks_name_allowed_in_format($block->name, $pageformat) && $bi->user_can_addto($this->page)) {
$block->title = $bi->get_title();
$this->addableblocks[$block->name] = $block;
}
}
core_collator::asort_objects_by_property($this->addableblocks, 'title');
return $this->addableblocks;
}
示例13: require_capability
require_capability('moodle/course:managegroups', $context);
$strgroups = get_string('groups');
$strparticipants = get_string('participants');
$stroverview = get_string('overview', 'group');
$strgrouping = get_string('grouping', 'group');
$strgroup = get_string('group', 'group');
$strnotingrouping = get_string('notingrouping', 'group');
$strfiltergroups = get_string('filtergroups', 'group');
$strnogroups = get_string('nogroups', 'group');
$strdescription = get_string('description');
// Get all groupings and sort them by formatted name.
$groupings = $DB->get_records('groupings', array('courseid' => $courseid), 'name');
foreach ($groupings as $gid => $grouping) {
$groupings[$gid]->formattedname = format_string($grouping->name, true, array('context' => $context));
}
core_collator::asort_objects_by_property($groupings, 'formattedname');
$members = array();
foreach ($groupings as $grouping) {
$members[$grouping->id] = array();
}
$members[-1] = array();
//groups not in a grouping
// Get all groups
$groups = $DB->get_records('groups', array('courseid' => $courseid), 'name');
$params = array('courseid' => $courseid);
if ($groupid) {
$groupwhere = "AND g.id = :groupid";
$params['groupid'] = $groupid;
} else {
$groupwhere = "";
}
示例14: order_all_observers
/**
* Reorder observers to allow quick lookup of observer for each event.
*/
protected static function order_all_observers()
{
foreach (self::$allobservers as $classname => $observers) {
\core_collator::asort_objects_by_property($observers, 'priority', \core_collator::SORT_NUMERIC);
self::$allobservers[$classname] = array_reverse($observers);
}
}
示例15: import_tour_from_json
/**
* Import the provided tour JSON.
*
* @param string $json The tour configuration.
* @return tour
*/
public static function import_tour_from_json($json)
{
$tourconfig = json_decode($json);
// We do not use this yet - we may do in the future.
unset($tourconfig->version);
$steps = $tourconfig->steps;
unset($tourconfig->steps);
$tourconfig->id = null;
$tourconfig->sortorder = null;
$tour = tour::load_from_record($tourconfig, true);
$tour->persist(true);
// Ensure that steps are orderered by their sortorder.
\core_collator::asort_objects_by_property($steps, 'sortorder', \core_collator::SORT_NUMERIC);
foreach ($steps as $stepconfig) {
$stepconfig->id = null;
$stepconfig->tourid = $tour->get_id();
$step = step::load_from_record($stepconfig, true);
$step->persist(true);
}
return $tour;
}