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

Revision 22433, 4.7 KB checked in by kim, 11 years ago (diff)

#2060 r22372,r22381,r22382,r22386-r22390,r22397-r22400,r22407-r22411,r22416,r22417,r22420,r22421,r22423,r22425,r22426 を差し戻す。

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