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

Revision 22856, 4.5 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

  • 主に空白・空白行の調整。もう少し整えたいが、一旦現状コミット。
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    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    {
44        $arrRequest = $this->doInitParam($arrParam);
45        if (!$this->isParamError()) {
46            $category_id = $arrRequest['BrowseNodeId'];
47            if ($category_id
48                 && !SC_Helper_DB_Ex::sfIsRecord('dtb_category', 'category_id', (array)$category_id, 'del_flg = 0')) {
49                $category_id = '0';
50            } else if (SC_Utils_Ex::isBlank($category_id)) {
51                $category_id = '0';
52            }
53            // LC_Page_Products_CategoryList::lfGetCategories() と相当類似しているので共通化したい
54            $arrCategory = null;    // 選択されたカテゴリ
55            $arrChildren = array(); // 子カテゴリ
56
57            $arrAll = SC_Helper_DB_Ex::sfGetCatTree($category_id, true);
58            foreach ($arrAll as $category) {
59                if ($category_id != 0 && $category['category_id'] == $category_id) {
60                    $arrCategory = $category;
61                    continue;
62                }
63                if ($category['parent_category_id'] != $category_id) {
64                    continue;
65                }
66
67                $arrGrandchildrenID = SC_Utils_Ex::sfGetUnderChildrenArray($arrAll, 'parent_category_id', 'category_id', $category['category_id']);
68                $category['has_children'] = count($arrGrandchildrenID) > 0;
69                $arrChildren[] = $category;
70            }
71
72            if (!SC_Utils_Ex::isBlank($arrCategory)) {
73                $arrData = array(
74                    'BrowseNodeId' => $category_id,
75                    'Name' => $arrCategory['category_name'],
76                    'PageURL' =>  HTTP_URL . 'products/list.php?category_id=' . $arr['category_id'],
77                    'has_children' => count($arrChildren) > 0
78                );
79            } else {
80                $arrData = array(
81                    'BrowseNodeId' => $category_id,
82                    'Name' => 'ホーム',
83                    'PageURL' =>  HTTP_URL,
84                    'has_children' => count($arrChildren) > 0
85                );
86            }
87
88            if (!SC_Utils_Ex::isBlank($arrChildren)) {
89                $arrData['Children'] = array();
90                foreach ($arrChildren as $category) {
91                    $arrData['Children']['BrowseNode'][] = array(
92                        'BrowseNodeId' => $category['category_id'],
93                        'Name' => $category['category_name'],
94                        'PageURL' => HTTP_URL . 'products/list.php?category_id=' . $category['category_id'],
95                        'has_children' => $category['has_children']
96                        );
97                }
98            }
99            $this->setResponse('BrowseNode', $arrData);
100
101            // TODO: Ancestors 親ノード
102            return true;
103        }
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.