From 8961316c8a086e4fa0c0297e0027263cc0adef60 Mon Sep 17 00:00:00 2001 From: TamaroWalter Date: Wed, 9 Aug 2023 15:47:57 +0200 Subject: [PATCH] first testing completed and successful. Test classes still needed --- classes/discussion/discussion.php | 51 ++++++++------ classes/post/post.php | 66 +++++++++--------- classes/post/post_control.php | 110 +++++++++++++++++------------- classes/subscriptions.php | 2 + locallib.php | 5 +- post.php | 1 - 6 files changed, 131 insertions(+), 104 deletions(-) diff --git a/classes/discussion/discussion.php b/classes/discussion/discussion.php index 479c1721f6..c7957a705d 100644 --- a/classes/discussion/discussion.php +++ b/classes/discussion/discussion.php @@ -36,6 +36,7 @@ defined('MOODLE_INTERNAL') || die(); +global $CFG; require_once($CFG->dirroot . '/mod/moodleoverflow/locallib.php'); /** @@ -133,42 +134,42 @@ public static function from_record($record) { $id = $record->id; } - $course = null; + $course = 0; if (object_property_exists($record, 'course') && $record->course) { $course = $record->course; } - $moodleoverflow = null; + $moodleoverflow = 0; if (object_property_exists($record, 'moodleoverflow') && $record->moodleoverflow) { $moodleoverflow = $record->moodleoverflow; } - $name = null; + $name = ''; if (object_property_exists($record, 'name') && $record->name) { $name = $record->name; } - $firstpost = null; + $firstpost = 0; if (object_property_exists($record, 'firstpost') && $record->firstpost) { $firstpost = $record->firstpost; } - $userid = null; + $userid = 0; if (object_property_exists($record, 'userid') && $record->userid) { $userid = $record->userid; } - $timemodified = null; + $timemodified = 0; if (object_property_exists($record, 'timemodified') && $record->timemodified) { $timemodified = $record->timemodified; } - $timestart = null; + $timestart = 0; if (object_property_exists($record, 'timestart') && $record->timestart) { $timestart = $record->timestart; } - $usermodified = null; + $usermodified = 0; if (object_property_exists($record, 'usermodified') && $record->usermodified) { $usermodified = $record->usermodified; } @@ -215,8 +216,8 @@ public function moodleoverflow_add_discussion($prepost) { $this->id = $DB->insert_record('moodleoverflow_discussions', $this->build_db_object()); // Create the first/parent post for the new discussion and add it do the DB. - $post = post::construct_without_id($this->id, 0, $prepost->userid, $prepost->timenow, $prepost->timenow, $preposts->message, - $prepost->messageformat, "", 0, $prepost->review, null, $prepost->formattachments); + $post = post::construct_without_id($this->id, 0, $prepost->userid, $prepost->timenow, $prepost->timenow, $prepost->message, + $prepost->messageformat, "", 0, $prepost->reviewed, null, $prepost->formattachments); // Add it to the DB and save the id of the first/parent post. $this->firstpost = $post->moodleoverflow_add_new_post(); @@ -230,7 +231,7 @@ public function moodleoverflow_add_discussion($prepost) { // Trigger event. $params = array( 'context' => $prepost->modulecontext, - 'objectid' => $post->discussion, + 'objectid' => $this->id, ); $event = \mod_moodleoverflow\event\discussion_viewed::create($params); $event->trigger(); @@ -256,7 +257,7 @@ public function moodleoverflow_delete_discussion($prepost) { $transaction = $DB->start_delegated_transaction(); // Delete every post of this discussion. - foreach ($posts as $post) { + foreach ($this->posts as $post) { $post->moodleoverflow_delete_post(false); } @@ -371,7 +372,7 @@ public function moodleoverflow_edit_post_from_discussion($prepost) { $this->timemodified = $prepost->timenow; $DB->update_record('moodleoverflow_discussions', $this->build_db_object()); } - $post->moodleoverflow_edit_post($prepost->timenow, $prepost->message, $prepost->messageformat, $prepost->formattachment); + $post->moodleoverflow_edit_post($prepost->timenow, $prepost->message, $prepost->messageformat, $prepost->formattachments); // The post has been edited successfully. return true; @@ -388,11 +389,13 @@ public function moodleoverflow_discussion_adapt_to_last_post() { $this->existence_check(); // Find the last reviewed post of the discussion (even if the user has review capability, because it's written to DB). - $sql = 'SELECT id, userid, modified + $sql = 'SELECT * FROM {moodleoverflow_posts} WHERE discussion = ' . $this->id . ' AND reviewed = 1 - AND modified = (SELECT MAX(modified) as modified FROM {moodleoverflow_posts})'; + AND modified = (SELECT MAX(modified) as modified + FROM {moodleoverflow_posts} + WHERE discussion = ' . $this->id . ');'; $record = $DB->get_record_sql($sql); $lastpost = post::from_record($record); @@ -483,9 +486,9 @@ public function moodleoverflow_get_discussion_posts() { if (!$this->postsbuild) { // Get the posts from the DB. Get the parent post first. $firstpostsql = 'SELECT * FROM {moodleoverflow_posts} posts - WHERE posts.discussion = ' . $this->id . ' AND posts.parent = 0;'; + WHERE discussion = ' . $this->id . ' AND parent = 0;'; $otherpostssql = 'SELECT * FROM {moodleoverflow_posts} posts - WHERE posts.discussion = ' . $this->id . ' AND posts.parent != 0;'; + WHERE discussion = ' . $this->id . ' AND parent != 0;'; $firstpostrecord = $DB->get_record_sql($firstpostsql); $otherpostsrecord = $DB->get_records_sql($otherpostssql); @@ -541,16 +544,24 @@ public function get_coursemodule() { return $this->cmobject; } + /** + * This getter works as an help function in case another file/function needs the db-object of this instance (as the function + * is not adapted/refactored to the new way of working with discussion). + * @return object + */ + public function get_db_object() { + $this->existence_check(); + return $this->build_db_object(); + } + // Helper functions. /** * Builds an object from this instance that has only DB-relevant attributes. + * As this is an private function, it doesn't need an existence check. * @return object $dbobject */ private function build_db_object() { - $this->existence_check(); - $this->posts_check(); - $dbobject = new \stdClass(); $dbobject->id = $this->id; $dbobject->course = $this->course; diff --git a/classes/post/post.php b/classes/post/post.php index 0e1d29d864..16e0ff6591 100644 --- a/classes/post/post.php +++ b/classes/post/post.php @@ -151,7 +151,7 @@ public function __construct($id, $discussion, $parent, $userid, $created, $modif /** * Builds a Post from a DB record. - * + * Look up database structure for standard values. * @param object $record Data object. * @return object post instance */ @@ -161,52 +161,52 @@ public static function from_record($record) { $id = $record->id; } - $discussion = null; + $discussion = 0; if (object_property_exists($record, 'discussion') && $record->discussion) { $discussion = $record->discussion; } - $parent = null; + $parent = 0; if (object_property_exists($record, 'parent') && $record->parent) { $parent = $record->parent; } - $userid = null; + $userid = 0; if (object_property_exists($record, 'userid') && $record->userid) { $userid = $record->userid; } - $created = null; + $created = 0; if (object_property_exists($record, 'created') && $record->created) { $created = $record->created; } - $modified = null; + $modified = 0; if (object_property_exists($record, 'modified') && $record->modified) { $modified = $record->modified; } - $message = null; + $message = ''; if (object_property_exists($record, 'message') && $record->message) { $message = $record->message; } - $messageformat = null; + $messageformat = 0; if (object_property_exists($record, 'messageformat') && $record->messageformat) { - $message = $record->messageformat; + $messageformat = $record->messageformat; } - $attachment = null; + $attachment = ''; if (object_property_exists($record, 'attachment') && $record->attachment) { $attachment = $record->attachment; } - $mailed = null; + $mailed = 0; if (object_property_exists($record, 'mailed') && $record->mailed) { $mailed = $record->mailed; } - $reviewed = null; + $reviewed = 1; if (object_property_exists($record, 'reviewed') && $record->reviewed) { $reviewed = $record->reviewed; } @@ -216,10 +216,8 @@ public static function from_record($record) { $timereviewed = $record->timereviewed; } - $instance = new self($id, $discussion, $parent, $userid, $created, $modified, $message, - $messageformat, $attachment, $mailed, $reviewed, $timereviewed); - - return $instance; + return new self($id, $discussion, $parent, $userid, $created, $modified, $message, $messageformat, $attachment, $mailed, + $reviewed, $timereviewed); } /** @@ -243,9 +241,8 @@ public static function from_record($record) { public static function construct_without_id($discussion, $parent, $userid, $created, $modified, $message, $messageformat, $attachment, $mailed, $reviewed, $timereviewed, $formattachments = false) { $id = null; - $instance = new self($id, $discussion, $parent, $userid, $created, $modified, $message, - $messageformat, $attachment, $mailed, $reviewed, $timereviewed, $formattachments); - return $instance; + return new self($id, $discussion, $parent, $userid, $created, $modified, $message, $messageformat, $attachment, $mailed, + $reviewed, $timereviewed, $formattachments); } // Post Functions. @@ -297,11 +294,13 @@ public function moodleoverflow_delete_post($deletechildren) { try { $transaction = $DB->start_delegated_transaction(); + // Get the coursemoduleid for later use. + $coursemoduleid = $this->get_coursemodule()->id; $childposts = $this->moodleoverflow_get_childposts(); if ($deletechildren && $childposts) { foreach ($childposts as $childpost) { $child = $this->from_record($childpost); - $child->moodleoverflow_delete_post(); + $child->moodleoverflow_delete_post($deletechildren); } } @@ -315,7 +314,7 @@ public function moodleoverflow_delete_post($deletechildren) { // Delete the attachments. $fs = get_file_storage(); - $context = \context_module::instance($this->get_coursemodule()->id); + $context = \context_module::instance($coursemoduleid); $attachments = $fs->get_area_files($context->id, 'mod_moodleoverflow', 'attachment', $this->id, "filename", true); foreach ($attachments as $attachment) { @@ -328,12 +327,9 @@ public function moodleoverflow_delete_post($deletechildren) { } } - // Get the context module. - $modulecontext = \context_module::instance($this->get_coursemodule()->id); - // Trigger the post deletion event. $params = array( - 'context' => $modulecontext, + 'context' => $context, 'objectid' => $this->id, 'other' => array( 'discussionid' => $this->discussion, @@ -343,7 +339,7 @@ public function moodleoverflow_delete_post($deletechildren) { if ($this->userid !== $USER->id) { $params['relateduserid'] = $this->userid; } - $event = post_deleted::create($params); + $event = \mod_moodleoverflow\event\post_deleted::create($params); $event->trigger(); // Set the id of this instance to null, so that working with it is not possible anymore. @@ -370,7 +366,7 @@ public function moodleoverflow_delete_post($deletechildren) { * * @return true if the post has been edited successfully */ - public function moodleoverflow_edit_post($time, $postmessage, $messageformat, $formattachment) { + public function moodleoverflow_edit_post($time, $postmessage, $messageformat, $formattachments) { global $DB; $this->existence_check(); @@ -378,7 +374,7 @@ public function moodleoverflow_edit_post($time, $postmessage, $messageformat, $f $this->modified = $time; $this->message = $postmessage; $this->messageformat = $messageformat; - $this->formattachment = $formattachment; // PLEASE CHECK LATER IF THIS IS NEEDED AFTER WORKING WITH THE POST_FORM CLASS. + $this->formattachments = $formattachments; // Update the record in the database. $DB->update_record('moodleoverflow_posts', $this->build_db_object()); @@ -431,10 +427,6 @@ public function moodleoverflow_add_attachment() { global $DB; $this->existence_check(); - if (!$this->formattachments) { - throw new \moodle_exception('missingformattachments', 'moodleoverflow'); - } - if (empty($this->formattachments)) { return true; // Nothing to do. } @@ -615,6 +607,16 @@ public function moodleoverflow_get_childposts() { return false; } + /** + * This getter works as an help function in case another file/function needs the db-object of this instance (as the function + * is not adapted/refactored to the new way of working with discussion). + * @return object + */ + public function get_db_object() { + $this->existence_check(); + return $this->build_db_object; + } + // Helper Functions. /** diff --git a/classes/post/post_control.php b/classes/post/post_control.php index e330f7f80b..33a7be9ab5 100644 --- a/classes/post/post_control.php +++ b/classes/post/post_control.php @@ -37,7 +37,7 @@ require_once($CFG->dirroot . '/mod/moodleoverflow/locallib.php'); require_once($CFG->libdir . '/completionlib.php'); -//require once($CFG->dirroot . 'mod/moodleoverflow/classes/post/post.php'); + /** * This Class controls the manipulation of posts and acts as controller of interactions with the post.php * @@ -118,7 +118,7 @@ public function detect_interaction($urlparameter) { } else if ($urlparameter->delete) { $this->interaction = 'delete'; - $this->info->deletepostid = $urlparameter->edit; + $this->info->deletepostid = $urlparameter->delete; $this->build_prepost_delete($this->info->deletepostid); } else { throw new \moodle_exception('unknownaction'); @@ -146,14 +146,7 @@ public function execute_interaction($form) { // Get the current time. $this->prepost->timenow = time(); - /* - var_dump($this->interaction); - var_dump('
'); - var_dump($this->prepost); - var_dump('
'); - var_dump($form->reply); - var_dump($this->prepost->parentid);*/ - var_dump($form); + // Execute the right function. if ($this->interaction == 'create' && $form->moodleoverflow == $this->prepost->moodleoverflowid) { $this->execute_create($form, $errordestination); @@ -347,30 +340,28 @@ private function build_prepost_edit($editpostid) { private function build_prepost_delete($deletepostid) { global $DB, $USER; - // Get the realted post, discussion, moodleoverflow, course, coursemodule and contexts. + // Get the related post, discussion, moodleoverflow, course, coursemodule and contexts. $this->collect_information($deletepostid, false); // Require a login and retrieve the modulecontext. require_login($this->info->course, false, $this->info->cm); // Check some capabilities. - $this->info->deleteownpost = has_capability('mod/moodleoverflow:deleteownpost', $this->info->modulecontext); - $this->info->deleteanypost = has_capability('mod/moodleoverflow:deleteanypost', $this->info->modulecontext); - if (!(($this->info->relatedpost->get_userid() == $USER->id && $this->info->deleteownpost) - || $this->info->deleteanypost)) { - - throw new \moodle_exception('cannotdeletepost', 'moodleoverflow'); - } + $this->check_user_can_delete_post(); // Count all replies of this post. $this->info->replycount = moodleoverflow_count_replies($this->info->relatedpost, false); - + if ($this->info->replycount >= 1) { + $this->info->deletetype = 'plural'; + } else { + $this->info->deletetype = 'singular'; + } // Build the prepost. $this->assemble_prepost(); $this->prepost->deletechildren = true; } - // Execute Functions, that execute an interaction. + // Execute Functions. private function execute_create($form, $errordestination) { global $USER; @@ -385,9 +376,12 @@ private function execute_create($form, $errordestination) { $this->prepost->reviewed = 1; } + // Get the discussion subject. + $this->prepost->subject = $form->subject; + // Create the discussion object. $discussion = discussion::construct_without_id($this->prepost->courseid, $this->prepost->moodleoverflowid, - $this->prepost->subject, null, $this->prepost->userid, + $this->prepost->subject, 0, $this->prepost->userid, $this->prepost->timenow, $this->prepost->timenow, $this->prepost->userid); if (!$discussion->moodleoverflow_add_discussion($this->prepost)) { throw new \moodle_exception('couldnotadd', 'moodleoverflow', $errordestination); @@ -397,13 +391,16 @@ private function execute_create($form, $errordestination) { $redirectmessage = '

' . get_string("postaddedsuccess", "moodleoverflow") . '

'; // Trigger the discussion created event. - $params = array( 'context' => $this->info->modulecontext, 'objectid' => $discussion->id,); + $params = array( 'context' => $this->info->modulecontext, 'objectid' => $discussion->get_id()); $event = \mod_moodleoverflow\event\discussion_created::create($params); $event->trigger(); // Subscribe to this thread. - //\mod_moodleoverflow\subscriptions::moodleoverflow_post_subscription($form, $this->info->moodleoverflow, - //$discussion, $this->info->modulecontext); + // Please be aware that in future the use of get_db_object() should be replaced with only $this->info->discussion, + // as the subscription class should be refactored with the new way of working with posts. + \mod_moodleoverflow\subscriptions::moodleoverflow_post_subscription($form, $this->info->moodleoverflow, + $discussion->get_db_object(), + $this->info->modulecontext); // Define the location to redirect the user after successfully posting. $redirectto = new \moodle_url('/mod/moodleoverflow/view.php', array('m' => $form->moodleoverflow)); @@ -413,7 +410,7 @@ private function execute_create($form, $errordestination) { private function execute_reply($form, $errordestination) { // Check if the user has the capability to write a reply. $this->check_user_can_create_reply(); - + // Set to not reviewed, if posts should be reviewed, and user is not a reviewer themselves. if (review::get_review_level($this->info->moodleoverflow) == review::EVERYTHING && !has_capability('mod/moodleoverflow:reviewpost', \context_module::instance($this->info->cm->id))) { @@ -431,7 +428,7 @@ private function execute_reply($form, $errordestination) { $redirectmessage = '

' . get_string("postaddedsuccess", "moodleoverflow") . '

'; $redirectmessage .= '

' . get_string("postaddedtimeleft", "moodleoverflow", format_time(get_config('moodleoverflow', 'maxeditingtime'))) . '

'; - + // Trigger the post created event. $params = array('context' => $this->info->modulecontext, 'objectid' => $newpostid, 'other' => array('discussionid' => $this->prepost->discussionid, @@ -440,30 +437,33 @@ private function execute_reply($form, $errordestination) { $event = \mod_moodleoverflow\event\post_created::create($params); $event->trigger(); - // Subscribe to this thread; - // \mod_moodleoverflow\subscriptions::moodleoverflow_post_subscription(form, $this->info->moodleoverflow, - //$this->info->discussion, $this->info->modulecontext); - + // Subscribe to this thread. + // Please be aware that in future the use of build_db_object() should be replaced with only $this->info->discussion, + // as the subscription class should be refactored with the new way of working with posts. + \mod_moodleoverflow\subscriptions::moodleoverflow_post_subscription($form, $this->info->moodleoverflow, + $this->info->discussion->get_db_object(), + $this->info->modulecontext); + // Define the location to redirect the user after successfully posting. - $redirectto = new \moodle_url('/mod/moodleoverflow/discussion.php', array('d' => $this->prepost->discussionid, 'p' => $newpostid)); + $redirectto = new \moodle_url('/mod/moodleoverflow/discussion.php', + array('d' => $this->prepost->discussionid, 'p' => $newpostid)); redirect(\moodleoverflow_go_back_to($redirectto->out()), $redirectmessage, null, \core\output\notification::NOTIFY_SUCCESS); - } private function execute_edit($form, $errordestination) { - global $USER; + global $USER, $DB; // Check if the user has the capability to edit his post. $this->check_user_can_edit_post(); - + // Update the post. if (!$this->info->discussion->moodleoverflow_edit_post_from_discussion($this->prepost)) { throw new \moodle_exception('couldnotupdate', 'moodleoverflow', $errordestination); } - - // The edit was successful. + + // The edit was successful. $redirectmessage = get_string('postupdated', 'moodleoverflow'); - /*if ($this->prepost->userid == $USER->id) { + if ($this->prepost->userid == $USER->id) { $redirectmessage = get_string('postupdated', 'moodleoverflow'); } else { if (\mod_moodleoverflow\anonymous::is_post_anonymous($this->info->discussion, $this->info->moodleoverflow, @@ -474,7 +474,7 @@ private function execute_edit($form, $errordestination) { $name = fullname($realuser); } $redirectmessage = get_string('editedpostupdated', 'moodleoverflow', $name); - }*/ + } // Trigger the post updated event. $params = array('context' => $this->info->modulecontext, 'objectid' => $form->edit, @@ -486,7 +486,8 @@ private function execute_edit($form, $errordestination) { $event->trigger(); // Define the location to redirect the user after successfully editing. - $redirectto = new \moodle_url('/mod/moodleoverflow/discussion.php', array('d' => $this->prepost->discussionid, 'p' => $form->edit)); + $redirectto = new \moodle_url('/mod/moodleoverflow/discussion.php', + array('d' => $this->prepost->discussionid, 'p' => $form->edit)); redirect(moodleoverflow_go_back_to($redirectto->out()), $redirectmessage, null, \core\output\notification::NOTIFY_SUCCESS); } @@ -501,16 +502,18 @@ public function execute_delete() { } // A normal user cannot delete his post if there are direct replies. - if ($this->infro->replycount && !$this->info->deleteanypost) { + if ($this->info->replycount && !$this->info->deleteanypost) { throw new \moodle_exception('cannotdeletereplies', 'moodleoverflow', moodleoverflow_go_back_to($url)); } // Check if the post is a parent post or not. if ($this->prepost->parentid == 0) { + // Save the moodleoverflowid. Then delete the discussion. + $moodleoverflowid = $this->info->discussion->get_moodleoverflowid(); $this->info->discussion->moodleoverflow_delete_discussion($this->prepost); // Redirect the user back to the start page of the moodleoverflow instance. - redirect('view.php?m=' . $this->info->discussion->get_moodleoverflowid()); + redirect('view.php?m=' . $moodleoverflowid); } else { $this->info->discussion->moodleoverflow_delete_post_from_discussion($this->prepost); $discussionurl = new \moodle_url('/mod/moodleoverflow/discussion.php', array('d' => $this->info->discussion->get_id())); @@ -645,13 +648,6 @@ private function collect_information($postid = false, $moodleoverflowid = false) } else { $localmoodleoverflowid = $moodleoverflowid; } - /* - var_dump($moodleoverflowid); - var_dump($postid); - var_dump($this->info->relatedpost); - var_dump($this->info->discussion); - var_dump($localmoodleoverflowid); - */ $this->info->moodleoverflow = $this->check_moodleoverflow_exists($localmoodleoverflowid); $this->info->course = $this->check_course_exists($this->info->moodleoverflow->course); $this->info->cm = $this->check_coursemodule_exists($this->info->moodleoverflow->id, $this->info->course->id); @@ -796,7 +792,7 @@ private function check_user_can_create_reply() { * Checks if a user can edit a post. * A user can edit if he can edit any post of if he edits his own post and has the ability to: * start a new discussion or to reply to a post. - * + * * @return true * @throws moodle_exception */ @@ -811,4 +807,20 @@ private function check_user_can_edit_post() { } return true; } + + /** + * Checks if a user can edit a post. + * @return true + * @thorws moodle_exception + */ + private function check_user_can_delete_post() { + global $USER; + $this->info->deleteownpost = has_capability('mod/moodleoverflow:deleteownpost', $this->info->modulecontext); + $this->info->deleteanypost = has_capability('mod/moodleoverflow:deleteanypost', $this->info->modulecontext); + if (!(($this->info->relatedpost->get_userid() == $USER->id && $this->info->deleteownpost) || $this->info->deleteanypost)) { + + throw new \moodle_exception('cannotdeletepost', 'moodleoverflow'); + } + return true; + } } diff --git a/classes/subscriptions.php b/classes/subscriptions.php index eb44389462..8ea2981846 100644 --- a/classes/subscriptions.php +++ b/classes/subscriptions.php @@ -761,6 +761,7 @@ public static function unsubscribe_user($userid, $moodleoverflow, $context, $use /** * Subscribes the user to the specified discussion. * + * TODO: Refactor this function to the new way of working with discussion and posts. * @param int $userid The user ID * @param \stdClass $discussion The discussion record * @param \context_module $context The module context @@ -985,6 +986,7 @@ public static function moodleoverflow_get_subscribe_link($moodleoverflow, $conte /** * Given a new post, subscribes the user to the thread the post was posted in. * + * TODO: Refactor this function to the new way of working with discussion and posts. * @param object $fromform The submitted form * @param \stdClass $moodleoverflow The moodleoverflow record * @param \stdClass $discussion The discussion record diff --git a/locallib.php b/locallib.php index 1187827aa2..f1f01528a9 100644 --- a/locallib.php +++ b/locallib.php @@ -944,8 +944,8 @@ function moodleoverflow_print_discussion($course, $cm, $moodleoverflow, $discuss $istracked = readtracking::moodleoverflow_is_tracked($moodleoverflow); // Retrieve all posts of the discussion. + // This part is adapted/refactored to the new way of working with posts (use of get_id() function and discussion object). $posts = moodleoverflow_get_all_discussion_posts($discussionobject->get_id(), $istracked, $modulecontext); - //$posts = $discussionobjects->posts; $usermapping = anonymous::get_userid_mapping($moodleoverflow, $discussionobject->get_id()); @@ -1773,6 +1773,7 @@ function moodleoverflow_update_post($newpost) { /** * Count all replies of a post. * + * INFO: This Function is adapted to the new way of working with posts (using the post classes) * @param object $post The post object * @param bool $onlyreviewed Whether to count only reviewed posts. * @@ -1781,7 +1782,7 @@ function moodleoverflow_update_post($newpost) { function moodleoverflow_count_replies($post, $onlyreviewed) { global $DB; - $conditions = ['parent' => $post->id]; + $conditions = ['parent' => $post->get_id()]; if ($onlyreviewed) { $conditions['reviewed'] = '1'; diff --git a/post.php b/post.php index 3a59050729..e2ec14e042 100644 --- a/post.php +++ b/post.php @@ -55,7 +55,6 @@ // Create a post_control object to control and lead the process. $postcontrol = new post_control(); -//$postcontrol = new post_control(); // Put all interaction parameters in one object for the post_control. $urlparameter = new \stdClass();