Source for file function.pnformcategoryselector.php
Documentation is available at function.pnformcategoryselector.php
* Category selector plugin
* @copyright (c) 2006, Zikula Development Team
* @link http://www.zikula.org
* @version $Id: function.pnformtextinput.php 21046 2007-01-11 21:36:57Z jornlind $
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* @package Zikula_Template_Plugins
/** Make sure to use require_once() instead of Loader::requireOnce() since "function.pnformdropdownlist.php"
is loaded by Smarty (the base render class) with the use of require_once(). We do not want to
get in conflict with that.*/
require_once 'system/pnForm/plugins/function.pnformdropdownlist.php';
* This plugin creates a category selector using a dropdown list.
* The selected value of the base dropdown list will be set to ID of the selected category.
* Enable inclusion of an empty null value element
* @var bool (default false)
* Enable save/load of values in separate __CATEGORIES_ field for use in DBUtil.
* If enabled then selected category is returned in a sub-array named __CATEGORIES__
* such that it can be used directly with DBUtils standard categorization of
* data items. Example code:
* // Template: <!--[pnformcategoryselector id=myCat category=xxx enableDBUtil=1]-->
* array('title' => 'Item title',
* '__CATEGORIES__' => array('myCat' => zzz)
* @var bool (default false)
/* Shared by other category plugins */
/* static */ function loadParameters(&$list, $includeEmptyElement, $params)
$list->category = isset ($params['category']) ? $params['category'] : 0;
$path = isset ($params['path']) ? $params['path'] : '';
$pathfield = isset ($params['pathfield']) ? $params['pathfield'] : 'path';
$lang = isset ($params['lang']) ? $params['lang'] : pnUserGetLang();
$recurse = isset ($params['recurse']) ? $params['recurse'] : true;
$relative = isset ($params['relative']) ? $params['relative'] : true;
$includeRoot = isset ($params['includeRoot']) ? $params['includeRoot'] : false;
$includeLeaf = isset ($params['includeLeaf']) ? $params['includeLeaf'] : true;
$all = isset ($params['all']) ? $params['all'] : false;
$list->editLink = isset ($params['editLink']) ? $params['editLink'] : true;
// if we don't have a category-id we see if we can get a category by path
if (!$list->category && $path) {
// check if we have an actual category object with a numeric ID set
if (is_array($list->category) && isset ($list->category['id']) && is_integer($list->category['id'])) {
// check if we have a numeric category
// check if we have a string/path category
$list->addItem('- - -', null);
$line = '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -';
if ($includeEmptyElement)
$list->addItem('', null);
foreach ($allCats as $cat)
$indent = '| ' . substr ($line, 0, $cslash* 2);
$list->addItem($indent . ' ' . (isset ($cat['display_name'][$lang]) ? $cat['display_name'][$lang] : $cat['name']), $cat['id']);
function load(&$render, $params)
$this->enableDBUtil = (isset ($params['enableDBUtil']) ? $params['enableDBUtil'] : false);
parent::load($render, $params);
$result = parent::render($render);
$result .= " <a href=\"$url\"><img src=\"images/icons/extrasmall/xedit.gif\" title=\"" . _EDIT . '" alt="' . _EDIT . '" /></a>';
if ($this->group == null)
$data['__CATEGORIES__'][$this->dataField] = $this->getSelectedValue();
$data[$this->group] = array();
$data[$this->group]['__CATEGORIES__'][$this->dataField] = $this->getSelectedValue();
parent::saveValue($render, $data);
if ($this->group == null)
if ($this->dataField != null && isset ($values['__CATEGORIES__'][$this->dataField]))
$value = $values['__CATEGORIES__'][$this->dataField];
if ($this->itemsDataField != null && isset ($values[$this->itemsDataField]))
$items = $values[$this->itemsDataField];
if (isset ($values[$this->group]))
$data = $values[$this->group];
if (isset ($data['__CATEGORIES__'][$this->dataField]))
$value = $data['__CATEGORIES__'][$this->dataField];
if ($this->itemsDataField != null && isset ($data[$this->itemsDataField]))
$items = $data[$this->itemsDataField];
$this->setSelectedValue($value);
parent::loadValue($render, $values);
return $render->pnFormRegisterPlugin('pnFormCategorySelector', $params);
|