/**
  * フリーマーケット詳細表示画面
  *
  * @access public
  * @param mixed $fleamarket_id フリーマーケットID
  * @return void
  * @author ida
  */
 public function get_detail($fleamarket_id)
 {
     Asset::css('jquery-ui.min.css', array(), 'add_css');
     Asset::js('jquery-ui.min.js', array(), 'add_js');
     if (!$fleamarket_id) {
         return $this->forward('errors/notfound', 404);
     }
     $fleamarket = \Model_Fleamarket::findDetail($fleamarket_id);
     if (!$fleamarket) {
         return $this->forward('errors/notfound', 404);
     }
     $this->setHtmlReplace(array('AREA' => $this->getArea($fleamarket['prefecture_id']), 'AREA_NAME' => $this->getAreaName($fleamarket['prefecture_id']), 'FLEAMARKET_NAME' => $fleamarket['name'], 'LOCATION_ID' => $fleamarket['location_id'], 'LOCATION_NAME' => $fleamarket['location_name']));
     $fleamarket_abouts = \Model_Fleamarket_About::findByFleamarketId($fleamarket_id);
     $fleamarket_images = \Model_Fleamarket_Image::findByFleamarketId($fleamarket_id);
     $entry_styles = \Model_Fleamarket_Entry_Style::findByFleamarketId($fleamarket_id);
     $entries = \Model_Entry::getTotalEntryByFleamarketId($fleamarket_id);
     $fleamarket['entries'] = $entries;
     $view_model = \ViewModel::forge('search/detail');
     $view_model->set('fleamarket', $fleamarket, false);
     $view_model->set('fleamarket_images', $fleamarket_images, false);
     $view_model->set('fleamarket_abouts', $fleamarket_abouts, false);
     $view_model->set('fleamarket_entry_styles', $entry_styles, false);
     $view_model->set('entries', $entries, false);
     $view_model->set('prefectures', \Config::get('master.prefectures'), false);
     $view_model->set('user', $this->login_user, false);
     $this->template->content = $view_model;
 }
 /**
  * 会場詳細
  *
  * @access public
  * @param mixed $location_id 会場ID
  * @param mixed $fleamarket_id フリマID
  * @return void
  * @author ida
  */
 public function action_detail($location_id = null, $fleamarket_id = null)
 {
     if (!$location_id) {
         return $this->forward('errors/notfound', 404);
     }
     \Asset::css('jquery-ui.min.css', array(), 'add_css');
     \Asset::js('jquery-ui.min.js', array(), 'add_js');
     // 会場に紐づくフリマを取得する
     $fleamarket_date_list = \Model_Fleamarket::find('all', array('select' => array('fleamarket_id', 'event_date'), 'where' => array(array('location_id' => $location_id)), 'order_by' => array('event_date' => 'asc')));
     if (!$location_id || !$fleamarket_date_list) {
         \Response::redirect('errors/notfound');
     }
     if (!$fleamarket_id) {
         $first_fleamarket = end($fleamarket_date_list);
         $fleamarket_id = $first_fleamarket['fleamarket_id'];
     }
     $fleamarket = \Model_Fleamarket::findDetail($fleamarket_id);
     if (!$fleamarket) {
         \Response::redirect('errors/notfound');
     }
     $this->setHtmlReplace(array('AREA' => $this->getArea($fleamarket['prefecture_id']), 'AREA_NAME' => $this->getAreaName($fleamarket['prefecture_id']), 'LOCATION_ID' => $fleamarket['location_id'], 'LOCATION_NAME' => $fleamarket['location_name'], 'FLEAMARKET_NAME' => $fleamarket['name']));
     $fleamarket_abouts = \Model_Fleamarket_About::findByFleamarketId($fleamarket_id);
     $fleamarket_images = \Model_Fleamarket_Image::findByFleamarketId($fleamarket_id);
     $entry_styles = \Model_Fleamarket_Entry_Style::findByFleamarketId($fleamarket_id);
     $view_model = \ViewModel::forge('location/detail');
     $view_model->set('fleamarket', $fleamarket, false);
     $view_model->set('fleamarket_date_list', $fleamarket_date_list, false);
     $view_model->set('fleamarket_images', $fleamarket_images, false);
     $view_model->set('fleamarket_abouts', $fleamarket_abouts, false);
     $view_model->set('fleamarket_entry_styles', $entry_styles, false);
     $view_model->set('prefectures', \Config::get('master.prefectures'), false);
     $view_model->set('user', $this->login_user, false);
     $this->template->content = $view_model;
 }
 /**
  * 移動
  *
  * @access public
  * @param
  * @return void
  * @author ida
  */
 public function run()
 {
     $fleamarket_images = \Model_Fleamarket_Image::find('all');
     if (!$fleamarket_images) {
         echo 'フリマのイメージ画像はありません';
         return;
     }
     echo "START";
     $prefix_list = array('ss', 's', 'm', 'l');
     $old_dir = DOCROOT . 'public/files/fleamarket/img/';
     $new_dir = DOCROOT . 'public/files/fleamarket/';
     foreach ($fleamarket_images as $fleamarket_image_id => $fleamarket_image) {
         echo $fleamarket_image_id . '=:' . $fleamarket_image->file_name;
         echo "\n-----\n";
         self::checkPath($new_dir . $fleamarket_image->fleamarket_id, true);
         $old_path = $old_dir . $fleamarket_image->file_name;
         $new_path = $new_dir . $fleamarket_image->fleamarket_id . '/';
         if (!copy($old_path, $new_path . $fleamarket_image->file_name)) {
             echo 'Error =: ' . $fleamarket_image_id;
         }
         foreach ($prefix_list as $prefix) {
             $file_name = $prefix . '_' . $fleamarket_image->file_name;
             if (!copy($old_path, $new_path . $file_name)) {
                 echo 'Error =: ' . $fleamarket_image_id;
             }
         }
     }
     echo "END";
 }
 /**
  * view method
  *
  * @access public
  * @return void
  * @author ida
  */
 public function view()
 {
     $fleamarket_images = \Model_Fleamarket_Image::findByFleamarketId($this->fleamarket_id);
     $this->set('location_fieldset', $this->fieldsets['location'], false);
     $this->set('fleamarket_fieldset', $this->fieldsets['fleamarket'], false);
     $this->set('fleamarket_about_fieldset', $this->fieldsets['fleamarket_about'], false);
     $this->set('fleamarket_images', $fleamarket_images, false);
     $this->prefectures = \Config::get('master.prefectures');
     $this->image_store_path = '/' . \Config::get('master.image_path.temporary_user');
     $this->image_temporary_path = '/' . \Config::get('master.image_path.temporary_user');
     $this->upload_file_limit = \Model_Fleamarket_Image::UPLOAD_FILE_LIMIT;
     $this->getFleamarketImageByPriority = function ($priority) use($fleamarket_images) {
         if (!$fleamarket_images) {
             return null;
         }
         foreach ($fleamarket_images as $fleamarket_image) {
             if ($priority == $fleamarket_image['priority']) {
                 return $fleamarket_image;
             }
         }
     };
 }
 /**
  * ファイル名をフリマ画像情報に登録する
  *
  * @access private
  * @param object $fleamarket フリマ情報
  * @param array $files フリマ画像情報
  * @return void
  * @author kobayashi
  */
 private function registerFleamarketImage($fleamarket, $files)
 {
     foreach ($files as $file) {
         $matches = array();
         if (preg_match('/^upload(\\d+)$/', $file['field'], $matches)) {
             $priority = $matches[1];
             $data = array('fleamarket_id' => $fleamarket->fleamarket_id, 'file_name' => $file['saved_as'], 'priority' => $priority);
             $fleamarket_image = \Model_Fleamarket_Image::query()->where('fleamarket_id', $fleamarket->fleamarket_id)->where('priority', $priority)->get_one();
             $administrator_id = $this->administrator->administrator_id;
             if ($fleamarket_image) {
                 $data['updated_user'] = $administrator_id;
             } else {
                 $fleamarket_image = \Model_Fleamarket_Image::forge(array('fleamarket_id' => $fleamarket->fleamarket_id, 'priority' => $priority));
                 $data['created_user'] = $administrator_id;
             }
             $fleamarket_image->set($data)->save();
         }
     }
 }
 /**
  * アップロードファイルを指定のフォルダに移動する
  *
  * @access private
  * @param
  * @return void
  * @author kobayashi
  */
 private function moveImages()
 {
     $options = array('path' => DOCROOT . \Config::get('master.image_path.temporary_user'), 'max_size' => 1024000, 'create_path' => true);
     list($is_upload, $upload_files) = \Model_Fleamarket_Image::moveUploadedFile($options);
     \Session::set_flash('upload_files', $upload_files);
     return array($is_upload, $upload_files);
 }