/** * User category selector. * * Available parameters: * - btnText: If set, the results are assigned to the corresponding variable instead of printed out * - cid: category ID * * Example * {selector_user_category cid="1" assign="category"} * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string HTML code of the selector. */ function smarty_function_selector_user_category($params, Zikula_View $view) { $field = isset($params['field']) ? $params['field'] : 'id'; $selectedValue = isset($params['selectedValue']) ? $params['selectedValue'] : 0; $defaultValue = isset($params['defaultValue']) ? $params['defaultValue'] : 0; $defaultText = isset($params['defaultText']) ? $params['defaultText'] : ''; $lang = isset($params['lang']) ? $params['lang'] : ZLanguage::getLanguageCode(); $name = isset($params['name']) ? $params['name'] : 'defautlselectorname'; $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; $displayPath = isset($params['displayPath']) ? $params['displayPath'] : false; $attributes = isset($params['attributes']) ? $params['attributes'] : null; $assign = isset($params['assign']) ? $params['assign'] : null; $editLink = isset($params['editLink']) ? $params['editLink'] : true; $submit = isset($params['submit']) ? $params['submit'] : false; $multipleSize = isset($params['multipleSize']) ? $params['multipleSize'] : 1; $doReplaceRootCat = false; $userCats = ModUtil::apiFunc('ZikulaCategoriesModule', 'user', 'getusercategories', array('returnCategory' => 1, 'relative' => $relative)); $html = CategoryUtil::getSelector_Categories($userCats, $field, $selectedValue, $name, $defaultValue, $defaultText, $submit, $displayPath, $doReplaceRootCat, $multipleSize); if ($editLink && $allowUserEdit && UserUtil::isLoggedIn() && SecurityUtil::checkPermission('ZikulaCategoriesModule::', "{$category['id']}::", ACCESS_EDIT)) { $url = ModUtil::url('ZikulaCategoriesModule', 'user', 'edituser'); $html .= " <a href=\"{$url}\">" . __('Edit sub-categories') . '</a>'; } if ($assign) { $view->assign($assign, $html); } else { return $html; } }
/** * Return the HTML selector code for the given category hierarchy, maps to CategoryUtil::getSelector_Categories(). * * @param array $cats The category hierarchy to generate a HTML selector for. * @param string $name The name of the selector field to generate (optional) (default='category[parent_id]'). * @param string $field The field value to return (optional) (default='id'). * @param integer $selectedValue The selected category (optional) (default=0). * @param integer $defaultValue The default value to present to the user (optional) (default=0). * @param string $defaultText The default text to present to the user (optional) (default=''). * @param integer $allValue The value to assign for the "All" choice (optional) (default=0). * @param string $allText The text to display for the "All" choice (optional) (default=''). * @param boolean $submit Whether or not to submit the form upon change (optional) (default=false). * @param boolean $displayPath If false, the path is simulated, if true, the full path is shown (optional) (default=false). * @param boolean $doReplaceRootCat Whether or not to replace the root category with a localized string (optional) (default=true). * @param integer $multipleSize If > 1, a multiple selector box is built, otherwise a normal/single selector box is build (optional) (default=1). * * @return The HTML selector code for the given category hierarchy. */ public static function getSelector_Categories($cats, $name, $field = 'id', $selectedValue = '0', $defaultValue = 0, $defaultText = '', $allValue = 0, $allText = '', $submit = false, $displayPath = false, $doReplaceRootCat = true, $multipleSize = 1) { return CategoryUtil::getSelector_Categories($cats, $field, $selectedValue, $name, $defaultValue, $defaultText, $allValue, $allText, $submit, $displayPath, $doReplaceRootCat, $multipleSize); }
public function deletedialog() { $this->checkAjaxToken(); $this->throwForbiddenUnless(SecurityUtil::checkPermission('Categories::', '::', ACCESS_DELETE)); $cid = $this->request->getPost()->get('cid'); $allCats = CategoryUtil::getSubCategories(1, true, true, true, false, true, $cid); $selector = CategoryUtil::getSelector_Categories($allCats); Zikula_AbstractController::configureView(); $this->view->setCaching(Zikula_View::CACHE_DISABLED); $this->view->assign('categorySelector', $selector); $result = array('result' => $this->view->fetch('categories_adminajax_delete.tpl')); return new Zikula_Response_Ajax($result); }
/** * Category selector. * * @param array $params All attributes passed to this function from the template. * @param Zikula_View $view Reference to the Zikula_View object. * * @return string */ function smarty_function_selector_category($params, Zikula_View $view) { $categoryRegistryModule = isset($params['categoryRegistryModule']) ? $params['categoryRegistryModule'] : ''; $categoryRegistryTable = isset($params['categoryRegistryTable']) ? $params['categoryRegistryTable'] : ''; $categoryRegistryProperty = isset($params['categoryRegistryProperty']) ? $params['categoryRegistryProperty'] : ''; $category = isset($params['category']) ? $params['category'] : 0; $path = isset($params['path']) ? $params['path'] : ''; $pathfield = isset($params['pathfield']) ? $params['pathfield'] : 'path'; $field = isset($params['field']) ? $params['field'] : 'id'; $fieldIsAttribute = isset($params['fieldIsAttribute']) ? $params['fieldIsAttribute'] : null; $selectedValue = isset($params['selectedValue']) ? $params['selectedValue'] : 0; $defaultValue = isset($params['defaultValue']) ? $params['defaultValue'] : 0; $defaultText = isset($params['defaultText']) ? $params['defaultText'] : ''; $allValue = isset($params['allValue']) ? $params['allValue'] : 0; $allText = isset($params['allText']) ? $params['allText'] : ''; $name = isset($params['name']) ? $params['name'] : 'defaultselectorname'; $submit = isset($params['submit']) ? $params['submit'] : false; $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; $displayPath = isset($params['displayPath']) ? $params['displayPath'] : false; $attributes = isset($params['attributes']) ? $params['attributes'] : null; $assign = isset($params['assign']) ? $params['assign'] : null; $editLink = isset($params['editLink']) ? $params['editLink'] : true; $multipleSize = isset($params['multipleSize']) ? $params['multipleSize'] : 1; $sortField = isset($params['sortField']) ? $params['sortField'] : 'sort_value'; $doReplaceRootCat = isset($params['doReplaceRootCat']) ? $params['doReplaceRootCat'] : null; $cssClass = isset($params['cssClass']) ? $params['cssClass'] : ''; if (isset($params['lang'])) { $lang = $params['lang']; $oldLocale = ZLanguage::getLocale(); ZLanguage::setLocale($lang); } else { $lang = ZLanguage::getLanguageCode(); } if (!$category && !$path && $categoryRegistryModule && $categoryRegistryTable && $categoryRegistryProperty) { $category = CategoryRegistryUtil::getRegisteredModuleCategory($categoryRegistryModule, $categoryRegistryTable, $categoryRegistryProperty); } // if we don't have a category-id we see if we can get a category by path if (!$category && $path) { $category = CategoryUtil::getCategoryByPath($path, $pathfield); } elseif (is_numeric($category)) { // check if we have a numeric category $category = CategoryUtil::getCategoryByID($category); } elseif (is_string($category) && strpos($category, '/') === 0) { // check if we have a string/path category $category = CategoryUtil::getCategoryByPath($category, $pathfield); } static $catCache; if (!$catCache) { $catCache = array(); } $cacheKey = "{$category['id']}||{$recurse}|{$relative}|{$includeRoot}|{$includeLeaf}|{$all}|||{$attributes}|{$sortField}"; if (!isset($catCache[$cacheKey])) { $catCache[$cacheKey] = CategoryUtil::getSubCategoriesForCategory($category, $recurse, $relative, $includeRoot, $includeLeaf, $all, '', '', $attributes, $sortField); } $html = CategoryUtil::getSelector_Categories($catCache[$cacheKey], $field, $selectedValue, $name, $defaultValue, $defaultText, $allValue, $allText, $submit, $displayPath, $doReplaceRootCat, $multipleSize, $fieldIsAttribute, $cssClass, $lang); if ($editLink && !empty($category) && SecurityUtil::checkPermission('ZikulaCategoriesModule::', "{$category['id']}::", ACCESS_EDIT)) { $url = DataUtil::formatForDisplay(ModUtil::url('ZikulaCategoriesModule', 'user', 'edit', array('dr' => $category['id']))); $html .= " <a href=\"{$url}\"><img src=\"" . System::getBaseUrl() . "images/icons/extrasmall/xedit.png\" title=\"" . __('Edit sub-category') . '" alt="' . __('Edit sub-category') . '" /></a>'; } if (isset($params['lang'])) { // Reset language again. ZLanguage::setLocale($oldLocale); } if ($assign) { $view->assign($assign, $html); } else { return $html; } }
/** * generic function to handle copy, delete and move operations */ public function op() { $cid = FormUtil::getPassedValue('cid', 1); $root_id = FormUtil::getPassedValue('dr', 1); $op = FormUtil::getPassedValue('op', 'NOOP'); if (!SecurityUtil::checkPermission('Categories::category', "ID::$cid", ACCESS_DELETE)) { return LogUtil::registerPermissionError(); } $category = new Categories_DBObject_Category(); $category = $category->select($cid); $subCats = CategoryUtil::getSubCategories($cid, false, false); $allCats = CategoryUtil::getSubCategories($root_id, true, true, true, false, true, $cid); $selector = CategoryUtil::getSelector_Categories($allCats); $this->view->assign('category', $category) ->assign('numSubcats', count($subCats)) ->assign('categorySelector', $selector); return $this->view->fetch("categories_admin_{$op}.tpl"); }