source: branches/feature-module-update/html/mobile/products/category_list.php @ 15532

Revision 15532, 3.1 KB checked in by nanasess, 17 years ago (diff)

svn:mime-type 修正

  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/**
3 *
4 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
5 *
6 * http://www.lockon.co.jp/
7 *
8 *
9 * モバイルサイト/カテゴリー一覧
10 */
11
12require_once('../require.php');
13
14class LC_Page {
15    function LC_Page() {
16        /** 必ず指定する **/
17        $this->tpl_mainpage = 'products/category_list.tpl';         // メインテンプレート
18        $this->tpl_title = 'カテゴリ一覧ページ';
19    }
20}
21
22$objPage = new LC_Page();
23$objView = new SC_MobileView();
24
25// レイアウトデザインを取得
26$objPage = sfGetPageLayout($objPage, false, DEF_LAYOUT);
27
28// カテゴリー情報を取得する。
29lfGetCategories(@$_GET['category_id'], true, $objPage);
30
31$objView->assignobj($objPage);
32$objView->display(SITE_FRAME);
33
34//-----------------------------------------------------------------------------------------------------------------------------------
35
36/**
37 * 選択されたカテゴリーとその子カテゴリーの情報を取得し、
38 * ページオブジェクトに格納する。
39 *
40 * @param string $category_id カテゴリーID
41 * @param boolean $count_check 有効な商品がないカテゴリーを除くかどうか
42 * @param object &$objPage ページオブジェクト
43 * @return void
44 */
45function lfGetCategories($category_id, $count_check = false, &$objPage) {
46    // カテゴリーの正しいIDを取得する。
47    $category_id = sfGetCategoryId('', $category_id);
48    if ($category_id == 0) {
49        sfDispSiteError(CATEGORY_NOT_FOUND, "", false, "", true);
50    }
51
52    $arrCategory = null;    // 選択されたカテゴリー
53    $arrChildren = array(); // 子カテゴリー
54
55    $arrAll = sfGetCatTree($category_id, $count_check);
56    foreach ($arrAll as $category) {
57        // 選択されたカテゴリーの場合
58        if ($category['category_id'] == $category_id) {
59            $arrCategory = $category;
60            continue;
61        }
62
63        // 関係のないカテゴリーはスキップする。
64        if ($category['parent_category_id'] != $category_id) {
65            continue;
66        }
67
68        // 子カテゴリーの場合は、孫カテゴリーが存在するかどうかを調べる。
69        $arrGrandchildrenID = sfGetUnderChildrenArray($arrAll, 'parent_category_id', 'category_id', $category['category_id']);
70        $category['has_children'] = count($arrGrandchildrenID) > 0;
71        $arrChildren[] = $category;
72    }
73
74    if (!isset($arrCategory)) {
75        sfDispSiteError(CATEGORY_NOT_FOUND, "", false, "", true);
76    }
77
78    // 子カテゴリーの商品数を合計する。
79    $children_product_count = 0;
80    foreach ($arrChildren as $category) {
81        $children_product_count += $category['product_count'];
82    }
83
84    // 選択されたカテゴリーに直属の商品がある場合は、子カテゴリーの先頭に追加する。
85    if ($arrCategory['product_count'] > $children_product_count) {
86        $arrCategory['product_count'] -= $children_product_count;   // 子カテゴリーの商品数を除く。
87        $arrCategory['has_children'] = false;   // 商品一覧ページに遷移させるため。
88        array_unshift($arrChildren, $arrCategory);
89    }
90
91    // 結果を格納する。
92    $objPage->arrCategory = $arrCategory;
93    $objPage->arrChildren = $arrChildren;
94}
95?>
Note: See TracBrowser for help on using the repository browser.