Beispiel #1
0
 /**
  * Save an entry
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Login is required
     if (User::isGuest()) {
         return $this->loginTask();
     }
     // Incoming
     $fields = Request::getVar('fields', array(), 'post', 'none', 2);
     // Get model
     $row = new Item();
     // Bind content
     if (!$row->bind($fields)) {
         $this->setError($row->getError());
         return $this->editTask($row);
     }
     // Add some data
     //$row->set('_files', $files);
     $row->set('_assets', Request::getVar('assets', array(), 'post'));
     $row->set('_tags', trim(Request::getVar('tags', '')));
     $row->set('state', 1);
     // Store new content
     if (!$row->store()) {
         $this->setError($row->getError());
         return $this->editTask($row);
     }
     // Create a post entry linking the item to the board
     $p = Request::getVar('post', array(), 'post');
     // Load a post entry
     $post = new Post($p['id']);
     if (!$post->exists()) {
         // No post existed so set some values
         $post->set('item_id', $row->get('id'));
         $post->set('original', 1);
     }
     // Are we creating a new collection for it?
     $coltitle = Request::getVar('collection_title', '', 'post');
     if (!$p['collection_id'] && $coltitle) {
         $collection = new Collection();
         $collection->set('title', $coltitle);
         $collection->set('object_id', User::get('id'));
         $collection->set('object_type', 'member');
         $collection->store();
         $p['collection_id'] = $collection->get('id');
     }
     $post->set('collection_id', $p['collection_id']);
     // Set the description
     if (isset($p['description'])) {
         $post->set('description', $p['description']);
     }
     // Store record
     if (!$post->store()) {
         $this->setError($post->getError());
     }
     // Check for any errors
     if ($this->getError()) {
         return $this->editTask($row);
     }
     // Redirect to main listing
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=collections'));
 }
Beispiel #2
0
 /**
  * Delete a post
  *
  * @apiMethod DELETE
  * @apiUri    /collections/{id}/posts/{id}
  * @apiParameter {
  * 		"name":        "id",
  * 		"description": "Entry identifier",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @return    void
  */
 public function deleteTask()
 {
     $this->requiresAuthentication();
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     if (count($ids) <= 0) {
         throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_MISSING_ID'), 500);
     }
     foreach ($ids as $id) {
         $row = new Post(intval($id));
         if (!$row->exists()) {
             throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_MISSING_RECORD'), 404);
         }
         if (!$row->delete()) {
             throw new Exception($row->getError(), 500);
         }
     }
     $this->send(null, 204);
 }
Beispiel #3
0
 /**
  * Delete one or more entries
  *
  * @return  void
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     if (count($ids) > 0) {
         // Loop through all the IDs
         foreach ($ids as $id) {
             $entry = new Post(intval($id));
             // Delete the entry
             if (!$entry->delete()) {
                 \Notify::error($entry->getError());
             }
         }
     }
     // Set the redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_COLLECTIONS_ITEMS_DELETED'));
 }