Ejemplo n.º 1
0
 /**
  * Get list
  * 
  * @access  public
  * @param   int     $parent_id  target parent record id
  * @return  Response(json|html)
  * @throws  Exception in Controller_Base::controller_common_api
  * @see  Controller_Base::controller_common_api
  */
 public function get_list($parent_id = null)
 {
     $this->api_accept_formats = array('html', 'json');
     $this->controller_common_api(function () use($parent_id) {
         $album_id = (int) \Input::get('album_id') ?: (int) $parent_id;
         $member_id = (int) \Input::get('member_id', 0);
         $is_member_page = (int) \Input::get('is_member_page', 0);
         $start_album_image_id = (int) \Input::get('start_id', 0);
         $is_asc = (bool) \Input::get('asc', 0);
         $album = $album_id ? Model_Album::check_authority($album_id, null, 'member') : null;
         list($is_mypage, $member) = $member_id ? $this->check_auth_and_is_mypage($member_id, true) : array(null, false);
         if ($album && $member) {
             $member = null;
             $is_mypage = false;
         }
         if (!$is_mypage && $album) {
             $is_mypage = $this->check_is_mypage($album->member_id);
         }
         list($limit, $page) = $this->common_get_pager_list_params(conf('articles.limit', 'album'), conf('articles.limit_max', 'album'));
         $params = array();
         if ($album) {
             $params['where'] = array(array('album_id', $album_id));
         }
         $data = Site_Model::get_album_images($limit, $page, get_uid(), $member, $is_mypage, $params, $this->format != 'html', $is_asc);
         $data['liked_album_image_ids'] = conf('like.isEnabled') && \Auth::check() ? \Site_Model::get_liked_ids('album_image', $this->u->id, $data['list']) : array();
         if ($this->format == 'html') {
             $data['is_member_page'] = $is_member_page;
             if (!empty($album)) {
                 $data['album'] = $album;
             }
             if (!empty($member)) {
                 $data['member'] = $member;
             }
         } else {
             $data['list'] = Site_Model::set_optional_data2album_image_list($data['list'], $start_album_image_id);
         }
         $this->set_response_body_api($data, $this->format == 'html' ? 'image/_parts/list' : null);
     });
 }
Ejemplo n.º 2
0
 /**
  * Album upload image
  * 
  * @access  public
  * @return  Response
  */
 public function action_upload_image($album_id = null)
 {
     \Util_security::check_method('POST');
     \Util_security::check_csrf();
     $album = Model_Album::check_authority($album_id, $this->u->id, 'member');
     if (Site_Util::check_album_disabled_to_update($album->foreign_table, true)) {
         throw new \HttpForbiddenException();
     }
     try {
         $val = self::get_validation_public_flag();
         if (!$val->run()) {
             throw new \ValidationFailedException($val->show_errors());
         }
         $post = $val->validated();
         \DB::start_transaction();
         list($album_image, $file) = Model_AlbumImage::save_with_relations($album_id, $this->u, $post['public_flag'], null, 'album_image');
         \DB::commit_transaction();
         \Session::set_flash('message', '写真を投稿しました。');
     } catch (\ValidationFailedException $e) {
         \Session::set_flash('error', $e->getMessage());
     } catch (\FuelException $e) {
         if (\DB::in_transaction()) {
             \DB::rollback_transaction();
         }
         \Session::set_flash('error', $e->getMessage());
     }
     \Response::redirect('album/' . $album_id);
 }
Ejemplo n.º 3
0
 /**
  * Update public_flag
  * 
  * @access  public
  * @param   int  $id  target id
  * @return  Response(html)
  * @throws  Exception in Controller_Base::controller_common_api
  * @see  Controller_Base::controller_common_api
  */
 public function post_update_public_flag($id = null)
 {
     $this->api_accept_formats = 'html';
     $this->controller_common_api(function () use($id) {
         $id = (int) $id;
         if (\Input::post('id')) {
             $id = (int) \Input::post('id');
         }
         $icon_only_flag = (int) \Input::post('icon_only_flag', 0);
         $have_children_public_flag = (int) \Input::post('have_children_public_flag', 0);
         $is_update_children_public_flag = (int) \Input::post('is_update_children_public_flag', 0);
         $album = Model_Album::check_authority($id, $this->u->id, 'member');
         if ($result = Site_Util::check_album_disabled_to_update($album->foreign_table)) {
             throw new \DisableToUpdateException($result['message']);
         }
         list($public_flag, $model) = \Site_Util::validate_params_for_update_public_flag($album->public_flag);
         \DB::start_transaction();
         $album->update_public_flag_with_relations($public_flag, !empty($is_update_children_public_flag));
         \DB::commit_transaction();
         $data = array('model' => $model, 'id' => $id, 'public_flag' => $public_flag, 'is_mycontents' => true, 'without_parent_box' => true, 'view_icon_only' => $icon_only_flag, 'have_children_public_flag' => $have_children_public_flag, 'child_model' => 'album_image');
         $this->set_response_body_api($data, '_parts/public_flag_selecter');
     });
 }