source: branches/version-2_12-dev/data/class/api/operations/BrowseNodeLookup.php @ 22567

Revision 22567, 4.5 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2013 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/**
25 * APIの基本クラス
26 *
27 * @package Api
28 * @author LOCKON CO.,LTD.
29 * @version $Id$
30 */
31require_once CLASS_EX_REALDIR . 'api_extends/SC_Api_Abstract_Ex.php';
32
33class API_BrowseNodeLookup extends SC_Api_Abstract_Ex
34{
35
36    protected $operation_name = 'BrowseNodeLookup';
37    protected $operation_description = 'カテゴリ取得';
38    protected $default_auth_types = self::API_AUTH_TYPE_OPEN;
39    protected $default_enable = '1';
40    protected $default_is_log = '0';
41    protected $default_sub_data = '';
42
43    public function doAction($arrParam)
44    {
45        $arrRequest = $this->doInitParam($arrParam);
46        if (!$this->isParamError()) {
47            $category_id = $arrRequest['BrowseNodeId'];
48            if ($category_id
49                 && !SC_Helper_DB_Ex::sfIsRecord('dtb_category', 'category_id', (array)$category_id, 'del_flg = 0')) {
50                $category_id = '0';
51            } else if (SC_Utils_Ex::isBlank($category_id)) {
52                $category_id = '0';
53            }
54            // LC_Page_Products_CategoryList::lfGetCategories() と相当類似しているので共通化したい
55            $arrCategory = null;    // 選択されたカテゴリ
56            $arrChildren = array(); // 子カテゴリ
57
58            $arrAll = SC_Helper_DB_Ex::sfGetCatTree($category_id, true);
59            foreach ($arrAll as $category) {
60                if ($category_id != 0 && $category['category_id'] == $category_id) {
61                    $arrCategory = $category;
62                    continue;
63                }
64                if ($category['parent_category_id'] != $category_id) {
65                    continue;
66                }
67
68                $arrGrandchildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrAll, 'parent_category_id', 'category_id', $category['category_id']);
69                $category['has_children'] = count($arrGrandchildrenID) > 0;
70                $arrChildren[] = $category;
71            }
72
73            if (!SC_Utils_Ex::isBlank($arrCategory)) {
74                $arrData = array(
75                    'BrowseNodeId' => $category_id,
76                    'Name' => $arrCategory['category_name'],
77                    'PageURL' =>  HTTP_URL . 'products/list.php?category_id=' . $arr['category_id'],
78                    'has_children' => count($arrChildren) > 0
79                );
80            } else {
81                $arrData = array(
82                    'BrowseNodeId' => $category_id,
83                    'Name' => 'ホーム',
84                    'PageURL' =>  HTTP_URL,
85                    'has_children' => count($arrChildren) > 0
86                );
87            }
88
89            if (!SC_Utils_Ex::isBlank($arrChildren)) {
90                $arrData['Children'] = array();
91                foreach ($arrChildren as $category) {
92                    $arrData['Children']['BrowseNode'][] = array(
93                        'BrowseNodeId' => $category['category_id'],
94                        'Name' => $category['category_name'],
95                        'PageURL' => HTTP_URL . 'products/list.php?category_id=' . $category['category_id'],
96                        'has_children' => $category['has_children']
97                        );
98                }
99            }
100            $this->setResponse('BrowseNode', $arrData);
101
102            // TODO: Ancestors 親ノード
103            return true;
104        }
105        return false;
106    }
107
108    protected function lfInitParam(&$objFormParam)
109    {
110        $objFormParam->addParam('対象カテゴリID', 'BrowseNodeId', INT_LEN, 'a', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
111        $objFormParam->addParam('返答種別', 'ResponseGroup', INT_LEN, 'a', array('GRAPH_CHECK', 'MAX_LENGTH_CHECK'));
112    }
113
114    public function getResponseGroupName()
115    {
116        return 'BrowseNodes';
117    }
118}
Note: See TracBrowser for help on using the repository browser.