Page
[ class tree: Page ] [ index: Page ] [ all elements ]

Source for file LC_Page_FrontParts_Bloc_Category.php

Documentation is available at LC_Page_FrontParts_Bloc_Category.php

  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) 2000-2011 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. // {{{ requires
  25. require_once CLASS_REALDIR 'pages/frontparts/bloc/LC_Page_FrontParts_Bloc.php';
  26.  
  27. /**
  28.  * カテゴリ のページクラス.
  29.  *
  30.  * @package Page
  31.  * @author LOCKON CO.,LTD.
  32.  * @version $Id: LC_Page_FrontParts_Bloc_Category.php 20810 2011-04-05 01:49:30Z kimoto $
  33.  */
  34.  
  35.     // }}}
  36.     // {{{ functions
  37.  
  38.     /**
  39.      * Page を初期化する.
  40.      *
  41.      * @return void 
  42.      */
  43.     function init({
  44.         parent::init();
  45.     }
  46.  
  47.     /**
  48.      * Page のプロセス.
  49.      *
  50.      * @return void 
  51.      */
  52.     function process({
  53.         $this->action();
  54.         $this->sendResponse();
  55.     }
  56.  
  57.     /**
  58.      * Page のアクション.
  59.      *
  60.      * @return void 
  61.      */
  62.     function action({
  63.         // モバイル判定
  64.         switch SC_Display_Ex::detectDevice() ) {
  65.             case DEVICE_TYPE_MOBILE:
  66.                 // メインカテゴリーの取得
  67.                 $this->arrCat $this->lfGetMainCat(true);
  68.                 break;
  69.             default:
  70.                 // 選択中のカテゴリID
  71.                 $this->tpl_category_id $this->lfGetSelectedCategoryId($_GET);
  72.                 // カテゴリツリーの取得
  73.                 $this->arrTree $this->lfGetCatTree($this->tpl_category_idtrue);
  74.                 break;
  75.         }
  76.     }
  77.  
  78.     /**
  79.      * デストラクタ.
  80.      *
  81.      * @return void 
  82.      */
  83.     function destroy({
  84.         parent::destroy();
  85.     }
  86.  
  87.     /**
  88.      * 選択中のカテゴリIDを取得する.
  89.      *
  90.      * @param array $arrRequest リクエスト配列
  91.      * @return array $arrCategoryId 選択中のカテゴリID
  92.      */
  93.     function lfGetSelectedCategoryId($arrRequest{
  94.             // 商品ID取得
  95.         $product_id '';
  96.         if isset($arrRequest['product_id']&& $arrRequest['product_id'!= '' && is_numeric($arrRequest['product_id']) ) {
  97.             $product_id $arrRequest['product_id'];
  98.         }
  99.         // カテゴリID取得
  100.         $category_id '';
  101.         if isset($arrRequest['category_id']&& $arrRequest['category_id'!= '' && is_numeric($arrRequest['category_id']) ) {
  102.             $category_id $arrRequest['category_id'];
  103.         }
  104.         // 選択中のカテゴリIDを判定する
  105.         $objDb new SC_Helper_DB_Ex();
  106.         $arrCategoryId $objDb->sfGetCategoryId($product_id$category_id);
  107.         if (empty($arrCategoryId)) {
  108.             $arrCategoryId array(0);
  109.         }
  110.         return $arrCategoryId;
  111.     }
  112.  
  113.     /**
  114.      * カテゴリツリーの取得.
  115.      *
  116.      * @param array $arrParentCategoryId 親カテゴリの配列
  117.      * @param boolean $count_check 登録商品数をチェックする場合はtrue
  118.      * @return array $arrRet カテゴリーツリーの配列を返す
  119.      */
  120.     function lfGetCatTree($arrParentCategoryId$count_check false{
  121.         $objQuery new SC_Query_Ex();
  122.         $objDb new SC_Helper_DB_Ex();
  123.         $col '*';
  124.         $from 'dtb_category left join dtb_category_total_count using (category_id)';
  125.         // 登録商品数のチェック
  126.         if($count_check{
  127.             $where 'del_flg = 0 AND product_count > 0';
  128.         else {
  129.             $where 'del_flg = 0';
  130.         }
  131.         $objQuery->setOption('ORDER BY rank DESC');
  132.         $arrRet $objQuery->select($col$from$where);
  133.         foreach ($arrParentCategoryId as $category_id{
  134.             $arrParentID $objDb->sfGetParents(
  135.                 'dtb_category',
  136.                 'parent_category_id',
  137.                 'category_id',
  138.                 $category_id
  139.             );
  140.             $arrBrothersID SC_Utils_Ex::sfGetBrothersArray(
  141.                 $arrRet,
  142.                 'parent_category_id',
  143.                 'category_id',
  144.                 $arrParentID
  145.             );
  146.             $arrChildrenID SC_Utils_Ex::sfGetUnderChildrenArray(
  147.                 $arrRet,
  148.                 'parent_category_id',
  149.                 'category_id',
  150.                 $category_id
  151.             );
  152.             $this->root_parent_id[$arrParentID[0];
  153.             $arrDispID array_merge($arrBrothersID$arrChildrenID);
  154.             foreach($arrRet as $key => $array{
  155.                 foreach($arrDispID as $val{
  156.                     if($array['category_id'== $val{
  157.                         $arrRet[$key]['display'1;
  158.                         break;
  159.                     }
  160.                 }
  161.             }
  162.         }
  163.         return $arrRet;
  164.     }
  165.  
  166.     /**
  167.      * メインカテゴリーの取得.
  168.      *
  169.      * @param boolean $count_check 登録商品数をチェックする場合はtrue
  170.      * @return array $arrMainCat メインカテゴリーの配列を返す
  171.      */
  172.     function lfGetMainCat($count_check false{
  173.         $objQuery new SC_Query_Ex();
  174.         $col '*';
  175.         $from 'dtb_category left join dtb_category_total_count using (category_id)';
  176.         // メインカテゴリーとその直下のカテゴリーを取得する。
  177.         $where 'level <= 2 AND del_flg = 0';
  178.         // 登録商品数のチェック
  179.         if($count_check{
  180.             $where .= ' AND product_count > 0';
  181.         }
  182.         $objQuery->setOption('ORDER BY rank DESC');
  183.         $arrRet $objQuery->select($col$from$where);
  184.         // メインカテゴリーを抽出する。
  185.         $arrMainCat array();
  186.         foreach ($arrRet as $cat{
  187.             if ($cat['level'!= 1{
  188.                 continue;
  189.             }
  190.             // 子カテゴリーを持つかどうかを調べる。
  191.             $arrChildrenID SC_Utils_Ex::sfGetUnderChildrenArray(
  192.                 $arrRet,
  193.                 'parent_category_id',
  194.                 'category_id',
  195.                 $cat['category_id']
  196.             );
  197.             $cat['has_children'count($arrChildrenID0;
  198.             $arrMainCat[$cat;
  199.         }
  200.         return $arrMainCat;
  201.     }
  202. }
  203. ?>

Documentation generated on Fri, 24 Feb 2012 14:01:59 +0900 by Seasoft