Пример #1
0
 /**
  * @name make
  *
  * Create new gallery from scratch
  * 
  * @param string $type [optional] - Type of the gallery that is created
  * @return bool|array - returns Eloquent model of gallery or FALSE if there was an error
  * @static
  */
 public static function make($type = self::DEFAULT_TYPE)
 {
     $gallery_params = array('type' => $type, 'status' => 'publish', 'name' => '', 'description' => '');
     $gallery = new GalleryModel();
     $gallery->fill($gallery_params);
     try {
         DB::beginTransaction();
         if (!$gallery->save()) {
             DB::rollBack();
             $this->errors[] = 'Failed to create Gallery';
             return false;
         }
         DB::commit();
         return $gallery;
     } catch (PDOException $e) {
         DB::rollBack();
         $this->errors[] = 'Fatal error' . $e->message;
         return false;
     }
 }
Пример #2
0
 /**
  * Delete gallery item
  */
 public function deleteItem($id)
 {
     if (empty($id)) {
         return Response::json(array('error' => array('message' => "Bad request. No Item", 'type' => "InvalidParameters", 'code' => 100)), 400);
     }
     $item = Gallery::fetchItemById($id);
     if (!$item) {
         return Response::json(array('error' => array('message' => "Bad request.", 'type' => "InvalidParameters", 'code' => 100)), 400);
     }
     $success = Gallery::deleteItems($id);
     if (!$success) {
         return Response::json(array('error' => array('message' => $model->errors, 'type' => "InvalidParameters", 'code' => 100)), 400);
     }
     return Response::json(array('deleted' => true), 200);
 }
Пример #3
0
 public function attach_gallery($gallery_id)
 {
     $gallery = Gallery::find($gallery_id);
     if (!$gallery) {
         $this->errors[] = 'No such gallery';
         return false;
     }
     if ($this->galleries->contains($gallery_id)) {
         return true;
     }
     $this->galleries()->attach($gallery_id, array('type' => Gallery::POST_ITEM_TYPE));
     return true;
 }
Пример #4
0
 protected function renderGalleryItemPage($post, $params)
 {
     $view_data = array();
     // get gallery item
     $model = new Gallery();
     $active_item = $model->get_item_by_id($params[0]);
     // next / prev
     $post->next = $post->galleries[0]->items->filter(function ($item) use($active_item) {
         return $item->id > $active_item->id;
     })->first();
     $post->prev = $post->galleries[0]->items->filter(function ($item) use($active_item) {
         return $item->id < $active_item->id;
     })->first();
     $add_data = array('pageParams' => $params, 'active_item' => $active_item);
     // --------------------------------------
     $meta_data = $this->setMetaData($post);
     $view_data = array_merge($view_data, $meta_data);
     // navigation
     // --------------------------------------
     $view_data['navigation'] = $this->renderNavigation();
     // --------------------------------------
     $template_data = $this->setPageData($post, $add_data);
     // page template (handlebars)
     $content = View::make('hbs::photo', $template_data);
     $view_data['content'] = $content;
     return View::make('layouts.application', $view_data);
 }