예제 #1
0
 /**
  * init.
  */
 public function __construct()
 {
     try {
         IkaGear::logger(__CLASS__);
         $this->smarty()->assign([])->display('bkrs/bkrs.tpl');
     } catch (\Exception $e) {
         $this->catchException($e);
     }
 }
예제 #2
0
 /**
  * init PDO Object.
  *
  * @return Object PDO Object
  */
 public function db()
 {
     if (is_null($this->db)) {
         IkaGear::logger()->info('DB connecting.');
         $this->db = new \PDO('sqlite:' . __DIR__ . '/Ika.db', null, null, [\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_CLASS, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_EMULATE_PREPARES => false]);
         //debug用
         //IkaGear::logger()->debug($this->db->query('SELECT sqlite_version()')->fetchAll());
     }
     return $this->db;
 }
예제 #3
0
 /**
  * 各ControllerでcatchしたExceptionのログを出力する.
  *
  * @param \Exception $e catchしたException
  */
 private function errorLog(\Exception $e)
 {
     $_message = $e->getMessage();
     $_file = $e->getFile();
     if (stripos($_message, 'log4php') !== false || stripos(basename($_file), 'logger.php') !== false) {
         // おそらくロガーの初期化に失敗しているので標準エラーにログを出力する。
         error_log('!!!エラー発生!!!');
         error_log($e);
     } else {
         // おそらくロガーは存在するのでロガーを経由する
         IkaGear::logger()->fatal('!!!エラー発生!!!');
         IkaGear::logger()->fatal($e);
     }
 }
예제 #4
0
 /**
  * init.
  */
 public function __construct()
 {
     try {
         IkaGear::logger(__CLASS__);
         $model = new IndexModel();
         $typeList = $model->getTypeList();
         $brandList = $model->getBrandList();
         $powerList = $model->getPowerList();
         $versionList = $model->getVersionList();
         $gearList = $model->searchGearList($this->searchParams(), $this->sortParams());
         $this->smarty()->assign(['sp' => $this->searchParams(), 'sort' => $this->sortParams(), 'types' => $typeList, 'brands' => $brandList, 'powers' => $powerList, 'versions' => $versionList, 'gears' => $gearList])->display('index/index.tpl');
     } catch (\Exception $e) {
         $this->catchException($e);
     }
 }
예제 #5
0
 /**
  * ギア検索.
  *
  * @param Array $searchParams 検索条件の配列
  * @param Array $sortParams   ソート条件の配列
  *
  * @return 検索結果
  *
  * @todo 検索条件、ソート条件、検索結果をそれぞれオブジェクト化する?
  */
 public function searchGearList($searchParams, $sortParams)
 {
     $sql = 'SELECT * FROM v_gear_list';
     $sqlWhere = [];
     $sqlParams = [];
     if (!empty($searchParams)) {
         if (isset($searchParams['name']) && !empty($searchParams['name'])) {
             $sqlWhere[] = 'name like ?';
             $sqlParams[] = '%' . addcslashes($searchParams['name'], '\\_%') . '%';
         }
         if (isset($searchParams['type']) && !empty($searchParams['type'])) {
             $sqlWhere[] = 'type = ?';
             $sqlParams[] = $searchParams['type'];
         }
         if (isset($searchParams['brand']) && !empty($searchParams['brand'])) {
             $sqlWhere[] = 'brand = ?';
             $sqlParams[] = $searchParams['brand'];
         }
         if (isset($searchParams['mainPower']) && !empty($searchParams['mainPower'])) {
             $sqlWhere[] = 'power = ?';
             $sqlParams[] = $searchParams['mainPower'];
         }
         if (isset($searchParams['rank']) && !empty($searchParams['rank'])) {
             $sqlWhere[] = 'rank = ?';
             $sqlParams[] = $searchParams['rank'];
         }
         if (isset($searchParams['version']) && !empty($searchParams['version'])) {
             foreach ($searchParams['version'] as $sv) {
                 $_in[] = '?';
                 $sqlParams[] = $sv;
             }
             $sqlWhere[] = 'version IN (' . implode(', ', $_in) . ')';
         }
         if (!empty($sqlWhere)) {
             $sql .= ' WHERE ' . implode(' AND ', $sqlWhere);
         }
     }
     if (!empty($sortParams) && isset($sortParams['name']) && isset($sortParams['order'])) {
         $sql .= ' ORDER BY ' . $this->getOrderKey($sortParams['name']) . ' ' . $sortParams['order'];
     }
     IkaGear::logger()->debug(['sql' => $sql, 'params' => $sqlParams]);
     $stmt = $this->db()->prepare($sql);
     $stmt->execute($sqlParams);
     $stmt->setFetchMode(\PDO::FETCH_CLASS | \PDO::FETCH_PROPS_LATE, '\\IkaGear\\model\\object\\GearObject');
     return $stmt->fetchAll();
 }