33
0
mirror of https://github.com/joomla-extensions/patchtester.git synced 2024-12-22 19:09:00 +00:00

Create an abstract controller, reshuffle controller logic between abstract and display

This commit is contained in:
Michael Babker 2016-02-20 11:34:23 -05:00
parent 9cec024a78
commit 2b185cb253
8 changed files with 94 additions and 69 deletions

View File

@ -0,0 +1,75 @@
<?php
/**
* Patch testing component for the Joomla! CMS
*
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2015 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\Controller;
use Joomla\Registry\Registry;
/**
* Base controller for the patch testing component
*
* @since 2.0
*
* @method \JApplicationCms getApplication() getApplication() Get the application object.
*/
abstract class AbstractController extends \JControllerBase
{
/**
* The object context
*
* @var string
* @since 2.0
*/
protected $context;
/**
* The default view to display
*
* @var string
* @since 2.0
*/
protected $defaultView = 'pulls';
/**
* Instantiate the controller
*
* @param \JInput $input The input object.
* @param \JApplicationBase $app The application object.
*
* @since 2.0
*/
public function __construct(\JInput $input = null, \JApplicationBase $app = null)
{
parent::__construct($input, $app);
// Set the context for the controller
$this->context = 'com_patchtester.' . $this->getInput()->getCmd('view', $this->defaultView);
}
/**
* Sets the state for the model object
*
* @param \JModel $model Model object
*
* @return Registry
*
* @since 2.0
*/
protected function initializeState(\JModel $model)
{
$state = new Registry;
// Load the parameters.
$params = \JComponentHelper::getParams('com_patchtester');
$state->set('github_user', $params->get('org', 'joomla'));
$state->set('github_repo', $params->get('repo', 'joomla-cms'));
return $state;
}
}

View File

@ -15,7 +15,7 @@ use PatchTester\Model\PullModel;
*
* @since 2.0
*/
class ApplyController extends DisplayController
class ApplyController extends AbstractController
{
/**
* Execute the controller.

View File

@ -14,19 +14,9 @@ use Joomla\Registry\Registry;
* Default display controller
*
* @since 2.0
*
* @method \JApplicationCms getApplication() getApplication() Get the application object.
*/
class DisplayController extends \JControllerBase
class DisplayController extends AbstractController
{
/**
* The object context
*
* @var string
* @since 2.0
*/
protected $context;
/**
* Default ordering column
*
@ -43,30 +33,6 @@ class DisplayController extends \JControllerBase
*/
protected $defaultDirection = 'DESC';
/**
* The default view to display
*
* @var string
* @since 2.0
*/
protected $defaultView = 'pulls';
/**
* Instantiate the controller
*
* @param \JInput $input The input object.
* @param \JApplicationBase $app The application object.
*
* @since 2.0
*/
public function __construct(\JInput $input = null, \JApplicationBase $app = null)
{
parent::__construct($input, $app);
// Set the context for the controller
$this->context = 'com_patchtester.' . $this->getInput()->getCmd('view', $this->defaultView);
}
/**
* Execute the controller.
*
@ -137,40 +103,26 @@ class DisplayController extends \JControllerBase
* @return Registry
*
* @since 2.0
* @todo This should really be more generic for a default controller
*/
protected function initializeState(\JModel $model)
{
$state = new Registry;
$state = parent::initializeState($model);
// Load the filter state.
$search = $this->getApplication()->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '');
$state->set('filter.search', $search);
$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', ''));
$applied = $this->getApplication()->getUserStateFromRequest($this->context . '.filter.applied', 'filter_applied', '');
$state->set('filter.applied', $applied);
// Load the parameters.
$params = \JComponentHelper::getParams('com_patchtester');
$state->set('params', $params);
$state->set('github_user', $params->get('org', 'joomla'));
$state->set('github_repo', $params->get('repo', 'joomla-cms'));
// Pre-fill the limits
// Pre-fill the limits.
$limit = $this->getApplication()->getUserStateFromRequest('global.list.limit', 'limit', $this->getApplication()->get('list_limit'), 'uint');
$state->set('list.limit', $limit);
// Check if the ordering field is in the white list, otherwise use the incoming value.
$value = $this->getApplication()->getUserStateFromRequest($this->context . '.ordercol', 'filter_order', $this->defaultOrderColumn);
if (method_exists($model, 'getSortFields'))
if (!in_array($value, $model->getSortFields()))
{
if (!in_array($value, $model->getSortFields()))
{
$value = $this->defaultOrderColumn;
$this->getApplication()->setUserState($this->context . '.ordercol', $value);
}
$value = $this->defaultOrderColumn;
$this->getApplication()->setUserState($this->context . '.ordercol', $value);
}
$state->set('list.ordering', $value);

View File

@ -15,7 +15,7 @@ use PatchTester\Model\PullsModel;
*
* @since 2.0
*/
class FetchController extends DisplayController
class FetchController extends AbstractController
{
/**
* Execute the controller.
@ -38,7 +38,6 @@ class FetchController extends DisplayController
// Fetch our page from the session
$page = \JFactory::getSession()->get('com_patchtester_fetcher_page', 1);
// TODO - Decouple the model and context?
$model = new PullsModel('com_patchtester.fetch', null, \JFactory::getDbo());
// Initialize the state for the model

View File

@ -15,7 +15,7 @@ use PatchTester\Model\PullModel;
*
* @since 2.0
*/
class RevertController extends DisplayController
class RevertController extends AbstractController
{
/**
* Execute the controller.

View File

@ -16,7 +16,7 @@ use PatchTester\Model\PullsModel;
*
* @since 2.0
*/
class StartfetchController extends DisplayController
class StartfetchController extends AbstractController
{
/**
* Execute the controller.

View File

@ -33,7 +33,7 @@ class PullsModel extends \JModelDatabase
* @var array
* @since 2.0
*/
protected $sortFields = array();
protected $sortFields = array('a.pull_id', 'a.title', 'applied');
/**
* Instantiate the model.
@ -48,8 +48,7 @@ class PullsModel extends \JModelDatabase
{
parent::__construct($state, $db);
$this->context = $context;
$this->sortFields = array('a.pull_id', 'a.title', 'applied');
$this->context = $context;
}
/**

View File

@ -32,8 +32,8 @@ class Com_PatchtesterInstallerScript
/**
* Function to act prior to installation process begins
*
* @param string $type The action being performed
* @param JInstallerComponent $parent The class calling this method
* @param string $type The action being performed
* @param JInstallerAdapterComponent $parent The class calling this method
*
* @return boolean True on success
*
@ -54,7 +54,7 @@ class Com_PatchtesterInstallerScript
/**
* Function to perform changes during install
*
* @param JInstallerComponent $parent The class calling this method
* @param JInstallerAdapterComponent $parent The class calling this method
*
* @return void
*
@ -68,7 +68,7 @@ class Com_PatchtesterInstallerScript
/**
* Function to perform changes during update
*
* @param JInstallerComponent $parent The class calling this method
* @param JInstallerAdapterComponent $parent The class calling this method
*
* @return void
*
@ -82,7 +82,7 @@ class Com_PatchtesterInstallerScript
/**
* Function to perform changes during uninstall
*
* @param JInstallerComponent $parent The class calling this method
* @param JInstallerAdapterComponent $parent The class calling this method
*
* @return void
*