/** * Returns user activity report information. * @param int $forumid forumng id * @param int $userid Moodle user id * @return object or false */ public static function get_user_activityreport($forumid, $userid) { global $CFG; $sql = 'SELECT COUNT(p.id) AS postcount, MAX(p.modified) AS lastpost FROM ' . $CFG->prefix . 'forumng_discussions d, ' . $CFG->prefix . 'forumng_posts p WHERE d.forumid = ' . $forumid . ' AND p.userid = ' . $userid . ' AND d.deleted=0 AND p.deleted=0 AND p.oldversion=0 AND p.discussionid = d.id'; try { $posts = forum_utils::get_record_sql($sql); return $posts; } catch (Exception $e) { return false; } }
/** * Obtains a search document given the ousearch parameters. * @param object $document Object containing fields from the ousearch documents table * @return mixed False if object can't be found, otherwise object containing the following * fields: ->content, ->title, ->url, ->activityname, ->activityurl, * and optionally ->extrastrings array, ->data, ->hide */ static function search_get_page($document) { global $CFG; // Implemented directly in SQL for performance, rather than using the // objects themselves $result = forum_utils::get_record_sql("\nSELECT\n fp.message AS content, fp.subject, firstpost.subject AS firstpostsubject,\n firstpost.id AS firstpostid, fd.id AS discussionid,\n f.name AS activityname, cm.id AS cmid, fd.timestart, fd.timeend,\n f.shared AS shared\nFROM\n {$CFG->prefix}forumng_posts fp\n INNER JOIN {$CFG->prefix}forumng_discussions fd ON fd.id=fp.discussionid\n INNER JOIN {$CFG->prefix}forumng_posts firstpost ON fd.postid=firstpost.id\n INNER JOIN {$CFG->prefix}forumng f ON fd.forumid = f.id\n INNER JOIN {$CFG->prefix}course_modules cm ON cm.instance = f.id AND cm.course = f.course\n INNER JOIN {$CFG->prefix}modules m ON cm.module = m.id\nWHERE\n fp.id = {$document->intref1} AND m.name='forumng'"); if (!$result) { return false; } // Title is either the post subject or Re: plus the discussion subject if the post subject is blank $result->title = $result->subject; if (is_null($result->title)) { $result->title = get_string('re', 'forumng', $result->firstpostsubject); } // Link is to value in url if present, otherwise to original forum if ($result->shared) { $clonebit = '&clone=' . optional_param('clone', $result->cmid, PARAM_INT); } else { $clonebit = ''; } // Work out URL to post $result->url = $CFG->wwwroot . '/mod/forumng/discuss.php?d=' . $result->discussionid . $clonebit . '#p' . $document->intref1; // Activity name and URL $result->activityurl = $CFG->wwwroot . '/mod/forumng/view.php?id=' . $result->cmid . $clonebit; // Hide results outside their time range (unless current user can see) $now = time(); if ($now < $result->timestart || $result->timeend && $now >= $result->timeend && !has_capability('mod/forumng:viewallposts', get_context_instance(CONTEXT_MODULE, $result->cmid))) { $result->hide = true; } return $result; }