/**
  * 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;
     }
 }
示例#2
0
/**
 * Returns an array of recipients for OU alerts
 * @param char $type
 * @param int $id
 * @returns array
 */
function forumng_oualerts_additional_recipients($type, $id)
{
    global $CFG;
    require_once $CFG->dirroot . '/mod/forumng/mod_forumng.php';
    require_once $CFG->dirroot . '/mod/forumng/mod_forumng_discussion.php';
    $recipents = array();
    if ($type == 'post') {
        $discussion = mod_forumng_discussion::get_from_post_id($id, mod_forumng::CLONE_DIRECT);
        $forum = $discussion->get_forum();
        $recipients = $forum->get_reportingemails();
    }
    return $recipients;
}
 /**
  * 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)
 {
     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);
         $newpost = new mod_forumng_post($discussion, $postfields);
         return $newpost;
     }
 }