Exemple #1
0
 private function _set_bool_by_input_and_redirect($field, $state, $msg_on, $msg_off)
 {
     JSession::checkToken() or jexit(JText::_('INVALID TOKEN'));
     $rights = AimySitemapRightsHelper::getRights();
     if (!$rights->get('core.edit')) {
         $this->setError(JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
         $this->setMessage($this->getError(), 'error');
         $this->setRedirect(JRoute::_('index.php?option=com_aimysitemap&view=urls', false));
         return false;
     }
     require_once JPATH_COMPONENT . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'message.php';
     $msg = new AimySitemapMessageHelper();
     $jin = JFactory::getApplication()->input;
     $ids = $jin->get('cid', array(), 'ARRAY');
     JArrayHelper::toInteger($ids);
     $model = $this->getModel('Url', 'AimySitemapModel');
     $method = "set_{$field}";
     if (!method_exists($model, $method)) {
         $this->setError(JText::_('JERROR_AN_ERROR_HAS_OCCURRED'));
         $this->setMessage($this->getError(), 'error');
         $this->setRedirect(JRoute::_('index.php?option=com_aimysitemap&view=urls', false));
         return false;
     }
     $n = 0;
     foreach ($ids as $id) {
         if ($id <= 0) {
             $msg->error(JText::_('JERROR_AN_ERROR_HAS_OCCURRED'));
             continue;
         }
         $model->{$method}($id, $state);
         $n++;
     }
     if ($n) {
         $msg->queue(sprintf($state == 1 ? $msg_on : $msg_off, count($ids)));
     }
     $this->setRedirect(JRoute::_('index.php?option=com_aimysitemap&view=urls', false));
     return true;
 }