/administrator/components/com_zoo/controllers/tag.php

https://gitlab.com/vnsoftdev/amms · PHP · 134 lines · 63 code · 40 blank · 31 comment · 5 complexity · 69024b01d0c726792b46abeddda0ea82 MD5 · raw file

  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. Class: TagController
  10. The controller class for tag
  11. */
  12. class TagController extends AppController {
  13. public $application;
  14. public function __construct($default = array()) {
  15. parent::__construct($default);
  16. // set table
  17. $this->table = $this->app->table->tag;
  18. // get application
  19. $this->application = $this->app->zoo->getApplication();
  20. // set base url
  21. $this->baseurl = $this->app->link(array('controller' => $this->controller), false);
  22. }
  23. public function display($cachable = false, $urlparams = false) {
  24. // set toolbar items
  25. $this->app->system->application->JComponentTitle = $this->application->getToolbarTitle(JText::_('Tags'));
  26. $this->app->toolbar->deleteList();
  27. $this->app->zoo->toolbarHelp();
  28. $this->app->html->_('behavior.tooltip');
  29. // get request vars
  30. $state_prefix = $this->option.'_'.$this->application->id.'.tags.';
  31. $filter_order = $this->app->system->application->getUserStateFromRequest($state_prefix.'filter_order', 'filter_order', '', 'cmd');
  32. $filter_order_Dir = $this->app->system->application->getUserStateFromRequest($state_prefix.'filter_order_Dir', 'filter_order_Dir', 'desc', 'word');
  33. $limit = $this->app->system->application->getUserStateFromRequest('global.list.limit', 'limit', $this->app->system->config->get('list_limit'), 'int');
  34. $limitstart = $this->app->system->application->getUserStateFromRequest($state_prefix.'limitstart', 'limitstart', 0, 'int');
  35. $search = $this->app->system->application->getUserStateFromRequest($state_prefix.'search', 'search', '', 'string');
  36. $search = $this->app->string->strtolower($search);
  37. // is filtered ?
  38. $this->is_filtered = !empty($search);
  39. // in case limit has been changed, adjust limitstart accordingly
  40. $limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
  41. // get data
  42. $filter = ($filter_order) ? $filter_order . ' ' . $filter_order_Dir : '';
  43. $count = (int) $this->table->count($this->application->id, $search);
  44. $limitstart = $limitstart > $count ? floor($count / $limit) * $limit : $limitstart;
  45. $this->tags = $this->table->getAll($this->application->id, $search, '', $filter, $limitstart, $limit);
  46. $this->pagination = $this->app->pagination->create($count, $limitstart, $limit);
  47. // table ordering and search filter
  48. $this->lists['order_Dir'] = $filter_order_Dir;
  49. $this->lists['order'] = $filter_order;
  50. $this->lists['search'] = $search;
  51. // display view
  52. $this->getView()->display();
  53. }
  54. public function remove() {
  55. // init vars
  56. $tags = $this->app->request->get('cid', 'array', array());
  57. if (count($tags) < 1) {
  58. $this->app->error->raiseError(500, JText::_('Select a tag to delete'));
  59. }
  60. try {
  61. // delete tags
  62. $this->table->delete($tags, $this->application->id);
  63. // set redirect message
  64. $msg = JText::_('Tag Deleted');
  65. } catch (AppException $e) {
  66. // raise notice on exception
  67. $this->app->error->raiseWarning(0, JText::_('Error Deleting Tag').' ('.$e.')');
  68. $msg = null;
  69. }
  70. $this->setRedirect($this->baseurl, $msg);
  71. }
  72. public function update() {
  73. // init vars
  74. $old = $this->app->request->getString('old');
  75. $new = $this->app->request->getString('new');
  76. $msg = null;
  77. try {
  78. // update tag
  79. if (!empty($new) && $old != $new) {
  80. $this->table->update($this->application->id, $old, $new);
  81. // set redirect message
  82. $msg = JText::_('Tag Updated Successfully');
  83. }
  84. } catch (AppException $e) {
  85. // raise notice on exception
  86. $this->app->error->raiseWarning(0, JText::_('Error Updating Tag').' ('.$e.')');
  87. }
  88. $this->setRedirect($this->baseurl, $msg);
  89. }
  90. }
  91. /*
  92. Class: TagControllerException
  93. */
  94. class TagControllerException extends AppException {}