Перейти к содержимому


Фотография
- - - - -

Фильтр в админке - сортировка


Лучший Ответ SmetDenis , 14 June 2016 - 06:37

Нужно сделать так.

 

35sa_200x0.png

 

  1.         } else {
  2.             $from .= ' LEFT JOIN ' . ZOO_TABLE_TAG . ' AS tTag ON a.id = tTag.item_id';
  3.         }

 

bm0n_200x0.png

Перейти к сообщению


  • Закрытая тема Тема закрыта
Сообщений в теме: 5

#1 CB9TOIIIA

CB9TOIIIA

Отправлено 21 March 2016 - 15:15

Всем привет!

 

Вывел доп. столбец в админке по publish_up  - но как задать по умолчанию сортировку по нему, а не по date не пойму. Есть идеи? 

 

vGmBx5w.png
 

 

Правил: administration\....\com_zoo\item\default.php


  • 0

#2 CB9TOIIIA

CB9TOIIIA

Отправлено 21 March 2016 - 18:27

и существует ли сортировка по тегам? попробовал - фаталку получил) a.tags

 

Сделал просто:

  1. <?php $tagsmas = $row->getTags();
  2. if (isset($tagsmas[0])) {
  3. echo "<center><img src='/administrator/components/com_zoo/assets/images/tick.png' width='16' height='16' border='0' alt='Да'></center>";
  4. } else {
  5.  
  6. }
  7. ?>

можно ли сортировать или нет?


Сообщение отредактировал CB9TOIIIA: 22 March 2016 - 09:35

  • 0

#3 SmetDenis

SmetDenis

Отправлено 22 March 2016 - 14:01

Значение по умолчанию для сортировки находится тут
y598_200x0.png

Замечу что оно может быть взять из настроек пользователя (сессии).

Выборка и соответственно сортировка происходит тут
zyu2_200x0.png


Массива $options это упрощенный конструктор запросов в мускул.
Он зависит от переменной $from. Думаю в неё нужно добавить LEFT JOIN таблицы тегов
Что-то вроде
  1. $from .= ' LEFT JOIN ' . ZOO_TABLE_TAG . ' AS tag ON a.id = tag.item_id';
Соответственно колонка для сортировки должна tag.name (имя тега)

"a.tags" - Это значит таблица "a" (алиас таблицы материалов) с полем tags (конечно же его нет, т.к они хранятся в другой таблице).
Поэтому получается фатальная ошибка.
  • 1
JBZoo v4.0 и новый чудный мир Open Source GPL
Отключайте проверку лицензий как можно скорее!



— Есть два типа людей: Кто еще не делает бекапы и кто уже делает бекапы.


#4 CB9TOIIIA

CB9TOIIIA

Отправлено 11 June 2016 - 09:21

Что-то никак.

 

Пробовал так:

 

default.php

  1. <th class="tags" style="width:30px;">
  2. <?php //echo "<center> Теги </center>";
  3. echo $this->app->html->_('grid.sort', 'Tags', 'tTag.item_id', @$this->lists['order_Dir'], @$this->lists['order']);
  4.  
  5. ?>
  1. <td class="tags">
  2. <?php $tagsmas = $row->getTags();
  3. if (isset($tagsmas[0])) {
  4. echo "<center><img src='/administrator/components/com_zoo/assets/images/tick.png' width='16' height='16' border='0' alt='Да'></center>";
  5. } else {
  6.  
  7. }
  8. ?>
  9. </td>

item.php

  1. <?php
  2. /**
  3. * @package com_zoo
  4. * @author YOOtheme http://www.yootheme.com
  5. * @copyright Copyright (C) YOOtheme GmbH
  6. * @license http://www.gnu.org/licenses/gpl.html GNU/GPL
  7. */
  8.  
  9. /*
  10. Class: ItemController
  11. The controller class for item
  12. */
  13. class ItemController extends AppController {
  14.  
  15. public $application;
  16.  
  17. const MAX_MOST_USED_TAGS = 8;
  18.  
  19. public function __construct($default = array()) {
  20. parent::__construct($default);
  21.  
  22. // set table
  23. $this->table = $this->app->table->item;
  24.  
  25. // get application
  26. $this->application = $this->app->zoo->getApplication();
  27.  
  28. // set base url
  29. $this->baseurl = $this->app->link(array('controller' => $this->controller), false);
  30.  
  31. // set user
  32. $this->user = $this->app->user->get();
  33.  
  34. // register tasks
  35. $this->registerTask('element', 'display');
  36. $this->registerTask('apply', 'save');
  37. $this->registerTask('save2new', 'save');
  38. }
  39.  
  40. public function display($cachable = false, $urlparams = false) {
  41.  
  42. // get app from Request (currently used in zooapplication element)
  43. if ($id = $this->app->request->getInt('app_id')) {
  44. $this->application = $this->app->table->application->get($id);
  45. }
  46.  
  47. // get database
  48. $this->db = $this->app->database;
  49.  
  50. // set toolbar items
  51. $canCreate = false;
  52. $canDelete = false;
  53. $canEditState = false;
  54.  
  55. foreach ($this->application->getTypes() as $type) {
  56. if ($type->canCreate()) {
  57. $canCreate = true;
  58. }
  59. if ($type->canDelete()) {
  60. $canDelete = true;
  61. }
  62. if ($type->canEditState()) {
  63. $canEditState = true;
  64. }
  65. }
  66. $this->app->system->application->JComponentTitle = $this->application->getToolbarTitle(JText::_('Items'));
  67. if ($canCreate) {
  68. $this->app->toolbar->addNew();
  69. }
  70. $this->app->toolbar->editList();
  71. if ($canEditState) {
  72. $this->app->toolbar->publishList();
  73. $this->app->toolbar->unpublishList();
  74. }
  75. if ($this->application->canManageFrontpage()) {
  76. $this->app->toolbar->custom('togglefrontpage', 'checkin', 'checkin', 'Toggle Frontpage', true);
  77. }
  78. if ($canCreate) {
  79. $this->app->toolbar->custom('docopy', 'copy.png', 'copy_f2.png', 'Copy');
  80. }
  81. if ($canDelete) {
  82. $this->app->toolbar->deleteList();
  83. }
  84.  
  85. $this->app->zoo->toolbarHelp();
  86.  
  87. $this->app->html->_('behavior.tooltip');
  88.  
  89. // get request vars
  90. $this->filter_item = $this->app->request->getInt('item_filter', 0);
  91. $this->type_filter = $this->app->request->get('type_filter', 'array', array());
  92. $state_prefix = $this->option.'_'.$this->application->id.'.'.($this->getTask() == 'element' ? 'element' : 'item').'.';
  93. $filter_order = $this->app->system->application->getUserStateFromRequest($state_prefix.'filter_order', 'filter_order', 'a.created', 'cmd');
  94. $filter_order_Dir = $this->app->system->application->getUserStateFromRequest($state_prefix.'filter_order_Dir', 'filter_order_Dir', 'desc', 'word');
  95. $filter_category_id = $this->app->system->application->getUserStateFromRequest($state_prefix.'filter_category_id', 'filter_category_id', '-1', 'string');
  96. $limit = $this->app->system->application->getUserStateFromRequest('global.list.limit', 'limit', $this->app->system->config->get('list_limit'), 'int');
  97. $limitstart = $this->app->system->application->getUserStateFromRequest($state_prefix.'limitstart', 'limitstart', 0, 'int');
  98. $filter_type = $this->app->system->application->getUserStateFromRequest($state_prefix.'filter_type', 'filter_type', '', 'string');
  99. $filter_author_id = $this->app->system->application->getUserStateFromRequest($state_prefix.'filter_author_id', 'filter_author_id', 0, 'int');
  100. $search = $this->app->system->application->getUserStateFromRequest($state_prefix.'search', 'search', '', 'string');
  101. $tags = $this->app->system->application->getUserStateFromRequest($state_prefix.'tTag.item_id', 'tags', '', 'string');
  102. $search = $this->app->string->strtolower($search);
  103.  
  104. // is filtered ?
  105. $this->is_filtered = $filter_category_id <> '-1' || !empty($filter_type) || !empty($filter_author_id) || !empty($search);
  106.  
  107. $this->users = $this->table->getUsers($this->application->id);
  108. $this->groups = $this->app->zoo->getGroups();
  109.  
  110. // select
  111. $select = 'a.*, EXISTS (SELECT true FROM '.ZOO_TABLE_CATEGORY_ITEM.' WHERE item_id = a.id AND category_id = 0) as frontpage';
  112.  
  113. // get from
  114. $from = $this->table->name.' AS a';
  115.  
  116. // get data from the table
  117. $where = array();
  118.  
  119. // application filter
  120. $where[] = 'a.application_id = ' . (int) $this->application->id;
  121.  
  122. // category filter
  123. if ($filter_category_id === '') {
  124. $from .= ' LEFT JOIN '.ZOO_TABLE_CATEGORY_ITEM.' AS ci ON a.id = ci.item_id';
  125. $where[] = 'ci.item_id IS NULL';
  126. } else if ($filter_category_id > -1) {
  127. $from .= ' LEFT JOIN '.ZOO_TABLE_CATEGORY_ITEM.' AS ci ON a.id = ci.item_id';
  128. $where[] = 'ci.category_id = ' . (int) $filter_category_id;
  129. }
  130.  
  131. // type filter
  132. if (!empty($this->type_filter)) {
  133. $where[] = 'a.type IN ("' . implode('", "', $this->type_filter) . '")';
  134. } else if (!empty($filter_type)) {
  135. $where[] = 'a.type = "' . (string) $filter_type . '"';
  136. }
  137.  
  138. // item filter
  139. if ($this->filter_item > 0) {
  140. $where[] = 'a.id != ' . (int) $this->filter_item;
  141. }
  142.  
  143. // author filter
  144. if ($filter_author_id > 0) {
  145. $where[] = 'a.created_by = ' . (int) $filter_author_id;
  146. }
  147.  
  148. // if ($search) {
  149. // $from .= ' LEFT JOIN '.ZOO_TABLE_TAG.' AS t ON a.id = t.item_id';
  150. // $where[] = '(LOWER(a.name) LIKE '.$this->db->Quote('%'.$this->db->escape($search, true).'%', false)
  151. // . ' OR LOWER(t.name) LIKE '.$this->db->Quote('%'.$this->db->escape($search, true).'%', false)
  152. // . ' OR LOWER(a.alias) LIKE '.$this->db->Quote('%'.$this->db->escape($search, true).'%', false) . ')';
  153. // }
  154.  
  155.  
  156. if ($search) {
  157.  
  158. $searchData = explode(' ', $search);
  159. $searchWhere = array();
  160.  
  161. $from .= ' LEFT JOIN ' . ZOO_TABLE_SEARCH . ' AS s ON a.id = s.item_id';
  162. $from .= ' LEFT JOIN ' . ZOO_TABLE_TAG . ' AS tTag ON tItem.id = tTag.item_id';
  163.  
  164. foreach ($searchData as $searchWord) {
  165.  
  166. $searchWord = JString::trim($searchWord);
  167.  
  168. $searchWhere[] = implode(' OR ', array(
  169. // 'LOWER(a.name) REGEXP ' . $this->db->Quote('^' . $this->db->escape($searchWord, true) . '', false),
  170. // 'LOWER(a.name) REGEXP ' . $this->db->Quote('' . $this->db->escape($searchWord, true) . '$', false),
  171. // 'LOWER(a.name) REGEXP ' . $this->db->Quote(' ' . $this->db->escape($searchWord, true) . '', false),
  172. // 'LOWER(a.name) REGEXP ' . $this->db->Quote('' . $this->db->escape($searchWord, true) . ' ', false),
  173. 'LOWER(a.name) REGEXP ' . $this->db->Quote('[[:<:]]' . $this->db->escape($searchWord, true) . '[[:>:]]', false),
  174. 'LOWER(a.name) LIKE '.$this->db->Quote('%'.$this->db->escape($search, true).'%', false)
  175.  
  176. ));
  177. }
  178.  
  179. $where[] = '((' . implode(') AND (', $searchWhere) . '))';
  180. }
  181.  
  182. $options = array(
  183. 'select' => 'a.id',
  184. 'from' => $from,
  185. 'conditions' => array(implode(' AND ', $where)),
  186. 'group' => 'a.id');
  187.  
  188. $count = $this->table->count($options);
  189.  
  190. $options['select'] = $select;
  191. $options['order'] = $filter_order.' '.$filter_order_Dir;
  192.  
  193. // in case limit has been changed, adjust limitstart accordingly
  194. $limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
  195. $limitstart = $limitstart > $count ? floor($count / $limit) * $limit : $limitstart;
  196.  
  197. $this->items = $this->table->all($limit > 0 ? array_merge($options, array('offset' => $limitstart, 'limit' => $limit)) : $options);
  198. $this->items = array_merge($this->items);
  199.  
  200. $this->pagination = $this->app->pagination->create($count, $limitstart, $limit);
  201.  
  202. // category select
  203. $options = array();
  204. $options[] = $this->app->html->_('select.option', '-1', '- ' . JText::_('Select Category') . ' -');
  205. $options[] = $this->app->html->_('select.option', '', '- ' . JText::_('uncategorized') . ' -');
  206. $options[] = $this->app->html->_('select.option', '0', '- '.JText::_('Frontpage'));
  207. $this->lists['select_category'] = $this->app->html->_('zoo.categorylist', $this->application, $options, 'filter_category_id', 'class="inputbox auto-submit"', 'value', 'text', $filter_category_id);
  208.  
  209. // type select
  210. $options = array($this->app->html->_('select.option', '0', '- '.JText::_('Select Type').' -'));
  211. $this->lists['select_type'] = $this->app->html->_('zoo.typelist', $this->application, $options, 'filter_type', 'class="inputbox auto-submit"', 'value', 'text', $filter_type, false, false, $this->type_filter);
  212.  
  213. // author select
  214. $options = array($this->app->html->_('select.option', '0', '- '.JText::_('Select Author').' -'));
  215. $this->lists['select_author'] = $this->app->html->_('zoo.itemauthorlist', $options, 'filter_author_id', 'class="inputbox auto-submit"', 'value', 'text', $filter_author_id);
  216.  
  217. // table ordering and search filter
  218. $this->lists['order_Dir'] = $filter_order_Dir;
  219. $this->lists['order'] = $filter_order;
  220. $this->lists['search'] = $search;
  221.  
  222. // display view
  223. $layout = $this->getTask() == 'element' ? 'element' : 'default';
  224. $this->getView()->setLayout($layout)->display();
  225. }
  226.  
  227. public function loadtags() {
  228.  
  229. // get request vars
  230. $tag = $this->app->request->getString('tag', '');
  231.  
  232. echo $this->app->tag->loadTags($this->application->id, $tag);
  233.  
  234. }
  235.  
  236. public function add() {
  237.  
  238. // set toolbar items
  239. $this->app->system->application->JComponentTitle = $this->application->getToolbarTitle(JText::_('Item') .': <small><small>[ '.JText::_('New').' ]</small></small>');
  240. $this->app->toolbar->cancel();
  241.  
  242. // get types
  243. $this->types = array();
  244. foreach ($this->application->getTypes() as $name => $type) {
  245. if ($this->app->user->canCreate(null, $type->getAssetName())) {
  246. $this->types[$name] = $type;
  247. }
  248. }
  249.  
  250. // no types available ?
  251. if (count($this->types) == 0) {
  252. $this->app->error->raiseNotice(0, JText::_('Please create a type first.'));
  253. $this->app->system->application->redirect($this->app->link(array('controller' => 'manager', 'task' => 'types', 'group' => $this->application->application_group), false));
  254. }
  255.  
  256. // only one type ? then skip type selection
  257. if (count($this->types) == 1) {
  258. $type = array_shift($this->types);
  259. $this->app->system->application->redirect($this->baseurl.'&task=edit&type='.$type->id);
  260. }
  261.  
  262. // display view
  263. $this->getView()->setLayout('add')->display();
  264. }
  265.  
  266. public function edit() {
  267.  
  268. // disable menu
  269. $this->app->request->setVar('hidemainmenu', 1);
  270.  
  271. // get request vars
  272. $cid = $this->app->request->get('cid.0', 'int');
  273. $edit = $cid > 0;
  274.  
  275. // get item
  276. if ($edit) {
  277. if (!$this->item = $this->app->table->item->get($cid)) {
  278. $this->app->error->raiseError(500, JText::sprintf('Unable to access item with id %s', $cid));
  279. return;
  280. }
  281.  
  282. // check ACL
  283. if (!$this->item->canEdit()) {
  284. throw new ItemControllerException("Invalid access permissions", 1);
  285. }
  286. } else {
  287. $this->item = $this->app->object->create('Item');
  288. $this->item->application_id = $this->application->id;
  289. $this->item->type = $this->app->request->getVar('type');
  290. $this->item->publish_down = $this->app->database->getNullDate();
  291. $this->item->access = $this->app->joomla->getDefaultAccess();
  292.  
  293. // check ACL
  294. if (!$this->item->canCreate()) {
  295. throw new ItemControllerException("Invalid access permissions", 1);
  296. }
  297. }
  298.  
  299. // get item params
  300. $this->params = $this->item->getParams();
  301.  
  302. // set toolbar items
  303. $this->app->system->application->JComponentTitle = $this->application->getToolbarTitle(JText::_('Item').': '.$this->item->name.' <small><small>[ '.($edit ? JText::_('Edit') : JText::_('New')).' ]</small></small>');
  304. $this->app->toolbar->apply();
  305. $this->app->toolbar->save();
  306. $this->app->toolbar->save2new();
  307. if ($edit) {
  308. $this->app->toolbar->save2copy();
  309. }
  310. $this->app->toolbar->cancel('cancel', $edit ? 'Close' : 'Cancel');
  311. $this->app->zoo->toolbarHelp();
  312.  
  313. // published select
  314. $this->lists['select_published'] = $this->app->html->_('select.booleanlist', 'state', null, $this->item->state);
  315.  
  316. // published searchable
  317. $this->lists['select_searchable'] = $this->app->html->_('select.booleanlist', 'searchable', null, $this->item->searchable);
  318.  
  319. // categories select
  320. $related_categories = $this->item->getRelatedCategoryIds();
  321. $this->lists['select_frontpage'] = $this->app->html->_('select.booleanlist', 'frontpage', null, in_array(0, $related_categories));
  322. $this->lists['select_categories'] = count($this->application->getCategoryTree()) > 1 ?
  323. $this->app->html->_('zoo.categorylist', $this->application, array(), 'categories[]', 'size="15" multiple="multiple" data-no_results_text="'.JText::_('No results match0r').'" data-placeholder="'.JText::_('Select Category').'"', 'value', 'text', $related_categories, false, false, 0 ,'<sup>|_</sup>&nbsp;', '.&nbsp;&nbsp;&nbsp;', '')
  324. : '<a href="'.$this->app->link(array('controller' => 'category'), false).'" >'.JText::_('Please add categories first').'</a>';
  325. $this->lists['select_primary_category'] = $this->app->html->_('zoo.categorylist', $this->application, array($this->app->html->_('select.option', '', JText::_('COM_ZOO_NONE'))), 'params[primary_category]', 'data-no_results_text="'.JText::_('No results match').'"', 'value', 'text', $this->params->get('config.primary_category'), false, false, 0 ,'<sup>|_</sup>&nbsp;', '.&nbsp;&nbsp;&nbsp;', '');
  326. // most used tags
  327. $this->lists['most_used_tags'] = $this->app->table->tag->getAll($this->application->id, null, null, 'items DESC, a.name ASC', null, self::MAX_MOST_USED_TAGS);
  328.  
  329. // comments enabled select
  330. $this->lists['select_enable_comments'] = $this->app->html->_('select.booleanlist', 'params[enable_comments]', null, $this->params->get('config.enable_comments', 1));
  331.  
  332. // display view
  333. $this->getView()->setLayout('edit')->display();
  334. }
  335.  
  336. public function save() {
  337.  
  338. // check for request forgeries
  339. $this->app->session->checkToken() or jexit('Invalid Token');
  340.  
  341. // init vars
  342. $now = $this->app->date->create();
  343. $frontpage = $this->app->request->getBool('frontpage', false);
  344. $categories = $this->app->request->get('categories', null);
  345. $details = $this->app->request->get('details', null);
  346. $cid = $this->app->request->get('cid.0', 'int');
  347. $tzoffset = $this->app->date->getOffset();
  348. $post = array_merge($this->app->request->get('post:', 'array', array()), $details);
  349.  
  350. try {
  351.  
  352. // get item
  353. if ($cid) {
  354. $item = $this->table->get($cid);
  355. } else {
  356. $item = $this->app->object->create('Item');
  357. $item->application_id = $this->application->id;
  358. $item->type = $this->app->request->getVar('type');
  359. }
  360.  
  361. // Check ACL
  362. if ($cid && !$item->canCreate() || !$cid && !$item->canEdit()) {
  363. throw new ItemControllerException("Invalid access permissions", 1);
  364. }
  365.  
  366. if (!$item->canEditState()) {
  367. unset($item->state);
  368. }
  369.  
  370. // bind item data
  371. self::bind($item, $post, array('elements', 'params', 'created_by'));
  372. $created_by = isset($post['created_by']) ? $post['created_by'] : '';
  373. $item->created_by = empty($created_by) ? $this->app->user->get()->id : $created_by == 'NO_CHANGE' ? $item->created_by : $created_by;
  374. $tags = isset($post['tags']) ? $post['tags'] : array();
  375. $item->setTags($tags);
  376.  
  377. // bind element data
  378. $item->elements = $this->app->data->create();
  379. foreach ($item->getElements() as $id => $element) {
  380. if (isset($post['elements'][$id])) {
  381. $element->bindData($post['elements'][$id]);
  382. } else {
  383. $element->bindData();
  384. }
  385. }
  386.  
  387. // set alias
  388. if (!strlen(trim($item->alias))) {
  389. $item->alias = $this->app->string->sluggify($item->name);
  390. }
  391. $item->alias = $this->app->alias->item->getUniqueAlias($item->id, $this->app->string->sluggify($item->alias));
  392.  
  393. // set modified
  394. $item->modified = $now->toSQL();
  395. $item->modified_by = $this->user->get('id');
  396.  
  397. // set created date
  398. try {
  399. $item->created = $this->app->date->create($item->created, $tzoffset)->toSQL();
  400. } catch (Exception $e) {
  401. $item->created = $this->app->date->create()->toSQL();
  402. }
  403.  
  404. // set publish up date
  405. try {
  406. $item->publish_up = $this->app->date->create($item->publish_up, $tzoffset)->toSQL();
  407. } catch (Exception $e) {
  408. $item->publish_up = $this->app->date->create()->toSQL();
  409. }
  410.  
  411. // set publish down date
  412. try {
  413. $item->publish_down = $this->app->date->create($item->publish_down, $tzoffset)->toSQL();
  414. } catch (Exception $e) {
  415. $item->publish_down = $this->app->database->getNullDate();
  416. }
  417.  
  418. // get primary category
  419. $primary_category = @$post['params']['primary_category'];
  420. if (empty($primary_category) && count($categories)) {
  421. $primary_category = $categories[0];
  422. }
  423.  
  424. // set params
  425. $item->getParams()
  426. ->remove('metadata.')
  427. ->remove('template.')
  428. ->remove('content.')
  429. ->remove('config.')
  430. ->set('metadata.', @$post['params']['metadata'])
  431. ->set('template.', @$post['params']['template'])
  432. ->set('content.', @$post['params']['content'])
  433. ->set('config.', @$post['params']['config'])
  434. ->set('config.enable_comments', @$post['params']['enable_comments'])
  435. ->set('config.primary_category', $primary_category);
  436.  
  437. // save item
  438. $this->table->save($item);
  439.  
  440. // make sure categories contain primary category
  441. if (!empty($primary_category) && !in_array($primary_category, $categories)) {
  442. $categories[] = $primary_category;
  443. }
  444.  
  445. // save category relations
  446. if ($frontpage) {
  447. $categories[] = 0;
  448. }
  449. $this->app->category->saveCategoryItemRelations($item, $categories);
  450.  
  451. // set redirect message
  452. $msg = JText::_('Item Saved');
  453.  
  454. } catch (AppException $e) {
  455.  
  456. // raise notice on exception
  457. $this->app->error->raiseNotice(0, JText::_('Error Saving Item').' ('.$e.')');
  458. $this->_task = 'apply';
  459. $msg = null;
  460.  
  461. }
  462.  
  463. $link = $this->baseurl;
  464. switch ($this->getTask()) {
  465. case 'save2copy' :
  466. case 'apply' :
  467. $link .= '&task=edit&type='.$item->type.'&cid[]='.$item->id;
  468. break;
  469. case 'save2new' :
  470. $link .= '&task=add';
  471. break;
  472. }
  473.  
  474. $this->setRedirect($link, $msg);
  475. }
  476.  
  477. public function save2copy() {
  478. $this->app->request->set('cid.0', 0)
  479. ->set('id', 0)
  480. ->set('name', $this->app->request->get('name', 'string').' ('.JText::_('Copy').')');
  481. $this->save();
  482. }
  483.  
  484. public function docopy() {
  485.  
  486. // check for request forgeries
  487. $this->app->session->checkToken() or jexit('Invalid Token');
  488.  
  489. // init vars
  490. $now = $this->app->date->create()->toSQL();
  491. $cid = $this->app->request->get('cid', 'array', array());
  492.  
  493. if (count($cid) < 1) {
  494. $this->app->error->raiseError(500, JText::_('Select a item to copy'));
  495. }
  496.  
  497. try {
  498.  
  499. // copy items
  500. foreach ($cid as $id) {
  501.  
  502. // get item
  503. $item = $this->table->get($id);
  504. $categories = $item->getRelatedCategoryIds();
  505.  
  506. // Check ACL
  507. if (!$item->canCreate()) {
  508. continue;
  509. }
  510.  
  511. // copy item
  512. $item->id = 0; // set id to 0, to force new item
  513. $item->name .= ' ('.JText::_('Copy').')'; // set copied name
  514. $item->alias = $this->app->alias->item->getUniqueAlias($id, $item->alias.'-copy'); // set copied alias
  515. $item->state = 0; // unpublish item
  516. $item->created = $item->modified = $now;
  517. $item->created_by = $item->modified_by = $this->user->get('id');
  518. $item->hits = 0;
  519.  
  520. // copy tags
  521. $item->setTags($this->app->table->tag->getItemTags($id));
  522.  
  523. // save copied item/element data
  524. $this->table->save($item);
  525.  
  526. // save category relations
  527. $this->app->category->saveCategoryItemRelations($item, $categories);
  528. }
  529.  
  530. // set redirect message
  531. $msg = JText::_('Item Copied');
  532.  
  533. } catch (AppException $e) {
  534.  
  535. // raise notice on exception
  536. $this->app->error->raiseNotice(0, JText::_('Error Copying Item').' ('.$e.')');
  537. $msg = null;
  538.  
  539. }
  540.  
  541. $this->setRedirect($this->baseurl, $msg);
  542. }
  543.  
  544. public function remove() {
  545.  
  546. // check for request forgeries
  547. $this->app->session->checkToken() or jexit('Invalid Token');
  548.  
  549. // init vars
  550. $cid = $this->app->request->get('cid', 'array', array());
  551.  
  552. if (count($cid) < 1) {
  553. $this->app->error->raiseError(500, JText::_('Select a item to delete'));
  554. }
  555.  
  556. try {
  557.  
  558. // delete items
  559. foreach ($cid as $id) {
  560. $item = $this->table->get($id);
  561.  
  562. // Check ACL
  563. if (!$item->canDelete()) {
  564. continue;
  565. }
  566.  
  567. $this->table->delete($item);
  568. }
  569.  
  570. // set redirect message
  571. $msg = JText::_('Item Deleted');
  572.  
  573. } catch (AppException $e) {
  574.  
  575. // raise notice on exception
  576. $this->app->error->raiseWarning(0, JText::_('Error Deleting Item').' ('.$e.')');
  577. $msg = null;
  578.  
  579. }
  580.  
  581. $this->setRedirect($this->baseurl, $msg);
  582. }
  583.  
  584. public function savepriority() {
  585.  
  586. // check for request forgeries
  587. $this->app->session->checkToken() or jexit('Invalid Token');
  588.  
  589. // init vars
  590. $msg = JText::_('Order Priority saved');
  591. // init vars
  592. $priority = $this->app->request->get('priority', 'array', array());
  593.  
  594. try {
  595.  
  596. // update the priority for items
  597. foreach ($priority as $id => $value) {
  598. $item = $this->table->get((int) $id);
  599.  
  600. // only update, if changed and ACL is checked
  601. if ($item->canEdit() && $item->priority != $value) {
  602. $item->priority = $value;
  603. $this->table->save($item);
  604. }
  605. }
  606.  
  607. // set redirect message
  608. $msg = json_encode(array(
  609. 'group' => 'info',
  610. 'title' => JText::_('Success!'),
  611. 'text' => JText::_('Item Priorities Saved')));
  612.  
  613. } catch (AppException $e) {
  614.  
  615. // raise error on exception
  616. $msg = json_encode(array(
  617. 'group' => 'error',
  618. 'title' => JText::_('Error!'),
  619. 'text' => JText::_('Error editing item priority').' ('.$e.')'));
  620.  
  621. }
  622.  
  623. echo $msg;
  624. }
  625.  
  626. public function resethits() {
  627.  
  628. // check for request forgeries
  629. $this->app->session->checkToken() or jexit('Invalid Token');
  630.  
  631. // init vars
  632. $msg = null;
  633. $cid = $this->app->request->get('cid.0', 'int');
  634.  
  635. try {
  636.  
  637. // get item
  638. $item = $this->table->get($cid);
  639.  
  640. // Check ACL
  641. if (!$item->canEdit()) {
  642. throw new ItemControllerException("Invalid access permissions", 1);
  643. }
  644.  
  645. // reset hits
  646. if ($item->hits > 0) {
  647. $item->hits = 0;
  648.  
  649. // save item
  650. $this->table->save($item);
  651.  
  652. // set redirect message
  653. $msg = JText::_('Item Hits Reseted');
  654. }
  655.  
  656. } catch (AppException $e) {
  657.  
  658. // raise notice on exception
  659. $this->app->error->raiseNotice(0, JText::_('Error Reseting Item Hits').' ('.$e.')');
  660. $msg = null;
  661.  
  662. }
  663.  
  664. $this->setRedirect($this->baseurl.'&task=edit&cid[]='.$item->id, $msg);
  665. }
  666.  
  667. public function publish() {
  668. $this->_editState(1);
  669. }
  670.  
  671. public function unpublish() {
  672. $this->_editState(0);
  673. }
  674.  
  675. public function makeSearchable() {
  676. $this->_editSearchable(1);
  677. }
  678.  
  679. public function makeNoneSearchable() {
  680. $this->_editSearchable(0);
  681. }
  682.  
  683. public function enableComments() {
  684. $this->_editComments(1);
  685. }
  686.  
  687. public function disableComments() {
  688. $this->_editComments(0);
  689. }
  690.  
  691. protected function _editState($state) {
  692.  
  693. // check for request forgeries
  694. $this->app->session->checkToken() or jexit('Invalid Token');
  695.  
  696. // init vars
  697. $cid = $this->app->request->get('cid', 'array', array());
  698.  
  699. if (count($cid) < 1) {
  700. $this->app->error->raiseError(500, JText::_('Select an item to edit publish state'));
  701. }
  702.  
  703. try {
  704.  
  705. // update item state
  706. foreach ($cid as $id) {
  707. // check ACL
  708. if ($this->table->get($id)->canEditState()) {
  709. $this->table->get($id)->setState($state, true);
  710. }
  711. }
  712.  
  713. } catch (AppException $e) {
  714.  
  715. // raise notice on exception
  716. $this->app->error->raiseNotice(0, JText::_('Error editing Item Published State').' ('.$e.')');
  717.  
  718. }
  719.  
  720. $this->setRedirect($this->baseurl);
  721. }
  722.  
  723. protected function _editSearchable($searchable) {
  724.  
  725. // check for request forgeries
  726. $this->app->session->checkToken() or jexit('Invalid Token');
  727.  
  728. // init vars
  729. $cid = $this->app->request->get('cid', 'array', array());
  730.  
  731. if (count($cid) < 1) {
  732. $this->app->error->raiseError(500, JText::_('Select an item to edit searchable state'));
  733. }
  734.  
  735. try {
  736.  
  737. // update item searchable
  738. foreach ($cid as $id) {
  739. $item = $this->table->get($id);
  740.  
  741. // Check ACL
  742. if (!$item->canEdit()) {
  743. continue;
  744. }
  745.  
  746. $item->searchable = $searchable;
  747. $this->table->save($item);
  748. }
  749.  
  750. } catch (AppException $e) {
  751.  
  752. // raise notice on exception
  753. $this->app->error->raiseNotice(0, JText::_('Error editing Item Searchable State').' ('.$e.')');
  754.  
  755. }
  756.  
  757. $this->setRedirect($this->baseurl);
  758. }
  759.  
  760. protected function _editComments($enabled) {
  761.  
  762. // check for request forgeries
  763. $this->app->session->checkToken() or jexit('Invalid Token');
  764.  
  765. // init vars
  766. $cid = $this->app->request->get('cid', 'array', array());
  767.  
  768. if (count($cid) < 1) {
  769. $this->app->error->raiseError(500, JText::_('Select an item to enable/disable comments'));
  770. }
  771.  
  772. try {
  773.  
  774. // update item comments
  775. foreach ($cid as $id) {
  776. $item = $this->table->get($id);
  777.  
  778. // Check ACL
  779. if (!$item->canEdit()) {
  780. continue;
  781. }
  782.  
  783. $item->params = $item
  784. ->getParams()
  785. ->set('config.enable_comments', $enabled);
  786.  
  787. $this->table->save($item);
  788. }
  789.  
  790. } catch (AppException $e) {
  791.  
  792. // raise notice on exception
  793. $this->app->error->raiseNotice(0, JText::_('Error enabling/disabling Item Comments').' ('.$e.')');
  794.  
  795. }
  796.  
  797. $this->setRedirect($this->baseurl);
  798. }
  799.  
  800. public function toggleFrontpage() {
  801.  
  802. // check for request forgeries
  803. $this->app->session->checkToken() or jexit('Invalid Token');
  804.  
  805. // init vars
  806. $cid = $this->app->request->get('cid', 'array', array());
  807.  
  808. if (count($cid) < 1) {
  809. $this->app->error->raiseError(500, JText::_('Select an item to toggle item frontpage setting'));
  810. }
  811.  
  812. try {
  813.  
  814. // toggle item frontpage
  815. foreach ($cid as $id) {
  816. $item = $this->table->get($id);
  817.  
  818. // Check ACL
  819. if (!$item->canEdit()) {
  820. continue;
  821. }
  822.  
  823. $categories = $item->getRelatedCategoryIds();
  824. if (($key = array_search('0', $categories, true)) !== false) {
  825. unset($categories[$key]);
  826. } else {
  827. array_push($categories, '0');
  828. }
  829.  
  830. $this->app->category->saveCategoryItemRelations($item, $categories);
  831.  
  832. }
  833.  
  834. } catch (AppException $e) {
  835.  
  836. // raise notice on exception
  837. $this->app->error->raiseNotice(0, JText::_('Error toggling item frontpage setting').' ('.$e.')');
  838.  
  839. }
  840.  
  841. $this->setRedirect($this->baseurl);
  842.  
  843. }
  844.  
  845. public function callElement() {
  846.  
  847. // get request vars
  848. $element_identifier = $this->app->request->getString('elm_id', '');
  849. $item_id = $this->app->request->getInt('item_id', 0);
  850. $type = $this->app->request->getString('type', '');
  851. $this->method = $this->app->request->getCmd('method', '');
  852. $this->args = $this->app->request->getVar('args', array(), 'default', 'array');
  853.  
  854. JArrayHelper::toString($this->args);
  855.  
  856. // load element
  857. if ($item_id) {
  858. $item = $this->table->get($item_id);
  859. } elseif (!empty($type)) {
  860. $item = $this->app->object->create('Item');
  861. $item->application_id = $this->application->id;
  862. $item->type = $type;
  863. } else {
  864. return;
  865. }
  866.  
  867. // Check ACL
  868. if (!$item->canEdit()) {
  869. return;
  870. }
  871.  
  872. // execute callback method
  873. if ($element = $item->getElement($element_identifier)) {
  874. echo $element->callback($this->method, $this->args);
  875. }
  876.  
  877. }
  878.  
  879. }
  880.  
  881. /*
  882. Class: ItemControllerException
  883. */
  884. class ItemControllerException extends AppException {}
  1. $from .= ' LEFT JOIN ' . ZOO_TABLE_TAG . ' AS tTag ON tItem.id = tTag.item_id';
  1. $tags = $this->app->system->application->getUserStateFromRequest($state_prefix.'tTag.item_id', 'tags', '', 'string');

Т.е. надо сделать сортировку - отобразить есть или нет тегов у статей.


  • 0

#5 CB9TOIIIA

CB9TOIIIA

Отправлено 11 June 2016 - 16:07

Я думаю тут проблема может в логике... надо проверить не на сам тег, а просто - есть ли у статьи теги или нет и вот по этому правилу - условия.


  • 0

#6 SmetDenis

SmetDenis

Отправлено 14 June 2016 - 06:37   Лучший Ответ

Нужно сделать так.

 

35sa_200x0.png

 

  1.         } else {
  2.             $from .= ' LEFT JOIN ' . ZOO_TABLE_TAG . ' AS tTag ON a.id = tTag.item_id';
  3.         }

 

bm0n_200x0.png


  • 1
JBZoo v4.0 и новый чудный мир Open Source GPL
Отключайте проверку лицензий как можно скорее!



— Есть два типа людей: Кто еще не делает бекапы и кто уже делает бекапы.





Click to return to top of page in style!