當前位置: 首頁>>代碼示例>>PHP>>正文


PHP collatorlib::asort_objects_by_property方法代碼示例

本文整理匯總了PHP中collatorlib::asort_objects_by_property方法的典型用法代碼示例。如果您正苦於以下問題:PHP collatorlib::asort_objects_by_property方法的具體用法?PHP collatorlib::asort_objects_by_property怎麽用?PHP collatorlib::asort_objects_by_property使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在collatorlib的用法示例。


在下文中一共展示了collatorlib::asort_objects_by_property方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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)';

    if ($messages_read = $DB->get_records_select('message_read', "((useridto = ? AND useridfrom = ?) OR
                                                    (useridto = ? AND useridfrom = ?)) $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', "((useridto = ? AND useridfrom = ?) OR
                                                    (useridto = ? AND useridfrom = ?)) $ownnotificationwhere",
                                                    array($user1->id, $user2->id, $user2->id, $user1->id, $user1->id),
                                                    "timecreated $sort", '*', 0, $limitnum)) {
        foreach ($messages_new as $message) {
            $messages[] = $message;
        }
    }

    $result = collatorlib::asort_objects_by_property($messages, 'timecreated', collatorlib::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;
}
開發者ID:neogic,項目名稱:moodle,代碼行數:56,代碼來源:lib.php

示例2: test_asort_objects_by_property

 /**
  * Tests the static asort_objects_by_method method
  * @return void
  */
 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 = collatorlib::asort_objects_by_property($objects, 'publicname');
     $this->assertSame(array_keys($objects), array(1, 'b', 0));
     $this->assertSame($this->get_ordered_names($objects, 'publicname'), array('aa', 'ab', 'cc'));
     $this->assertTrue($result);
     $objects = array('b' => new string_test_class('a20'), 1 => new string_test_class('a1'), 0 => new string_test_class('a100'));
     $result = collatorlib::asort_objects_by_property($objects, 'publicname', collatorlib::SORT_NATURAL);
     $this->assertSame(array_keys($objects), array(1, 'b', 0));
     $this->assertSame($this->get_ordered_names($objects, 'publicname'), array('a1', 'a20', 'a100'));
     $this->assertTrue($result);
 }
開發者ID:masaterutakeno,項目名稱:MoodleMobile,代碼行數:17,代碼來源:textlib_test.php

示例3: 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);
 }
開發者ID:Jtgadbois,項目名稱:Pedadida,代碼行數:40,代碼來源:coursecatlib.php

示例4: 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
開發者ID:ncsu-delta,項目名稱:moodle,代碼行數:31,代碼來源:category.php

示例5: test_asort_objects_by_property

 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'));
     collatorlib::asort_objects_by_property($objects, 'publicname');
     $this->assertIdentical(array_keys($objects), array(1, 'b', 0));
     $this->assertIdentical($this->get_ordered_names($objects, 'publicname'), array('aa', 'ab', 'cc'));
     $objects = array('a' => new string_test_class('áb'), 'b' => new string_test_class('ab'), 1 => new string_test_class('aa'), 0 => new string_test_class('cc'));
     collatorlib::asort_objects_by_property($objects, 'publicname');
     $this->assertIdentical(array_keys($objects), array(1, 'b', 'a', 0), $this->error);
     $this->assertIdentical($this->get_ordered_names($objects, 'publicname'), array('aa', 'ab', 'áb', 'cc'), $this->error);
 }
開發者ID:,項目名稱:,代碼行數:11,代碼來源:

示例6: 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;
}
開發者ID:verbazend,項目名稱:AWFA,代碼行數:101,代碼來源:lib.php

示例7: 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);
    }
//.........這裏部分代碼省略.........
開發者ID:masaterutakeno,項目名稱:MoodleMobile,代碼行數:101,代碼來源:filterlib.php

示例8: array

/// Print header
$PAGE->set_title($strgroupings);
$PAGE->set_heading($course->fullname);
$PAGE->set_pagelayout('standard');
echo $OUTPUT->header();
// Add tabs
$currenttab = 'groupings';
require 'tabs.php';
echo $OUTPUT->heading($strgroupings);
$data = array();
if ($groupings = $DB->get_records('groupings', array('courseid' => $course->id), 'name')) {
    $canchangeidnumber = has_capability('moodle/course:changeidnumber', $context);
    foreach ($groupings as $gid => $grouping) {
        $groupings[$gid]->formattedname = format_string($grouping->name, true, array('context' => $context));
    }
    collatorlib::asort_objects_by_property($groupings, 'formattedname');
    foreach ($groupings as $grouping) {
        $line = array();
        $line[0] = $grouping->formattedname;
        if ($groups = groups_get_all_groups($courseid, 0, $grouping->id)) {
            $groupnames = array();
            foreach ($groups as $group) {
                $groupnames[] = format_string($group->name);
            }
            $line[1] = implode(', ', $groupnames);
        } else {
            $line[1] = get_string('none');
        }
        $line[2] = $DB->count_records('course_modules', array('course' => $course->id, 'groupingid' => $grouping->id));
        $url = new moodle_url('/group/grouping.php', array('id' => $grouping->id));
        $buttons = html_writer::link($url, $OUTPUT->pix_icon('t/edit', $stredit, 'core', array('class' => 'iconsmall')), array('title' => $stredit));
開發者ID:masaterutakeno,項目名稱:MoodleMobile,代碼行數:31,代碼來源:groupings.php


注:本文中的collatorlib::asort_objects_by_property方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。