/contentmanager/code/trunk/administrator/components/com_contentmanager/controllers/template.php
PHP | 231 lines | 123 code | 37 blank | 71 comment | 17 complexity | 571891a851684c48df00bcec7d11257c MD5 | raw file
- <?php
- /**
- * @version $Id: template.php 39 2009-05-21 07:32:36Z eddieajau $
- * @copyright Copyright (C) 2009 New Life in IT Pty Ltd. All rights reserved.
- * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
- * @link http://www.theartofjoomla.com
- */
- // no direct access
- defined('_JEXEC') or die;
- jimport('joomla.application.component.controller');
- /**
- * @package TAOJ.ContentManager
- * @subpackage com_contentmanager
- */
- class ContentManagerControllerTemplate extends JController
- {
- /**
- * Constructor
- */
- function __construct()
- {
- parent::__construct();
- $this->registerTask('save2copy', 'save');
- $this->registerTask('save2new', 'save');
- $this->registerTask('apply', 'save');
- }
- /**
- * Display the view
- */
- function display()
- {
- }
- /**
- * Proxy for getModel
- */
- function &getModel()
- {
- return parent::getModel('Template', '', array('ignore_request' => true));
- }
- /**
- * Method to edit a object
- *
- * Sets object ID in the session from the request, checks the item out, and then redirects to the edit page.
- *
- * @access public
- * @return void
- */
- function edit()
- {
- $cid = JRequest::getVar('cid', array(), '', 'array');
- $id = JRequest::getInt('id', @$cid[0]);
- $session = &JFactory::getSession();
- $session->set('contentmanager.edit.template.id', $id);
- // Checkout item
- $model = $this->getModel();
- if ($id) {
- $model->checkout($id);
- }
- $this->setRedirect(JRoute::_('index.php?option=com_contentmanager&view=template&layout=edit', false));
- }
- /**
- * Method to cancel an edit
- *
- * Checks the item in, sets item ID in the session to null, and then redirects to the list page.
- *
- * @access public
- * @return void
- */
- function cancel()
- {
- // Checkin item if checked out
- $session = &JFactory::getSession();
- if ($id = (int) $session->get('contentmanager.edit.template.id')) {
- $model = $this->getModel();
- $model->checkin($id);
- }
- // Clear the session of the item
- $session->set('contentmanager.edit.template.id', null);
- $this->setRedirect(JRoute::_('index.php?option=com_contentmanager&view=templates', false));
- }
- /**
- * Save the record
- */
- function save()
- {
- // Check for request forgeries.
- JRequest::checkToken();
- // Get posted form variables.
- $values = JRequest::getVar('jxform', array(), 'post', 'array');
- // Get the id of the item out of the session.
- $session = &JFactory::getSession();
- $id = (int) $session->get('contentmanager.edit.template.id');
- $values['id'] = $id;
- // Get the extensions model and set the post request in its state.
- $model = &$this->getModel();
- $post = JRequest::get('post');
- $model->setState('request', $post);
- // Get the form model object and validate it.
- $form = &$model->getForm('model');
- $form->filter($values);
- $result = $form->validate($values);
- if (JError::isError($result)) {
- JError::raiseError(500, $result->message);
- }
- $result = $model->save($values);
- $msg = JError::isError($result) ? $result->message : 'Saved';
- if ($this->_task == 'apply')
- {
- $session->set('contentmanager.edit.template.id', $model->getState('id'));
- $this->setRedirect(JRoute::_('index.php?option=com_contentmanager&view=template&layout=edit', false), JText::_($msg));
- }
- else if ($this->_task == 'save2new')
- {
- $session->set('contentmanager.edit.template.id', null);
- $model->checkin($id);
- $this->setRedirect(JRoute::_('index.php?option=com_contentmanager&view=template&layout=edit', false), JText::_($msg));
- }
- else
- {
- $session->set('contentmanager.edit.template.id', null);
- $model->checkin($id);
- $this->setRedirect(JRoute::_('index.php?option=com_contentmanager&view=templates', false), JText::_($msg));
- }
- }
- /**
- * Removes an item
- */
- function delete()
- {
- // Check for request forgeries
- JRequest::checkToken() or die('Invalid Token');
- // Get items to remove from the request.
- $cid = JRequest::getVar('cid', array(), '', 'array');
- if (!is_array($cid) || count($cid) < 1) {
- JError::raiseWarning(500, JText::_('Select an item to delete'));
- }
- else {
- // Get the model.
- $model = $this->getModel();
- // Make sure the item ids are integers
- jimport('joomla.utilities.arrayhelper');
- JArrayHelper::toInteger($cid);
- // Remove the items.
- if (!$model->delete($cid)) {
- JError::raiseWarning(500, $model->getError());
- }
- }
- $this->setRedirect('index.php?option=com_contentmanager&view=templates');
- }
- /**
- * Method to publish a list of taxa
- *
- * @access public
- * @return void
- * @since 1.0
- */
- function publish()
- {
- // Check for request forgeries
- JRequest::checkToken() or die('Invalid Token');
- // Get items to publish from the request.
- $cid = JRequest::getVar('cid', array(), '', 'array');
- $values = array('publish' => 1, 'unpublish' => 0, 'trash' => -2);
- $task = $this->getTask();
- $value = JArrayHelper::getValue($values, $task, 0, 'int');
- if (!is_array($cid) || count($cid) < 1) {
- JError::raiseWarning(500, JText::_('Select an item to publish'));
- }
- else {
- // Get the model.
- $model = $this->getModel();
- // Make sure the item ids are integers
- JArrayHelper::toInteger($cid);
- // Publish the items.
- if (!$model->publish($cid, $value)) {
- JError::raiseWarning(500, $model->getError());
- }
- }
- $this->setRedirect('index.php?option=com_contentmanager&view=templates');
- }
- /**
- * Changes the order of an item
- */
- function ordering()
- {
- // Check for request forgeries
- JRequest::checkToken() or die('Invalid Token');
- $cid = JRequest::getVar('cid', null, 'post', 'array');
- $inc = $this->getTask() == 'orderup' ? -1 : +1;
- $model = & $this->getModel();
- $model->ordering($cid, $inc);
- $this->setRedirect('index.php?option=com_contentmanager&view=templates');
- }
- }