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-2007 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_PATH . "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 15532 2007-08-31 14:39:46Z nanasess $
  33.  */
  34.  
  35.     // }}}
  36.     // {{{ functions
  37.  
  38.     /**
  39.      * Page を初期化する.
  40.      *
  41.      * @return void 
  42.      */
  43.     function init() {
  44.         parent::init();
  45.         $bloc_file = 'category.tpl';
  46.         $this->setTplMainpage($bloc_file);
  47.     }
  48.  
  49.     /**
  50.      * Page のプロセス.
  51.      *
  52.      * @return void 
  53.      */
  54.     function process() {
  55.         $objSubView = new SC_SiteView();
  56.         $objDb = new SC_Helper_DB_Ex();
  57.  
  58.         // 選択中のカテゴリIDを判定する
  59.         $arrCategory_id = $objDb->sfGetCategoryId($_GET['product_id'], $_GET['category_id']);
  60.  
  61.         // 選択中のカテゴリID
  62.         $this->tpl_category_id = empty($arrCategory_id) ? array(0) : $arrCategory_id;;
  63.         $this->lfGetCatTree($this->tpl_category_id, true, $this);
  64.  
  65.         $objSubView->assignobj($this);
  66.         $objSubView->display($this->tpl_mainpage);
  67.     }
  68.  
  69.     /**
  70.      * モバイルページを初期化する.
  71.      *
  72.      * @return void 
  73.      */
  74.     function mobileInit() {
  75.         $this->tpl_mainpage = MOBILE_TEMPLATE_DIR . "frontparts/"
  76.             . BLOC_DIR . 'category.tpl';
  77.     }
  78.  
  79.     /**
  80.      * Page のプロセス(モバイル).
  81.      *
  82.      * @return void 
  83.      */
  84.     function mobileProcess() {
  85.         $objSubView = new SC_MobileView();
  86.  
  87.        $this->lfGetMainCat(true, $this);
  88.  
  89.         $objSubView->assignobj($this);
  90.         $objSubView->display($this->tpl_mainpage);
  91.     }
  92.  
  93.     /**
  94.      * デストラクタ.
  95.      *
  96.      * @return void 
  97.      */
  98.     function destroy() {
  99.         parent::destroy();
  100.     }
  101.  
  102.     // カテゴリツリーの取得
  103.     function lfGetCatTree($arrParent_category_id, $count_check = false) {
  104.         $objQuery = new SC_Query();
  105.         $objDb = new SC_Helper_DB_Ex();
  106.         $col = "*";
  107.         $from = "dtb_category left join dtb_category_total_count using (category_id)";
  108.         // 登録商品数のチェック
  109.         if($count_check) {
  110.             $where = "del_flg = 0 AND product_count > 0";
  111.         } else {
  112.             $where = "del_flg = 0";
  113.         }
  114.         $objQuery->setoption("ORDER BY rank DESC");
  115.         $arrRet = $objQuery->select($col, $from, $where);
  116.  
  117.         foreach ($arrParent_category_id as $category_id) {
  118.             $arrParentID = $objDb->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id);
  119.             $arrBrothersID = SC_Utils_Ex::sfGetBrothersArray($arrRet, 'parent_category_id', 'category_id', $arrParentID);
  120.             $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrRet, 'parent_category_id', 'category_id', $category_id);
  121.  
  122.             $this->root_parent_id[] = $arrParentID[0];
  123.  
  124.             $arrDispID = array_merge($arrBrothersID, $arrChildrenID);
  125.  
  126.             foreach($arrRet as $key => $array) {
  127.                 foreach($arrDispID as $val) {
  128.                     if($array['category_id'] == $val) {
  129.                         $arrRet[$key]['display'] = 1;
  130.                         break;
  131.                     }
  132.                 }
  133.             }
  134.         }
  135.  
  136.         $this->arrTree = $arrRet;
  137.     }
  138.  
  139.     // メインカテゴリーの取得
  140.     function lfGetMainCat($count_check = false, &$objSubPage) {
  141.         $objQuery = new SC_Query();
  142.         $col = "*";
  143.         $from = "dtb_category left join dtb_category_total_count using (category_id)";
  144.         // メインカテゴリーとその直下のカテゴリーを取得する。
  145.         $where = 'level <= 2 AND del_flg = 0';
  146.         // 登録商品数のチェック
  147.         if($count_check) {
  148.             $where .= " AND product_count > 0";
  149.         }
  150.         $objQuery->setoption("ORDER BY rank DESC");
  151.         $arrRet = $objQuery->select($col, $from, $where);
  152.  
  153.         // メインカテゴリーを抽出する。
  154.         $arrMainCat = array();
  155.         foreach ($arrRet as $cat) {
  156.             if ($cat['level'] != 1) {
  157.                 continue;
  158.             }
  159.  
  160.             // 子カテゴリーを持つかどうかを調べる。
  161.             $arrChildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrRet, 'parent_category_id', 'category_id', $cat['category_id']);
  162.             $cat['has_children'] = count($arrChildrenID) > 0;
  163.             $arrMainCat[] = $cat;
  164.         }
  165.  
  166.         $objSubPage->arrCat = $arrMainCat;
  167.         return $objSubPage;
  168.     }
  169. }
  170. ?>

Documentation generated on Tue, 28 Apr 2009 18:12:14 +0900 by phpDocumentor 1.4.2