Exemple #1
0
 /**
  * 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));
 }
Exemple #2
0
 /**
  * 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));
 }