1: <?php
2: /**
3: *
4: * @package Legacy
5: * @version $Id: function.xoops_optionsArray.php,v 1.3 2008/09/25 15:12:36 kilica Exp $
6: * @copyright Copyright 2005-2007 XOOPS Cube Project <https://github.com/xoopscube/legacy>
7: * @license https://github.com/xoopscube/legacy/blob/master/docs/GPL_V2.txt GNU GENERAL PUBLIC LICENSE Version 2
8: *
9: */
10:
11: /*
12: * Smarty plugin
13: * -------------------------------------------------------------
14: * Type: function
15: * Name: xoops_optionsArray
16: * Version: 0.1
17: * Date: Apr 6, 2006
18: * Author: minahito
19: * Purpose: Build option tags from array of object who have value and text in
20: own properties.
21: * Input: from = template variable that is array of object
22: * label = property name to get the text.
23: * value = property name to get the value.
24: * default = selected value. variable (include Array).
25: *
26: * -------------------------------------------------------------
27: */
28:
29: // This overlaps with "xoops_input".
30: //define ("XOOPS_INPUT_DEFID_PREFIX", "legacy_xoopsform_");
31:
32: function smarty_function_xoops_optionsArray($params, &$smarty)
33: {
34: //
35: // We should check more.
36: //
37: $tags = '';
38: $objectArr =& $params['from'];
39: $default = isset($params['default']) ? $params['default'] : null;
40: $id = isset($params['id']) ? XOOPS_INPUT_DEFID_PREFIX . $params['id'] . '_': null;
41: static $textFilter;
42: if (!isset($textFilter)) {
43: $root =& XCube_Root::getSingleton();
44: $textFilter = $root->getTextFilter();
45: }
46: $vname = $params['value'];
47: $lname = $params['label'];
48: $isarr = is_array($default);
49: foreach ($objectArr as $object) {
50: $value = $object->get($vname);
51:
52: $selected = ($isarr?in_array($value, $default):$value==$default)?' selected="selected"':'';
53: $value = $textFilter->toShow($value);
54: $label = $textFilter->toShow($object->get($lname));
55: $tags .= $id?"<option id=\"$id$value\" value=\"$value\"$selected>$label</option>\n":"<option value=\"$value\"$selected>$label</option>\n";
56: }
57:
58: print $tags;
59: }
60:
61: ?>
62: