/** * Display intro section for forum. * @param mod_forumng $forum Forum * @return string Intro HTML or '' if none */ public function render_intro($forum) { // Don't output anything if no text, so we don't get styling around // something blank $text = $forum->get_intro(); if (trim($text) === '') { return ''; } // Make fake activity object in required format, and use to format // intro for module with standard function (which handles images etc.) $activity = (object) array('intro' => $forum->get_intro(), 'introformat' => $forum->get_intro_format()); $intro = format_module_intro('forumng', $activity, $forum->get_course_module_id(true)); // Box styling appears to be consistent with some other modules $intro = html_writer::tag('div', $intro, array('class' => 'generalbox box', 'id' => 'intro')); return $intro; }
/** * Moves discussion to another forum. This will also move any attachments * in the filesystem. You can also use this method to change group. * (Note that once a discussion has been moved its data fields are no longer * valid and the object should be discarded.) * @param mod_forumng $targetforum Target forum for move * @param int $targetforumngid New forum ID * @param int $targetgroupid New group ID */ public function move($targetforum, $targetgroupid) { global $DB; $update = new StdClass(); if ($targetforum->get_id() != $this->discussionfields->forumngid) { $update->forumngid = $targetforum->get_id(); } if ($targetgroupid != $this->discussionfields->groupid) { $update->groupid = $targetgroupid; } if (count((array) $update) == 0) { // No change return; } //Delete search data for this discussion before moving $this->ismakingsearchchange = true; $root = $this->get_root_post(); $root->search_update(); $root->search_update_children(); $this->ismakingsearchchange = false; $update->id = $this->discussionfields->id; $transaction = $DB->start_delegated_transaction(); $DB->update_record('forumng_discussions', $update); $targetcloneid = $targetforum->is_shared() ? $targetforum->get_course_module_id() : 0; $newdiscussion = self::get_from_id($this->get_id(), $targetcloneid, -1); if ($targetforum->get_id() != $this->forum->get_id()) { // Moving to different forum, we need to move attachments if any... // Get old and new contexts $fs = get_file_storage(); $filecontext = $this->get_forum()->get_context(true); $newfilecontext = $targetforum->get_context(true); // Get list of all affected post ids (includes edited, deleted) // that have attachments $postids = $DB->get_records('forumng_posts', array('discussionid' => $this->get_id(), 'attachments' => 1), '', 'id'); // Loop through all posts copying attachments & deleting old one foreach ($postids as $postid => $junk) { foreach (array('attachment', 'message') as $filearea) { $oldfiles = $fs->get_area_files($filecontext->id, 'mod_forumng', $filearea, $postid, 'id', false); foreach ($oldfiles as $oldfile) { $filerecord = new stdClass(); $filerecord->contextid = $newfilecontext->id; $fs->create_file_from_storedfile($filerecord, $oldfile); $oldfile->delete(); } } } // Completion status may have changed in source and target forums // Performance optimise: only do this if completion is enabled if ($this->forum->is_auto_completion_enabled()) { $this->update_completion(false); $newdiscussion->update_completion(true); } } //Update the search data after the move $newroot = $newdiscussion->get_root_post(); $newroot->search_update(); $newroot->search_update_children(); $this->uncache(); $transaction->allow_commit(); }
/** * Checks forum object created in test_get_forum() * In function so same tests can be carried out on multiple forum setups * @param object $forum * @param object $course * @param object $cm */ private function check_forum_settings(mod_forumng $forum, $course, $cm) { $this->assertEquals('TEST', $forum->get_name()); $this->assertEquals('abc123', $forum->get_intro()); $this->assertEquals('abc123', $forum->get_intro(true)); // Pick up errors in abbreviation. $this->assertEquals(FORMAT_MOODLE, $forum->get_intro_format()); $this->assertEquals($cm->instance, $forum->get_id()); $this->assertEquals($course->id, $forum->get_course_id()); $this->assertEquals($course->id, $forum->get_course()->id); $this->assertEquals($cm->id, $forum->get_course_module_id()); $this->assertEquals(mod_forumng::NO_GROUPS, $forum->get_activity_group($cm)); $context = context_module::instance($cm->id); $this->assertEquals($context->id, $forum->get_context()->id); $this->assertInstanceOf('forumngtype', $forum->get_type()); }