Beispiel #1
0
 /**
  * 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);
 }
Beispiel #2
0
 /**
  * Save post reordering
  *
  * @return   void
  */
 public function reorderTask()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     // Incoming
     $posts = Request::getVar('post', array());
     if (is_array($posts)) {
         $folder = null;
         $i = 0;
         foreach ($posts as $post) {
             $post = intval($post);
             if (!$post) {
                 continue;
             }
             $row = new Post($post);
             if (!$row->exists()) {
                 continue;
             }
             $row->set('ordering', $i + 1);
             $row->store(false);
             $i++;
         }
     }
     if (!$no_html) {
         // Output messsage and redirect
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller), Lang::txt('COM_COLLECTIONS_POSTS_REORDERED'));
         return;
     }
     $response = new \stdClass();
     $response->success = 1;
     $response->message = Lang::txt('COM_COLLECTIONS_POSTS_REORDERED');
     echo json_encode($response);
 }