Ejemplo n.º 1
0
 /**
  * Delete Attachment
  */
 public function deleteAttachment($id)
 {
     if (empty($id)) {
         return Response::json(array('error' => array('message' => "Bad request. No Item", 'type' => "InvalidParameters", 'code' => 100)), 400);
     }
     $model = new Attachment();
     $success = $model->deleteSafe($id);
     if (!$success) {
         return Response::json(array('error' => array('message' => $model->errors, 'type' => "InvalidParameters", 'code' => 100)), 400);
     }
     return Response::json(array('deleted' => true), 200);
 }
Ejemplo n.º 2
0
 /**
  * @name make
  *
  * Create new attachment from scratch
  * 
  * @param string $parent_type [optional] - Type of the attachment parent
  * @param string $type [optional] - Type of the attachment that is created
  * @return bool|array - returns Eloquent model of attachment or FALSE if there was an error
  * @static
  */
 public static function make($parent_type = self::DEFAULT_PARENT, $type = self::DEFAULT_TYPE)
 {
     $attachment_params = array('parent_type', $parent_type, 'type' => $type, 'file_id' => 0, 'status' => 'publish', 'name' => '', 'description' => '');
     $attachment = new AttachmentModel();
     $attachment->fill($attachment_params);
     try {
         DB::beginTransaction();
         if (!$attachment->save()) {
             DB::rollBack();
             $this->errors[] = 'Failed to create attachment';
             return false;
         }
         DB::commit();
         return $attachment;
     } catch (PDOException $e) {
         DB::rollBack();
         $this->errors[] = 'Fatal error' . $e->message;
         return false;
     }
 }
Ejemplo n.º 3
0
 public function attach_attachment($attachment_id)
 {
     $attachment = Attachment::find($attachment_id);
     if (!$attachment) {
         $this->errors[] = 'No such attachment';
         return false;
     }
     $this->featured_image()->save($attachment);
     return true;
 }