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

Revision 21864, 4.5 KB checked in by h_yoshimoto, 12 years ago (diff)

#1831 Copyrightを更新

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 doAction($arrParam) {
43        $arrRequest = $this->doInitParam($arrParam);
44        if (!$this->isParamError()) {
45            $category_id = $arrRequest['BrowseNodeId'];
46            if ($category_id
47                 && !SC_Helper_DB_Ex::sfIsRecord('dtb_category', 'category_id', (array)$category_id, 'del_flg = 0')) {
48                $category_id = '0';
49            } else if (SC_Utils_Ex::isBlank($category_id)) {
50                $category_id = '0';
51            }
52            // LC_Page_Products_CategoryList::lfGetCategories() と相当類似しているので共通化したい
53            $arrCategory = null;    // 選択されたカテゴリ
54            $arrChildren = array(); // 子カテゴリ
55
56            $arrAll = SC_Helper_DB_Ex::sfGetCatTree($category_id, true);
57            foreach ($arrAll as $category) {
58                if ($category_id != 0 && $category['category_id'] == $category_id) {
59                    $arrCategory = $category;
60                    continue;
61                }
62                if ($category['parent_category_id'] != $category_id) {
63                    continue;
64                }
65
66                $arrGrandchildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrAll, 'parent_category_id', 'category_id', $category['category_id']);
67                $category['has_children'] = count($arrGrandchildrenID) > 0;
68                $arrChildren[] = $category;
69            }
70
71            if (!SC_Utils_Ex::isBlank($arrCategory)) {
72                $arrData = array(
73                    'BrowseNodeId' => $category_id,
74                    'Name' => $arrCategory['category_name'],
75                    'PageURL' =>  HTTP_URL . 'products/list.php?category_id=' . $arr['category_id'],
76                    'has_children' => count($arrChildren) > 0
77                );
78            } else {
79                $arrData = array(
80                    'BrowseNodeId' => $category_id,
81                    'Name' => 'ホーム',
82                    'PageURL' =>  HTTP_URL,
83                    'has_children' => count($arrChildren) > 0
84                );
85            }
86
87            if (!SC_Utils_Ex::isBlank($arrChildren)) {
88                $arrData['Children'] = array();
89                foreach ($arrChildren as $category) {
90                    $arrData['Children']['BrowseNode'][] = array(
91                        'BrowseNodeId' => $category['category_id'],
92                        'Name' => $category['category_name'],
93                        'PageURL' => HTTP_URL . 'products/list.php?category_id=' . $category['category_id'],
94                        'has_children' => $category['has_children']
95                        );
96                }
97            }
98            $this->setResponse('BrowseNode', $arrData);
99
100            // TODO: Ancestors 親ノード
101            return true;
102        }
103        return false;
104    }
105
106    protected function lfInitParam(&$objFormParam) {
107        $objFormParam->addParam('対象カテゴリID', 'BrowseNodeId', INT_LEN, 'a', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
108        $objFormParam->addParam('返答種別', 'ResponseGroup', INT_LEN, 'a', array('GRAPH_CHECK', 'MAX_LENGTH_CHECK'));
109    }
110
111    public function getResponseGroupName() {
112        return 'BrowseNodes';
113    }
114}
Note: See TracBrowser for help on using the repository browser.