当前位置: 首页>>代码示例>>PHP>>正文


PHP rating_manager::get_ratings方法代码示例

本文整理汇总了PHP中rating_manager::get_ratings方法的典型用法代码示例。如果您正苦于以下问题:PHP rating_manager::get_ratings方法的具体用法?PHP rating_manager::get_ratings怎么用?PHP rating_manager::get_ratings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rating_manager的用法示例。


在下文中一共展示了rating_manager::get_ratings方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: array

     $ratingoptions->context = $cm->context;
     $ratingoptions->items = array($post);
     $ratingoptions->aggregate = $forum->assessed;
     //the aggregation method
     $ratingoptions->scaleid = $forum->scale;
     $ratingoptions->userid = $user->id;
     $ratingoptions->assesstimestart = $forum->assesstimestart;
     $ratingoptions->assesstimefinish = $forum->assesstimefinish;
     if ($forum->type == 'single' or !$post->discussion) {
         $ratingoptions->returnurl = $forumurl;
     } else {
         $ratingoptions->returnurl = "{$CFG->wwwroot}/mod/forum/discuss.php?d={$discussion->id}";
     }
     $ratingoptions->assesstimestart = $forum->assesstimestart;
     $ratingoptions->assesstimefinish = $forum->assesstimefinish;
     $updatedpost = $rm->get_ratings($ratingoptions);
     //updating the array this way because we're iterating over a collection and updating them one by one
     $result->posts[$updatedpost[0]->id] = $updatedpost[0];
 }
 $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
 $forumname = format_string($forum->name, true, array('context' => $cm->context));
 $fullsubjects = array();
 if (!$isspecificcourse && !$hasparentaccess) {
     $fullsubjects[] = html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)), $courseshortname);
     $fullsubjects[] = html_writer::link($forumurl, $forumname);
 } else {
     $fullsubjects[] = html_writer::tag('span', $courseshortname);
     $fullsubjects[] = html_writer::tag('span', $forumname);
 }
 if ($forum->type != 'single') {
     $discussionname = format_string($discussion->name, true, array('context' => $cm->context));
开发者ID:esyacelga,项目名称:sisadmaca,代码行数:31,代码来源:user.php

示例2: update_rating

    /**
    * Update this rating in the database
    * @param int $rating the integer value of this rating
    * @return void
    */
    public function update_rating($rating) {
        global $DB;

        $data = new stdclass();
        $table = 'rating';

        $item = new stdclass();
        $item->id = $this->itemid;
        $items = array($item);

        $ratingoptions = new stdclass();
        $ratingoptions->context = $this->context;
        $ratingoptions->items = $items;
        $ratingoptions->aggregate = RATING_AGGREGATE_AVERAGE;//we dont actually care what aggregation method is applied
        $ratingoptions->scaleid = $this->scaleid;
        $ratingoptions->userid = $this->userid;

        $rm = new rating_manager();
        $items = $rm->get_ratings($ratingoptions);
        if( empty($items) || empty($items[0]->rating) || empty($items[0]->rating->id) ) {
            $data->contextid    = $this->context->id;
            $data->rating       = $rating;
            $data->scaleid      = $this->scaleid;
            $data->userid       = $this->userid;
            $data->itemid       = $this->itemid;

            $time = time();
            $data->timecreated = $time;
            $data->timemodified = $time;

            $DB->insert_record($table, $data);
        }
        else {
            $data->id       = $items[0]->rating->id;
            $data->rating       = $rating;

            $time = time();
            $data->timemodified = $time;

            $DB->update_record($table, $data);
        }
    }
开发者ID:nuckey,项目名称:moodle,代码行数:47,代码来源:lib.php

示例3: stdClass

 require_once $CFG->dirroot . '/rating/lib.php';
 if ($glossary->assessed != RATING_AGGREGATE_NONE) {
     $ratingoptions = new stdClass();
     $ratingoptions->context = $context;
     $ratingoptions->component = 'mod_glossary';
     $ratingoptions->ratingarea = 'entry';
     $ratingoptions->items = $allentries;
     $ratingoptions->aggregate = $glossary->assessed;
     //the aggregation method
     $ratingoptions->scaleid = $glossary->scale;
     $ratingoptions->userid = $USER->id;
     $ratingoptions->returnurl = $CFG->wwwroot . '/mod/glossary/view.php?id=' . $cm->id;
     $ratingoptions->assesstimestart = $glossary->assesstimestart;
     $ratingoptions->assesstimefinish = $glossary->assesstimefinish;
     $rm = new rating_manager();
     $allentries = $rm->get_ratings($ratingoptions);
 }
 foreach ($allentries as $entry) {
     // Setting the pivot for the current entry
     $pivot = $entry->glossarypivot;
     $upperpivot = $textlib->strtoupper($pivot);
     $pivottoshow = $textlib->strtoupper(format_string($pivot, true, $fmtoptions));
     // Reduce pivot to 1cc if necessary
     if (!$fullpivot) {
         $upperpivot = $textlib->substr($upperpivot, 0, 1);
         $pivottoshow = $textlib->substr($pivottoshow, 0, 1);
     }
     // if there's a group break
     if ($currentpivot != $upperpivot) {
         // print the group break if apply
         if ($printpivot) {
开发者ID:sebastiansanio,项目名称:tallerdeprogramacion2fiuba,代码行数:31,代码来源:view.php

示例4: array

     }
 }
 $post->subject = $fullsubject;
 $post->subjectnoformat = true;
 //add the ratings information to the post
 //Unfortunately seem to have do this individually as posts may be from different forums
 if ($forum->assessed != RATING_AGGREGATE_NONE) {
     $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
     $ratingoptions->context = $modcontext;
     $ratingoptions->items = array($post);
     $ratingoptions->aggregate = $forum->assessed;
     //the aggregation method
     $ratingoptions->scaleid = $forum->scale;
     $ratingoptions->assesstimestart = $forum->assesstimestart;
     $ratingoptions->assesstimefinish = $forum->assesstimefinish;
     $postswithratings = $rm->get_ratings($ratingoptions);
     if ($postswithratings && count($postswithratings) == 1) {
         $post = $postswithratings[0];
     }
 }
 // Identify search terms only found in HTML markup, and add a warning about them to
 // the start of the message text. However, do not do the highlighting here. forum_print_post
 // will do it for us later.
 $missing_terms = "";
 $options = new stdClass();
 $options->trusted = $post->messagetrust;
 $post->message = highlight($strippedsearch, format_text($post->message, $post->messageformat, $options, $course->id), 0, '<fgw9sdpq4>', '</fgw9sdpq4>');
 foreach ($searchterms as $searchterm) {
     if (preg_match("/{$searchterm}/i", $post->message) && !preg_match('/<fgw9sdpq4>' . $searchterm . '<\\/fgw9sdpq4>/i', $post->message)) {
         $missing_terms .= " {$searchterm}";
     }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:31,代码来源:search.php

示例5: update_rating

 /**
  * Update this rating in the database
  *
  * @param int $rating the integer value of this rating
  */
 public function update_rating($rating)
 {
     global $DB;
     $time = time();
     $data = new stdClass();
     $data->rating = $rating;
     $data->timemodified = $time;
     $item = new stdclass();
     $item->id = $this->itemid;
     $items = array($item);
     $ratingoptions = new stdClass();
     $ratingoptions->context = $this->context;
     $ratingoptions->component = $this->component;
     $ratingoptions->ratingarea = $this->ratingarea;
     $ratingoptions->items = $items;
     $ratingoptions->aggregate = RATING_AGGREGATE_AVERAGE;
     // We dont actually care what aggregation method is applied.
     $ratingoptions->scaleid = $this->scaleid;
     $ratingoptions->userid = $this->userid;
     $rm = new rating_manager();
     $items = $rm->get_ratings($ratingoptions);
     $firstitem = $items[0]->rating;
     if (empty($firstitem->id)) {
         // Insert a new rating.
         $data->contextid = $this->context->id;
         $data->component = $this->component;
         $data->ratingarea = $this->ratingarea;
         $data->rating = $rating;
         $data->scaleid = $this->scaleid;
         $data->userid = $this->userid;
         $data->itemid = $this->itemid;
         $data->timecreated = $time;
         $data->timemodified = $time;
         $DB->insert_record('rating', $data);
     } else {
         // Update the rating.
         $data->id = $firstitem->id;
         $DB->update_record('rating', $data);
     }
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:45,代码来源:lib.php

示例6: get_root_post

 /**
  * Obtains the root post of the discussion. This actually requests all
  * posts from the database; the first is returned, but others are
  * accessible from methods in the first.
  * If available, cached information is used unless
  * you set $usecache to false. The cache is stored within the discussion
  * object so will not persist beyond a request unless you make the
  * discussion object persist too.
  * @param bool $usecache True to use cache if available, false to
  *    request fresh data
  * @param int $userid User ID to get user-specific data (initially, post
  *   flags) for; 0 = current
  * @return mod_forumng_post Post object
  */
 public function get_root_post($usecache = true, $userid = 0)
 {
     global $CFG, $USER;
     require_once $CFG->dirroot . '/rating/lib.php';
     if (!$usecache || !$this->rootpost) {
         if (!$usecache || !$this->postscache) {
             $read = !mod_forumng::mark_read_automatically($userid);
             // Retrieve most posts in the discussion - even deleted
             // ones. These are necessary in case somebody deletes a post that has
             // replies. They will display as 'deleted post'. We don't retrieve
             // old versions of edited posts. Posts are retrieved in created order
             // so that the order of replies remains constant when we build the tree.
             $posts = mod_forumng_post::query_posts('fp.discussionid=? AND fp.oldversion=0', array($this->discussionfields->id), 'fp.created', $this->forum->has_ratings(), true, false, $userid, false, false, '', '', $read);
             // Load standard ratings.
             if ($this->get_forum()->get_enableratings() == mod_forumng::FORUMNG_STANDARD_RATING) {
                 // If grading is 'No grading' or 'Teacher grades students'.
                 if ($this->get_forum()->get_grading() == mod_forumng::GRADING_NONE || $this->get_forum()->get_grading() == mod_forumng::GRADING_MANUAL) {
                     // Set the aggregation method.
                     if ($this->get_forum()->get_rating_scale() > 0) {
                         $aggregate = RATING_AGGREGATE_AVERAGE;
                     } else {
                         $aggregate = RATING_AGGREGATE_COUNT;
                     }
                 } else {
                     $aggregate = $this->get_forum()->get_grading();
                 }
                 $ratingoptions = new stdClass();
                 $ratingoptions->context = $this->get_forum()->get_context();
                 $ratingoptions->component = 'mod_forumng';
                 $ratingoptions->ratingarea = 'post';
                 $ratingoptions->items = $posts;
                 $ratingoptions->aggregate = $aggregate;
                 $ratingoptions->scaleid = $this->get_forum()->get_rating_scale();
                 $ratingoptions->userid = $USER->id;
                 $ratingoptions->assesstimestart = $this->forum->get_ratingfrom();
                 $ratingoptions->assesstimefinish = $this->forum->get_ratinguntil();
                 $ratingoptions->returnurl = $this->get_moodle_url();
                 $rm = new rating_manager();
                 $posts = $rm->get_ratings($ratingoptions);
             }
             $this->postscache = serialize($posts);
         } else {
             $posts = unserialize($this->postscache);
         }
         // Add numbers to posts
         $i = 1;
         foreach ($posts as $post) {
             $post->number = $i++;
         }
         // Obtain post relationships
         $children = array();
         foreach ($posts as $id => $fields) {
             if (!array_key_exists($fields->parentpostid, $children)) {
                 $children[$fields->parentpostid] = array();
             }
             $children[$fields->parentpostid][] = $id;
         }
         // Recursively build posts
         $this->rootpost = $this->build_posts($posts, $children, $this->discussionfields->postid, null);
         // Update the 'next/previous' unread lists stored in posts
         if ($this->get_unread_data_user_id() != -1) {
             $linear = array();
             $this->rootpost->build_linear_children($linear);
             $nextunread = array();
             $dump = '';
             foreach ($linear as $index => $post) {
                 $nextunread[$index] = null;
                 if ($post->is_unread() && (!$post->get_deleted() || $post->can_undelete($dump))) {
                     for ($j = $index - 1; $j >= 0; $j--) {
                         if ($nextunread[$j]) {
                             break;
                         }
                         $nextunread[$j] = $post;
                     }
                 }
             }
             $previous = null;
             foreach ($linear as $index => $post) {
                 $post->set_unread_list($nextunread[$index], $previous);
                 if ($post->is_unread() && (!$post->get_deleted() || $post->can_undelete($dump))) {
                     $previous = $post;
                 }
             }
             // Update cached version to include this data
             if ($this->incache) {
                 $this->cache();
//.........这里部分代码省略.........
开发者ID:ULCC-QMUL,项目名称:moodle-mod_forumng,代码行数:101,代码来源:mod_forumng_discussion.php

示例7: pcast_display_episode_ratings

/**
 * Displays the ratingsfor a specific episode
 * @global stdClass $CFG
 * @global stdClass $USER
 * @global stdClass $DB
 * @global stdClass $OUTPUT
 * @param object $episode
 * @param object $cm
 * @param object $course
 */
function pcast_display_episode_ratings($episode, $cm, $course)
{
    global $CFG, $USER, $DB, $OUTPUT;
    $sql = pcast_get_episode_sql();
    $sql .= " WHERE p.id = ?";
    $episodes = $DB->get_records_sql($sql, array('id' => $episode->id));
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    // load ratings
    require_once $CFG->dirroot . '/rating/lib.php';
    if ($episode->assessed != RATING_AGGREGATE_NONE) {
        $ratingoptions = new stdClass();
        // $ratingoptions->plugintype = 'mod';
        // $ratingoptions->pluginname = 'pcast';
        $ratingoptions->component = 'mod_pcast';
        $ratingoptions->context = $context;
        $ratingoptions->items = $episodes;
        $ratingoptions->aggregate = $episode->assessed;
        //the aggregation method
        $ratingoptions->scaleid = $episode->scale;
        $ratingoptions->userid = $USER->id;
        $ratingoptions->returnurl = new moodle_url('/mod/pcast/showepisode.php', array('eid' => $episode->id, 'mode' => PCAST_EPISODE_COMMENT_AND_RATE));
        $ratingoptions->assesstimestart = $episode->assesstimestart;
        $ratingoptions->assesstimefinish = $episode->assesstimefinish;
        $ratingoptions->ratingarea = 'episode';
        $rm = new rating_manager();
        $allepisodes = $rm->get_ratings($ratingoptions);
    }
    foreach ($allepisodes as $thisepisode) {
        if (!empty($thisepisode->rating)) {
            echo html_writer::tag('div', $OUTPUT->render($thisepisode->rating), array('class' => 'pcast-episode-rating'));
        }
    }
}
开发者ID:rtsfc,项目名称:moodle-mod_pcast,代码行数:43,代码来源:locallib.php

示例8: get_from_id

 /**
  * Creates a forum post object, forum object, and all related data from a
  * single forum post ID. Intended when entering a page which uses post ID
  * as a parameter.
  * @param int $id ID of forum post
  * @param int $cloneid If this is in a shared forum, must be the id of the
  *   clone forum currently in use, or CLONE_DIRECT; otherwise must be 0
  * @param bool $wholediscussion If true, retrieves entire discussion
  *   instead of just this single post
  * @param bool $usecache True to use cache when retrieving the discussion
  * @param int $userid User ID to get post on behalf of (controls flag data
  *   retrieved)
  * @return mod_forumng_post Post object
  */
 public static function get_from_id($id, $cloneid, $wholediscussion = false, $usecache = false, $userid = 0)
 {
     global $CFG, $USER;
     require_once $CFG->dirroot . '/rating/lib.php';
     if ($wholediscussion) {
         $discussion = mod_forumng_discussion::get_from_post_id($id, $cloneid, $usecache, $usecache);
         $root = $discussion->get_root_post();
         return $root->find_child($id);
     } else {
         // Get post data (including extra data such as ratings and flags)
         $records = self::query_posts('fp.id = ?', array($id), 'fp.id', true, true, false, $userid);
         if (count($records) != 1) {
             throw new coding_exception("Invalid post ID {$id}");
         }
         $postfields = reset($records);
         $discussion = mod_forumng_discussion::get_from_id($postfields->discussionid, $cloneid);
         // Load standard ratings.
         $forum = $discussion->get_forum();
         if ($forum->get_enableratings() == mod_forumng::FORUMNG_STANDARD_RATING) {
             // If grading is 'No grading' or 'Teacher grades students'.
             if ($forum->get_grading() == mod_forumng::GRADING_NONE || $forum->get_grading() == mod_forumng::GRADING_MANUAL) {
                 // Set the aggregation method.
                 if ($forum->get_rating_scale() > 0) {
                     $aggregate = RATING_AGGREGATE_AVERAGE;
                 } else {
                     $aggregate = RATING_AGGREGATE_COUNT;
                 }
             } else {
                 $aggregate = $forum->get_grading();
             }
             $ratingoptions = new stdClass();
             $ratingoptions->context = $forum->get_context(true);
             $ratingoptions->component = 'mod_forumng';
             $ratingoptions->ratingarea = 'post';
             $ratingoptions->items = array('post' => $postfields);
             $ratingoptions->aggregate = $aggregate;
             $ratingoptions->scaleid = $forum->get_rating_scale();
             $ratingoptions->userid = $USER->id;
             $ratingoptions->id = $id;
             $ratingoptions->assesstimestart = $forum->get_ratingfrom();
             $ratingoptions->assesstimefinish = $forum->get_ratinguntil();
             $ratingoptions->returnurl = $discussion->get_moodle_url();
             $rm = new rating_manager();
             $postwithratings = $rm->get_ratings($ratingoptions);
             $postfields = $postwithratings['post'];
             // Update 'post' object.
         }
         $newpost = new mod_forumng_post($discussion, $postfields);
         return $newpost;
     }
 }
开发者ID:ULCC-QMUL,项目名称:moodle-mod_forumng,代码行数:65,代码来源:mod_forumng_post.php

示例9: get_rated_posts_by_user

 /**
  * Returns all posts in this forum by the given user within the given group.
  * @param object $forum
  * @param int $userid
  * @param int $groupid
  * @param int $ratedstart
  * @param int $ratedend
  * @param string $order Sort order; the default is fp.id - note this is preferable
  *   to fp.timecreated because it works correctly if there are two posts in
  *   the same second
  * @param bool $hasrating if true only returns posts which ahve been rated
  * @return array Array of mod_forumng_post objects
  */
 public function get_rated_posts_by_user($forum, $userid, $groupid, $order = 'fp.id', $ratedstart = null, $ratedend = null, $start = null, $end = null)
 {
     global $CFG, $USER;
     if ($forum->get_enableratings() != mod_forumng::FORUMNG_STANDARD_RATING) {
         return array();
     }
     $where = 'fd.forumngid = ? AND fp.userid <> ? AND fp.oldversion = 0 AND fp.deleted = 0';
     $whereparams = array($this->get_id(), $userid);
     if ($groupid != self::NO_GROUPS && $groupid != self::ALL_GROUPS) {
         $where .= ' AND (fd.groupid = ? OR fd.groupid IS NULL)';
         $whereparams[] = $groupid;
     }
     if (!empty($start)) {
         $where .= ' AND fp.created >= ?';
         $whereparams[] = $start;
     }
     if (!empty($end)) {
         $where .= ' AND fp.created <= ?';
         $whereparams[] = $end;
     }
     $sqlselectstring = 'SELECT r.itemid FROM {rating} r WHERE r.itemid = fp.id AND r.ratingarea = \'post\'
             AND r.contextid = ? AND r.userid = ?';
     $extraparams = array();
     if (!empty($ratedstart)) {
         $sqlselectstring .= ' AND r.timemodified >= ?';
         $extraparams[] = $ratedstart;
     }
     if (!empty($ratedend)) {
         $sqlselectstring .= ' AND r.timemodified <= ?';
         $extraparams[] = $ratedend;
     }
     $where .= ' AND ' . self::select_exists($sqlselectstring);
     $whereparams[] = $this->get_context(true)->id;
     $whereparams[] = $userid;
     $whereparams = array_merge($whereparams, $extraparams);
     $result = array();
     $posts = mod_forumng_post::query_posts($where, $whereparams, $order, false, false, true, 0, true, true);
     // Add standard ratings if enabled.
     if ($this->get_enableratings() == mod_forumng::FORUMNG_STANDARD_RATING) {
         require_once $CFG->dirroot . '/rating/lib.php';
         // If grading is 'No grading' or 'Teacher grades students'.
         if ($this->get_grading() == mod_forumng::GRADING_NONE || $this->get_grading() == mod_forumng::GRADING_MANUAL) {
             // Set the aggregation method.
             if ($this->get_rating_scale() > 0) {
                 $aggregate = RATING_AGGREGATE_AVERAGE;
             } else {
                 $aggregate = RATING_AGGREGATE_COUNT;
             }
         } else {
             $aggregate = $this->get_grading();
         }
         $ratingoptions = new stdClass();
         $ratingoptions->context = $this->get_context(true);
         $ratingoptions->component = 'mod_forumng';
         $ratingoptions->ratingarea = 'post';
         $ratingoptions->items = $posts;
         $ratingoptions->aggregate = $aggregate;
         $ratingoptions->scaleid = $this->get_rating_scale();
         $ratingoptions->userid = $USER->id;
         $ratingoptions->assesstimestart = $this->get_ratingfrom();
         $ratingoptions->assesstimefinish = $this->get_ratinguntil();
         $rm = new rating_manager();
         $posts = $rm->get_ratings($ratingoptions);
     }
     foreach ($posts as $fields) {
         $discussionfields = mod_forumng_utils::extract_subobject($fields, 'fd_');
         $discussion = new mod_forumng_discussion($this, $discussionfields, false, -1);
         $result[$fields->id] = new mod_forumng_post($discussion, $fields);
     }
     return $result;
 }
开发者ID:ULCC-QMUL,项目名称:moodle-mod_forumng,代码行数:84,代码来源:mod_forumng.php

示例10: array

    /**
     * Test the current get_ratings method main sql
     */
    function test_get_ratings_sql() {

        // We load 3 items. Each is rated twice. For simplicity itemid == user id of the item owner
        $ctxid = SYSCONTEXTID;
        $this->load_test_data('rating',
                array('contextid', 'component', 'ratingarea', 'itemid', 'scaleid', 'rating', 'userid', 'timecreated', 'timemodified'), array(

                //user 1's items. Average == 2
                array(    $ctxid , 'mod_forum',       'post',       1 ,       10 ,       1 ,       2 ,            1 ,              1),
                array(    $ctxid , 'mod_forum',       'post',       1 ,       10 ,       3 ,       3 ,            1 ,              1),

                //user 2's items. Average == 3
                array(    $ctxid , 'mod_forum',       'post',       2 ,       10 ,       1 ,       1 ,            1 ,              1),
                array(    $ctxid , 'mod_forum',       'post',       2 ,       10 ,       5 ,       3 ,            1 ,              1),

                //user 3's items. Average == 4
                array(    $ctxid , 'mod_forum',       'post',       3 ,       10 ,       3 ,       1 ,            1 ,              1),
                array(    $ctxid , 'mod_forum',       'post',       3 ,       10 ,       5 ,       2 ,            1 ,              1)
                ));

        // a post (item) by user 1 (rated above by user 2 and 3 with average = 2)
        $user1posts = array(
                (object)array('id' => 1, 'userid' => 1, 'message' => 'hello'));
        // a post (item) by user 2 (rated above by user 1 and 3 with average = 3)
        $user2posts = array(
                (object)array('id' => 2, 'userid' => 2, 'message' => 'world'));
        // a post (item) by user 3 (rated above by user 1 and 2 with average = 4)
        $user3posts = array(
                (object)array('id' => 3, 'userid' => 3, 'message' => 'moodle'));

        // Prepare the default options
        $defaultoptions = array (
                'context'    => get_context_instance(CONTEXT_SYSTEM),
                'component'  => 'mod_forum',
                'ratingarea' => 'post',
                'scaleid'    => 10,
                'aggregate'  => RATING_AGGREGATE_AVERAGE);

        $rm = new rating_manager();

        // STEP 1: Retreive ratings using the current user

        // Get results for user 1's item (expected average 1 + 3 / 2 = 2)
        $toptions = (object)array_merge($defaultoptions, array('items' => $user1posts));
        $result = $rm->get_ratings($toptions);
        $this->assertEqual(count($result), count($user1posts));
        $this->assertEqual($result[0]->id, $user1posts[0]->id);
        $this->assertEqual($result[0]->userid, $user1posts[0]->userid);
        $this->assertEqual($result[0]->message, $user1posts[0]->message);
        $this->assertEqual($result[0]->rating->count, 2);
        $this->assertEqual($result[0]->rating->aggregate, 2);
        // Note that $result[0]->rating->rating is somewhat random
        // We didn't supply a user ID so $USER was used which will vary depending on who runs the tests

        // Get results for items of user 2 (expected average 1 + 5 / 2 = 3)
        $toptions = (object)array_merge($defaultoptions, array('items' => $user2posts));
        $result = $rm->get_ratings($toptions);
        $this->assertEqual(count($result), count($user2posts));
        $this->assertEqual($result[0]->id, $user2posts[0]->id);
        $this->assertEqual($result[0]->userid, $user2posts[0]->userid);
        $this->assertEqual($result[0]->message, $user2posts[0]->message);
        $this->assertEqual($result[0]->rating->count, 2);
        $this->assertEqual($result[0]->rating->aggregate, 3);
        // Note that $result[0]->rating->rating is somewhat random
        // We didn't supply a user ID so $USER was used which will vary depending on who runs the tests

        // Get results for items of user 3 (expected average 3 + 5 / 2 = 4)
        $toptions = (object)array_merge($defaultoptions, array('items' => $user3posts));
        $result = $rm->get_ratings($toptions);
        $this->assertEqual(count($result), count($user3posts));
        $this->assertEqual($result[0]->id, $user3posts[0]->id);
        $this->assertEqual($result[0]->userid, $user3posts[0]->userid);
        $this->assertEqual($result[0]->message, $user3posts[0]->message);
        $this->assertEqual($result[0]->rating->count, 2);
        $this->assertEqual($result[0]->rating->aggregate, 4);
        // Note that $result[0]->rating->rating is somewhat random
        // We didn't supply a user ID so $USER was used which will vary depending on who runs the tests

        // Get results for items of user 1 & 2 together (expected averages are 2 and 3, as tested above)
        $posts = array_merge($user1posts, $user2posts);
        $toptions = (object)array_merge($defaultoptions, array('items' => $posts));
        $result = $rm->get_ratings($toptions);
        $this->assertEqual(count($result), count($posts));
        $this->assertEqual($result[0]->id, $posts[0]->id);
        $this->assertEqual($result[0]->userid, $posts[0]->userid);
        $this->assertEqual($result[0]->message, $posts[0]->message);
        $this->assertEqual($result[0]->rating->count, 2);
        $this->assertEqual($result[0]->rating->aggregate, 2);
        // Note that $result[0]->rating->rating is somewhat random
        // We didn't supply a user ID so $USER was used which will vary depending on who runs the tests

        $this->assertEqual($result[1]->id, $posts[1]->id);
        $this->assertEqual($result[1]->userid, $posts[1]->userid);
        $this->assertEqual($result[1]->message, $posts[1]->message);
        $this->assertEqual($result[1]->rating->count, 2);
        $this->assertEqual($result[1]->rating->aggregate, 3);
        // Note that $result[0]->rating->rating is somewhat random
//.........这里部分代码省略.........
开发者ID:nigeldaley,项目名称:moodle,代码行数:101,代码来源:testrating.php

示例11: hsuforum_print_discussion

/**
 * Prints a forum discussion
 *
 * @uses CONTEXT_MODULE
 * @param stdClass $course
 * @param stdClass $cm
 * @param stdClass $forum
 * @param stdClass $discussion
 * @param stdClass $post
 * @param mixed $canreply
 * @param bool $canrate
 */
function hsuforum_print_discussion($course, $cm, $forum, $discussion, $post, $canreply = NULL, $canrate = false)
{
    global $USER, $CFG, $OUTPUT, $PAGE;
    require_once $CFG->dirroot . '/rating/lib.php';
    $modcontext = context_module::instance($cm->id);
    if ($canreply === NULL) {
        $reply = hsuforum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext);
    } else {
        $reply = $canreply;
    }
    $posters = array();
    $posts = hsuforum_get_all_discussion_posts($discussion->id);
    $post = $posts[$post->id];
    foreach ($posts as $pid => $p) {
        $posters[$p->userid] = $p->userid;
    }
    //load ratings
    if ($forum->assessed != RATING_AGGREGATE_NONE) {
        $ratingoptions = new stdClass();
        $ratingoptions->context = $modcontext;
        $ratingoptions->component = 'mod_hsuforum';
        $ratingoptions->ratingarea = 'post';
        $ratingoptions->items = $posts;
        $ratingoptions->aggregate = $forum->assessed;
        //the aggregation method
        $ratingoptions->scaleid = $forum->scale;
        $ratingoptions->userid = $USER->id;
        if ($forum->type == 'single' or !$discussion->id) {
            $ratingoptions->returnurl = "{$CFG->wwwroot}/mod/hsuforum/view.php?id={$cm->id}";
        } else {
            $ratingoptions->returnurl = "{$CFG->wwwroot}/mod/hsuforum/discuss.php?d={$discussion->id}";
        }
        $ratingoptions->assesstimestart = $forum->assesstimestart;
        $ratingoptions->assesstimefinish = $forum->assesstimefinish;
        $rm = new rating_manager();
        $posts = $rm->get_ratings($ratingoptions);
    }
    $post->forum = $forum->id;
    // Add the forum id to the post object, later used for rendering
    $post->forumtype = $forum->type;
    $post->subject = format_string($post->subject);
    $postread = !empty($post->postread);
    echo $OUTPUT->box_start("mod-hsuforum-posts-container article");
    $renderer = $PAGE->get_renderer('mod_hsuforum');
    echo $renderer->discussion_thread($cm, $discussion, $post, $posts, $reply);
    echo $OUTPUT->box_end();
    // End mod-hsuforum-posts-container
    return;
}
开发者ID:cdsmith-umn,项目名称:moodle-mod_hsuforum,代码行数:61,代码来源:lib.php

示例12: stdClass

        if (function_exists($functionname)) {
            $functionname($modinstance, $rateduserid);
        }
    }
}
//object to return to client as json
$result = new stdClass();
$result->success = true;
//need to retrieve the updated item to get its new aggregate value
$item = new stdclass();
$item->id = $itemid;
$items = array($item);
//most of $ratingoptions variables were previously set
$ratingoptions->items = $items;
$ratingoptions->aggregate = $aggregationmethod;
$items = $rm->get_ratings($ratingoptions);
//for custom scales return text not the value
//this scales weirdness will go away when scales are refactored
$scalearray = null;
$aggregatetoreturn = round($items[0]->rating->aggregate, 1);
// Output a dash if aggregation method == COUNT as the count is output next to the aggregate anyway
if ($items[0]->rating->settings->aggregationmethod == RATING_AGGREGATE_COUNT or $items[0]->rating->count == 0) {
    $aggregatetoreturn = ' - ';
} else {
    if ($items[0]->rating->settings->scale->id < 0) {
        //if its non-numeric scale
        //dont use the scale item if the aggregation method is sum as adding items from a custom scale makes no sense
        if ($items[0]->rating->settings->aggregationmethod != RATING_AGGREGATE_SUM) {
            $scalerecord = $DB->get_record('scale', array('id' => -$items[0]->rating->settings->scale->id));
            if ($scalerecord) {
                $scalearray = explode(',', $scalerecord->scale);
开发者ID:esyacelga,项目名称:sisadmaca,代码行数:31,代码来源:rate_ajax.php

示例13: oublog_get_posts


//.........这里部分代码省略.........
        } else {
            $context = context_module::instance($cm->id);
            if (has_capability('mod/oublog:view', $context)) {
                $sqlwhere .= " AND (p.visibility >= " . OUBLOG_VISIBILITY_COURSEUSER . " )";
            } else {
                $sqlwhere .= " AND p.visibility > " . OUBLOG_VISIBILITY_COURSEUSER;
            }
        }
    }
    $usernamefields = get_all_user_name_fields(true, 'u');
    $delusernamefields = get_all_user_name_fields(true, 'ud', null, 'del');
    $editusernamefields = get_all_user_name_fields(true, 'ue', null, 'ed');
    // Get posts. The post has the field timeposted not timecreated,
    // which is tested in rating::user_can_rate().
    $fieldlist = "p.*, p.timeposted AS timecreated,  bi.oublogid, {$usernamefields},\n                  bi.userid, u.idnumber, u.picture, u.imagealt, u.email, u.username,\n                {$delusernamefields},\n                {$editusernamefields}";
    $from = "FROM {oublog_posts} p\n                INNER JOIN {oublog_instances} bi ON p.oubloginstancesid = bi.id\n                INNER JOIN {user} u ON bi.userid = u.id\n                LEFT JOIN {user} ud ON p.deletedby = ud.id\n                LEFT JOIN {user} ue ON p.lasteditedby = ue.id\n                {$sqljoin}";
    $sql = "SELECT {$fieldlist}\n            {$from}\n            WHERE  {$sqlwhere}\n            ORDER BY p.timeposted DESC\n            ";
    $countsql = "SELECT count(p.id) {$from} WHERE {$sqlwhere}";
    $rs = $DB->get_recordset_sql($sql, $params, $offset, OUBLOG_POSTS_PER_PAGE);
    // Get paging info
    $recordcnt = $DB->count_records_sql($countsql, $params);
    if (!$rs->valid()) {
        return array(false, $recordcnt);
    }
    $cnt = 0;
    $posts = array();
    $postids = array();
    foreach ($rs as $post) {
        if ($cnt > OUBLOG_POSTS_PER_PAGE) {
            break;
        }
        if (oublog_can_view_post($post, $USER, $context, $oublog->global)) {
            if ($oublog->maxvisibility < $post->visibility) {
                $post->visibility = $oublog->maxvisibility;
            }
            if ($oublog->allowcomments == OUBLOG_COMMENTS_PREVENT) {
                $post->allowcomments = OUBLOG_COMMENTS_PREVENT;
            }
            $posts[$post->id] = $post;
            $postids[] = (int) $post->id;
            $cnt++;
        }
    }
    $rs->close();
    if (empty($posts)) {
        return array(true, $recordcnt);
    }
    // Get tags for all posts on page
    $sql = "SELECT t.*, ti.postid\n            FROM {oublog_taginstances} ti\n            INNER JOIN {oublog_tags} t ON ti.tagid = t.id\n            WHERE ti.postid IN (" . implode(",", $postids) . ") ";
    $rs = $DB->get_recordset_sql($sql);
    foreach ($rs as $tag) {
        $posts[$tag->postid]->tags[$tag->id] = $tag->tag;
    }
    // Load ratings.
    require_once $CFG->dirroot . '/rating/lib.php';
    if ($oublog->assessed != RATING_AGGREGATE_NONE) {
        $ratingoptions = new stdClass();
        $ratingoptions->context = $context;
        $ratingoptions->component = 'mod_oublog';
        $ratingoptions->ratingarea = 'post';
        $ratingoptions->items = $posts;
        $ratingoptions->aggregate = $oublog->assessed;
        // The aggregation method.
        $ratingoptions->scaleid = $oublog->scale;
        $ratingoptions->userid = $USER->id;
        $ratingoptions->assesstimestart = $oublog->assesstimestart;
        $ratingoptions->assesstimefinish = $oublog->assesstimefinish;
        $rm = new rating_manager();
        $posts = $rm->get_ratings($ratingoptions);
    }
    $rs->close();
    // Get comments for post on the page
    $sql = "SELECT c.id, c.postid, c.timeposted, c.authorname, c.authorip, c.timeapproved, c.userid, {$usernamefields}, u.picture, u.imagealt, u.email, u.idnumber\n            FROM {oublog_comments} c\n            LEFT JOIN {user} u ON c.userid = u.id\n            WHERE c.postid IN (" . implode(",", $postids) . ") AND c.deletedby IS NULL\n            ORDER BY c.timeposted ASC ";
    $rs = $DB->get_recordset_sql($sql);
    foreach ($rs as $comment) {
        $posts[$comment->postid]->comments[$comment->id] = $comment;
    }
    $rs->close();
    // Get count of comments waiting approval for posts on the page...
    if ($oublog->allowcomments >= OUBLOG_COMMENTS_ALLOWPUBLIC) {
        // Make list of all posts that allow public comments
        $publicallowed = array();
        foreach ($posts as $post) {
            if ($post->allowcomments >= OUBLOG_COMMENTS_ALLOWPUBLIC) {
                $publicallowed[] = (int) $post->id;
            }
        }
        // Only run a db query if there are some posts that allow public
        // comments (so, no performance degradation if feature is not used)
        if (count($publicallowed) > 0) {
            $sql = "SELECT cm.postid, COUNT(1) AS numpending\n                    FROM {oublog_comments_moderated} cm\n                    WHERE cm.postid IN (" . implode(",", $publicallowed) . ")\n                    AND cm.approval = 0\n                    GROUP BY cm.postid";
            $rs = $DB->get_recordset_sql($sql);
            foreach ($rs as $postinfo) {
                $posts[$postinfo->postid]->pendingcomments = $postinfo->numpending;
            }
            $rs->close();
        }
    }
    return array($posts, $recordcnt);
}
开发者ID:eugeneventer,项目名称:moodle-mod_oublog,代码行数:101,代码来源:locallib.php

示例14: stdClass

     require_once $CFG->dirroot . '/rating/lib.php';
     if ($data->assessed != RATING_AGGREGATE_NONE) {
         $ratingoptions = new stdClass();
         $ratingoptions->context = $context;
         $ratingoptions->component = 'mod_data';
         $ratingoptions->ratingarea = 'entry';
         $ratingoptions->items = $records;
         $ratingoptions->aggregate = $data->assessed;
         //the aggregation method
         $ratingoptions->scaleid = $data->scale;
         $ratingoptions->userid = $USER->id;
         $ratingoptions->returnurl = $CFG->wwwroot . '/mod/data/' . $baseurl;
         $ratingoptions->assesstimestart = $data->assesstimestart;
         $ratingoptions->assesstimefinish = $data->assesstimefinish;
         $rm = new rating_manager();
         $records = $rm->get_ratings($ratingoptions);
     }
     data_print_template('singletemplate', $records, $data, $search, $page);
     echo $OUTPUT->paging_bar($totalcount, $page, $nowperpage, $baseurl);
 } else {
     // List template
     $baseurl = 'view.php?d=' . $data->id . '&amp;';
     //send the advanced flag through the URL so it is remembered while paging.
     $baseurl .= 'advanced=' . $advanced . '&amp;';
     if (!empty($search)) {
         $baseurl .= 'filter=1&amp;';
     }
     //pass variable to allow determining whether or not we are paging through results.
     $baseurl .= 'paging=' . $paging . '&amp;';
     echo $OUTPUT->paging_bar($totalcount, $page, $nowperpage, $baseurl);
     if (empty($data->listtemplate)) {
开发者ID:hatone,项目名称:moodle,代码行数:31,代码来源:view.php

示例15: display_homepage


//.........这里部分代码省略.........
         $courseids = array();
         //all result courses
         $courseimagenumbers = array();
         //number of screenshots of all courses (must be exact same order than $courseids)
         foreach ($courses as $course) {
             $courseids[] = $course->id;
             $courseimagenumbers[] = $course->screenshots;
         }
         $PAGE->requires->yui_module('moodle-block_community-imagegallery', 'M.blocks_community.init_imagegallery', array(array('imageids' => $courseids, 'imagenumbers' => $courseimagenumbers, 'huburl' => $CFG->wwwroot)));
         //get courses content
         foreach ($courses as $course) {
             $contents = $this->get_course_contents($course->id);
             if (!empty($contents)) {
                 foreach ($contents as $content) {
                     $course->contents[] = $content;
                 }
             }
         }
         //load ratings and comments
         require_once $CFG->dirroot . '/rating/lib.php';
         $ratingoptions = new stdclass();
         $ratingoptions->context = context_course::instance(SITEID);
         //front page course
         $ratingoptions->items = $courses;
         $ratingoptions->aggregate = RATING_AGGREGATE_COUNT;
         //the aggregation method
         $ratingoptions->scaleid = 0 - get_config('local_hub', 'courseratingscaleid');
         //rating API is expecting "minus scaleid"
         $ratingoptions->userid = $USER->id;
         $ratingoptions->returnurl = $CFG->wwwroot . "/local/hub/index.php";
         $ratingoptions->component = 'local_hub';
         $ratingoptions->ratingarea = 'featured';
         $rm = new rating_manager();
         $courses = $rm->get_ratings($ratingoptions);
         //this function return $ratingoptions->items with information about the ratings
         foreach ($courses as $course) {
             $course->rating->settings->permissions->viewany = 1;
         }
         require_once $CFG->dirroot . '/comment/lib.php';
         foreach ($courses as $course) {
             $commentoptions = new stdClass();
             $commentoptions->context = context_course::instance(SITEID);
             $commentoptions->area = 'local_hub';
             $commentoptions->itemid = $course->id;
             $commentoptions->showcount = true;
             $commentoptions->component = 'local_hub';
             $course->comment = new comment($commentoptions);
             $course->comment->set_view_permission(true);
         }
     }
     //create rss feed link
     $enablerssfeeds = get_config('local_hub', 'enablerssfeeds');
     if (!empty($enablerssfeeds)) {
         require $CFG->libdir . '/rsslib.php';
         $audience = key_exists('audience', $options) ? $options['audience'] : 'all';
         $educationallevel = key_exists('educationallevel', $options) ? $options['educationallevel'] : 'all';
         if (key_exists('downloadable', $options)) {
             $downloadable = empty($options['downloadable']) ? 0 : 1;
         } else {
             $downloadable = 'all';
         }
         $subject = key_exists('subject', $options) ? $options['subject'] : 'all';
         $licence = key_exists('licence', $options) ? $options['licence'] : 'all';
         $language = key_exists('language', $options) ? $options['language'] : 'all';
         $audience = key_exists('audience', $options) ? $options['audience'] : 'all';
         $orderby = key_exists('orderby', $options) ? $options['orderby'] : 'newest';
开发者ID:k-holland,项目名称:moodle-local_hub,代码行数:67,代码来源:lib.php


注:本文中的rating_manager::get_ratings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。