/** * @param $value * @return int|null */ public function fromCSV($value) { if ($value && ($category = JBModelCategory::model()->getByAlias($value))) { $this->_category->parent = $category->id; } else { $parentCategory = JBModelCategory::model()->createEmpty($this->_category->application_id); $this->_category->parent = $parentCategory->id; } return $this->_category; }
/** * Get current app id and category list. * * @return array */ protected function _getCategoryList() { $config = $this->_jbconfig->getList('export.items'); list($appId, $categoryList) = explode(':', $this->_getItemsAppCategory()); $categoryList = (array) $categoryList; // get full category list if ((int) $config->get('category_nested', 0) && !in_array('-1', $categoryList)) { $categoryList = \JBModelCategory::model()->getNestedCategories($categoryList); } return array($appId, $categoryList); }
/** * @param $value * @param null $position * @return Item|void */ public function fromCSV($value, $position = null) { $categoriesAlias = $this->_getArray($value, JBCSVItem::SEP_ROWS, 'alias'); $result = array(); foreach ($categoriesAlias as $alias) { if ($category = JBModelCategory::model()->getByAlias($alias, $this->_item->application_id)) { $result[] = $category->id; } $result = array_unique($result); } $this->_element->bindData(array('category' => $result)); return $this->_item; }
/** * @return array|string */ public function toCSV() { $result = array(); $categories = JBModelItem::model()->getItemCategories($this->_item->id); foreach ($categories as $category) { $name = $category->name . JBCSVItem::SEP_CELL . $category->alias; while ($category && ($category = JBModelCategory::model()->getParent($category->parent))) { $name = $category->name . JBCSVItem::SEP_CELL . $category->alias . JBCSVItem::SEP_ROWS . $name; } $result[] = $name; } return $result; }
/** * @param $key * @param $value * @return array */ public function validateValues($key, $value) { $app = App::getInstance('zoo'); $result = array(); if (is_numeric($value)) { $result[$key] = $value; } else { $slug = $app->string->sluggify($value); $cat = JBModelCategory::model()->getByAlias($slug); if (!empty($cat)) { $result[$key] = $cat->id; } } return !empty($result) ? $result : false; }
// set vars $subcategory = $vars['object']; $params = $subcategory->getParams('site'); $link = $this->app->route->category($subcategory); $task = $this->app->jbrequest->get('task', 'category'); // teaser content $text = $params->get('content.category_teaser_text', ''); $imageAlign = $params->get('template.subcategory_teaser_image_align', 'left'); // items $itemsOrder = $vars['params']->get('config.item_order', 'none'); $maxItems = $vars['params']->get('template.subcategory_items_count', 5); $showCount = $vars['params']->get('template.subcategory_items_count_show', 1); $items = array(); $countItems = 0; if ($showCount || $maxItems != "0" || $maxItems == "-1") { $items = JBModelCategory::model()->getItemsByCategory($subcategory->application_id, $subcategory->id, $itemsOrder, $maxItems); $countItems = $subcategory->itemCount(); } $image = $this->app->jbimage->get('category_teaser_image', $params); ?> <div class="subcategory clearfix subcategory-<?php echo $subcategory->alias; ?> "> <?php if ($vars['params']->get('template.subcategory_teaser_image', 1) && $image['src']) { ?> <div class="subcategory-image pull-<?php echo $imageAlign; ?>
/** * Get category list * @param $appId * @param array $options * @return mixed */ protected function _getCategoryList($appId = null, $options = array()) { return JBModelCategory::model()->getList($appId, $options); }
/** * Get Zoo items * @param int $appId * @param int|array $catId * @param string $typeId * @param array $options * @return array */ public function getList($appId = null, $catId = null, $typeId = null, $options = array()) { $options = $this->app->data->create($options); // create select $select = $this->_getSelect()->select('tItem.id')->from(ZOO_TABLE_ITEM . ' AS tItem'); // check type if (!empty($typeId)) { $typeId = (array) $typeId; $select->where('tItem.type IN ("' . implode('", "', $typeId) . '")'); } // check appId if (is_array($appId)) { $select->where('tItem.application_id IN (' . implode(',', $appId) . ')'); } elseif ((int) $appId) { $select->where('tItem.application_id = ?', (int) $appId); } // check category if (!empty($catId) && $catId != -1) { $select->innerJoin(ZOO_TABLE_CATEGORY_ITEM . ' AS tCategoryItem ON tItem.id = tCategoryItem.item_id'); $catId = (array) $catId; $subcatId = array(); if ((int) $options->get('category_nested')) { $subcatId = JBModelCategory::model()->getNestedCategories($catId); } $catId += $subcatId; if (!empty($catId)) { $select->where('tCategoryItem.category_id IN ("' . implode('", "', $catId) . '")'); } } // set limit if ($options->get('limit')) { $limit = $options->get('limit'); if (is_array($limit)) { $select->limit($limit[1], $limit[0]); } else { $select->limit($limit); } } if ($options->get('id')) { $idList = (array) $options->get('id'); $select->where('tItem.id IN (' . implode(',', $idList) . ')'); } // check access if ($options->get('user')) { $select->where('tItem.' . $this->app->user->getDBAccessString()); } // check status if ($options->get('published') == 1) { $select->where('tItem.state = ?', 1)->where('(tItem.publish_up = ' . $this->_dbNull . ' OR tItem.publish_up <= ' . $this->_dbNow . ')')->where('(tItem.publish_down = ' . $this->_dbNull . ' OR tItem.publish_down >= ' . $this->_dbNow . ')'); } else { if ($options->get('state') == 2) { $select->where('tItem.state = ?', 1); } else { if ($options->get('state') == 3) { $select->where('tItem.state = ?', 0); } } } $order = $options->get('order', 'id'); if (isset($order)) { $select->order($this->app->jborder->get($options->get('order', 'id'), 'tItem')); } $rows = $this->_query($select); if (!empty($rows)) { // convert id list to Zoo Items $ids = $this->_groupBy($rows, 'id'); $result = $this->getZooItemsByIds($ids, $order); return $result; } return array(); }
/** * Call after all items loaded */ public function categoriesPostProcess() { $addedIds = $this->app->jbsession->get('ids', 'import-ids'); $this->_initSessionData(); if ($this->_data->lose == self::LOSE_DISABLE) { JBModelCategory::model()->disableAll($this->_data->appid, $addedIds); } else { if ($this->_data->lose == self::LOSE_REMOVE) { JBModelCategory::model()->removeAll($this->_data->appid, $addedIds); } } $this->app->jbsession->clearGroup('import-ids'); }
/** * Get category list * @return array */ protected function _getCategories() { $categories = JBModelCategory::model()->getList($this->_params->get('app_id'), array('limit' => $this->_params->get('category_limit'), 'parent' => $this->_params->get('cat_id'), 'order' => $this->_params->get('category_order'), 'published' => 1)); return $categories; }