PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/pdf/code/trunk/administrator/components/com_artofpdf/libraries/joomla/application/component/controlleradmin.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 277 lines | 139 code | 36 blank | 102 comment | 28 complexity | e74b0fd229849ddd3579c7b0a319f3b9 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: controlleradmin.php 278 2010-09-14 11:11:09Z eddieajau $
  4. * @package Joomla.Framework
  5. * @subpackage Application
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. // No direct access.
  10. defined('JPATH_BASE') or die;
  11. jimport('joomla.application.component.controller');
  12. /**
  13. * Base class for a Joomla Administrator Controller
  14. *
  15. * Controller (controllers are where you put all the actual code) Provides basic
  16. * functionality, such as rendering views (aka displaying templates).
  17. *
  18. * @abstract
  19. * @package Joomla.Framework
  20. * @subpackage Application
  21. * @since 1.6
  22. */
  23. class JControllerAdmin extends JController
  24. {
  25. /**
  26. * @var string The URL option for the component.
  27. * @since 1.6
  28. */
  29. protected $option;
  30. /**
  31. * @var string The prefix to use with controller messages.
  32. * @since 1.6
  33. */
  34. protected $text_prefix;
  35. /**
  36. * @var string The URL view list variable.
  37. * @since 1.6
  38. */
  39. protected $view_list;
  40. /**
  41. * Constructor.
  42. *
  43. * @param array An optional associative array of configuration settings.
  44. * @see JController
  45. * @since 1.6
  46. */
  47. public function __construct($config = array())
  48. {
  49. parent::__construct($config);
  50. // Define standard task mappings.
  51. $this->registerTask('unpublish', 'publish'); // value = 0
  52. $this->registerTask('archive', 'publish'); // value = 2
  53. $this->registerTask('trash', 'publish'); // value = -2
  54. $this->registerTask('report', 'publish'); // value = -3
  55. $this->registerTask('orderup', 'reorder');
  56. $this->registerTask('orderdown', 'reorder');
  57. // Guess the option as com_NameOfController.
  58. if (empty($this->option)) {
  59. $this->option = 'com_'.strtolower($this->getName());
  60. }
  61. // Guess the JText message prefix. Defaults to the option.
  62. if (empty($this->text_prefix)) {
  63. $this->text_prefix = strtoupper($this->option);
  64. }
  65. // Guess the list view as the suffix, eg: OptionControllerSuffix.
  66. if (empty($this->view_list)) {
  67. $r = null;
  68. if (!preg_match('/(.*)Controller(.*)/i', get_class($this), $r)) {
  69. JError::raiseError(500, JText::_('JLIB_APPLICATION_ERROR_CONTROLLER_GET_NAME'));
  70. }
  71. $this->view_list = strtolower($r[2]);
  72. }
  73. }
  74. /**
  75. * Removes an item.
  76. *
  77. * @since 1.6
  78. */
  79. function delete()
  80. {
  81. // Check for request forgeries
  82. JRequest::checkToken() or die(JText::_('JINVALID_TOKEN'));
  83. // Get items to remove from the request.
  84. $cid = JRequest::getVar('cid', array(), '', 'array');
  85. if (!is_array($cid) || count($cid) < 1) {
  86. JError::raiseWarning(500, JText::_($this->text_prefix.'_NO_ITEM_SELECTED'));
  87. } else {
  88. // Get the model.
  89. $model = $this->getModel();
  90. // Make sure the item ids are integers
  91. jimport('joomla.utilities.arrayhelper');
  92. JArrayHelper::toInteger($cid);
  93. // Remove the items.
  94. if ($model->delete($cid)) {
  95. $this->setMessage(JText::plural($this->text_prefix.'_N_ITEMS_DELETED', count($cid)));
  96. } else {
  97. $this->setMessage($model->getError());
  98. }
  99. }
  100. $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list, false));
  101. }
  102. /**
  103. * Display is not supported by this controller.
  104. *
  105. * @param boolean If true, the view output will be cached
  106. * @param array An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
  107. *
  108. * @return JController This object to support chaining.
  109. * @since 1.6
  110. */
  111. public function display($cachable = false, $urlparams = false)
  112. {
  113. return $this;
  114. }
  115. /**
  116. * Method to publish a list of taxa
  117. *
  118. * @since 1.6
  119. */
  120. function publish()
  121. {
  122. // Check for request forgeries
  123. JRequest::checkToken() or die(JText::_('JINVALID_TOKEN'));
  124. // Get items to publish from the request.
  125. $cid = JRequest::getVar('cid', array(), '', 'array');
  126. $data = array('publish' => 1, 'unpublish' => 0, 'archive'=> 2, 'trash' => -2, 'report'=>-3);
  127. $task = $this->getTask();
  128. $value = JArrayHelper::getValue($data, $task, 0, 'int');
  129. if (empty($cid)) {
  130. JError::raiseWarning(500, JText::_($this->text_prefix.'_NO_ITEM_SELECTED'));
  131. } else {
  132. // Get the model.
  133. $model = $this->getModel();
  134. // Make sure the item ids are integers
  135. JArrayHelper::toInteger($cid);
  136. // Publish the items.
  137. if (!$model->publish($cid, $value)) {
  138. JError::raiseWarning(500, $model->getError());
  139. } else {
  140. if ($value == 1) {
  141. $ntext = $this->text_prefix.'_N_ITEMS_PUBLISHED';
  142. } else if ($value == 0) {
  143. $ntext = $this->text_prefix.'_N_ITEMS_UNPUBLISHED';
  144. } else if ($value == 2) {
  145. $ntext = $this->text_prefix.'_N_ITEMS_ARCHIVED';
  146. } else {
  147. $ntext = $this->text_prefix.'_N_ITEMS_TRASHED';
  148. }
  149. //$this->setMessage(JText::plural($ntext, count($cid)));
  150. $this->setMessage(JText::sprintf($ntext, count($cid)));
  151. }
  152. }
  153. $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list, false));
  154. }
  155. /**
  156. * Changes the order of one or more records.
  157. *
  158. * @since 1.6
  159. */
  160. public function reorder()
  161. {
  162. // Check for request forgeries.
  163. JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
  164. // Initialise variables.
  165. $user = JFactory::getUser();
  166. $ids = JRequest::getVar('cid', null, 'post', 'array');
  167. $inc = ($this->getTask() == 'orderup') ? -1 : +1;
  168. $model = $this->getModel();
  169. $return = $model->reorder($ids, $inc);
  170. if ($return === false) {
  171. // Reorder failed.
  172. $message = JText::sprintf('JLIB_APPLICATION_ERROR_REORDER_FAILED', $model->getError());
  173. $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list, false), $message, 'error');
  174. return false;
  175. } else {
  176. // Reorder succeeded.
  177. $message = JText::_('JLIB_APPLICATION_SUCCESS_ITEM_REORDERED');
  178. $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list, false), $message);
  179. return true;
  180. }
  181. }
  182. /**
  183. * Method to save the submitted ordering values for records.
  184. *
  185. * @since 1.6
  186. */
  187. public function saveorder()
  188. {
  189. // Check for request forgeries.
  190. JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
  191. // Get the input
  192. $pks = JRequest::getVar('cid', null, 'post', 'array');
  193. $order = JRequest::getVar('order', null, 'post', 'array');
  194. // Sanitize the input
  195. JArrayHelper::toInteger($pks);
  196. JArrayHelper::toInteger($order);
  197. // Get the model
  198. $model = $this->getModel();
  199. // Save the ordering
  200. $return = $model->saveorder($pks, $order);
  201. if ($return === false)
  202. {
  203. // Reorder failed
  204. $message = JText::sprintf('JLIB_APPLICATION_ERROR_REORDER_FAILED', $model->getError());
  205. $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list, false), $message, 'error');
  206. return false;
  207. } else
  208. {
  209. // Reorder succeeded.
  210. $this->setMessage(JText::_('JLIB_APPLICATION_SUCCESS_ORDERING_SAVED'));
  211. $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list, false));
  212. return true;
  213. }
  214. }
  215. /**
  216. * Check in of one or more records.
  217. *
  218. * @since 1.6
  219. */
  220. public function checkin()
  221. {
  222. // Check for request forgeries.
  223. JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
  224. // Initialise variables.
  225. $user = JFactory::getUser();
  226. $ids = JRequest::getVar('cid', null, 'post', 'array');
  227. $model = $this->getModel();
  228. $return = $model->checkin($ids);
  229. if ($return === false) {
  230. // Checkin failed.
  231. $message = JText::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED', $model->getError());
  232. $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list, false), $message, 'error');
  233. return false;
  234. } else {
  235. // Checkin succeeded.
  236. $message = JText::plural($this->text_prefix.'_N_ITEMS_CHECKED_IN', count($ids));
  237. $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list, false), $message);
  238. return true;
  239. }
  240. }
  241. }