Пример #1
0
 public function doAction($arrParam)
 {
     $arrRequest = $this->doInitParam($arrParam);
     if (!$this->isParamError()) {
         $category_id = $arrRequest['BrowseNodeId'];
         if ($category_id && !SC_Helper_DB_Ex::sfIsRecord('dtb_category', 'category_id', (array) $category_id, 'del_flg = 0')) {
             $category_id = '0';
         } else {
             if (SC_Utils_Ex::isBlank($category_id)) {
                 $category_id = '0';
             }
         }
         // LC_Page_Products_CategoryList::lfGetCategories() と相当類似しているので共通化したい
         $arrCategory = null;
         // 選択されたカテゴリ
         $arrChildren = array();
         // 子カテゴリ
         $arrAll = SC_Helper_DB_Ex::sfGetCatTree($category_id, true);
         foreach ($arrAll as $category) {
             if ($category_id != 0 && $category['category_id'] == $category_id) {
                 $arrCategory = $category;
                 continue;
             }
             if ($category['parent_category_id'] != $category_id) {
                 continue;
             }
             $arrGrandchildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrAll, 'parent_category_id', 'category_id', $category['category_id']);
             $category['has_children'] = count($arrGrandchildrenID) > 0;
             $arrChildren[] = $category;
         }
         if (!SC_Utils_Ex::isBlank($arrCategory)) {
             $arrData = array('BrowseNodeId' => $category_id, 'Name' => $arrCategory['category_name'], 'PageURL' => HTTP_URL . 'products/list.php?category_id=' . $arr['category_id'], 'has_children' => count($arrChildren) > 0);
         } else {
             $arrData = array('BrowseNodeId' => $category_id, 'Name' => 'ホーム', 'PageURL' => HTTP_URL, 'has_children' => count($arrChildren) > 0);
         }
         if (!SC_Utils_Ex::isBlank($arrChildren)) {
             $arrData['Children'] = array();
             foreach ($arrChildren as $category) {
                 $arrData['Children']['BrowseNode'][] = array('BrowseNodeId' => $category['category_id'], 'Name' => $category['category_name'], 'PageURL' => HTTP_URL . 'products/list.php?category_id=' . $category['category_id'], 'has_children' => $category['has_children']);
             }
         }
         $this->setResponse('BrowseNode', $arrData);
         // TODO: Ancestors 親ノード
         return true;
     }
     return false;
 }
 /**
  * メインカテゴリの取得.
  *
  * @param  boolean $count_check 登録商品数をチェックする場合はtrue
  * @return array   $arrMainCat メインカテゴリの配列を返す
  */
 public function lfGetMainCat($count_check = false)
 {
     $objQuery =& SC_Query_Ex::getSingletonInstance();
     $col = '*';
     $from = 'dtb_category left join dtb_category_total_count ON dtb_category.category_id = dtb_category_total_count.category_id';
     // メインカテゴリとその直下のカテゴリを取得する。
     $where = 'level <= 2 AND del_flg = 0';
     // 登録商品数のチェック
     if ($count_check) {
         $where .= ' AND product_count > 0';
     }
     $objQuery->setOption('ORDER BY rank DESC');
     $arrRet = $objQuery->select($col, $from, $where);
     // メインカテゴリを抽出する。
     $arrMainCat = array();
     foreach ($arrRet as $cat) {
         if ($cat['level'] != 1) {
             continue;
         }
         // 子カテゴリを持つかどうかを調べる。
         $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrRet, 'parent_category_id', 'category_id', $cat['category_id']);
         $cat['has_children'] = count($arrChildrenID) > 0;
         $arrMainCat[] = $cat;
     }
     return $arrMainCat;
 }
 /**
  * 選択されたカテゴリとその子カテゴリの情報を取得し、
  * ページオブジェクトに格納する。
  *
  * @param string $category_id カテゴリID
  * @param boolean $count_check 有効な商品がないカテゴリを除くかどうか
  * @param object &$objPage ページオブジェクト
  * @return void
  */
 function lfGetCategories($category_id, $count_check = false, &$objPage)
 {
     // カテゴリの正しいIDを取得する。
     $category_id = $this->lfCheckCategoryId($category_id);
     if ($category_id == 0) {
         SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND);
     }
     $arrCategory = null;
     // 選択されたカテゴリ
     $arrChildren = array();
     // 子カテゴリ
     $arrAll = SC_Helper_DB_Ex::sfGetCatTree($category_id, $count_check);
     foreach ($arrAll as $category) {
         // 選択されたカテゴリの場合
         if ($category['category_id'] == $category_id) {
             $arrCategory = $category;
             continue;
         }
         // 関係のないカテゴリはスキップする。
         if ($category['parent_category_id'] != $category_id) {
             continue;
         }
         // 子カテゴリの場合は、孫カテゴリが存在するかどうかを調べる。
         $arrGrandchildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrAll, 'parent_category_id', 'category_id', $category['category_id']);
         $category['has_children'] = count($arrGrandchildrenID) > 0;
         $arrChildren[] = $category;
     }
     if (!isset($arrCategory)) {
         SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND);
     }
     // 子カテゴリの商品数を合計する。
     $children_product_count = 0;
     foreach ($arrChildren as $category) {
         $children_product_count += $category['product_count'];
     }
     // 選択されたカテゴリに直属の商品がある場合は、子カテゴリの先頭に追加する。
     if ($arrCategory['product_count'] > $children_product_count) {
         $arrCategory['product_count'] -= $children_product_count;
         // 子カテゴリの商品数を除く。
         $arrCategory['has_children'] = false;
         // 商品一覧ページに遷移させるため。
         array_unshift($arrChildren, $arrCategory);
     }
     return array('arrChildren' => $arrChildren, 'arrCategory' => $arrCategory);
 }
 /**
  * 選択されたカテゴリーとその子カテゴリーの情報を取得し、
  * ページオブジェクトに格納する。
  *
  * @param string $category_id カテゴリーID
  * @param boolean $count_check 有効な商品がないカテゴリーを除くかどうか
  * @param object &$objPage ページオブジェクト
  * @return void
  */
 function lfGetCategories($category_id, $count_check = false, &$objPage)
 {
     $objDb = new SC_Helper_DB_Ex();
     // カテゴリーの正しいIDを取得する。
     $arrCategory_id = $objDb->sfGetCategoryId('', $category_id);
     $category_id = $arrCategory_id[0];
     if ($category_id == 0) {
         SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND, "", false, "", true);
     }
     $arrCategory = null;
     // 選択されたカテゴリー
     $arrChildren = array();
     // 子カテゴリー
     $arrAll = $objDb->sfGetCatTree($category_id, $count_check);
     foreach ($arrAll as $category) {
         // 選択されたカテゴリーの場合
         if ($category['category_id'] == $category_id) {
             $arrCategory = $category;
             continue;
         }
         // 関係のないカテゴリーはスキップする。
         if ($category['parent_category_id'] != $category_id) {
             continue;
         }
         // 子カテゴリーの場合は、孫カテゴリーが存在するかどうかを調べる。
         $arrGrandchildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrAll, 'parent_category_id', 'category_id', $category['category_id']);
         $category['has_children'] = count($arrGrandchildrenID) > 0;
         $arrChildren[] = $category;
     }
     if (!isset($arrCategory)) {
         SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND, "", false, "", true);
     }
     // 子カテゴリーの商品数を合計する。
     $children_product_count = 0;
     foreach ($arrChildren as $category) {
         $children_product_count += $category['product_count'];
     }
     // 選択されたカテゴリーに直属の商品がある場合は、子カテゴリーの先頭に追加する。
     if ($arrCategory['product_count'] > $children_product_count) {
         $arrCategory['product_count'] -= $children_product_count;
         // 子カテゴリーの商品数を除く。
         $arrCategory['has_children'] = false;
         // 商品一覧ページに遷移させるため。
         array_unshift($arrChildren, $arrCategory);
     }
     // 結果を格納する。
     $objPage->arrCategory = $arrCategory;
     $objPage->arrChildren = $arrChildren;
 }
 function lfGetMainCat($count_check = false, &$objSubPage)
 {
     $objQuery = new SC_Query();
     $col = "*";
     $from = "dtb_category left join dtb_category_total_count using (category_id)";
     // メインカテゴリーとその直下のカテゴリーを取得する。
     $where = 'level <= 2 AND del_flg = 0';
     // 登録商品数のチェック
     if ($count_check) {
         $where .= " AND product_count > 0";
     }
     $objQuery->setoption("ORDER BY rank DESC");
     $arrRet = $objQuery->select($col, $from, $where);
     // メインカテゴリーを抽出する。
     $arrMainCat = array();
     foreach ($arrRet as $cat) {
         if ($cat['level'] != 1) {
             continue;
         }
         // 子カテゴリーを持つかどうかを調べる。
         $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrRet, 'parent_category_id', 'category_id', $cat['category_id']);
         $cat['has_children'] = count($arrChildrenID) > 0;
         $arrMainCat[] = $cat;
     }
     $objSubPage->arrCat = $arrMainCat;
     return $objSubPage;
 }