/** * Set Group Home Page * * @return void */ public function setHomeTask() { // get request vars $pageid = Request::getInt('pageid', 0, 'get'); // load page model $page = new Page($pageid); // make sure its out page if (!$page->belongsToGroup($this->group)) { App::abort(403, Lang::txt('COM_GROUPS_PAGES_PAGE_NOT_AUTH')); } // make sure we have an approved version $version = $page->approvedVersion(); if ($version === null) { $this->setNotification(Lang::txt('COM_GROUPS_PAGES_PAGE_HOME_ERROR', $page->get('title')), 'error'); App::redirect(Route::url('index.php?option=' . $this->_option . '&cn=' . $this->group->get('cn') . '&controller=pages')); return; } // remove any current home page $pageArchive = Page\Archive::getInstance(); $pageArchive->reset('home', 0, array('gidNumber' => $this->group->get('gidNumber'))); // toggle home state $home = 1; if ($page->get('home') == 1) { $home = 0; } $page->set('home', $home); // store new group home page if (!$page->store()) { $this->setNotification($page->getError(), 'error'); return $this->displayTask(); } // inform user $this->setNotification(Lang::txt('COM_GROUPS_PAGES_PAGE_HOME_SET', $page->get('title')), 'passed'); // redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&cn=' . $this->group->get('cn') . '&controller=pages')); if ($return = Request::getVar('return', '', 'get')) { App::redirect(base64_decode($return)); } }
/** * Delete Page * * @return void */ public function deleteTask() { // get request vars $ids = Request::getVar('id', array()); // delete each module foreach ($ids as $pageid) { // load modules $page = new Page($pageid); // cant delete home if ($page->get('home') == 1) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&gid=' . $this->gid, false), Lang::txt('COM_GROUPS_PAGES_CANT_DELETE_HOME'), 'error'); return; } //set to deleted state $page->set('state', $page::APP_STATE_DELETED); // set ordering to 999 when deleting $page->set('ordering', 999); // save module if (!$page->store(true)) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&gid=' . $this->gid, false), $page->getError(), 'error'); return; } } // log change Log::log(array('gidNumber' => $this->group->get('gidNumber'), 'action' => 'group_page_deleted', 'comments' => $ids)); //inform user & redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&gid=' . $this->gid, false), Lang::txt('COM_GROUPS_PAGES_DELETED'), 'passed'); }
/** * Set page state * * @return void */ public function setStateTask($state = 1, $status = 'published') { //get request vars $pageid = Request::getInt('pageid', 0, 'get'); // load page model $page = new \Components\Groups\Models\Page($pageid); // make sure its out page if (!$page->belongsToGroup($this->group)) { App::abort(403, Lang::txt('COM_GROUPS_PAGES_PAGE_NOT_AUTH')); } // make sure state is a valid state if (!in_array($state, array(0, 1, 2))) { $state = 1; } // set the page state $page->set('state', $state); // make sure the home page cant be deleted if ($page->get('home') == 1 && $page->get('state') != 1) { $page->set('state', 1); } // save if (!$page->store(false)) { $this->setNotification($page->getError(), 'error'); $this->displayTask(); return; } // get page children $children = $page->getChildren(); // if we are publishing/unpublishing if ($state == 0 || $state == 1) { // lets mark each child the same as parent foreach ($children as $child) { $child->set('state', $state); $child->store(false); } } else { if ($state == 2) { // update the first childs parent if ($firstChild = $children->first()) { $firstChild->set('parent', $page->get('parent')); $firstChild->store(false); } // adjust depth foreach child // the proper depth is needed when viewing pages foreach ($children as $child) { $child->set('depth', $child->get('depth') - 1); $child->store(false); } } } //inform user & redirect $return = Route::url('index.php?option=' . $this->_option . '&cn=' . $this->group->get('cn') . '&controller=pages'); if ($r = Request::getVar('return', '', 'get')) { $return = base64_decode($r); } App::redirect($return, Lang::txt('COM_GROUPS_PAGES_PAGE_STATUS_CHANGE', $status)); }
/** * Set page state * * @param integer $state * @param string $status * @return void */ public function setStateTask($state = 1, $status = 'published') { //get request vars $pageid = Request::getInt('pageid', 0, 'get'); // load page model $page = new \Components\Groups\Models\Page($pageid); // make sure its out page if (!$page->belongsToGroup($this->group)) { App::abort(403, Lang::txt('COM_GROUPS_PAGES_PAGE_NOT_AUTH')); } // make sure state is a valid state if (!in_array($state, array(0, 1, 2))) { $state = 1; } // set the page state $page->set('state', $state); // make sure the home page cant be deleted if ($page->get('home') == 1 && $page->get('state') != 1) { $page->set('state', 1); } // save if (!$page->store(false)) { $this->setNotification($page->getError(), 'error'); return $this->displayTask(); } // get page children $children = $page->getChildren(); // if we are publishing/unpublishing if ($state == 0 || $state == 1) { // lets mark each child the same as parent foreach ($children as $child) { $child->set('state', $state); $child->store(false); } } else { if ($state == 2) { // update the first childs parent if ($firstChild = $children->first()) { $firstChild->set('parent', $page->get('parent')); $firstChild->store(false); } // adjust depth foreach child // the proper depth is needed when viewing pages foreach ($children as $child) { $child->set('depth', $child->get('depth') - 1); $child->store(false); } } } //inform user & redirect $url = Route::url('index.php?option=' . $this->_option . '&cn=' . $this->group->get('cn') . '&controller=pages'); if ($r = Request::getVar('return', '', 'get')) { $url = base64_decode($r); } // Log activity $recipients = array(['group', $this->group->get('gidNumber')], ['user', User::get('id')]); foreach ($this->group->get('managers') as $recipient) { $recipients[] = ['user', $recipient]; } Event::trigger('system.logActivity', ['activity' => ['action' => $state == 2 ? 'deleted' : 'updated', 'scope' => 'group.page', 'scope_id' => $page->get('id'), 'description' => Lang::txt('COM_GROUPS_ACTIVITY_PAGE_' . ($state == 2 ? 'DELETED' : ($state == 1 ? 'PUBLISHED' : 'UNPUBLISHED')), $page->get('title'), '<a href="' . $url . '">' . $this->group->get('description') . '</a>'), 'details' => array('title' => $page->get('title'), 'url' => $url, 'gidNumber' => $this->group->get('gidNumber'))], 'recipients' => $recipients]); App::redirect($url, Lang::txt('COM_GROUPS_PAGES_PAGE_STATUS_CHANGE', $status)); }