[22610] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
| 5 | * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved. |
---|
| 6 | * |
---|
| 7 | * http://www.lockon.co.jp/ |
---|
| 8 | * |
---|
| 9 | * This program is free software; you can redistribute it and/or |
---|
| 10 | * modify it under the terms of the GNU General Public License |
---|
| 11 | * as published by the Free Software Foundation; either version 2 |
---|
| 12 | * of the License, or (at your option) any later version. |
---|
| 13 | * |
---|
| 14 | * This program is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this program; if not, write to the Free Software |
---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | /** |
---|
| 25 | * ブロックを管理するヘルパークラス. |
---|
| 26 | * |
---|
| 27 | * @package Helper |
---|
| 28 | * @author pineray |
---|
| 29 | * @version $Id:$ |
---|
| 30 | */ |
---|
| 31 | class SC_Helper_Bloc |
---|
| 32 | { |
---|
| 33 | private $device_type_id = NULL; |
---|
| 34 | |
---|
| 35 | function __construct($devide_type_id = DEVICE_TYPE_PC) |
---|
| 36 | { |
---|
| 37 | $this->device_type_id = $devide_type_id; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | /** |
---|
| 41 | * ブロックの情報を取得. |
---|
| 42 | * |
---|
| 43 | * @param integer $bloc_id ブロックID |
---|
| 44 | * @return array |
---|
| 45 | */ |
---|
[22735] | 46 | public function getBloc($bloc_id) |
---|
[22610] | 47 | { |
---|
| 48 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
| 49 | $col = '*'; |
---|
| 50 | $where = 'bloc_id = ? AND device_type_id = ?'; |
---|
| 51 | $arrRet = $objQuery->getRow($col, 'dtb_bloc', $where, array($bloc_id, $this->device_type_id)); |
---|
| 52 | if (SC_Utils_Ex::isAbsoluteRealPath($arrRet['tpl_path'])) { |
---|
| 53 | $tpl_path = $arrRet['tpl_path']; |
---|
| 54 | } else { |
---|
| 55 | $tpl_path = SC_Helper_PageLayout_Ex::getTemplatePath($this->device_type_id) . BLOC_DIR . $arrRet['tpl_path']; |
---|
| 56 | } |
---|
| 57 | if (file_exists($tpl_path)) { |
---|
| 58 | $arrRet['bloc_html'] = file_get_contents($tpl_path); |
---|
| 59 | } |
---|
| 60 | return $arrRet; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | * ブロック一覧の取得. |
---|
| 65 | * |
---|
| 66 | * @return array |
---|
| 67 | */ |
---|
| 68 | public function getList() |
---|
| 69 | { |
---|
| 70 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
| 71 | $col = '*'; |
---|
| 72 | $where = 'device_type_id = ?'; |
---|
| 73 | $table = 'dtb_bloc'; |
---|
| 74 | $arrRet = $objQuery->select($col, $table, $where, array($this->device_type_id)); |
---|
| 75 | return $arrRet; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | /** |
---|
| 79 | * where句で条件を指定してブロック一覧を取得. |
---|
| 80 | * |
---|
| 81 | * @param string $where |
---|
| 82 | * @param array $sqlval |
---|
| 83 | */ |
---|
| 84 | public function getWhere($where = '', $sqlval = array()) |
---|
| 85 | { |
---|
| 86 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
| 87 | $col = '*'; |
---|
| 88 | $where = 'device_type_id = ? ' . (SC_Utils_Ex::isBlank($where) ? $where : 'AND ' . $where); |
---|
| 89 | array_unshift($sqlval, $this->device_type_id); |
---|
| 90 | $table = 'dtb_bloc'; |
---|
| 91 | $arrRet = $objQuery->select($col, $table, $where, $sqlval); |
---|
| 92 | return $arrRet; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | /** |
---|
| 96 | * ブロックの登録. |
---|
| 97 | * |
---|
| 98 | * @param array $sqlval |
---|
| 99 | * @return multiple 登録成功:ブロックID, 失敗:FALSE |
---|
| 100 | */ |
---|
| 101 | public function save($sqlval) |
---|
| 102 | { |
---|
| 103 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
| 104 | $objQuery->begin(); |
---|
| 105 | |
---|
| 106 | // blod_id が空の場合は新規登録 |
---|
| 107 | $is_new = SC_Utils_Ex::isBlank($sqlval['bloc_id']); |
---|
| 108 | $bloc_dir = SC_Helper_PageLayout_Ex::getTemplatePath($sqlval['device_type_id']) . BLOC_DIR; |
---|
| 109 | // 既存データの重複チェック |
---|
| 110 | if (!$is_new) { |
---|
[22735] | 111 | $arrExists = $this->getBloc($sqlval['bloc_id']); |
---|
[22610] | 112 | |
---|
| 113 | // 既存のファイルが存在する場合は削除しておく |
---|
| 114 | $exists_file = $bloc_dir . $arrExists[0]['filename'] . '.tpl'; |
---|
| 115 | if (file_exists($exists_file)) { |
---|
| 116 | unlink($exists_file); |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | $table = 'dtb_bloc'; |
---|
| 121 | $arrValues = $objQuery->extractOnlyColsOf($table, $sqlval); |
---|
| 122 | $arrValues['tpl_path'] = $sqlval['filename'] . '.tpl'; |
---|
| 123 | $arrValues['update_date'] = 'CURRENT_TIMESTAMP'; |
---|
| 124 | |
---|
| 125 | // 新規登録 |
---|
| 126 | if ($is_new || SC_Utils_Ex::isBlank($arrExists)) { |
---|
| 127 | $objQuery->setOrder(''); |
---|
| 128 | $arrValues['bloc_id'] = 1 + $objQuery->max('bloc_id', $table, 'device_type_id = ?', |
---|
| 129 | array($arrValues['device_type_id'])); |
---|
| 130 | $arrValues['create_date'] = 'CURRENT_TIMESTAMP'; |
---|
| 131 | $objQuery->insert($table, $arrValues); |
---|
| 132 | } |
---|
| 133 | // 更新 |
---|
| 134 | else { |
---|
| 135 | $objQuery->update($table, $arrValues, 'bloc_id = ? AND device_type_id = ?', |
---|
| 136 | array($arrValues['bloc_id'], $arrValues['device_type_id'])); |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | $bloc_path = $bloc_dir . $arrValues['tpl_path']; |
---|
| 140 | if (!SC_Helper_FileManager_Ex::sfWriteFile($bloc_path, $sqlval['bloc_html'])) { |
---|
| 141 | $objQuery->rollback(); |
---|
| 142 | return false; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | $objQuery->commit(); |
---|
| 146 | return $arrValues['bloc_id']; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | /** |
---|
| 150 | * ブロックの削除. |
---|
| 151 | * |
---|
| 152 | * @param integer $bloc_id |
---|
| 153 | * @return boolean |
---|
| 154 | */ |
---|
| 155 | public function delete($bloc_id) |
---|
| 156 | { |
---|
| 157 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
| 158 | $objQuery->begin(); |
---|
| 159 | |
---|
| 160 | $arrExists = $this->getWhere('bloc_id = ? AND deletable_flg = 1', array($bloc_id)); |
---|
| 161 | $is_error = false; |
---|
| 162 | if (!SC_Utils_Ex::isBlank($arrExists)) { |
---|
| 163 | $objQuery->delete('dtb_bloc', 'bloc_id = ? AND device_type_id = ?', |
---|
| 164 | array($arrExists[0]['bloc_id'], $arrExists[0]['device_type_id'])); |
---|
| 165 | $objQuery->delete('dtb_blocposition', 'bloc_id = ? AND device_type_id = ?', |
---|
| 166 | array($arrExists[0]['bloc_id'], $arrExists[0]['device_type_id'])); |
---|
| 167 | |
---|
| 168 | $bloc_dir = SC_Helper_PageLayout_Ex::getTemplatePath($this->device_type_id) . BLOC_DIR; |
---|
| 169 | $exists_file = $bloc_dir . $arrExists[0]['filename'] . '.tpl'; |
---|
| 170 | |
---|
| 171 | // ファイルの削除 |
---|
| 172 | if (file_exists($exists_file)) { |
---|
| 173 | if (!unlink($exists_file)) { |
---|
| 174 | $is_error = true; |
---|
| 175 | } |
---|
| 176 | } |
---|
| 177 | } else { |
---|
| 178 | $is_error = true; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | if ($is_error) { |
---|
| 182 | $objQuery->rollback(); |
---|
| 183 | return false; |
---|
| 184 | } |
---|
| 185 | $objQuery->commit(); |
---|
| 186 | return true; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | /** |
---|
| 190 | * 端末種別IDのメンバー変数を取得. |
---|
| 191 | * |
---|
| 192 | * @return integer 端末種別ID |
---|
| 193 | */ |
---|
| 194 | public function getDeviceTypeID() |
---|
| 195 | { |
---|
| 196 | return $this->device_type_id; |
---|
| 197 | } |
---|
| 198 | } |
---|