2014-05-03 23:48:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Patch testing component for the Joomla! CMS
|
|
|
|
*
|
2018-09-01 14:32:23 +00:00
|
|
|
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2018 Open Source Matters, Inc. All rights reserved.
|
2014-05-03 23:48:08 +00:00
|
|
|
* @license GNU General Public License version 2 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace PatchTester\Controller;
|
|
|
|
|
2017-08-17 23:22:01 +00:00
|
|
|
use Joomla\CMS\Factory;
|
2019-08-28 01:20:49 +00:00
|
|
|
use Joomla\CMS\Language\Text;
|
2014-05-03 23:48:08 +00:00
|
|
|
use Joomla\Registry\Registry;
|
2019-08-28 01:07:28 +00:00
|
|
|
use PatchTester\Model\AbstractModel;
|
2014-05-03 23:48:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default display controller
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
2016-02-20 16:34:23 +00:00
|
|
|
class DisplayController extends AbstractController
|
2014-05-03 23:48:08 +00:00
|
|
|
{
|
|
|
|
/**
|
2019-08-28 00:44:51 +00:00
|
|
|
* Default ordering value
|
2014-05-03 23:48:08 +00:00
|
|
|
*
|
|
|
|
* @var string
|
2019-08-28 00:44:51 +00:00
|
|
|
* @since __DEPLOY_VERSION__
|
2014-05-03 23:48:08 +00:00
|
|
|
*/
|
2019-08-28 00:44:51 +00:00
|
|
|
protected $defaultFullOrdering = 'a.pull_id DESC';
|
2014-05-03 23:48:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the controller.
|
|
|
|
*
|
|
|
|
* @return boolean True on success
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
* @throws \RuntimeException
|
|
|
|
*/
|
|
|
|
public function execute()
|
|
|
|
{
|
|
|
|
// Set up variables to build our classes
|
|
|
|
$view = $this->getInput()->getCmd('view', $this->defaultView);
|
|
|
|
$format = $this->getInput()->getCmd('format', 'html');
|
|
|
|
|
|
|
|
// Register the layout paths for the view
|
|
|
|
$paths = new \SplPriorityQueue;
|
|
|
|
|
|
|
|
// Add the path for template overrides
|
2015-12-05 17:43:54 +00:00
|
|
|
$paths->insert(JPATH_THEMES . '/' . $this->getApplication()->getTemplate() . '/html/com_patchtester/' . $view, 2);
|
2014-05-03 23:48:08 +00:00
|
|
|
|
|
|
|
// Add the path for the default layouts
|
2016-02-20 16:56:58 +00:00
|
|
|
$paths->insert(dirname(__DIR__) . '/View/' . ucfirst($view) . '/tmpl', 1);
|
2014-05-03 23:48:08 +00:00
|
|
|
|
|
|
|
// Build the class names for the model and view
|
|
|
|
$viewClass = '\\PatchTester\\View\\' . ucfirst($view) . '\\' . ucfirst($view) . ucfirst($format) . 'View';
|
|
|
|
$modelClass = '\\PatchTester\\Model\\' . ucfirst($view) . 'Model';
|
|
|
|
|
|
|
|
// Sanity check - Ensure our classes exist
|
|
|
|
if (!class_exists($viewClass))
|
|
|
|
{
|
2015-02-23 01:49:59 +00:00
|
|
|
// Try to use a default view
|
|
|
|
$viewClass = '\\PatchTester\\View\\Default' . ucfirst($format) . 'View';
|
|
|
|
|
|
|
|
if (!class_exists($viewClass))
|
|
|
|
{
|
2019-08-28 01:20:49 +00:00
|
|
|
throw new \RuntimeException(Text::sprintf('COM_PATCHTESTER_ERROR_VIEW_NOT_FOUND', $view, $format), 500);
|
2015-02-23 01:49:59 +00:00
|
|
|
}
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!class_exists($modelClass))
|
|
|
|
{
|
2019-08-28 01:20:49 +00:00
|
|
|
throw new \RuntimeException(Text::sprintf('COM_PATCHTESTER_ERROR_MODEL_NOT_FOUND', $modelClass), 500);
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the model class now; need to do it before setting the state to get required data from it
|
2017-08-17 23:22:01 +00:00
|
|
|
$model = new $modelClass($this->context, null, Factory::getDbo());
|
2014-05-03 23:48:08 +00:00
|
|
|
|
|
|
|
// Initialize the state for the model
|
|
|
|
$model->setState($this->initializeState($model));
|
|
|
|
|
|
|
|
// Initialize the view class now
|
|
|
|
$view = new $viewClass($model, $paths);
|
|
|
|
|
|
|
|
// Echo the rendered view for the application
|
|
|
|
echo $view->render();
|
|
|
|
|
|
|
|
// Finished!
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the state for the model object
|
|
|
|
*
|
2019-08-28 01:07:28 +00:00
|
|
|
* @param AbstractModel $model Model object
|
2014-05-03 23:48:08 +00:00
|
|
|
*
|
|
|
|
* @return Registry
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
2019-08-28 01:07:28 +00:00
|
|
|
protected function initializeState(AbstractModel $model)
|
2014-05-03 23:48:08 +00:00
|
|
|
{
|
2016-02-20 16:34:23 +00:00
|
|
|
$state = parent::initializeState($model);
|
2014-05-03 23:48:08 +00:00
|
|
|
|
|
|
|
// Load the filter state.
|
2016-02-20 16:34:23 +00:00
|
|
|
$state->set('filter.search', $this->getApplication()->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', ''));
|
|
|
|
$state->set('filter.applied', $this->getApplication()->getUserStateFromRequest($this->context . '.filter.applied', 'filter_applied', ''));
|
2017-04-22 16:55:17 +00:00
|
|
|
$state->set('filter.branch', $this->getApplication()->getUserStateFromRequest($this->context . '.filter.branch', 'filter_branch', ''));
|
2016-03-27 18:39:34 +00:00
|
|
|
$state->set('filter.rtc', $this->getApplication()->getUserStateFromRequest($this->context . '.filter.rtc', 'filter_rtc', ''));
|
2014-05-03 23:48:08 +00:00
|
|
|
|
2016-02-20 16:34:23 +00:00
|
|
|
// Pre-fill the limits.
|
2016-03-11 16:36:53 +00:00
|
|
|
$limit = $this->getApplication()->getUserStateFromRequest('global.list.limit', 'limit', $this->getApplication()->get('list_limit', 20), 'uint');
|
2014-05-03 23:48:08 +00:00
|
|
|
$state->set('list.limit', $limit);
|
|
|
|
|
2019-08-28 00:44:51 +00:00
|
|
|
$fullOrdering = $this->getApplication()->getUserStateFromRequest($this->context . '.fullorder', 'list_fullordering', $this->defaultFullOrdering);
|
2014-05-03 23:48:08 +00:00
|
|
|
|
2019-08-28 00:44:51 +00:00
|
|
|
$orderingParts = explode(' ', $fullOrdering);
|
|
|
|
|
|
|
|
if (count($orderingParts) !== 2)
|
2014-05-03 23:48:08 +00:00
|
|
|
{
|
2019-08-28 00:44:51 +00:00
|
|
|
$fullOrdering = $this->defaultFullOrdering;
|
|
|
|
|
|
|
|
$orderingParts = explode(' ', $fullOrdering);
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
|
|
|
|
2019-08-28 00:44:51 +00:00
|
|
|
$state->set('list.fullordering', $fullOrdering);
|
2014-05-03 23:48:08 +00:00
|
|
|
|
2019-08-28 00:44:51 +00:00
|
|
|
// The 2nd part will be considered the direction
|
|
|
|
$direction = $orderingParts[array_key_last($orderingParts)];
|
2014-05-03 23:48:08 +00:00
|
|
|
|
2019-08-28 00:44:51 +00:00
|
|
|
if (in_array(strtoupper($direction), array('ASC', 'DESC', '')))
|
2014-05-03 23:48:08 +00:00
|
|
|
{
|
2019-08-28 00:44:51 +00:00
|
|
|
$state->set('list.direction', $direction);
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
|
|
|
|
2019-08-28 00:44:51 +00:00
|
|
|
// The 1st part will be the ordering
|
|
|
|
$ordering = $orderingParts[array_key_first($orderingParts)];
|
|
|
|
|
|
|
|
if (in_array($ordering, $model->getSortFields()))
|
|
|
|
{
|
|
|
|
$state->set('list.ordering', $ordering);
|
|
|
|
}
|
2014-05-03 23:48:08 +00:00
|
|
|
|
|
|
|
$value = $this->getApplication()->getUserStateFromRequest($this->context . '.limitstart', 'limitstart', 0);
|
|
|
|
$limitstart = ($limit != 0 ? (floor($value / $limit) * $limit) : 0);
|
|
|
|
$state->set('list.start', $limitstart);
|
|
|
|
|
|
|
|
return $state;
|
|
|
|
}
|
|
|
|
}
|