本文整理汇总了PHP中collatorlib类的典型用法代码示例。如果您正苦于以下问题:PHP collatorlib类的具体用法?PHP collatorlib怎么用?PHP collatorlib使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了collatorlib类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: activities_inuse
function activities_inuse($id) {
static $modnames = null;
global $DB, $CFG;
if ($modnames === null) {
$modnames = array(0 => array(), 1 => array());
if ($allmods = $DB->get_records("modules")) {
foreach ($allmods as $mod) {
if (file_exists("$CFG->dirroot/mod/$mod->name/lib.php") && $mod->visible) {
$modnames[0][$mod->name] = get_string("modulename", "$mod->name");
$modnames[1][$mod->name] = get_string("modulenameplural", "$mod->name");
}
}
collatorlib::asort($modnames[0]);
collatorlib::asort($modnames[1]);
}
}
$modnames = $modnames[(int) $plural];
$modulesinuse = array();
$modulesinuse[null] = '---------Select----------';
$dbmanager = $DB->get_manager();
foreach ($modnames as $module => $details) {
if ($dbmanager->table_exists($module) && $DB->record_exists($module, array('course' => $id))) {
$modulesinuse[$module] = $details;
}
}
return $modulesinuse;
}
示例2: cpm_userinfo
static public function cpm_userinfo($a,$b){ //Compare two userinfo fields
$field = self::$field;
$adata = $a->userinfo->$field;
$bdata = $b->userinfo->$field;
if($adata == $bdata) {
return self::cpm_userid($a,$b);
}
if(is_string($adata) && function_exists('collatorlib::compare')){
return (collatorlib::compare($adata, $bdata))*(self::$ascending);
}
if($adata < $bdata){
return self::$ascending;
}else{
return -self::$ascending;
}
}
示例3: get_content
function get_content()
{
global $CFG, $DB, $OUTPUT;
if ($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass();
$this->content->items = array();
$this->content->icons = array();
$this->content->footer = '';
$course = $this->page->course;
require_once $CFG->dirroot . '/course/lib.php';
$modinfo = get_fast_modinfo($course);
$modfullnames = array();
$archetypes = array();
foreach ($modinfo->cms as $cm) {
// Exclude activities which are not visible or have no link (=label)
if (!$cm->uservisible or !$cm->has_view()) {
continue;
}
if (array_key_exists($cm->modname, $modfullnames)) {
continue;
}
if (!array_key_exists($cm->modname, $archetypes)) {
$archetypes[$cm->modname] = plugin_supports('mod', $cm->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
}
if ($archetypes[$cm->modname] == MOD_ARCHETYPE_RESOURCE) {
if (!array_key_exists('resources', $modfullnames)) {
$modfullnames['resources'] = get_string('resources');
}
} else {
$modfullnames[$cm->modname] = $cm->modplural;
}
}
collatorlib::asort($modfullnames);
foreach ($modfullnames as $modname => $modfullname) {
if ($modname === 'resources') {
$icon = '<img src="' . $OUTPUT->pix_url('f/html') . '" class="icon" alt="" /> ';
$this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/resources.php?id=' . $course->id . '">' . $icon . $modfullname . '</a>';
} else {
$icon = '<img src="' . $OUTPUT->pix_url('icon', $modname) . '" class="icon" alt="" /> ';
$this->content->items[] = '<a href="' . $CFG->wwwroot . '/mod/' . $modname . '/index.php?id=' . $course->id . '">' . $icon . $modfullname . '</a>';
}
}
return $this->content;
}
示例4: filter_get_all_installed
/**
* Get the names of all the filters installed in this Moodle.
*
* @global object
* @return array path => filter name from the appropriate lang file. e.g.
* array('mod/glossary' => 'Glossary Auto-linking', 'filter/tex' => 'TeX Notation');
* sorted in alphabetical order of name.
*/
function filter_get_all_installed()
{
global $CFG;
$filternames = array();
// TODO: deprecated since 2.2, will be out in 2.3, see MDL-29996
$filterlocations = array('mod', 'filter');
foreach ($filterlocations as $filterlocation) {
// TODO: move get_list_of_plugins() to get_plugin_list()
$filters = get_list_of_plugins($filterlocation);
foreach ($filters as $filter) {
// MDL-29994 - Ignore mod/data and mod/glossary filters forever, this will be out in 2.3
if ($filterlocation == 'mod' && ($filter == 'data' || $filter == 'glossary')) {
continue;
}
$path = $filterlocation . '/' . $filter;
if (is_readable($CFG->dirroot . '/' . $path . '/filter.php')) {
$strfiltername = filter_get_name($path);
$filternames[$path] = $strfiltername;
}
}
}
collatorlib::asort($filternames);
return $filternames;
}
示例5: get_all_mods
/**
* Returns a number of useful structures for course displays
*/
function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused)
{
global $CFG, $DB, $COURSE;
$mods = array();
// course modules indexed by id
$modnames = array();
// all course module names (except resource!)
$modnamesplural = array();
// all course module names (plural form)
$modnamesused = array();
// course module names used
if ($allmods = $DB->get_records("modules")) {
foreach ($allmods as $mod) {
if (!file_exists("{$CFG->dirroot}/mod/{$mod->name}/lib.php")) {
continue;
}
if ($mod->visible) {
$modnames[$mod->name] = get_string("modulename", "{$mod->name}");
$modnamesplural[$mod->name] = get_string("modulenameplural", "{$mod->name}");
}
}
collatorlib::asort($modnames);
} else {
print_error("nomodules", 'debug');
}
$course = $courseid == $COURSE->id ? $COURSE : $DB->get_record('course', array('id' => $courseid));
$modinfo = get_fast_modinfo($course);
if ($rawmods = $modinfo->cms) {
foreach ($rawmods as $mod) {
// Index the mods
if (empty($modnames[$mod->modname])) {
continue;
}
$mods[$mod->id] = $mod;
$mods[$mod->id]->modfullname = $modnames[$mod->modname];
if (!$mod->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $courseid))) {
continue;
}
// Check groupings
if (!groups_course_module_visible($mod)) {
continue;
}
$modnamesused[$mod->modname] = $modnames[$mod->modname];
}
if ($modnamesused) {
collatorlib::asort($modnamesused);
}
}
}
示例6: grade_get_categories_menu
/**
* Returns grade options for gradebook grade category menu
*
* @param int $courseid The course ID
* @param bool $includenew Include option for new category at array index -1
* @return array of grade categories in course
*/
function grade_get_categories_menu($courseid, $includenew = false)
{
$result = array();
if (!($categories = grade_category::fetch_all(array('courseid' => $courseid)))) {
//make sure course category exists
if (!grade_category::fetch_course_category($courseid)) {
debugging('Can not create course grade category!');
return $result;
}
$categories = grade_category::fetch_all(array('courseid' => $courseid));
}
foreach ($categories as $key => $category) {
if ($category->is_course_category()) {
$result[$category->id] = get_string('uncategorised', 'grades');
unset($categories[$key]);
}
}
if ($includenew) {
$result[-1] = get_string('newcategory', 'grades');
}
$cats = array();
foreach ($categories as $category) {
$cats[$category->id] = $category->get_name();
}
collatorlib::asort($cats);
return $result + $cats;
}
示例7: sort_records
/**
* Sorts list of records by several fields
*
* @param array $records array of stdClass objects
* @param array $sortfields assoc array where key is the field to sort and value is 1 for asc or -1 for desc
* @return int
*/
protected static function sort_records(&$records, $sortfields)
{
if (empty($records)) {
return;
}
// If sorting by course display name, calculate it (it may be fullname or shortname+fullname)
if (array_key_exists('displayname', $sortfields)) {
foreach ($records as $key => $record) {
if (!isset($record->displayname)) {
$records[$key]->displayname = get_course_display_name_for_list($record);
}
}
}
// sorting by one field - use collatorlib
if (count($sortfields) == 1) {
$property = key($sortfields);
if (in_array($property, array('sortorder', 'id', 'visible', 'parent', 'depth'))) {
$sortflag = collatorlib::SORT_NUMERIC;
} else {
if (in_array($property, array('idnumber', 'displayname', 'name', 'shortname', 'fullname'))) {
$sortflag = collatorlib::SORT_STRING;
} else {
$sortflag = collatorlib::SORT_REGULAR;
}
}
collatorlib::asort_objects_by_property($records, $property, $sortflag);
if ($sortfields[$property] < 0) {
$records = array_reverse($records, true);
}
return;
}
$records = coursecat_sortable_records::sort($records, $sortfields);
}
示例8: test_ksort
/**
* Tests the static ksort method
* @return void
*/
public function test_ksort()
{
$arr = array('b' => 'ab', 1 => 'aa', 0 => 'cc');
$result = collatorlib::ksort($arr);
$this->assertSame(array_keys($arr), array(0, 1, 'b'));
$this->assertSame(array_values($arr), array('cc', 'aa', 'ab'));
$this->assertTrue($result);
$obj = new stdClass();
$arr = array('1.1.1' => array(), '1.2' => $obj, '1.20.2' => null);
$result = collatorlib::ksort($arr, collatorlib::SORT_NATURAL);
$this->assertSame(array_keys($arr), array('1.1.1', '1.2', '1.20.2'));
$this->assertSame(array_values($arr), array(array(), $obj, null));
$this->assertTrue($result);
$a = array(2 => 'b', 1 => 'c');
$c =& $a;
$b =& $a;
collatorlib::ksort($b);
$this->assertSame($a, $b);
$this->assertSame($c, $b);
}
示例9: get_listing
/**
* Get file listing
*
* @param string $path
* @param string $page
* @return mixed
*/
public function get_listing($fullpath = '', $page = '')
{
global $OUTPUT;
$ret = array();
$ret['list'] = array();
$ret['manage'] = self::MANAGE_URL;
$ret['dynload'] = true;
$crumbs = explode('/', $fullpath);
$path = array_pop($crumbs);
if (empty($path)) {
$type = 'folder';
$pathid = 0;
$pathname = get_string('pluginname', 'repository_boxnet');
} else {
list($type, $pathid, $pathname) = $this->split_part($path);
}
$ret['path'] = $this->build_breadcrumb($fullpath);
$folders = array();
$files = array();
if ($type == 'search') {
$result = $this->boxnetclient->search($pathname);
} else {
$result = $this->boxnetclient->get_folder_items($pathid);
}
foreach ($result->entries as $item) {
if ($item->type == 'folder') {
$folders[$item->name . ':' . $item->id] = array('title' => $item->name, 'path' => $fullpath . '/' . $this->build_part('folder', $item->id, $item->name), 'date' => strtotime($item->modified_at), 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(64))->out(false), 'thumbnail_height' => 64, 'thumbnail_width' => 64, 'children' => array(), 'size' => $item->size);
} else {
$files[$item->name . ':' . $item->id] = array('title' => $item->name, 'source' => $this->build_part('file', $item->id, $item->name), 'size' => $item->size, 'date' => strtotime($item->modified_at), 'thumbnail' => $OUTPUT->pix_url(file_extension_icon($item->name, 64))->out(false), 'thumbnail_height' => 64, 'thumbnail_width' => 64, 'author' => $item->owned_by->name);
}
}
collatorlib::ksort($folders, core_collator::SORT_NATURAL);
collatorlib::ksort($files, core_collator::SORT_NATURAL);
$ret['list'] = array_merge($folders, $files);
$ret['list'] = array_filter($ret['list'], array($this, 'filter'));
return $ret;
}
示例10: 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);
collatorlib::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;
}
示例11: sesskey
}
if (!$blockobject) {
// ignore
$undeletable = '';
} else {
if (in_array($blockname, $undeletableblocktypes)) {
$undeletable = '<a href="blocks.php?unprotect=' . $blockid . '&sesskey=' . sesskey() . '" title="' . $strunprotect . '">' . '<img src="' . $OUTPUT->pix_url('t/unlock') . '" class="icon" alt="' . $strunprotect . '" /></a>';
} else {
$undeletable = '<a href="blocks.php?protect=' . $blockid . '&sesskey=' . sesskey() . '" title="' . $strprotect . '">' . '<img src="' . $OUTPUT->pix_url('t/unlock_gray') . '" class="icon" alt="' . $strprotect . '" /></a>';
}
}
$row = array('<span' . $class . '>' . $strblockname . '</span>', $blocklist, '<span' . $class . '>' . $version . '</span>', $visible, $undeletable, $delete, $settings);
$tablerows[] = array(strip_tags($strblockname), $row);
// first element will be used for sorting
}
collatorlib::asort($tablerows);
foreach ($tablerows as $row) {
$table->add_data($row[1]);
}
$table->print_html();
if (!empty($incompatible)) {
echo $OUTPUT->heading(get_string('incompatibleblocks', 'blockstable', 'admin'));
$table = new flexible_table('admin-blocks-incompatible');
$table->define_columns(array('block', 'delete'));
$table->define_headers(array($strname, $strdelete));
$table->define_baseurl($CFG->wwwroot . '/' . $CFG->admin . '/blocks.php');
$table->set_attribute('class', 'incompatibleblockstable generaltable');
$table->setup();
foreach ($incompatible as $block) {
$table->add_data(array($block->name, '<a href="blocks.php?delete=' . $block->id . '&sesskey=' . sesskey() . '">' . $strdelete . '</a>'));
}
示例12: filter_set_global_state
/**
* Set the global activated state for a text filter.
*
* @param string $filtername The filter name, for example 'tex'.
* @param int $state One of the values TEXTFILTER_ON, TEXTFILTER_OFF or TEXTFILTER_DISABLED.
* @param int $move 1 means up, 0 means the same, -1 means down
*/
function filter_set_global_state($filtername, $state, $move = 0)
{
global $DB;
// Check requested state is valid.
if (!in_array($state, array(TEXTFILTER_ON, TEXTFILTER_OFF, TEXTFILTER_DISABLED))) {
throw new coding_exception("Illegal option '{$state}' passed to filter_set_global_state. " . "Must be one of TEXTFILTER_ON, TEXTFILTER_OFF or TEXTFILTER_DISABLED.");
}
if ($move > 0) {
$move = 1;
} else {
if ($move < 0) {
$move = -1;
}
}
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) {
$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) {
$filter->active = $state;
$DB->update_record('filter_active', $filter);
if ($filter->active != TEXTFILTER_DISABLED) {
unset($off[$filtername]);
$on[$filter->filter] = $filter;
}
}
} else {
$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;
}
}
}
collatorlib::asort_objects_by_property($on, 'newsortorder', collatorlib::SORT_NUMERIC);
}
//.........这里部分代码省略.........
示例13: asort
/**
* Locale aware sorting, the key associations are kept, values are sorted alphabetically.
*
* @param array $arr array to be sorted (reference)
* @param int $sortflag One of Collator::SORT_REGULAR, Collator::SORT_NUMERIC, Collator::SORT_STRING
* @return void modifies parameter
*/
public static function asort(array &$arr, $sortflag = null)
{
debugging('textlib::asort has been superseeded by collatorlib::asort please upgrade your code to use that', DEBUG_DEVELOPER);
collatorlib::asort($arr, $sortflag);
}
示例14: test_legacy_collatorlib
public function test_legacy_collatorlib()
{
$arr = array('b' => 'ab', 1 => 'aa', 0 => 'cc');
$result = collatorlib::asort($arr);
$this->assertSame(array('aa', 'ab', 'cc'), array_values($arr));
$this->assertSame(array(1, 'b', 0), array_keys($arr));
$this->assertTrue($result);
}
示例15: require_capability
}
$editingon = false;
}
if (!$category->visible) {
require_capability('moodle/category:viewhiddencategories', $context);
}
$canmanage = has_capability('moodle/category:manage', $context);
$sesskeyprovided = !empty($sesskey) && confirm_sesskey($sesskey);
// Process any category actions.
if ($canmanage && $resort && $sesskeyprovided) {
// Resort the category if requested
if ($courses = get_courses($category->id, '', 'c.id,c.fullname,c.sortorder')) {
collatorlib::asort_objects_by_property($courses, 'fullname', collatorlib::SORT_NATURAL);
$i = 1;
foreach ($courses as $course) {
$DB->set_field('course', 'sortorder', $category->sortorder+$i, array('id'=>$course->id));
$i++;
}
fix_course_sortorder(); // should not be needed
}
}
// Process any course actions.
if ($editingon && $sesskeyprovided) {
// Move a specified course to a new category
if (!empty($moveto) and $data = data_submitted()) {
// Some courses are being moved