Exemplo n.º 1
0
 /**
  * @name getAttachAttachment
  *
  * Attaches attachment to post by given IDs
  * 
  * @param int $id - ID of post to which attachment should be attached
  * @param in $attachmentId - ID of attachment that should be attached
  * @return Response - returns Respons in json format including success or error
  */
 public function getAttachAttachment($id, $attachmentId)
 {
     if (empty($id) || empty($attachmentId)) {
         return Response::json(array('error' => array('message' => "Bad request. Error", 'type' => "InvalidParameters", 'code' => 100)), 400);
     }
     $post = Post::find($id);
     if (!$post) {
         return Response::json(array('error' => array('message' => "Bad request. Error", 'type' => "InvalidParameters", 'code' => 100)), 400);
     }
     if (!$post->attach_attachment($attachmentId)) {
         return Response::json(array('error' => array('message' => Post::$errors[0], 'type' => "InvalidParameters", 'code' => 100)), 400);
     }
     return Response::json(array('attached' => true), 200);
 }
Exemplo n.º 2
0
 /**
  * @name attachToPost
  *
  * Attach gallery to post by post ID
  * NOTE: gallery should be instantiated in $this
  * 
  * @param int $post_id - Array of IDs or single ID of item/items for delete
  * @return bool - returns TRUE on success or FALSE if there was an error
  */
 public function attachToPost($post_id)
 {
     $post = Post::find($post_id);
     if (!$post) {
         $this->errors[] = 'No such post';
         return false;
     }
     if (!$this->post_owners()->attach($post_id, array('type' => self::POST_ITEM_TYPE))) {
         $this->errors[] = 'Failed to attach gallery to post';
         return false;
     }
     return true;
 }
Exemplo n.º 3
0
 /**
  * @name attachToPost
  *
  * Attach attachment to post by post ID
  * NOTE: attachment should be instantiated in $this
  * 
  * @param int $post_id - ID of post to which it will be attached
  * @return bool - returns TRUE on success or FALSE if there was an error
  */
 public function attachToPost($post_id)
 {
     $post = Post::find($post_id);
     if (!$post) {
         $this->errors[] = 'No such post';
         return false;
     }
     $this->fill(array('parent_id' => $post_id, 'parent_type' => self::POST_ITEM_PARENT));
     try {
         DB::beginTransaction();
         if (!$this->save()) {
             DB::rollBack();
             $this->errors[] = 'Failed to save attachment';
             return false;
         }
         DB::commit();
         return true;
     } catch (PDOException $e) {
         DB::rollBack();
         $this->errors[] = 'Fatal error' . $e->message;
         return false;
     }
 }