CoreFiles by mySites.guru
HistoryController.php132 lines, 2,848 bytes, from Joomla_4.1.2-Stable-Full_Package.zip
Raw History Compare with 4.1.1
md5
1aa6b449a0455f1584492bf93cd6f650
sha1
663e863e6d12427aaea15b98b5918c249ae697cd
sha256
9928363a276927f105b32f434cc5bf169562c2af1658f27ae8e1e18d5296ff8b
<?php
/**
 * @package     Joomla.API
 * @subpackage  com_contenthistory
 *
 * @copyright   (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Component\Contenthistory\Api\Controller;

\defined('_JEXEC') or die;

use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\ApiController;
use Joomla\CMS\MVC\Controller\Exception;
use Joomla\Component\Contenthistory\Administrator\Model\HistoryModel;

/**
 * The history controller
 *
 * @since  4.0.0
 */
class HistoryController extends ApiController
{
	/**
	 * The content type of the item.
	 *
	 * @var    string
	 * @since  4.0.0
	 */
	protected $contentType = 'history';

	/**
	 * The default view for the display method.
	 *
	 * @var    string
	 * @since  3.0
	 */
	protected $default_view = 'history';

	/**
	 * Basic display of a list view
	 *
	 * @return  static  A \JControllerLegacy object to support chaining.
	 *
	 * @since   4.0.0
	 */
	public function displayList()
	{
		$this->modelState->set('type_alias', $this->getTypeAliasFromInput());
		$this->modelState->set('type_id', $this->getTypeIdFromInput());
		$this->modelState->set('item_id', $this->getTypeAliasFromInput() . '.' . $this->getItemIdFromInput());
		$this->modelState->set('list.ordering', 'h.save_date');
		$this->modelState->set('list.direction', 'DESC');

		return parent::displayList();
	}

	/**
	 * Method to edit an existing record.
	 *
	 * @return  static  A \JControllerLegacy object to support chaining.
	 *
	 * @since   4.0.0
	 */
	public function keep()
	{
		/** @var HistoryModel $model */
		$model = $this->getModel($this->contentType);

		if (!$model)
		{
			throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_MODEL_CREATE'));
		}

		$recordId = $this->input->getInt('id');

		if (!$recordId)
		{
			throw new Exception\ResourceNotFound(Text::_('JLIB_APPLICATION_ERROR_RECORD'), 404);
		}

		$cid = [$recordId];

		if (!$model->keep($cid))
		{
			throw new Exception\Save(Text::plural('COM_CONTENTHISTORY_N_ITEMS_KEEP_TOGGLE', \count($cid)));
		}

		return $this;
	}

	/**
	 * Get item id from input
	 *
	 * @return string
	 *
	 * @since 4.0.0
	 */
	private function getItemIdFromInput()
	{
		return $this->input->exists('id') ?
			$this->input->get('id') : $this->input->post->get('id');
	}

	/**
	 * Get type id from input
	 *
	 * @return string
	 *
	 * @since 4.0.0
	 */
	private function getTypeIdFromInput()
	{
		return $this->input->exists('type_id') ?
			$this->input->get('type_id') : $this->input->post->get('type_id');
	}

	/**
	 * Get type alias from input
	 *
	 * @return string
	 *
	 * @since 4.0.0
	 */
	private function getTypeAliasFromInput()
	{
		return $this->input->exists('type_alias') ?
			$this->input->get('type_alias') : $this->input->post->get('type_alias');
	}
}

The same content is in 20 releases, Joomla 4.1.0-rc2 to 4.2.0-beta2. See them all, or every version of this file.