protected function getItems(&$group) { $items = parent::getItems($group); foreach ($items as $item) { $cats = CategoryUtil::getSubCategories($item); foreach ($cats as $item) { if (!in_array($item['id'], $items)) { $items[] = $item['id']; } } } return $items; }
/** * resequence categories */ public function resequence() { if (!SecurityUtil::checkPermission('Categories::', '::', ACCESS_EDIT)) { return LogUtil::registerPermissionError(); } $dr = (int)FormUtil::getPassedValue('dr', 0, 'GET'); $url = System::serverGetVar('HTTP_REFERER'); if (!$dr) { return LogUtil::registerError($this->__('Error! The document root is invalid.'), null, $url); } $cats = CategoryUtil::getSubCategories($dr, false, false, false, false); $cats = CategoryUtil::resequence($cats, 10); $ak = array_keys($cats); foreach ($ak as $k) { $obj = new Categories_DBObject_Category($cats[$k]); $obj->update(); } $this->redirect(System::serverGetVar('HTTP_REFERER')); }
/** * Executes additional actions for the editing mode. */ public function startEditing() { // ensure that the view does not look for templates in the Content module (#218) $this->view->toplevelmodule = 'MUVideo'; // ensure our custom plugins are loaded array_push($this->view->plugins_dir, 'modules/MUVideo/templates/plugins'); // assign category data $this->view->assign('registries', $this->catRegistries); $this->view->assign('properties', $this->catProperties); // assign categories lists for simulating category selectors $dom = ZLanguage::getModuleDomain('MUVideo'); $locale = ZLanguage::getLanguageCode(); $categories = array(); foreach ($this->catRegistries as $registryId => $registryCid) { $propName = ''; foreach ($this->catProperties as $propertyName => $propertyId) { if ($propertyId == $registryId) { $propName = $propertyName; break; } } //$mainCategory = CategoryUtil::getCategoryByID($registryCid); $cats = CategoryUtil::getSubCategories($registryCid, true, true, false, true, false, null, '', null, 'sort_value'); $catsForDropdown = array(array('value' => '', 'text' => __('All', $dom))); foreach ($cats as $cat) { $catName = isset($cat['display_name'][$locale]) ? $cat['display_name'][$locale] : $cat['name']; $catsForDropdown[] = array('value' => $cat['id'], 'text' => $catName); } $categories[$propName] = $catsForDropdown; } $this->view->assign('categories', $categories); }
/** * Returns DQL code. * * @param string $field Field name. * @param string $op Operator. * @param string $value Test value. * * @return array Doctrine Query where clause and parameters. */ public function getDql($field, $op, $value) { if (array_search($op, $this->ops) === false || !$this->fieldExists($field)) { return ''; } $where = ''; $column = $this->getColumn($field); switch ($op) { case 'eq': $where = "{$column} = '{$value}'"; break; case 'ne': $where = "{$column} <> '{$value}'"; break; case 'sub': $cats = CategoryUtil::getSubCategories($value); $items = array(); $items[] = $value; foreach ($cats as $item) { $items[] = $item['id']; } if (count($items) == 1) { $where = "{$column} = '" . implode("", $items) . "'"; } else { $where = "{$column} IN ('" . implode("','", $items) . "')"; } break; } return array('where' => $where); }
public function save() { $this->checkAjaxToken(); $mode = $this->request->getPost()->get('mode', 'new'); $accessLevel = $mode == 'edit' ? ACCESS_EDIT : ACCESS_ADD; $this->throwForbiddenUnless(SecurityUtil::checkPermission('Categories::', '::', $accessLevel)); $result = array(); $cat = new Categories_DBObject_Category(); $cat->getDataFromInput(); if (!$cat->validate()) { $args = array('cid' => $cat->getDataField('id'), 'parent' => $cat->getDataField('parent_id'), 'mode' => $mode); return $this->edit($args); } $attributes = array(); $values = $this->request->getPost()->get('attribute_value'); foreach ($this->request->getPost()->get('attribute_name') as $index => $name) { if (!empty($name)) { $attributes[$name] = $values[$index]; } } $cat->setDataField('__ATTRIBUTES__', $attributes); if ($mode == 'edit') { // retrieve old category from DB $category = $this->request->getPost()->get('category'); $oldCat = new Categories_DBObject_Category(DBObject::GET_FROM_DB, $category['id']); // update new category data $cat->update(); // since a name change will change the object path, we must rebuild it here if ($oldCat->getDataField('name') != $cat->getDataField('name')) { CategoryUtil::rebuildPaths('path', 'name', $cat->getDataField('id')); } } else { $cat->insert(); // update new category data $cat->update(); } $categories = CategoryUtil::getSubCategories($cat->getDataField('id'), true, true, true, true, true); $options = array('nullParent' => $cat->getDataField('parent_id'), 'withWraper' => false); $node = CategoryUtil::getCategoryTreeJS((array) $categories, true, true, $options); $leafStatus = array('leaf' => array(), 'noleaf' => array()); foreach ($categories as $c) { if ($c['is_leaf']) { $leafStatus['leaf'][] = $c['id']; } else { $leafStatus['noleaf'][] = $c['id']; } } $result = array('action' => $mode == 'edit' ? 'edit' : 'add', 'cid' => $cat->getDataField('id'), 'parent' => $cat->getDataField('parent_id'), 'node' => $node, 'leafstatus' => $leafStatus, 'result' => true); return new Zikula_Response_Ajax($result); }
/** * decode custom url string * * @author Philipp Niethammer * @return bool true if succeded false otherwise */ public function decodeurl($args) { $suffix = $this->getVar('shorturlsuffix'); $supportedfunctions = array('main', 'list', 'view', 'subpages', 'sitemap', 'extlist', 'categoriesList', 'pagelist'); $argsnum = count($args['vars']); if (!isset($args['vars'][2]) || empty($args['vars'][2])) { System::queryStringSetVar('func', 'sitemap'); return true; } if (in_array($args['vars'][2], $supportedfunctions)) { return false; } $lastarg = end($args['vars']); $urlname = ''; if (substr($lastarg, strlen($lastarg) - strlen($suffix)) == $suffix) { for ($i = 2; $i < $argsnum; $i++) { if (!empty($urlname)) { $urlname .= '/'; } $urlname .= $args['vars'][$i]; } if (($suffixLen = strlen($suffix)) > 0) { $urlname = substr($urlname, 0, -$suffixLen); } System::queryStringSetVar('func', 'view'); System::queryStringSetVar('name', $urlname); return true; } if (!isset($args['vars'][3]) || empty($args['vars'][3])) { $mainCategory = CategoryRegistryUtil::getRegisteredModuleCategory('Content', 'content_page', $this->getVar('categoryPropPrimary'), 30); // 30 == /__SYSTEM__/Modules/Global //$cats = CategoryUtil::getCategoriesByParentID($mainCategory); $cats = CategoryUtil::getSubCategories($mainCategory); foreach ($cats as $cat) { if ($args['vars'][2] == $cat['name'] || $args['vars'][2] == DataUtil::formatForURL($cat['name'])) { System::queryStringSetVar('func', 'listpages'); System::queryStringSetVar('cat', $cat['id']); return true; } } } for ($i = 2; $i < $argsnum; $i++) { if (!empty($urlname)) { $urlname .= '/'; } $urlname .= $args['vars'][$i]; } System::queryStringSetVar('func', 'subpages'); System::queryStringSetVar('name', $urlname); return true; }
/** * 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"); }
/** * Returns SQL code. * * @param string $field Field name. * @param string $op Operator. * @param string $value Test value. * * @return array SQL code array. */ public function getSQL($field, $op, $value) { if (array_search($op, $this->availableOperators()) === false || array_search($field, $this->fields) === false) { return ''; } $items = array($value); if ($op == 'sub') { $cats = CategoryUtil::getSubCategories($value); foreach ($cats as $item) { $items[] = $item['id']; } } $filter = array('__META__' => array('module' => $this->module)); foreach ($this->property as $prop) { $filter[$prop] = $items; } $where = DBUtil::generateCategoryFilterWhere($this->dbtable, false, $filter); if ($op == 'ne') { $where = str_replace(' IN ', ' NOT IN ', $where); } return array('where' => $where); }
/** * Return some useful News links * * Syntax used in menutree * {ext:Blocks:news:[flat=BOOL&links=view,add,cat,arch|ALL]} * Params in [] are optional and * flat - true or false, if set to true links are ungrouped (default is false) * links - list of elements, default is ALL, avaiable items: * - view - link to main News view * - add - link do Submit News form * - cat - list of News categories * - arch - link to News archive * Items are displayed in order provided in menutree * * @param array $args['item'] menu node to be replaced * @param string $args['lang'] current menu language * @param string $args['extrainfo'] additional params * @return mixed array of links if successful, false otherwise */ public function news($args) { $dom = ZLanguage::getModuleDomain('menutree'); $item = isset($args['item']) && !empty($args['item']) ? $args['item'] : null; $lang = isset($args['lang']) && !empty($args['lang']) ? $args['lang'] : null; $bid = isset($args['bid']) && !empty($args['bid']) ? $args['bid'] : null; $extrainfo = isset($args['extrainfo']) && !empty($args['extrainfo']) ? $args['extrainfo'] : null; // $item ang lang params are required if (!$item || !$lang) { return false; } // is there is extrainfo - convert it into array, parse_str is quite handy if ($extrainfo) { parse_str($extrainfo, $extrainfo); } $extrainfo['flat'] = isset($extrainfo['flat']) ? (bool) $extrainfo['flat'] : false; $extrainfo['links'] = isset($extrainfo['links']) ? explode(',', $extrainfo['links']) : array('all'); // get id for first element, use api func to aviod id conflicts inside menu $idoffset = Blocks_MenutreeUtil::getIdOffset($item['id']); $lineno = 0; // load plugin language file $modinfo = ModUtil::getInfo(ModUtil::getIdFromName('News')); $links = array(); // build some link // you may use associative array keys if (!$extrainfo['flat']) { $links['news'] = array($lang => array('id' => $idoffset++, 'name' => $item['name'], 'href' => ModUtil::url('News'), 'title' => $item['title'], 'className' => $item['className'], 'state' => $item['state'], 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $item['parent'])); } $parentNode = !$extrainfo['flat'] ? $links['news'][$lang]['id'] : $item['parent']; if (in_array('all', $extrainfo['links']) || in_array('view', $extrainfo['links'])) { $links['view'] = array($lang => array('id' => $idoffset++, 'name' => $modinfo['displayname'], 'href' => ModUtil::url('News'), 'title' => __('View news', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode)); } if (in_array('all', $extrainfo['links']) || in_array('arch', $extrainfo['links'])) { $links['arch'] = array($lang => array('id' => $idoffset++, 'name' => __('Archive', $dom), 'href' => ModUtil::url('News', 'user', 'archives'), 'title' => __('Archive', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode)); } if (in_array('all', $extrainfo['links']) || in_array('add', $extrainfo['links'])) { $links['add'] = array($lang => array('id' => $idoffset++, 'name' => __('Submit news', $dom), 'href' => ModUtil::url('News', 'user', 'new'), 'title' => __('Submit news', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode)); } if (in_array('all', $extrainfo['links']) || in_array('cat', $extrainfo['links'])) { if (!$extrainfo['flat']) { $links['cat'] = array($lang => array('id' => $idoffset++, 'name' => __('Categories', $dom), 'href' => ModUtil::url('News'), 'title' => __('Categories', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $parentNode)); } $catParentNode = !$extrainfo['flat'] ? $links['cat'][$lang]['id'] : $item['parent']; Loader::loadClass('CategoryRegistryUtil'); Loader::loadClass('CategoryUtil'); $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('News', 'stories'); if (!empty($catregistry)) { $multicategory = count($catregistry) > 1; $catLinks = array(); foreach ($catregistry as $prop => $catid) { if ($multicategory && !$extrainfo['flat']) { $parentCategory = CategoryUtil::getCategoryByID($catid); $catLinks[$catid] = array($lang => array('id' => $idoffset++, 'name' => isset($parentCategory['display_name'][$lang]) && !empty($parentCategory['display_name'][$lang]) ? $parentCategory['display_name'][$lang] : $parentCategory['name'], 'href' => '', 'title' => isset($parentCategory['display_name'][$lang]) && !empty($parentCategory['display_name'][$lang]) ? $parentCategory['display_name'][$lang] : $parentCategory['name'], 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => $catParentNode)); } $categories = CategoryUtil::getSubCategories($catid); foreach ($categories as $cat) { $catLinks[$cat['id']] = array($lang => array('id' => $idoffset++, 'name' => isset($cat['display_name'][$lang]) && !empty($cat['display_name'][$lang]) ? $cat['display_name'][$lang] : $cat['name'], 'href' => ModUtil::url('News', 'user', 'view', array('prop' => $prop, 'cat' => $cat['name'])), 'title' => isset($cat['display_name'][$lang]) && !empty($cat['display_name'][$lang]) ? $cat['display_name'][$lang] : $cat['name'], 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => $lineno++, 'parent' => isset($catLinks[$cat['parent_id']]) ? $catLinks[$cat['parent_id']][$lang]['id'] : $catParentNode)); } } } elseif (!$extrainfo['flat']) { unset($links['cat']); } } // sort links in order provided in menutree if (!in_array('all', $extrainfo['links'])) { $sortedLinks = array(); if (!$extrainfo['flat']) { $sortedLinks[] = $links['news']; } foreach ($extrainfo['links'] as $l) { if (isset($links[$l]) && !empty($links[$l])) { $sortedLinks[] = $links[$l]; } if ($l == 'cat') { $sortedLinks = array_merge((array) $sortedLinks, (array) $catLinks); } } $links = $sortedLinks; } return $links; }