Changeset 20726
- Timestamp:
- 2011/03/18 21:42:22 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_5-dev/data/class/helper/SC_Helper_DB.php
r20718 r20726 744 744 $arrTgtCategory_id[] = $parent_category_id; 745 745 $arrParentID = $this->sfGetParents('dtb_category', 'parent_category_id', 'category_id', $parent_category_id); 746 foreach($arrParentID as $pid) { 747 $arrTgtCategory_id[] = $pid; 748 } 746 $arrTgtCategory_id = array_merge($arrTgtCategory_id, $arrParentID); 749 747 } 750 748 … … 815 813 */ 816 814 function sfGetChildrenArray($table, $pid_name, $id_name, $id) { 817 $objQuery =& SC_Query_Ex::getSingletonInstance();818 $col = $pid_name . "," . $id_name;819 $arrData = $objQuery->select($col, $table);820 821 $arrPID = array();822 $arrPID[] = $id;823 815 $arrChildren = array(); 824 $arrChildren[] = $id; 825 826 $arrRet = SC_Helper_DB_Ex::sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID); 816 $arrRet = array($id); 827 817 828 818 while(count($arrRet) > 0) { 829 819 $arrChildren = array_merge($arrChildren, $arrRet); 830 $arrRet = SC_Helper_DB_Ex::sfGetChildrenArraySub($ arrData, $pid_name, $id_name, $arrRet);820 $arrRet = SC_Helper_DB_Ex::sfGetChildrenArraySub($table, $pid_name, $id_name, $arrRet); 831 821 } 832 822 … … 843 833 * @return array 子IDの配列 844 834 */ 845 function sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID) { 835 function sfGetChildrenArraySub($table, $pid_name, $id_name, $arrPID) { 836 $objQuery =& SC_Query_Ex::getSingletonInstance(); 837 838 $where = "$pid_name IN (" . implode(',', array_fill(0, count($arrPID), '?')) . ")"; 839 840 $ret = $objQuery->select($id_name, $table, $where, $arrPID); 841 846 842 $arrChildren = array(); 847 $max = count($arrData); 848 849 for($i = 0; $i < $max; $i++) { 850 foreach($arrPID as $val) { 851 if($arrData[$i][$pid_name] == $val) { 852 $arrChildren[] = $arrData[$i][$id_name]; 853 } 854 } 855 } 843 foreach ($ret as $val) { 844 $arrChildren[] = $val[$id_name]; 845 } 846 856 847 return $arrChildren; 857 848 } … … 869 860 function sfGetParents($table, $pid_name, $id_name, $id) { 870 861 $arrRet = SC_Helper_DB_Ex::sfGetParentsArray($table, $pid_name, $id_name, $id); 871 // 配列の先頭1つを削除する。872 array_shift($arrRet);873 862 return $arrRet; 874 863 } … … 884 873 */ 885 874 function sfGetParentsArray($table, $pid_name, $id_name, $id) { 886 $objQuery =& SC_Query_Ex::getSingletonInstance();887 $col = $pid_name . "," . $id_name;888 $arrData = $objQuery->select($col, $table);889 890 875 $arrParents = array(); 891 $arrParents[] = $id; 892 $child = $id; 893 894 $ret = SC_Helper_DB_Ex::sfGetParentsArraySub($arrData, $pid_name, $id_name, $child); 895 896 while($ret != "") { 876 $ret = $id; 877 878 while($ret != "0") { 897 879 $arrParents[] = $ret; 898 $ret = SC_Helper_DB_Ex::sfGetParentsArraySub($arrData, $pid_name, $id_name, $ret); 899 } 900 901 $arrParents = array_reverse($arrParents); 880 $ret = SC_Helper_DB_Ex::sfGetParentsArraySub($table, $pid_name, $id_name, $ret); 881 } 902 882 903 883 return $arrParents; … … 905 885 906 886 /* 子ID所属する親IDを取得する */ 907 function sfGetParentsArraySub($arrData, $pid_name, $id_name, $child) { 908 $max = count($arrData); 909 $parent = ""; 910 for($i = 0; $i < $max; $i++) { 911 if($arrData[$i][$id_name] == $child) { 912 $parent = $arrData[$i][$pid_name]; 913 break; 914 } 915 } 887 function sfGetParentsArraySub($table, $pid_name, $id_name, $child) { 888 $objQuery =& SC_Query_Ex::getSingletonInstance(); 889 $parent = $objQuery->get($pid_name, $table, "$id_name = ?", $child); 916 890 return $parent; 917 891 } … … 926 900 // 子カテゴリIDの取得 927 901 $arrRet = SC_Helper_DB_Ex::sfGetChildrenArray("dtb_category", "parent_category_id", "category_id", $category_id); 928 $tmp_where = ""; 929 foreach ($arrRet as $val) { 930 if($tmp_where == "") { 931 $tmp_where.= "category_id IN ( ?"; 932 } else { 933 $tmp_where.= ",? "; 934 } 935 $arrval[] = $val; 936 } 937 $tmp_where.= " ) "; 938 return array($tmp_where, $arrval); 902 903 $where = "category_id IN (" . implode(',', array_fill(0, count($arrRet), '?')) . ")"; 904 905 return array($where, $arrRet); 939 906 } 940 907
Note: See TracChangeset
for help on using the changeset viewer.