/** * Remove all items associated with the gorup being deleted * * @param object $group Group being deleted * @return string Log of items removed */ public function onGroupDelete($group) { $log = Lang::txt('PLG_GROUPS_FORUM') . ': '; require_once PATH_CORE . DS . 'components' . DS . 'com_forum' . DS . 'tables' . DS . 'post.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_forum' . DS . 'tables' . DS . 'category.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_forum' . DS . 'tables' . DS . 'section.php'; require_once PATH_CORE . DS . 'components' . DS . 'com_forum' . DS . 'tables' . DS . 'attachment.php'; $this->database = App::get('db'); $sModel = new \Components\Forum\Tables\Section($this->database); $sections = $sModel->getRecords(array('scope' => 'group', 'scope_id' => $group->get('gidNumber'))); // Do we have any IDs? if (count($sections) > 0) { // Loop through each ID foreach ($sections as $section) { // Get the categories in this section $cModel = new \Components\Forum\Tables\Category($this->database); $categories = $cModel->getRecords(array('section_id' => $section->id, 'scope' => 'group', 'scope_id' => $group->get('gidNumber'))); if ($categories) { // Build an array of category IDs $cats = array(); foreach ($categories as $category) { $cats[] = $category->id; } // Set all the threads/posts in all the categories to "deleted" $tModel = new \Components\Forum\Tables\Post($this->database); if (!$tModel->setStateByCategory($cats, 2)) { $this->setError($tModel->getError()); } $log .= 'forum.section.' . $section->id . '.category.' . $category->id . '.post' . "\n"; // Set all the categories to "deleted" if (!$cModel->setStateBySection($sModel->id, 2)) { $this->setError($cModel->getError()); } $log .= 'forum.section.' . $section->id . '.category.' . $category->id . "\n"; } // Set the section to "deleted" $sModel->load($section->id); $sModel->state = 2; /* 0 = unpublished, 1 = published, 2 = deleted */ if (!$sModel->store()) { $this->setError($sModel->getError()); return ''; } $log .= 'forum.section.' . $section->id . ' ' . "\n"; } } else { $log .= Lang::txt('PLG_GROUPS_FORUM_NO_RESULTS') . "\n"; } return $log; }
/** * Remove all items associated with the gorup being deleted * * @param object $course Course being deleted * @return string Log of items removed */ public function onCourseDelete($course) { if (!$course->exists()) { return ''; } $log = Lang::txt('PLG_COURSES_FORUM') . ': '; $this->database = App::get('db'); $sModel = new \Components\Forum\Tables\Section($this->database); $sections = array(); foreach ($course->offerings() as $offering) { if (!$offering->exists()) { continue; } $sec = $sModel->getRecords(array('scope' => 'course', 'scope_id' => $offering->get('id'))); foreach ($sec as $s) { $sections[] = $s; } } // Do we have any IDs? if (count($sections) > 0) { // Loop through each ID foreach ($sections as $section) { // Get the categories in this section $cModel = new \Components\Forum\Tables\Category($this->database); $categories = $cModel->getRecords(array('section_id' => $section->id, 'scope' => 'course', 'scope_id' => $course->offering()->get('id'))); if ($categories) { // Build an array of category IDs $cats = array(); foreach ($categories as $category) { $cats[] = $category->id; } // Set all the threads/posts in all the categories to "deleted" $tModel = new \Components\Forum\Tables\Post($this->database); if (!$tModel->setStateByCategory($cats, 2)) { $this->setError($tModel->getError()); } $log .= 'forum.section.' . $section->id . '.category.' . $category->id . '.post' . "\n"; // Set all the categories to "deleted" if (!$cModel->setStateBySection($section->id, 2)) { $this->setError($cModel->getError()); } $log .= 'forum.section.' . $section->id . '.category.' . $category->id . "\n"; } // Set the section to "deleted" $sModel->load($section->id); $sModel->state = 2; /* 0 = unpublished, 1 = published, 2 = deleted */ if (!$sModel->store()) { $this->setError($sModel->getError()); return ''; } $log .= 'forum.section.' . $section->id . ' ' . "\n"; } } else { $log .= Lang::txt('PLG_COURSES_DISCUSSIONS_NO_RESULTS') . "\n"; } return $log; }