Exemplo n.º 1
0
 /**
  * Save an entry
  *
  * @return     void
  */
 private function _save()
 {
     // Check for request forgeries
     Request::checkToken();
     // Login check
     if (User::isGuest()) {
         return $this->_login();
     }
     // Access check
     if (!$this->params->get('access-edit-item') || !$this->params->get('access-create-item')) {
         $this->setError(Lang::txt('PLG_GROUPS_' . strtoupper($this->_name) . '_NOT_AUTHORIZED'));
         return $this->_collections();
     }
     // Incoming
     $fields = Request::getVar('fields', array(), 'post', 'none', 2);
     if ($fields['id'] && !is_numeric($fields['id'])) {
         App::abort(404, Lang::txt('Post does not exist'));
     }
     // Get model
     $row = new \Components\Collections\Models\Item(intval($fields['id']));
     // Bind content
     if (!$row->bind($fields)) {
         $this->setError($row->getError());
         return $this->_edit($row);
     }
     // Add some data
     if ($files = Request::getVar('fls', '', 'files', 'array')) {
         $row->set('_files', $files);
     }
     $row->set('_assets', Request::getVar('assets', null, 'post'));
     $row->set('_tags', trim(Request::getVar('tags', '')));
     $row->set('state', 1);
     if (!$row->exists()) {
         $row->set('access', 0);
     }
     // Store new content
     if (!$row->store()) {
         $this->setError($row->getError());
         return $this->_edit($row);
     }
     // Create a post entry linking the item to the board
     $p = Request::getVar('post', array(), 'post');
     $post = new \Components\Collections\Models\Post($p['id']);
     if (!$post->exists()) {
         $post->set('item_id', $row->get('id'));
         $post->set('original', 1);
     }
     if (!isset($p['collection_id'])) {
         $p['collection_id'] = 0;
         if ($coltitle = Request::getVar('collection_title', '', 'post')) {
             $collection = new \Components\Collections\Models\Collection();
             $collection->set('title', $coltitle);
             $collection->set('object_id', $this->group->get('gidNumber'));
             $collection->set('object_type', 'group');
             $collection->set('access', $this->params->get('access-plugin'));
             $collection->store();
             $p['collection_id'] = $collection->get('id');
         }
     }
     $post->set('collection_id', $p['collection_id']);
     if (isset($p['description'])) {
         $post->set('description', $p['description']);
     }
     if (!$post->store()) {
         $this->setError($post->getError());
     }
     // Check for any errors
     if ($this->getError()) {
         Request::setVar('post', $p['id']);
         return $this->_edit($post->item()->bind($fields));
     }
     App::redirect(Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=' . $this->_name . '&scope=' . $this->model->collection($p['collection_id'])->get('alias')));
 }
Exemplo n.º 2
0
 /**
  * Save an entry
  *
  * @return  void
  */
 private function _save()
 {
     // Check for request forgeries
     Request::checkToken();
     // Login check
     if (User::isGuest()) {
         return $this->_login();
     }
     // Access check
     if (!$this->params->get('access-edit-item') || !$this->params->get('access-create-item')) {
         $this->setError(Lang::txt('PLG_GROUPS_' . strtoupper($this->_name) . '_NOT_AUTHORIZED'));
         return $this->_collections();
     }
     // Incoming
     $fields = Request::getVar('fields', array(), 'post', 'none', 2);
     if ($fields['id'] && !is_numeric($fields['id'])) {
         App::abort(404, Lang::txt('Post does not exist'));
     }
     // Get model
     $item = new \Components\Collections\Models\Item(intval($fields['id']));
     // Bind content
     if (!$item->bind($fields)) {
         $this->setError($item->getError());
         return $this->_edit($item);
     }
     // Add some data
     if ($files = Request::getVar('fls', '', 'files', 'array')) {
         $item->set('_files', $files);
     }
     $item->set('_assets', Request::getVar('assets', null, 'post'));
     $item->set('_tags', trim(Request::getVar('tags', '')));
     $item->set('state', 1);
     if (!$item->exists()) {
         $item->set('access', 0);
     }
     // Store new content
     if (!$item->store()) {
         $this->setError($item->getError());
         return $this->_edit($item);
     }
     // Create a post entry linking the item to the board
     $p = Request::getVar('post', array(), 'post');
     $post = new \Components\Collections\Models\Post($p['id']);
     if (!$post->exists()) {
         $post->set('item_id', $item->get('id'));
         $post->set('original', 1);
     }
     if (!isset($p['collection_id'])) {
         $p['collection_id'] = 0;
         if ($coltitle = Request::getVar('collection_title', '', 'post')) {
             $collection = new \Components\Collections\Models\Collection();
             $collection->set('title', $coltitle);
             $collection->set('object_id', $this->group->get('gidNumber'));
             $collection->set('object_type', 'group');
             $collection->set('access', $this->params->get('access-plugin'));
             $collection->store();
             $p['collection_id'] = $collection->get('id');
         }
     }
     $post->set('collection_id', $p['collection_id']);
     if (isset($p['description'])) {
         $post->set('description', $p['description']);
     }
     if (!$post->store()) {
         $this->setError($post->getError());
     }
     // Check for any errors
     if ($this->getError()) {
         Request::setVar('post', $p['id']);
         return $this->_edit($post->item()->bind($fields));
     }
     if (!isset($collection)) {
         $collection = new \Components\Collections\Models\Collection($p['collection_id']);
     }
     $url = 'index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=' . $this->_name . '&scope=' . $collection->get('alias');
     // Record the activity
     $recipients = array(['group', $this->group->get('gidNumber')], ['collection', $collection->get('id')], ['user', $item->get('created_by')]);
     foreach ($this->group->get('managers') as $recipient) {
         $recipients[] = ['user', $recipient];
     }
     Event::trigger('system.logActivity', ['activity' => ['action' => $p['id'] ? 'updated' : 'created', 'scope' => 'collections.item', 'scope_id' => $item->get('id'), 'description' => Lang::txt('PLG_GROUPS_COLLECTIONS_ACTIVITY_POST_' . ($p['id'] ? 'UPDATED' : 'CREATED'), '<a href="' . Route::url($url) . '">' . $collection->get('title') . '</a>'), 'details' => array('collection_id' => $collection->get('id'), 'post_id' => $post->get('id'), 'item_id' => $post->get('item_id'), 'url' => $url)], 'recipients' => $recipients]);
     // Redirect
     App::redirect(Route::url($url));
 }