/** * Update a post * * @apiMethod PUT * @apiUri /collections/{id}/posts/{id} * @apiParameter { * "name": "id", * "description": "Entry identifier", * "type": "integer", * "required": true, * "default": null * } * @apiParameter { * "name": "collection_id", * "description": "Collection identifier", * "type": "integer", * "required": false, * "default": null * } * @apiParameter { * "name": "title", * "description": "Entry title", * "type": "string", * "required": true, * "default": null * } * @apiParameter { * "name": "description", * "description": "Entry description", * "type": "string", * "required": false, * "default": null * } * @apiParameter { * "name": "url", * "description": "Entry URL; Requires 'type'='link'", * "type": "string", * "required": false, * "default": null * } * @apiParameter { * "name": "created", * "description": "Created timestamp (YYYY-MM-DD HH:mm:ss)", * "type": "string", * "required": false, * "default": "now" * } * @apiParameter { * "name": "created_by", * "description": "User ID of entry creator", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "state", * "description": "Published state (0 = unpublished, 1 = published)", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "access", * "description": "Access level (0 = public, 1 = registered users, 4 = private)", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "type", * "description": "Item type", * "type": "string", * "required": false, * "default": "file" * } * @apiParameter { * "name": "object_id", * "description": "Object ID", * "type": "integer", * "required": false, * "default": 0 * } * @return void */ public function updateTask() { $this->requiresAuthentication(); $fields = array('id' => Request::getInt('id', 0, 'post'), 'title' => Request::getVar('title', null, 'post', 'none', 2), 'description' => Request::getVar('description', null, 'post', 'none', 2), 'url' => Request::getVar('url', null, 'post'), 'created' => Request::getVar('created', new Date('now'), 'post'), 'created_by' => Request::getInt('created_by', 0, 'post'), 'state' => Request::getInt('state', 1, 'post'), 'access' => Request::getInt('access', 0, 'post'), 'type' => Request::getVar('type', 'file', 'post'), 'object_id' => Request::getInt('object_id', 0, 'post'), 'collection_id' => Request::getInt('collection_id', 0, 'post')); $row = new Post($fields['id']); if (!$row->exists()) { throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_MISSING_RECORD'), 404); } if (!$row->bind($fields)) { throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_BINDING_DATA'), 422); } if (!$row->store(true)) { throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_SAVING_DATA'), 500); } $this->send($row); }
/** * Save an entry * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); // Incoming $fields = Request::getVar('fields', array(), 'post', 'none', 2); // Initiate extended database class $row = new Post($fields['id']); if (!$row->bind($fields)) { $this->setError($row->getError()); $this->editTask($row); return; } // Store new content if (!$row->store(true)) { $this->setError($row->getError()); $this->editTask($row); return; } // Process tags //$row->tag(trim(Request::getVar('tags', ''))); if ($this->_task == 'apply') { return $this->editTask($row); } // Set the redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_COLLECTIONS_POST_SAVED')); }