public static function like_post($course) { $likes = likes::instance($course); // Suitable capability checks are made in save_likes_from_submit! return $likes->save_likes_from_submit(); }
/** * Add all post data, which is necessary for rendering the posts * * @param object $course * @param object $postsdata containing retrieved posts in $postdata->post * @return object the postdata object with all of the data added */ protected function add_posts_data($course, &$postsdata) { global $DB; if (empty($postsdata->posts)) { return $postsdata; } $courseid = $course->id; // ... gather all the authors ids from posts. foreach ($postsdata->posts as &$post) { $postsdata->authors[$post->fromuserid] = $post->fromuserid; } // ... add all comments, replies to comments and add more authors. comments::add_comments_to_posts($postsdata, $course->tlnumcomments, $course->tlnumreplies); // ... add all likes from this user. $likes = likes::instance($course); $likes->add_likes_to_posts($postsdata); // ... add all attachments. attaches::add_attaches_to_posts($courseid, $postsdata); // ... finally gather all the required userdata for authors. if (!($users = $DB->get_records_list('user', 'id', array_keys($postsdata->authors)))) { debugging('error while retrieving post authors'); } $postsdata->authors = $users; return $postsdata; }
/** add all post data, which is necessary for rendering the posts * * @global object $DB * @param record $course * @param object $postsdata containing retrieved posts in $postdata->post * @return object the postdata object with all of the data added */ protected function add_posts_data($course, &$postsdata) { global $DB; if (empty($postsdata->posts)) { return $postsdata; } $courseid = $course->id; // ... gather all the authors ids from posts. foreach ($postsdata->posts as &$post) { $postsdata->authors[$post->fromuserid] = $post->fromuserid; } // ... add all comments and add more authors. comments::add_comments_to_posts($postsdata, $course->tlnumcomments); // ... add all likes from this user. $likes = likes::instance($course); $likes->add_likes_to_posts($postsdata); // ... add all attachments. attaches::add_attaches_to_posts($courseid, $postsdata); // ... finally gather all the required userdata for authors. $params = array(); list($inuserids, $params) = $DB->get_in_or_equal(array_keys($postsdata->authors)); $sql = "SELECT * FROM {user} WHERE id {$inuserids}"; if (!($users = $DB->get_records_sql($sql, $params))) { debugging('error while retrieving post authors'); } $postsdata->authors = $users; return $postsdata; }