/**
  * フリーマーケット詳細表示画面
  *
  * @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 private
  * @param
  * @return void
  * @author kobayashi
  */
 private function createFieldsetFleamarketAbouts()
 {
     $fieldsets = array();
     foreach (\Model_Fleamarket_About::getAboutTitles() as $id => $title) {
         $fieldset = Fieldset::forge("fleamarket_about_{$id}");
         if (isset($this->fleamarket_abouts[$id])) {
             $fieldset->add_model($this->fleamarket_abouts[$id])->populate($this->fleamarket_abouts[$id], false);
         } else {
             $fieldset->add_model('Model_Fleamarket_About');
         }
         if (\Input::method() == 'POST') {
             $fieldset->field('description')->set_value(\Input::post("fleamarket_about_{$id}_description"));
         }
         $fieldsets[$id] = $fieldset;
     }
     return $fieldsets;
 }
            $max_booth = mt_rand(20, 100);
            $reservation_booth_limit = mt_rand(1, 10);
            $entry_style_line = array('fleamarket_id' => $fleamarket_id, 'entry_style_id' => $entry_style_id, 'booth_fee' => $booth_fee, 'max_booth' => $max_booth, 'reservation_booth_limit' => $reservation_booth_limit, 'created_user' => 0, 'updated_user' => null, 'created_at' => \Date::forge()->format('mysql'));
            \Model_Fleamarket_Entry_Style::forge($entry_style_line)->save();
        }
    }
    // フリマ説明情報
    $about_rand = mt_rand(0, 7);
    if ($about_rand > 0) {
        $about_list = array_rand($about_titles, $about_rand);
        if (!is_array($about_list)) {
            $about_list = (array) $about_list;
        }
        foreach ($about_list as $about_id) {
            $about_line = array('fleamarket_id' => $fleamarket_id, 'about_id' => $about_id, 'title' => $about_titles[$about_id], 'description' => $abouts[$about_id], 'created_user' => 0, 'updated_user' => null, 'created_at' => \Date::forge()->format('mysql'));
            \Model_Fleamarket_About::forge($about_line)->save();
        }
    }
}
/**
 * 住所から都道府県を省く
 *
 * @access private
 * @param string $address 住所
 * @return string
 * @author ida
 */
function getAddress($address)
{
    $address_pattern = '/(東京都|北海道|(?:京都|大阪)府|.{6,9}県)' . '((?:四日市|廿日市|野々市|かすみがうら|つくばみらい|いちき串木野)市|' . '(?:杵島郡大町|余市郡余市|高市郡高取)町|' . '.{3,12}市.{3,12}区|.{3,9}区|.{3,15}市(?=.*市)|' . '.{3,15}市|.{6,27}町(?=.*町)|.{6,27}町|' . '.{9,24}村(?=.*村)|.{9,24}村)(.*)/';
    preg_match($address_pattern, $address, $matches);
                    <input type="file" class="form-control" name="upload<?php 
    echo $priority;
    ?>
">
                  </td>
                </tr>
                <?php 
}
?>
              </table>
            </div>
            <h3>説明</h3>
            <div>
              <table class="table-fixed table">
                <?php 
foreach (\Model_Fleamarket_About::getAboutTitles() as $id => $title) {
    ?>
                <tr>
                  <th><?php 
    echo e($title);
    ?>
</th>
                  <td>
                    <textarea name="fleamarket_about_<?php 
    echo $id;
    ?>
_description" class="form-control" cols="55" rows="8"><?php 
    echo e($fieldsets['fleamarket_abouts'][$id]->field('description')->value);
    ?>
</textarea>
                    <?php 
 /**
  * フリマ説明情報を取得する
  *
  * @access private
  * @param mixed fleamarket_id
  * @return object
  * @author ida
  */
 private function getFleamarketAbout($fleamarket_id)
 {
     $result = \Model_Fleamarket_About::findFirstBy(array('fleamarket_id' => $fleamarket_id, 'about_id' => \Model_Fleamarket_About::ACCESS));
     return $result;
 }
 /**
  * フリマ説明情報のフィールドセットを取得する
  *
  * @access private
  * @param
  * @return object Fieldsetオブジェクト
  * @author ida
  */
 private function getFleamarketAboutFieldset()
 {
     $fieldset = \Session::get_flash('fleamarket_about.fieldset');
     if (!$fieldset) {
         $fieldset = \Model_Fleamarket_About::createFieldset();
     }
     $input = \Input::post('fa');
     if (!empty($input)) {
         $fieldset->populate($input);
     }
     return $fieldset;
 }
 /**
  * ユーザーにメールを送信
  *
  * 渡されていない場合、entry_statusで決める
  * 渡されてきた場合、$mail_typeで決める
  *
  * @access private
  * @para object $user ユーザ情報
  * @para string $template_name 送信するメール名(テンプレート名)
  * @return void
  * @author kobayashi
  * @author ida
  */
 public function sendmail($user = null, $template_name = null)
 {
     if (empty($user)) {
         return false;
     }
     $params = array();
     $objects = array('entry' => $this, 'fleamarket' => $this->fleamarket, 'fleamarket_entry_style' => $this->fleamarket_entry_style, 'user' => $this->user, 'location' => $this->fleamarket->location);
     $fleamarket_abouts = array();
     foreach ($this->fleamarket->fleamarket_abouts as $fleamarket_about) {
         $fleamarket_abouts[$fleamarket_about->about_id] = $fleamarket_about;
     }
     foreach (Model_Fleamarket_About::getAboutTitles() as $id => $title) {
         if (isset($fleamarket_abouts[$id])) {
             $objects["fleamarket_about_{$id}"] = $fleamarket_abouts[$id];
         } else {
             $params["fleamarket_about_{$id}.description"] = '';
         }
     }
     foreach ($objects as $name => $obj) {
         foreach (array_keys($obj->properties()) as $column) {
             $params["{$name}.{$column}"] = $obj->get($column);
         }
     }
     $entry_styles = \Config::get('master.entry_styles');
     $params['fleamarket_entry_style.entry_style_name'] = $entry_styles[$this->fleamarket_entry_style->entry_style_id];
     // 出店形態を成形
     $entry_style_list = array_map(function ($obj) use($entry_styles) {
         return $entry_styles[$obj->entry_style_id];
     }, $this->fleamarket->fleamarket_entry_styles);
     $params['fleamarket_entry_styles.entry_style_name'] = implode('/', $entry_style_list);
     // 出店形態:金額を成形
     $fee_list = array_map(function ($obj) use($entry_styles) {
         return $entry_styles[$obj->entry_style_id] . ':' . number_format($obj->booth_fee);
     }, $this->fleamarket->fleamarket_entry_styles);
     $params['fleamarket_entry_styles.fee'] = implode('/', $fee_list);
     foreach (array('fleamarket.event_time_start', 'fleamarket.event_time_end') as $column) {
         $params[$column] = substr($params[$column], 0, 5);
     }
     if ($template_name) {
         $user->sendmail($template_name, $params);
     } elseif ($this->entry_status == \Model_Entry::ENTRY_STATUS_RESERVED) {
         $user->sendmail('reservation', $params);
     } elseif ($this->entry_status == \Model_Entry::ENTRY_STATUS_WAITING) {
         $user->sendmail('waiting', $params);
     }
 }