From: <nk...@us...> - 2011-09-09 19:53:38
|
Revision: 37090 http://tikiwiki.svn.sourceforge.net/tikiwiki/?rev=37090&view=rev Author: nkoth Date: 2011-09-09 19:53:32 +0000 (Fri, 09 Sep 2011) Log Message: ----------- [NEW] Search results formatter for categories listings Added Paths: ----------- trunk/lib/core/Search/Formatter/ValueFormatter/Categorylist.php Added: trunk/lib/core/Search/Formatter/ValueFormatter/Categorylist.php =================================================================== --- trunk/lib/core/Search/Formatter/ValueFormatter/Categorylist.php (rev 0) +++ trunk/lib/core/Search/Formatter/ValueFormatter/Categorylist.php 2011-09-09 19:53:32 UTC (rev 37090) @@ -0,0 +1,121 @@ +<?php +// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project +// +// All Rights Reserved. See copyright.txt for details and a complete list of authors. +// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. +// $Id: Date.php 36060 2011-08-11 14:19:41Z lphuberdeau $ + +class Search_Formatter_ValueFormatter_Categorylist implements Search_Formatter_ValueFormatter_Interface +{ + private $requiredParents = array(); + private $excludeParents = array(); + private $singleList = 'y'; + private $separator; + + function __construct($arguments) + { + if (isset($arguments['requiredParents'])) { + if(!empty($arguments['requiredParents'])) { + $this->requiredParents = explode(',',$arguments['requiredParents']); + } else { + $this->requiredParents = 'all'; + } + } + + if (isset($arguments['excludeParents'])) { + $this->excludeParents = explode(',',$arguments['excludeParents']); + } + + if (isset($arguments['singleList'])) { + $this->singleList = $arguments['singleList']; + } + + if (isset($arguments['separator'])) { + $this->separator = $arguments['separator']; + } + } + + function render($name, $value, array $entry) + { + global $smarty; + $smarty->loadPlugin('smarty_function_object_link'); + + $arr = TikiLib::lib('categ')->getCategories(); + + foreach($arr as $arx) { + $myArr[$arx['categId']] = Array('parentId' => $arx['parentId'],'name' => $arx['name']); + } + + if($this->singleList == 'y') { + + foreach ($value as $ar) + { + if($ar == 'orphan') { + break; + } + + $p_info = $myArr[$ar]; + if( ($this->requiredParents=='all' || in_array( $p_info['parentId'], $this->requiredParents)) && !in_array( $p_info['parentId'], $this->excludeParents)) { + $params = array('type' => 'category', 'id' => $ar); + $link = smarty_function_object_link($params, $smarty); + + if(!empty($this->separator)) { + $list .= $link . $this->separator; + } else { + if(empty($list)) { + $list = "<ul class=\"categoryLinks\">"; + } + $list .= ' <li>' . $link . "</li>"; + } + + } + } + if(!empty($this->separator)) { + $g = 0-strlen($this->separator); + $list = substr($list,0,$g); + } else if (!empty($list)) { + $list .= "</ul>"; + } + } else { + $parent = array(); + + foreach ($value as $ar) + { + if($ar == 'orphan') { + break; + } + + $p_info = $myArr[$ar]; + + if( ($this->requiredParents=='all' || in_array( $p_info['parentId'], $this->requiredParents)) && !in_array( $p_info['parentId'], $this->excludeParents)) { + $parent[$p_info['parentId']][] = $ar; + } + } + + foreach ($parent as $k=>$v) { + if(empty($this->separator)) { + $list .= "<h5>{$myArr[$k]['name']}</h5><ul class=\"categoryLinks\">"; + foreach($v as $t) { + $params = array('type' => 'category', 'id' => $t); + $link = smarty_function_object_link($params, $smarty); + $list .= "<li>".$link."</li>"; + } + $list .= "</ul>"; + } else { + $list .= "{$myArr[$k]['name']}: "; + foreach($v as $t) { + $params = array('type' => 'category', 'id' => $t); + $link = smarty_function_object_link($params, $smarty); + $list .= $link.$this->separator; + } + } + if(!empty($this->separator)) { + $g = 0-strlen($this->separator); + $list = substr($list,0,$g); + $list .= "<br />"; + } + } + } + return '~np~' . $list . '~/np~'; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |