/administrator/components/com_banners/controllers/banners.php

https://bitbucket.org/eternaware/joomus · PHP · 118 lines · 55 code · 16 blank · 47 comment · 8 complexity · 5af15156a6238731c36d9ed34334c9ee MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Administrator
  4. * @subpackage com_banners
  5. *
  6. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. defined('_JEXEC') or die;
  10. /**
  11. * Banners list controller class.
  12. *
  13. * @package Joomla.Administrator
  14. * @subpackage com_banners
  15. * @since 1.6
  16. */
  17. class BannersControllerBanners extends JControllerAdmin
  18. {
  19. /**
  20. * @var string The prefix to use with controller messages.
  21. * @since 1.6
  22. */
  23. protected $text_prefix = 'COM_BANNERS_BANNERS';
  24. /**
  25. * Constructor.
  26. *
  27. * @param array An optional associative array of configuration settings.
  28. * @see JController
  29. * @since 1.6
  30. */
  31. public function __construct($config = array())
  32. {
  33. parent::__construct($config);
  34. $this->registerTask('sticky_unpublish', 'sticky_publish');
  35. }
  36. /**
  37. * Proxy for getModel.
  38. * @since 1.6
  39. */
  40. public function getModel($name = 'Banner', $prefix = 'BannersModel', $config = array('ignore_request' => true))
  41. {
  42. $model = parent::getModel($name, $prefix, $config);
  43. return $model;
  44. }
  45. /**
  46. * @since 1.6
  47. */
  48. public function sticky_publish()
  49. {
  50. // Check for request forgeries.
  51. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
  52. $user = JFactory::getUser();
  53. $ids = $this->input->get('cid', array(), 'array');
  54. $values = array('sticky_publish' => 1, 'sticky_unpublish' => 0);
  55. $task = $this->getTask();
  56. $value = JArrayHelper::getValue($values, $task, 0, 'int');
  57. if (empty($ids)) {
  58. JError::raiseWarning(500, JText::_('COM_BANNERS_NO_BANNERS_SELECTED'));
  59. } else {
  60. // Get the model.
  61. $model = $this->getModel();
  62. // Change the state of the records.
  63. if (!$model->stick($ids, $value)) {
  64. JError::raiseWarning(500, $model->getError());
  65. } else {
  66. if ($value == 1) {
  67. $ntext = 'COM_BANNERS_N_BANNERS_STUCK';
  68. } else {
  69. $ntext = 'COM_BANNERS_N_BANNERS_UNSTUCK';
  70. }
  71. $this->setMessage(JText::plural($ntext, count($ids)));
  72. }
  73. }
  74. $this->setRedirect('index.php?option=com_banners&view=banners');
  75. }
  76. /**
  77. * Method to save the submitted ordering values for records via AJAX.
  78. *
  79. * @return void
  80. *
  81. * @since 3.0
  82. */
  83. public function saveOrderAjax()
  84. {
  85. // Get the input
  86. $pks = $this->input->post->get('cid', array(), 'array');
  87. $order = $this->input->post->get('order', array(), 'array');
  88. // Sanitize the input
  89. JArrayHelper::toInteger($pks);
  90. JArrayHelper::toInteger($order);
  91. // Get the model
  92. $model = $this->getModel();
  93. // Save the ordering
  94. $return = $model->saveorder($pks, $order);
  95. if ($return)
  96. {
  97. echo "1";
  98. }
  99. // Close the application
  100. JFactory::getApplication()->close();
  101. }
  102. }