- Timestamp:
- 2013/05/02 18:11:36 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_12-dev/data/class/helper/SC_Helper_DB.php
r22595 r22796 29 29 * @version $Id:SC_Helper_DB.php 15532 2007-08-31 14:39:46Z nanasess $ 30 30 */ 31 class SC_Helper_DB 32 { 31 class SC_Helper_DB { 33 32 34 33 // {{{ properties … … 65 64 * 引数 $add == false でカラムが存在しない場合 false 66 65 */ 67 function sfColumnExists($table_name, $col_name, $col_type = '', $dsn = '', $add = false) 68 { 66 function sfColumnExists($table_name, $col_name, $col_type = '', $dsn = '', $add = false) { 69 67 $dbFactory = SC_DB_DBFactory_Ex::getInstance(); 70 68 $dsn = $dbFactory->getDSN($dsn); … … 104 102 * $add == false で, データが存在しない場合 false 105 103 */ 106 function sfDataExists($table_name, $where, $arrWhereVal, $dsn = '', $sql = '', $add = false) 107 { 104 function sfDataExists($table_name, $where, $arrWhereVal, $dsn = '', $sql = '', $add = false) { 108 105 $dbFactory = SC_DB_DBFactory_Ex::getInstance(); 109 106 $dsn = $dbFactory->getDSN($dsn); … … 134 131 * @return array 店舗基本情報の配列 135 132 */ 136 function sfGetBasisData($force = false, $col = '') 137 { 133 function sfGetBasisData($force = false, $col = '') { 138 134 static $data = array(); 139 135 … … 157 153 158 154 /** 159 * 基本情報のキャッシュデータを取得する160 *161 * @param boolean $generate キャッシュファイルが無い時、DBのデータを基にキャッシュを生成するか162 * @return array 店舗基本情報の配列163 */164 function sfGetBasisDataCache($generate = false)165 {166 // テーブル名167 $name = 'dtb_baseinfo';168 // キャッシュファイルパス169 $filepath = MASTER_DATA_REALDIR . $name . '.serial';170 // ファイル存在確認171 if (!file_exists($filepath) && $generate) {172 // 存在していなければキャッシュ生成173 $this->sfCreateBasisDataCache();174 }175 // 戻り値初期化176 $cacheData = array();177 // キャッシュファイルが存在すれば読み込む178 if (file_exists($filepath)) {179 // キャッシュデータファイルを読み込みアンシリアライズした配列を取得180 $cacheData = unserialize(file_get_contents($filepath));181 }182 // return183 return $cacheData;184 }185 186 /**187 * 基本情報のキャッシュデータファイルを生成する188 * データはsfGetBasisDataより取得。189 *190 * このメソッドが直接呼ばれるのは、191 *「基本情報管理>SHOPマスター」の更新完了後。192 * sfGetBasisDataCacheでは、193 * キャッシュデータファイルが無い場合に呼ばれます。194 *195 * @return bool キャッシュデータファイル生成結果196 */197 function sfCreateBasisDataCache()198 {199 // テーブル名200 $name = 'dtb_baseinfo';201 // キャッシュファイルパス202 $filepath = MASTER_DATA_REALDIR . $name . '.serial';203 // データ取得204 $arrData = $this->sfGetBasisData(true);205 // シリアライズ206 $data = serialize($arrData);207 // ファイルを書き出しモードで開く208 $handle = fopen($filepath, 'w');209 if (!$handle) {210 // ファイル生成失敗211 return false;212 }213 // ファイルの内容を書き出す.214 $res = fwrite($handle, $data);215 // ファイルを閉じる216 fclose($handle);217 if ( $res === false) {218 // ファイル生成失敗219 return false;220 }221 // ファイル生成成功222 return true;223 }224 225 /**226 155 * 基本情報の登録数を取得する 227 156 * … … 229 158 * @deprecated 230 159 */ 231 function sfGetBasisCount() 232 { 160 function sfGetBasisCount() { 233 161 $objQuery =& SC_Query_Ex::getSingletonInstance(); 234 162 … … 241 169 * @return boolean 有無 242 170 */ 243 function sfGetBasisExists() 244 { 171 function sfGetBasisExists() { 245 172 $objQuery =& SC_Query_Ex::getSingletonInstance(); 246 173 … … 249 176 250 177 /* 選択中のアイテムのルートカテゴリIDを取得する */ 251 function sfGetRootId() 252 { 178 function sfGetRootId() { 253 179 254 180 if (!$this->g_root_on) { … … 286 212 * @return array オーダー前ポイントの配列 287 213 */ 288 function sfGetRollbackPoint($order_id, $use_point, $add_point, $order_status) 289 { 214 function sfGetRollbackPoint($order_id, $use_point, $add_point, $order_status) { 290 215 $objQuery =& SC_Query_Ex::getSingletonInstance(); 291 216 $arrRet = $objQuery->select('customer_id', 'dtb_order', 'order_id = ?', array($order_id)); … … 319 244 * @return array カテゴリツリーの配列 320 245 */ 321 function sfGetCatTree($parent_category_id, $count_check = false) 322 { 246 function sfGetCatTree($parent_category_id, $count_check = false) { 323 247 $objQuery =& SC_Query_Ex::getSingletonInstance(); 324 248 $col = ''; … … 343 267 $arrRet = $objQuery->select($col, $from, $where); 344 268 345 $arrParentID = SC_ Utils_Ex::getTreeTrail($parent_category_id, 'category_id', 'parent_category_id', $arrRet);269 $arrParentID = SC_Helper_DB_Ex::sfGetParents('dtb_category', 'parent_category_id', 'category_id', $parent_category_id); 346 270 347 271 foreach ($arrRet as $key => $array) { … … 366 290 * @see sfGetCatTree() 367 291 */ 368 function findTree(&$arrTree, $parent, &$result) 369 { 292 function findTree(&$arrTree, $parent, &$result) { 370 293 if ($result[count($result) - 1]['parent_category_id'] === 0) { 371 294 return; … … 391 314 * @return array カテゴリツリーの配列 392 315 */ 393 function sfGetMultiCatTree($product_id, $count_check = false) 394 { 316 function sfGetMultiCatTree($product_id, $count_check = false) { 395 317 $objQuery =& SC_Query_Ex::getSingletonInstance(); 396 318 $col = ''; … … 440 362 * @return string 親カテゴリを連結した文字列 441 363 */ 442 function sfGetCatCombName($category_id) 443 { 364 function sfGetCatCombName($category_id) { 444 365 // 商品が属するカテゴリIDを縦に取得 445 366 $objQuery =& SC_Query_Ex::getSingletonInstance(); … … 461 382 462 383 /** 384 * 指定したカテゴリIDのカテゴリを取得する. 385 * 386 * @param integer $category_id カテゴリID 387 * @return array 指定したカテゴリIDのカテゴリ 388 */ 389 function sfGetCat($category_id) { 390 $objQuery =& SC_Query_Ex::getSingletonInstance(); 391 392 // カテゴリを取得する 393 $arrVal = array($category_id); 394 $res = $objQuery->select('category_id AS id, category_name AS name', 'dtb_category', 'category_id = ?', $arrVal); 395 396 return $res[0]; 397 } 398 399 /** 463 400 * 指定したカテゴリIDの大カテゴリを取得する. 464 401 * … … 466 403 * @return array 指定したカテゴリIDの大カテゴリ 467 404 */ 468 function sfGetFirstCat($category_id) 469 { 405 function sfGetFirstCat($category_id) { 470 406 // 商品が属するカテゴリIDを縦に取得 471 407 $objQuery =& SC_Query_Ex::getSingletonInstance(); … … 492 428 * @return array カテゴリツリーの配列 493 429 */ 494 function sfGetCategoryList($addwhere = '', $products_check = false, $head = CATEGORY_HEAD) 495 { 430 function sfGetCategoryList($addwhere = '', $products_check = false, $head = CATEGORY_HEAD) { 496 431 $objQuery =& SC_Query_Ex::getSingletonInstance(); 497 432 $where = 'del_flg = 0'; … … 532 467 * @return array カテゴリツリーの配列 533 468 */ 534 function sfGetLevelCatList($parent_zero = true) 535 { 469 function sfGetLevelCatList($parent_zero = true) { 536 470 $objQuery =& SC_Query_Ex::getSingletonInstance(); 537 471 … … 582 516 * 583 517 */ 584 function sfGetCategoryId($product_id, $category_id = 0, $closed = false) 585 { 518 function sfGetCategoryId($product_id, $category_id = 0, $closed = false) { 586 519 if ($closed) { 587 520 $status = ''; … … 610 543 * @return void 611 544 */ 612 function addProductBeforCategories($category_id, $product_id) 613 { 545 function addProductBeforCategories($category_id, $product_id) { 614 546 $objQuery =& SC_Query_Ex::getSingletonInstance(); 615 547 … … 632 564 * @return void 633 565 */ 634 function addProductAfterCategories($category_id, $product_id) 635 { 566 function addProductAfterCategories($category_id, $product_id) { 636 567 $sqlval = array('category_id' => $category_id, 637 568 'product_id' => $product_id); … … 665 596 * @return void 666 597 */ 667 function removeProductByCategories($category_id, $product_id) 668 { 598 function removeProductByCategories($category_id, $product_id) { 669 599 $objQuery =& SC_Query_Ex::getSingletonInstance(); 670 600 $objQuery->delete('dtb_product_categories', … … 679 609 * @return void 680 610 */ 681 function updateProductCategories($arrCategory_id, $product_id) 682 { 611 function updateProductCategories($arrCategory_id, $product_id) { 683 612 $objQuery =& SC_Query_Ex::getSingletonInstance(); 684 613 … … 713 642 * @return void 714 643 */ 715 function sfCountCategory($objQuery = NULL, $is_force_all_count = false) 716 { 644 function sfCountCategory($objQuery = NULL, $is_force_all_count = false) { 717 645 $objProduct = new SC_Product_Ex(); 718 646 … … 891 819 * @param array 子ID の配列 892 820 */ 893 function sfGetChildsID($table, $pid_name, $id_name, $id) 894 { 821 function sfGetChildsID($table, $pid_name, $id_name, $id) { 895 822 $arrRet = $this->sfGetChildrenArray($table, $pid_name, $id_name, $id); 896 823 return $arrRet; … … 906 833 * @return array 子IDの配列 907 834 */ 908 function sfGetChildrenArray($table, $pid_name, $id_name, $id) 909 { 835 function sfGetChildrenArray($table, $pid_name, $id_name, $id) { 910 836 $arrChildren = array(); 911 837 $arrRet = array($id); … … 928 854 * @return array 子IDの配列 929 855 */ 930 function sfGetChildrenArraySub($table, $pid_name, $id_name, $arrPID) 931 { 856 function sfGetChildrenArraySub($table, $pid_name, $id_name, $arrPID) { 932 857 $objQuery =& SC_Query_Ex::getSingletonInstance(); 933 858 … … 949 874 * @return array 親IDの配列 950 875 */ 951 function sfGetParents($table, $pid_name, $id_name, $id) 952 { 876 function sfGetParents($table, $pid_name, $id_name, $id) { 953 877 $arrRet = SC_Helper_DB_Ex::sfGetParentsArray($table, $pid_name, $id_name, $id); 954 878 return $arrRet; … … 964 888 * @return array 親IDの配列 965 889 */ 966 function sfGetParentsArray($table, $pid_name, $id_name, $id) 967 { 890 function sfGetParentsArray($table, $pid_name, $id_name, $id) { 968 891 $arrParents = array(); 969 892 $ret = $id; … … 980 903 981 904 /* 子ID所属する親IDを取得する */ 982 function sfGetParentsArraySub($table, $pid_name, $id_name, $child) 983 { 905 function sfGetParentsArraySub($table, $pid_name, $id_name, $child) { 984 906 if (SC_Utils_Ex::isBlank($child)) { 985 907 return false; … … 999 921 * @return array 商品を検索する場合の配列 1000 922 */ 1001 function sfGetCatWhere($category_id) 1002 { 923 function sfGetCatWhere($category_id) { 1003 924 // 子カテゴリIDの取得 1004 925 $arrRet = SC_Helper_DB_Ex::sfGetChildrenArray('dtb_category', 'parent_category_id', 'category_id', $category_id); … … 1019 940 * @return array SELECT ボックス用リストの配列 1020 941 */ 1021 function sfGetIDValueList($table, $keyname, $valname, $where = '', $arrVal = array()) 1022 { 942 function sfGetIDValueList($table, $keyname, $valname, $where = '', $arrVal = array()) { 1023 943 $objQuery =& SC_Query_Ex::getSingletonInstance(); 1024 944 $col = "$keyname, $valname"; … … 1045 965 * @return void 1046 966 */ 1047 function sfRankUp($table, $colname, $id, $andwhere = '') 1048 { 967 function sfRankUp($table, $colname, $id, $andwhere = '') { 1049 968 $objQuery =& SC_Query_Ex::getSingletonInstance(); 1050 969 $objQuery->begin(); … … 1097 1016 * @return void 1098 1017 */ 1099 function sfRankDown($table, $colname, $id, $andwhere = '') 1100 { 1018 function sfRankDown($table, $colname, $id, $andwhere = '') { 1101 1019 $objQuery =& SC_Query_Ex::getSingletonInstance(); 1102 1020 $objQuery->begin(); … … 1149 1067 * @return void 1150 1068 */ 1151 function sfMoveRank($tableName, $keyIdColumn, $keyId, $pos, $where = '') 1152 { 1069 function sfMoveRank($tableName, $keyIdColumn, $keyId, $pos, $where = '') { 1153 1070 $objQuery =& SC_Query_Ex::getSingletonInstance(); 1154 1071 $objQuery->begin(); … … 1277 1194 * @return array 特定のカラムの配列 1278 1195 */ 1279 function sfGetParentsCol($objQuery, $table, $id_name, $col_name, $arrId) 1280 { 1196 function sfGetParentsCol($objQuery, $table, $id_name, $col_name, $arrId) { 1281 1197 $col = $col_name; 1282 1198 $len = count($arrId); … … 1310 1226 * @return void 1311 1227 */ 1312 function sfMoveCatRank($objQuery, $table, $id_name, $cat_name, $old_catid, $new_catid, $id) 1313 { 1228 function sfMoveCatRank($objQuery, $table, $id_name, $cat_name, $old_catid, $new_catid, $id) { 1314 1229 if ($old_catid == $new_catid) { 1315 1230 return; … … 1350 1265 * @return bool レコードが存在する場合 true 1351 1266 */ 1352 function sfIsRecord($table, $col, $arrVal, $addwhere = '') 1353 { 1267 function sfIsRecord($table, $col, $arrVal, $addwhere = '') { 1354 1268 $objQuery =& SC_Query_Ex::getSingletonInstance(); 1355 1269 $arrCol = preg_split('/[, ]/', $col); … … 1384 1298 * @return void 1385 1299 */ 1386 function sfCountMaker($objQuery) 1387 { 1300 function sfCountMaker($objQuery) { 1388 1301 $sql = ''; 1389 1302 … … 1409 1322 * 1410 1323 */ 1411 function sfGetMakerId($product_id, $maker_id = 0, $closed = false) 1412 { 1324 function sfGetMakerId($product_id, $maker_id = 0, $closed = false) { 1413 1325 if ($closed) { 1414 1326 $status = ''; … … 1444 1356 * @return array カテゴリツリーの配列 1445 1357 */ 1446 function sfGetMakerList($addwhere = '', $products_check = false) 1447 { 1358 function sfGetMakerList($addwhere = '', $products_check = false) { 1448 1359 $objQuery =& SC_Query_Ex::getSingletonInstance(); 1449 1360 $where = 'del_flg = 0'; … … 1482 1393 * @return integer 税金額 1483 1394 */ 1484 function sfTax($price) 1485 { 1395 function sfTax($price) { 1486 1396 // 店舗基本情報を取得 1487 1397 $CONF = SC_Helper_DB_Ex::sfGetBasisData(); … … 1497 1407 * @return integer 税金付与した金額 1498 1408 */ 1499 function sfCalcIncTax($price, $tax = null, $tax_rule = null) 1500 { 1409 function sfCalcIncTax($price, $tax = null, $tax_rule = null) { 1501 1410 // 店舗基本情報を取得 1502 1411 $CONF = SC_Helper_DB_Ex::sfGetBasisData(); 1503 $tax = $tax === null ? $CONF['tax'] : $tax; 1504 $tax_rule = $tax_rule === null ? $CONF['tax_rule'] : $tax_rule; 1505 1506 return SC_Utils_Ex::sfCalcIncTax($price, $tax, $tax_rule); 1412 1413 return SC_Utils_Ex::sfCalcIncTax($price, $CONF['tax'], $CONF['tax_rule']); 1507 1414 } 1508 1415 … … 1514 1421 * @return integer 加算ポイント 1515 1422 */ 1516 function sfGetAddPoint($totalpoint, $use_point) 1517 { 1423 function sfGetAddPoint($totalpoint, $use_point) { 1518 1424 // 店舗基本情報を取得 1519 1425 $CONF = SC_Helper_DB_Ex::sfGetBasisData(); … … 1530 1436 * @return void 1531 1437 */ 1532 function sfExecSqlByFile($sqlFilePath) 1533 { 1438 function sfExecSqlByFile($sqlFilePath) { 1534 1439 if (file_exists($sqlFilePath)) { 1535 1440 $objQuery =& SC_Query_Ex::getSingletonInstance(); … … 1552 1457 * @return bool 商品規格が存在する場合:true, それ以外:false 1553 1458 */ 1554 function sfHasProductClass($product_id) 1555 { 1459 function sfHasProductClass($product_id) { 1556 1460 if (!SC_Utils_Ex::sfIsInt($product_id)) return false; 1557 1461 … … 1562 1466 return $exists; 1563 1467 } 1564 1565 /**1566 * 店舗基本情報を登録する1567 *1568 * @param array $arrData 登録するデータ1569 * @return void1570 */1571 static function registerBasisData($arrData)1572 {1573 $objQuery =& SC_Query_Ex::getSingletonInstance();1574 1575 $arrData = $objQuery->extractOnlyColsOf('dtb_baseinfo', $arrData);1576 1577 if (isset($arrData['regular_holiday_ids']) && is_array($arrData['regular_holiday_ids'])) {1578 // 定休日をパイプ区切りの文字列に変換1579 $arrData['regular_holiday_ids'] = implode('|', $arrData['regular_holiday_ids']);1580 }1581 1582 $arrData['update_date'] = 'CURRENT_TIMESTAMP';1583 1584 // UPDATEの実行1585 $ret = $objQuery->update('dtb_baseinfo', $arrData);1586 GC_Utils_Ex::gfPrintLog('dtb_baseinfo に UPDATE を実行しました。');1587 1588 // UPDATE できなかった場合、INSERT1589 if ($ret == 0) {1590 $arrData['id'] = 1;1591 $ret = $objQuery->insert('dtb_baseinfo', $arrData);1592 GC_Utils_Ex::gfPrintLog('dtb_baseinfo に INSERT を実行しました。');1593 }1594 }1595 1596 /**1597 * レコード件数を計算.1598 *1599 * @param string $table1600 * @param string $where1601 * @param array $arrval1602 * @return integer レコード件数1603 */1604 public function countRecords($table, $where = '', $arrval = array())1605 {1606 $objQuery =& SC_Query_Ex::getSingletonInstance();1607 $col = 'COUNT(*)';1608 return $objQuery->get($col, $table, $where, $arrval);1609 }1610 1468 }
Note: See TracChangeset
for help on using the changeset viewer.