[Svn-src-all:3674] [version-2_12-dev 22586] #2166 カテゴリーツリーのデータをツリー状に取得
pineray
admin @ mail.ec-cube.net
2013年 2月 28日 (木) 09:30:36 JST
Subversion committed to /home/svn/open 22586
http://svn.ec-cube.net/open_trac/changeset/22586
┌────────────────────────────┐
│更新者 : pineray │
│更新日時: 2013-02-28 09:30:36 +0900 (木, 28 2月 2013)│
└────────────────────────────┘
Log:
--------------------------------------------------------
#2166 カテゴリーツリーのデータをツリー状に取得
Changed: [U:修正,A:追加,D:削除]
--------------------------------------------------------
U branches/version-2_12-dev/data/Smarty/templates/default/frontparts/bloc/category.tpl
A branches/version-2_12-dev/data/Smarty/templates/default/frontparts/bloc/category_tree_fork.tpl
U branches/version-2_12-dev/data/Smarty/templates/sphone/frontparts/bloc/category.tpl
A branches/version-2_12-dev/data/Smarty/templates/sphone/frontparts/bloc/category_tree_fork.tpl
U branches/version-2_12-dev/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Category.php
U branches/version-2_12-dev/data/class/util/SC_Utils.php
U branches/version-2_12-dev/html/user_data/packages/sphone/js/category.js
変更: branches/version-2_12-dev/data/Smarty/templates/default/frontparts/bloc/category.tpl
===================================================================
--- branches/version-2_12-dev/data/Smarty/templates/default/frontparts/bloc/category.tpl 2013-02-26 15:01:06 UTC (rev 22585)
+++ branches/version-2_12-dev/data/Smarty/templates/default/frontparts/bloc/category.tpl 2013-02-28 00:30:36 UTC (rev 22586)
@@ -25,52 +25,12 @@
$('#category_area li.level1:last').css('border-bottom', 'none');
});
//]]></script>
+
<div class="block_outer">
<div id="category_area">
<div class="block_body">
<h2><img src="<!--{$TPL_URLPATH}-->img/title/tit_bloc_category.gif" alt="商品カテゴリ" /></h2>
- <!--{strip}-->
- <ul id="categorytree">
- <!--{assign var=preLev value=1}-->
- <!--{assign var=firstdone value=0}-->
- <!--{section name=cnt loop=$arrTree}-->
- <!--{* 表示フラグがTRUEなら表示 *}-->
- <!--{if $arrTree[cnt].display == 1}-->
- <!--{assign var=level value=`$arrTree[cnt].level`}-->
- <!--{assign var=levdiff value=`$level-$preLev`}-->
- <!--{if $levdiff > 0}-->
- <ul>
- <!--{elseif $levdiff == 0 && $firstdone == 1}-->
- </li>
- <!--{elseif $levdiff < 0}-->
- <!--{section name=d loop=`$levdiff*-1`}-->
- </li>
- </ul>
- <!--{/section}-->
- </li>
- <!--{/if}-->
- <li class="level<!--{$level}--><!--{if in_array($arrTree[cnt].category_id, $tpl_category_id)}--> onmark<!--{/if}-->">
- <p>
- <a href="<!--{$smarty.const.ROOT_URLPATH}-->products/list.php?category_id=<!--{$arrTree[cnt].category_id}-->"<!--{if in_array($arrTree[cnt].category_id, $tpl_category_id)}--> class="onlink"<!--{/if}-->><!--{$arrTree[cnt].category_name|h}-->(<!--{$arrTree[cnt].product_count|default:0}-->)</a>
- </p>
- <!--{if $firstdone == 0}--><!--{assign var=firstdone value=1}--><!--{/if}-->
- <!--{assign var=preLev value=`$level`}-->
- <!--{/if}-->
- <!--{* セクションの最後に閉じタグを追加 *}-->
- <!--{if $smarty.section.cnt.last}-->
- <!--{if $preLev-1 > 0}-->
- <!--{section name=d loop=`$preLev-1`}-->
- </li>
- </ul>
- <!--{/section}-->
- </li>
- <!--{else}-->
- </li>
- <!--{/if}-->
- <!--{/if}-->
- <!--{/section}-->
- </ul>
- <!--{/strip}-->
+ <!--{include file="`$smarty.const.TEMPLATE_REALDIR`frontparts/bloc/category_tree_fork.tpl" children=$arrTree treeID="categorytreelist"}-->
</div>
</div>
</div>
追加: branches/version-2_12-dev/data/Smarty/templates/default/frontparts/bloc/category_tree_fork.tpl
===================================================================
--- branches/version-2_12-dev/data/Smarty/templates/default/frontparts/bloc/category_tree_fork.tpl (rev 0)
+++ branches/version-2_12-dev/data/Smarty/templates/default/frontparts/bloc/category_tree_fork.tpl 2013-02-28 00:30:36 UTC (rev 22586)
@@ -0,0 +1,32 @@
+<!--{*
+ * This file is part of EC-CUBE
+ *
+ * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved.
+ *
+ * http://www.lockon.co.jp/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *}-->
+
+<ul<!--{if $treeID != ""}--> id="<!--{$treeID}-->"<!--{/if}-->>
+<!--{foreach from=$children item=child}-->
+ <li<!--{if !in_array($child.category_id, $arrDispID)}--> style="display: none;"<!--{/if}--> class="level<!--{$child.level}--><!--{if in_array($child.category_id, $tpl_category_id)}--> onmark<!--{/if}-->">
+ <p><a href="<!--{$smarty.const.ROOT_URLPATH}-->products/list.php?category_id=<!--{$child.category_id}-->"<!--{if in_array($child.category_id, $tpl_category_id)}--> class="onlink"<!--{/if}-->><!--{$child.category_name|h}-->(<!--{$child.product_count|default:0}-->)</a></p>
+ <!--{if isset($child.children|smarty:nodefaults)}-->
+ <!--{include file="`$smarty.const.TEMPLATE_REALDIR`frontparts/bloc/category_tree_fork.tpl" children=$child.children}-->
+ <!--{/if}-->
+ </li>
+<!--{/foreach}-->
+</ul>
\ No newline at end of file
変更: branches/version-2_12-dev/data/Smarty/templates/sphone/frontparts/bloc/category.tpl
===================================================================
--- branches/version-2_12-dev/data/Smarty/templates/sphone/frontparts/bloc/category.tpl 2013-02-26 15:01:06 UTC (rev 22585)
+++ branches/version-2_12-dev/data/Smarty/templates/sphone/frontparts/bloc/category.tpl 2013-02-28 00:30:36 UTC (rev 22586)
@@ -24,53 +24,8 @@
<section id="category_area">
<h2 class="title_block">商品カテゴリ</h2>
<nav id="categorytree">
- <ul id="categorytreelist">
- <!--{assign var=preLev value=1}-->
- <!--{assign var=firstdone value=0}-->
- <!--{section name=cnt loop=$arrTree}-->
- <!--{* インデントは Smarty 構文を優先としています。 *}-->
- <!--{* カテゴリ表示・非表示切り替え *}-->
- <!--{if $arrTree[cnt].view_flg != "2"}-->
- <!--{* 表示フラグがTRUEなら表示 *}-->
- <!--{assign var=level value=`$arrTree[cnt].level`}-->
- <!--{* level2以下なら表示(level指定可能) *}-->
- <!--{if $level <= 5 || $arrTree[cnt].display == 1}-->
- <!--{assign var=levdiff value=`$level-$preLev`}-->
- <!--{if $levdiff > 0}-->
- <ul>
- <!--{elseif $levdiff == 0 && $firstdone == 1}-->
- </li>
- <!--{elseif $levdiff < 0}-->
- <!--{section name=d loop=`$levdiff*-1`}-->
- </li>
- </ul>
- <!--{/section}-->
- </li>
- <!--{/if}-->
+ <!--{include file="`$smarty.const.SMARTPHONE_TEMPLATE_REALDIR`frontparts/bloc/category_tree_fork.tpl" children=$arrTree treeID="categorytreelist"}-->
- <li class="level<!--{$level}--><!--{if in_array($arrTree[cnt].category_id, $tpl_category_id)}--> onmark<!--{/if}-->"><span class="category_header"></span><span class="category_body"><a rel="external" href="<!--{$smarty.const.ROOT_URLPATH}-->products/list.php?category_id=<!--{$arrTree[cnt].category_id}-->"<!--{if in_array($arrTree[cnt].category_id, $tpl_category_id)}--> class="onlink"<!--{/if}-->><!--{$arrTree[cnt].category_name|h}-->(<!--{$arrTree[cnt].product_count|default:0}-->)</a></span>
- <!--{if $firstdone == 0}-->
- <!--{assign var=firstdone value=1}-->
- <!--{/if}-->
- <!--{assign var=preLev value=`$level`}-->
- <!--{/if}-->
-
- <!--{* セクションの最後に閉じタグを追加 *}-->
- <!--{if $smarty.section.cnt.last}-->
- <!--{if $preLev-1 > 0}-->
- <!--{section name=d loop=`$preLev-1`}-->
- </li>
- </ul>
- <!--{/section}-->
- </li>
- <!--{else}-->
- </li>
- <!--{/if}-->
- <!--{/if}-->
- <!--{/if}-->
- <!--{/section}-->
- </ul>
-
<script>//<![CDATA[
initCategoryList(); //カテゴリリストの初期化
//]]></script>
追加: branches/version-2_12-dev/data/Smarty/templates/sphone/frontparts/bloc/category_tree_fork.tpl
===================================================================
--- branches/version-2_12-dev/data/Smarty/templates/sphone/frontparts/bloc/category_tree_fork.tpl (rev 0)
+++ branches/version-2_12-dev/data/Smarty/templates/sphone/frontparts/bloc/category_tree_fork.tpl 2013-02-28 00:30:36 UTC (rev 22586)
@@ -0,0 +1,32 @@
+<!--{*
+ * This file is part of EC-CUBE
+ *
+ * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved.
+ *
+ * http://www.lockon.co.jp/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *}-->
+
+<ul<!--{if $treeID != ""}--> id="<!--{$treeID}-->"<!--{/if}-->>
+<!--{foreach from=$children item=child}-->
+ <li<!--{if $child.view_flg == "2" || $child.level > 5 || !in_array($child.category_id, $arrDispID)}--> style="display: none;"<!--{/if}--> class="level<!--{$child.level}--><!--{if in_array($child.category_id, $tpl_category_id)}--> onmark<!--{/if}-->">
+ <span class="category_header"></span><span class="category_body"><a rel="external" href="<!--{$smarty.const.ROOT_URLPATH}-->products/list.php?category_id=<!--{$child.category_id}-->"<!--{if in_array($child.category_id, $tpl_category_id)}--> class="onlink"<!--{/if}-->><!--{$child.category_name|h}-->(<!--{$child.product_count|default:0}-->)</a></span>
+ <!--{if isset($child.children|smarty:nodefaults)}-->
+ <!--{include file="`$smarty.const.SMARTPHONE_TEMPLATE_REALDIR`frontparts/bloc/category_tree_fork.tpl" children=$child.children treeID=""}-->
+ <!--{/if}-->
+ </li>
+<!--{/foreach}-->
+</ul>
\ No newline at end of file
変更: branches/version-2_12-dev/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Category.php
===================================================================
--- branches/version-2_12-dev/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Category.php 2013-02-26 15:01:06 UTC (rev 22585)
+++ branches/version-2_12-dev/data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc_Category.php 2013-02-28 00:30:36 UTC (rev 22586)
@@ -131,6 +131,7 @@
{
$objQuery =& SC_Query_Ex::getSingletonInstance();
$objDb = new SC_Helper_DB_Ex();
+
$col = '*';
$from = 'dtb_category left join dtb_category_total_count ON dtb_category.category_id = dtb_category_total_count.category_id';
// 登録商品数のチェック
@@ -141,6 +142,9 @@
}
$objQuery->setOption('ORDER BY rank DESC');
$arrRet = $objQuery->select($col, $from, $where);
+
+ $arrTree = SC_Utils_Ex::buildTree('category_id', 'parent_category_id', 10, $arrRet);
+
foreach ($arrParentCategoryId as $category_id) {
$arrParentID = $objDb->sfGetParents(
'dtb_category',
@@ -161,14 +165,10 @@
$category_id
);
$this->root_parent_id[] = $arrParentID[0];
- $arrDispID = array_merge($arrBrothersID, $arrChildrenID);
- foreach ($arrRet as &$arrCategory) {
- if (in_array($arrCategory['category_id'], $arrDispID)) {
- $arrCategory['display'] = 1;
- }
- }
+ $this->arrDispID = array_merge($arrBrothersID, $arrChildrenID);
}
- return $arrRet;
+
+ return $arrTree;
}
/**
変更: branches/version-2_12-dev/data/class/util/SC_Utils.php
===================================================================
--- branches/version-2_12-dev/data/class/util/SC_Utils.php 2013-02-26 15:01:06 UTC (rev 22585)
+++ branches/version-2_12-dev/data/class/util/SC_Utils.php 2013-02-28 00:30:36 UTC (rev 22586)
@@ -1921,4 +1921,48 @@
}
return $return;
}
+
+ /**
+ *
+ * @param string $primary_key
+ * @param string $glue_key
+ * @param integer $max_depth
+ * @param array $correction
+ * @param integer $base_id
+ * @return array ツリーの配列
+ */
+ public static function buildTree($primary_key, $glue_key, $max_depth, $correction = array(), $base_id = 0)
+ {
+ $children = array();
+ foreach ($correction as $child) {
+ $children[$child[$glue_key]][] = $child;
+ }
+ $arrTree = $children[$base_id];
+ foreach ($arrTree as &$child) {
+ SC_Utils_Ex::addChild($child, $primary_key, 1, $max_depth, $children);
+ }
+ return $arrTree;
+ }
+
+ /**
+ * ツリーの親子をつなげるルーチン.
+ *
+ * @param array $target 親
+ * @param string $primary_key 主キーの識別子
+ * @param integer $level 親の階層
+ * @param integer $max_depth 階層の深さの最大値
+ * @param array $children 子の配列(キーが親ID)
+ * @return void
+ */
+ public static function addChild(&$target, $primary_key, $level, $max_depth, &$children = array())
+ {
+ if (isset($children[$target[$primary_key]])) {
+ $target['children'] = $children[$target[$primary_key]];
+ if ($level + 1 < $max_depth) {
+ foreach ($target['children'] as &$child) {
+ SC_Utils_Ex::addChild($child, $primary_key, $level++, $max_depth, $children);
+ }
+ }
+ }
+ }
}
変更: branches/version-2_12-dev/html/user_data/packages/sphone/js/category.js
===================================================================
--- branches/version-2_12-dev/html/user_data/packages/sphone/js/category.js 2013-02-26 15:01:06 UTC (rev 22585)
+++ branches/version-2_12-dev/html/user_data/packages/sphone/js/category.js 2013-02-28 00:30:36 UTC (rev 22586)
@@ -91,8 +91,9 @@
//を表示し、リストオープン関数を追加
var linkObj = document.createElement("a");
linkObj.innerText = '+';
- tgt.childNodes[0].className="category_header plus";
- tgt.childNodes[0].appendChild(linkObj);
+ $(tgt).children('span.category_header')
+ .addClass('plus')
+ .append(linkObj);
j++;
linkObj.parentNode.setAttribute('onclick', 'listopen(' + lv + ',' + num + ')');
Svn-src-all メーリングリストの案内