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


PHP rating_manager::get_all_ratings_for_item方法代碼示例

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


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

示例1: forum_get_ratings

/**
 * Returns a list of ratings for a particular post - sorted.
 *
 * TODO: Check if this function is actually used anywhere.
 * Up until the fix for MDL-27471 this function wasn't even returning.
 *
 * @param stdClass $context
 * @param int $postid
 * @param string $sort
 * @return array Array of ratings or false
 */
function forum_get_ratings($context, $postid, $sort = "u.firstname ASC") {
    $options = new stdClass;
    $options->context = $context;
    $options->component = 'mod_forum';
    $options->ratingarea = 'post';
    $options->itemid = $postid;
    $options->sort = "ORDER BY $sort";

    $rm = new rating_manager();
    return $rm->get_all_ratings_for_item($options);
}
開發者ID:Jtgadbois,項目名稱:Pedadida,代碼行數:22,代碼來源:lib.php

示例2: forum_get_ratings

/**
 * Returns a list of ratings for a particular post - sorted.
 *
 * @global object
 * @global object
 * @param int $postid
 * @param string $sort
 * @return array Array of ratings or false
 */
function forum_get_ratings($context, $postid, $sort="u.firstname ASC") {
    global $PAGE;

    $options = new stdclass();
    $options->context = $PAGE->context;
    $options->itemid = $postid;
    $options->sort = "ORDER BY $sort";

    $rm = new rating_manager();
    $rm->get_all_ratings_for_item($options);
}
開發者ID:nfreear,項目名稱:moodle,代碼行數:20,代碼來源:lib.php

示例3: quora_get_ratings

/**
 * Returns a list of ratings for a particular post - sorted.
 *
 * @param stdClass $context
 * @param int $postid
 * @param string $sort
 * @return array Array of ratings or false
 * @deprecated since Moodle 2.0 MDL-21657 - please do not use this function any more.
 */
function quora_get_ratings($context, $postid, $sort = "u.firstname ASC")
{
    debugging('quora_get_ratings() is deprecated.', DEBUG_DEVELOPER);
    $options = new stdClass();
    $options->context = $context;
    $options->component = 'mod_quora';
    $options->ratingarea = 'post';
    $options->itemid = $postid;
    $options->sort = "ORDER BY {$sort}";
    $rm = new rating_manager();
    return $rm->get_all_ratings_for_item($options);
}
開發者ID:Gavinthisisit,項目名稱:Moodle,代碼行數:21,代碼來源:deprecatedlib.php

示例4: get_item_ratings

 /**
  * Retrieve a list of ratings for a given item (forum post etc)
  *
  * @param string $contextlevel course, module, user...
  * @param int $instanceid the instance if for the context element
  * @param string $component the name of the component
  * @param string $ratingarea rating area
  * @param int $itemid the item id
  * @param int $scaleid the scale id
  * @param string $sort sql order (firstname, rating or timemodified)
  * @return array Result and possible warnings
  * @throws moodle_exception
  * @since Moodle 2.9
  */
 public static function get_item_ratings($contextlevel, $instanceid, $component, $ratingarea, $itemid, $scaleid, $sort)
 {
     global $USER, $PAGE;
     $warnings = array();
     $arrayparams = array('contextlevel' => $contextlevel, 'instanceid' => $instanceid, 'component' => $component, 'ratingarea' => $ratingarea, 'itemid' => $itemid, 'scaleid' => $scaleid, 'sort' => $sort);
     // Validate and normalize parameters.
     $params = self::validate_parameters(self::get_item_ratings_parameters(), $arrayparams);
     $context = self::get_context_from_params($params);
     self::validate_context($context);
     // Minimal capability required.
     $callbackparams = array('contextid' => $context->id, 'component' => $component, 'ratingarea' => $ratingarea, 'itemid' => $itemid, 'scaleid' => $scaleid);
     if (!has_capability('moodle/rating:view', $context) || !component_callback($component, 'rating_can_see_item_ratings', array($callbackparams), true)) {
         throw new moodle_exception('noviewrate', 'rating');
     }
     list($context, $course, $cm) = get_context_info_array($context->id);
     // Can we see all ratings?
     $canviewallratings = has_capability('moodle/rating:viewall', $context);
     // Create the Sql sort order string.
     switch ($params['sort']) {
         case 'firstname':
             $sqlsort = "u.firstname ASC";
             break;
         case 'rating':
             $sqlsort = "r.rating ASC";
             break;
         default:
             $sqlsort = "r.timemodified ASC";
     }
     $ratingoptions = new stdClass();
     $ratingoptions->context = $context;
     $ratingoptions->component = $params['component'];
     $ratingoptions->ratingarea = $params['ratingarea'];
     $ratingoptions->itemid = $params['itemid'];
     $ratingoptions->sort = $sqlsort;
     $rm = new rating_manager();
     $ratings = $rm->get_all_ratings_for_item($ratingoptions);
     $scalemenu = make_grades_menu($params['scaleid']);
     // If the scale was changed after ratings were submitted some ratings may have a value above the current maximum.
     // We can't just do count($scalemenu) - 1 as custom scales start at index 1, not 0.
     $maxrating = max(array_keys($scalemenu));
     $results = array();
     foreach ($ratings as $rating) {
         if ($canviewallratings || $USER->id == $rating->userid) {
             if ($rating->rating > $maxrating) {
                 $rating->rating = $maxrating;
             }
             // The rating object has all the required fields for generating the picture url.
             $userpicture = new user_picture($rating);
             $userpicture->size = 1;
             // Size f1.
             $profileimageurl = $userpicture->get_url($PAGE)->out(false);
             $result = array();
             $result['id'] = $rating->id;
             $result['userid'] = $rating->userid;
             $result['userpictureurl'] = $profileimageurl;
             $result['userfullname'] = fullname($rating);
             $result['rating'] = $scalemenu[$rating->rating];
             $result['timemodified'] = $rating->timemodified;
             $results[] = $result;
         }
     }
     return array('ratings' => $results, 'warnings' => $warnings);
 }
開發者ID:janeklb,項目名稱:moodle,代碼行數:77,代碼來源:external.php

示例5: get_item_ratings

 /**
  * Retrieve a list of ratings for a given item (forum post etc)
  *
  * @param string $contextlevel course, module, user...
  * @param int $instanceid the instance if for the context element
  * @param string $component the name of the component
  * @param string $ratingarea rating area
  * @param int $itemid the item id
  * @param int $scaleid the scale id
  * @param string $sort sql order (firstname, rating or timemodified)
  * @return array Result and possible warnings
  * @throws moodle_exception
  * @since Moodle 2.9
  */
 public static function get_item_ratings($contextlevel, $instanceid, $component, $ratingarea, $itemid, $scaleid, $sort)
 {
     global $USER;
     $warnings = array();
     $arrayparams = array('contextlevel' => $contextlevel, 'instanceid' => $instanceid, 'component' => $component, 'ratingarea' => $ratingarea, 'itemid' => $itemid, 'scaleid' => $scaleid, 'sort' => $sort);
     // Validate and normalize parameters.
     $params = self::validate_parameters(self::get_item_ratings_parameters(), $arrayparams);
     $context = self::get_context_from_params($params);
     self::validate_context($context);
     // Minimal capability required.
     if (!has_capability('moodle/rating:view', $context)) {
         throw new moodle_exception('noviewrate', 'rating');
     }
     list($context, $course, $cm) = get_context_info_array($context->id);
     // Can we see all ratings?
     $canviewallratings = has_capability('moodle/rating:viewall', $context);
     // Create the Sql sort order string.
     switch ($params['sort']) {
         case 'firstname':
             $sqlsort = "u.firstname ASC";
             break;
         case 'rating':
             $sqlsort = "r.rating ASC";
             break;
         default:
             $sqlsort = "r.timemodified ASC";
     }
     $ratingoptions = new stdClass();
     $ratingoptions->context = $context;
     $ratingoptions->component = $params['component'];
     $ratingoptions->ratingarea = $params['ratingarea'];
     $ratingoptions->itemid = $params['itemid'];
     $ratingoptions->sort = $sqlsort;
     $rm = new rating_manager();
     $ratings = $rm->get_all_ratings_for_item($ratingoptions);
     $scalemenu = make_grades_menu($params['scaleid']);
     // If the scale was changed after ratings were submitted some ratings may have a value above the current maximum.
     // We can't just do count($scalemenu) - 1 as custom scales start at index 1, not 0.
     $maxrating = max(array_keys($scalemenu));
     $results = array();
     foreach ($ratings as $rating) {
         if ($canviewallratings || $USER->id == $rating->userid) {
             if ($rating->rating > $maxrating) {
                 $rating->rating = $maxrating;
             }
             $profileimageurl = '';
             // We can have ratings from deleted users. In this case, those users don't have a valid context.
             $usercontext = context_user::instance($rating->userid, IGNORE_MISSING);
             if ($usercontext) {
                 $profileimageurl = moodle_url::make_webservice_pluginfile_url($usercontext->id, 'user', 'icon', null, '/', 'f1')->out(false);
             }
             $result = array();
             $result['id'] = $rating->id;
             $result['userid'] = $rating->userid;
             $result['userpictureurl'] = $profileimageurl;
             $result['userfullname'] = fullname($rating);
             $result['rating'] = $scalemenu[$rating->rating];
             $result['timemodified'] = $rating->timemodified;
             $results[] = $result;
         }
     }
     return array('ratings' => $results, 'warnings' => $warnings);
 }
開發者ID:Keneth1212,項目名稱:moodle,代碼行數:77,代碼來源:external.php


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