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