Commit 4ce2b206 authored by lphuberdeau's avatar lphuberdeau

[MOD] Allow value formatters to have parameters and include a new type to...

[MOD] Allow value formatters to have parameters and include a new type to convert references to links to the reference
parent 6329af16
......@@ -1864,6 +1864,7 @@ lib/core/Search/Formatter/ValueFormatter/Date.php -text
lib/core/Search/Formatter/ValueFormatter/Interface.php -text
lib/core/Search/Formatter/ValueFormatter/Objectlink.php -text
lib/core/Search/Formatter/ValueFormatter/Plain.php -text
lib/core/Search/Formatter/ValueFormatter/Reference.php -text
lib/core/Search/Formatter/ValueFormatter/Trackerrender.php -text
lib/core/Search/GlobalSource/AdvancedRatingSource.php -text
lib/core/Search/GlobalSource/CategorySource.php -text
......
......@@ -73,7 +73,9 @@ class Search_Formatter_Plugin_WikiTemplate implements Search_Formatter_Plugin_In
$format = 'plain';
}
return $valueFormatter->$format($name);
unset($arguments['format']);
unset($arguments['name']);
return $valueFormatter->$format($name, $arguments);
}
}
......@@ -22,6 +22,9 @@ class Search_Formatter_ValueFormatter
function __call($format, $arguments)
{
$name = array_shift($arguments);
if (! $arguments = array_shift($arguments)) {
$arguments = array();
}
if (! isset($this->valueSet[$name]) || is_null($this->valueSet[$name])) {
return tr("No value for '%0'", $name);
......@@ -29,7 +32,7 @@ class Search_Formatter_ValueFormatter
$class = 'Search_Formatter_ValueFormatter_' . ucfirst($format);
if (class_exists($class)) {
$formatter = new $class;
$formatter = new $class($arguments);
return $formatter->render($name, $this->valueSet[$name], $this->valueSet);
} else {
return tr("Unknown formatting rule '%0' for '%1'", $format, $name);
......
......@@ -7,10 +7,19 @@
class Search_Formatter_ValueFormatter_Plain implements Search_Formatter_ValueFormatter_Interface
{
private $separator = ', ';
function __construct($arguments)
{
if (isset($arguments['separator'])) {
$this->separator = $arguments['separator'];
}
}
function render($name, $value, array $entry)
{
if (is_array($value)) {
return implode(', ', $value);
return implode($this->separator, $value);
} else {
return $value;
}
......
<?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$
class Search_Formatter_ValueFormatter_Reference implements Search_Formatter_ValueFormatter_Interface
{
private $separator = ', ';
private $type = 'wiki page';
function __construct($arguments)
{
if (isset($arguments['separator'])) {
$this->separator = $arguments['separator'];
}
if (isset($arguments['type'])) {
$this->type = $arguments['type'];
}
}
function render($name, $value, array $entry)
{
global $smarty;
require_once $smarty->_get_plugin_filepath('function', 'object_link');
foreach ((array) $value as $id) {
$params = array(
'type' => $this->type,
'id' => $id,
);
$links[] = smarty_function_object_link($params, $smarty);
}
return '~np~' . implode($this->separator, $links) . '~/np~';
}
}
......@@ -194,6 +194,8 @@ class ObjectLib extends TikiLib
switch ($type) {
case 'trackeritem':
return TikiLib::lib('trk')->get_isMain_value(null, $id);
case 'category':
return TikiLib::lib('categ')->get_category_name($id);
}
$title = $this->table('tiki_objects')->fetchOne('name', array(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment