/** * 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')); }
/** * Create a post * * @apiMethod POST * @apiUri /collections/{id}/posts * @apiParameter { * "name": "collection_id", * "description": "Collection identifier", * "type": "integer", * "required": true, * "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 createTask() { $this->requiresAuthentication(); $fields = array('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')); if (!$fields['collection_id']) { throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_MISSING_COLLECTION'), 422); } $row = new Item(); if (!$row->bind($fields)) { throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_BINDING_DATA'), 500); } if (!$row->store(true)) { throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_SAVING_DATA'), 500); } $post = new Post(); $post->set('item_id', $row->get('id')); $post->set('original', 1); $post->set('collection_id', $fields['collection_id']); if (!$post->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 Item($fields['id']); if (!$row->bind($fields)) { $this->setError($row->getError()); $this->editTask($row); return; } // 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', ''))); // 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->getTask() == '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')); }