PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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