- Timestamp:
- 2007/08/24 12:52:51 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/feature-module-update/data/class/util/SC_Utils.php
r15340 r15343 453 453 } 454 454 for($i = 1; $i <= $max; $i++) { 455 if(isset($arrTmp ) && $arrTmp[$i] == "1") {455 if(isset($arrTmp[$i]) && $arrTmp[$i] == "1") { 456 456 $ret.= "1"; 457 457 } else { … … 705 705 } 706 706 707 // カテゴリツリーの取得($products_check:true商品登録済みのものだけ取得)708 function sfGetCategoryList($addwhere = "", $products_check = false, $head = CATEGORY_HEAD) {709 $objQuery = new SC_Query();710 $where = "del_flg = 0";711 712 if($addwhere != "") {713 $where.= " AND $addwhere";714 }715 716 $objQuery->setoption("ORDER BY rank DESC");717 718 if($products_check) {719 $col = "T1.category_id, category_name, level";720 $from = "dtb_category AS T1 LEFT JOIN dtb_category_total_count AS T2 ON T1.category_id = T2.category_id";721 $where .= " AND product_count > 0";722 } else {723 $col = "category_id, category_name, level";724 $from = "dtb_category";725 }726 727 $arrRet = $objQuery->select($col, $from, $where);728 729 $max = count($arrRet);730 for($cnt = 0; $cnt < $max; $cnt++) {731 $id = $arrRet[$cnt]['category_id'];732 $name = $arrRet[$cnt]['category_name'];733 $arrList[$id] = "";734 /*735 for($n = 1; $n < $arrRet[$cnt]['level']; $n++) {736 $arrList[$id].= " ";737 }738 */739 for($cat_cnt = 0; $cat_cnt < $arrRet[$cnt]['level']; $cat_cnt++) {740 $arrList[$id].= $head;741 }742 $arrList[$id].= $name;743 }744 return $arrList;745 }746 747 // カテゴリツリーの取得(親カテゴリのValue:0)748 function sfGetLevelCatList($parent_zero = true) {749 $objQuery = new SC_Query();750 $col = "category_id, category_name, level";751 $where = "del_flg = 0";752 $objQuery->setoption("ORDER BY rank DESC");753 $arrRet = $objQuery->select($col, "dtb_category", $where);754 $max = count($arrRet);755 756 for($cnt = 0; $cnt < $max; $cnt++) {757 if($parent_zero) {758 if($arrRet[$cnt]['level'] == LEVEL_MAX) {759 $arrValue[$cnt] = $arrRet[$cnt]['category_id'];760 } else {761 $arrValue[$cnt] = "";762 }763 } else {764 $arrValue[$cnt] = $arrRet[$cnt]['category_id'];765 }766 767 $arrOutput[$cnt] = "";768 /*769 for($n = 1; $n < $arrRet[$cnt]['level']; $n++) {770 $arrOutput[$cnt].= " ";771 }772 */773 for($cat_cnt = 0; $cat_cnt < $arrRet[$cnt]['level']; $cat_cnt++) {774 $arrOutput[$cnt].= CATEGORY_HEAD;775 }776 $arrOutput[$cnt].= $arrRet[$cnt]['category_name'];777 }778 return array($arrValue, $arrOutput);779 }780 781 707 function sfGetErrorColor($val) { 782 708 if($val != "") { … … 785 711 return ""; 786 712 } 787 788 713 789 714 function sfGetEnabled($val) { … … 998 923 $where = "product_id = ?"; 999 924 $objQuery->delete("dtb_products_class", $where, array($product_id)); 925 926 // 配列の添字を定義 927 $checkArray = array("product_code", "stock", "stock_unlimited", "price01", "price02"); 928 $arrList = SC_Utils_Ex::arrayDefineIndexes($arrList, $checkArray); 929 1000 930 $sqlval['product_id'] = $product_id; 1001 931 $sqlval['classcategory_id1'] = '0'; … … 1432 1362 $category_id = (int) $category_id; 1433 1363 $product_id = (int) $product_id; 1434 if(SC_Utils_Ex::sfIsInt($category_id) && SC_Utils_Ex::sfIsRecord("dtb_category","category_id", $category_id)) { 1364 $objDb = new SC_Helper_DB_Ex(); 1365 if(SC_Utils_Ex::sfIsInt($category_id) && $objDb->sfIsRecord("dtb_category","category_id", $category_id)) { 1435 1366 $g_category_id = $category_id; 1436 } else if (SC_Utils_Ex::sfIsInt($product_id) && SC_Utils_Ex::sfIsRecord("dtb_products","product_id", $product_id, "status = 1")) {1367 } else if (SC_Utils_Ex::sfIsInt($product_id) && $objDb->sfIsRecord("dtb_products","product_id", $product_id, "status = 1")) { 1437 1368 $objQuery = new SC_Query(); 1438 1369 $where = "product_id = ?"; … … 1813 1744 } 1814 1745 1815 if( $_GET['tpl'] != "") {1746 if(isset($_GET['tpl']) && $_GET['tpl'] != "") { 1816 1747 $tpl_name = $_GET['tpl']; 1817 1748 } else { … … 1903 1834 } 1904 1835 1905 function sfCategory_Count($objQuery){1906 $sql = "";1907 1908 //テーブル内容の削除1909 $objQuery->query("DELETE FROM dtb_category_count");1910 $objQuery->query("DELETE FROM dtb_category_total_count");1911 1912 //各カテゴリ内の商品数を数えて格納1913 $sql = " INSERT INTO dtb_category_count(category_id, product_count, create_date) ";1914 $sql .= " SELECT T1.category_id, count(T2.category_id), now() FROM dtb_category AS T1 LEFT JOIN dtb_products AS T2 ";1915 $sql .= " ON T1.category_id = T2.category_id ";1916 $sql .= " WHERE T2.del_flg = 0 AND T2.status = 1 ";1917 $sql .= " GROUP BY T1.category_id, T2.category_id ";1918 $objQuery->query($sql);1919 1920 //子カテゴリ内の商品数を集計する1921 $arrCat = $objQuery->getAll("SELECT * FROM dtb_category");1922 1923 $sql = "";1924 foreach($arrCat as $key => $val){1925 1926 // 子ID一覧を取得1927 $arrRet = sfGetChildrenArray('dtb_category', 'parent_category_id', 'category_id', $val['category_id']);1928 $line = sfGetCommaList($arrRet);1929 1930 $sql = " INSERT INTO dtb_category_total_count(category_id, product_count, create_date) ";1931 $sql .= " SELECT ?, SUM(product_count), now() FROM dtb_category_count ";1932 $sql .= " WHERE category_id IN (" . $line . ")";1933 1934 $objQuery->query($sql, array($val['category_id']));1935 }1936 }1937 1938 1836 // 2つの配列を用いて連想配列を作成する 1939 1837 function sfarrCombine($arrKeys, $arrValues) { … … 1952 1850 1953 1851 return false; 1954 }1955 1956 /* 階層構造のテーブルから子ID配列を取得する */1957 function sfGetChildrenArray($table, $pid_name, $id_name, $id) {1958 $objQuery = new SC_Query();1959 $col = $pid_name . "," . $id_name;1960 $arrData = $objQuery->select($col, $table);1961 1962 $arrPID = array();1963 $arrPID[] = $id;1964 $arrChildren = array();1965 $arrChildren[] = $id;1966 1967 $arrRet = SC_Utils::sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID);1968 1969 while(count($arrRet) > 0) {1970 $arrChildren = array_merge($arrChildren, $arrRet);1971 $arrRet = SC_Utils::sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrRet);1972 }1973 1974 return $arrChildren;1975 }1976 1977 /* 親ID直下の子IDをすべて取得する */1978 function sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID) {1979 $arrChildren = array();1980 $max = count($arrData);1981 1982 for($i = 0; $i < $max; $i++) {1983 foreach($arrPID as $val) {1984 if($arrData[$i][$pid_name] == $val) {1985 $arrChildren[] = $arrData[$i][$id_name];1986 }1987 }1988 }1989 return $arrChildren;1990 }1991 1992 1993 /* 階層構造のテーブルから親ID配列を取得する */1994 function sfGetParentsArray($table, $pid_name, $id_name, $id) {1995 $objQuery = new SC_Query();1996 $col = $pid_name . "," . $id_name;1997 $arrData = $objQuery->select($col, $table);1998 1999 $arrParents = array();2000 $arrParents[] = $id;2001 $child = $id;2002 2003 $ret = SC_Utils::sfGetParentsArraySub($arrData, $pid_name, $id_name, $child);2004 2005 while($ret != "") {2006 $arrParents[] = $ret;2007 $ret = SC_Utils::sfGetParentsArraySub($arrData, $pid_name, $id_name, $ret);2008 }2009 2010 $arrParents = array_reverse($arrParents);2011 2012 return $arrParents;2013 1852 } 2014 1853 … … 2349 2188 } 2350 2189 2190 /** 2191 * 配列の添字が未定義の場合は空文字を代入して定義する. 2192 * 2193 * @param array $array 添字をチェックする配列 2194 * @param array $defineIndexes チェックする添字 2195 * @return array 添字を定義した配列 2196 */ 2197 function arrayDefineIndexes($array, $defineIndexes) { 2198 foreach ($defineIndexes as $key) { 2199 if (!isset($array[$key])) $array[$key] = ""; 2200 } 2201 return $array; 2202 } 2203 2351 2204 /* デバッグ用 ------------------------------------------------------------------------------------------------*/ 2352 2205 function sfPrintR($obj) {
Note: See TracChangeset
for help on using the changeset viewer.
