diff --git a/administrator/components/com_patchtester/PatchTester/Controller/AbstractController.php b/administrator/components/com_patchtester/PatchTester/Controller/AbstractController.php new file mode 100644 index 0000000..83ae1c5 --- /dev/null +++ b/administrator/components/com_patchtester/PatchTester/Controller/AbstractController.php @@ -0,0 +1,75 @@ +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; + } +} diff --git a/administrator/components/com_patchtester/PatchTester/Controller/ApplyController.php b/administrator/components/com_patchtester/PatchTester/Controller/ApplyController.php index 00ae2db..05b8cec 100644 --- a/administrator/components/com_patchtester/PatchTester/Controller/ApplyController.php +++ b/administrator/components/com_patchtester/PatchTester/Controller/ApplyController.php @@ -15,7 +15,7 @@ use PatchTester\Model\PullModel; * * @since 2.0 */ -class ApplyController extends DisplayController +class ApplyController extends AbstractController { /** * Execute the controller. diff --git a/administrator/components/com_patchtester/PatchTester/Controller/DisplayController.php b/administrator/components/com_patchtester/PatchTester/Controller/DisplayController.php index ccd61fd..431b8cc 100644 --- a/administrator/components/com_patchtester/PatchTester/Controller/DisplayController.php +++ b/administrator/components/com_patchtester/PatchTester/Controller/DisplayController.php @@ -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); diff --git a/administrator/components/com_patchtester/PatchTester/Controller/FetchController.php b/administrator/components/com_patchtester/PatchTester/Controller/FetchController.php index fe4691f..79b367e 100644 --- a/administrator/components/com_patchtester/PatchTester/Controller/FetchController.php +++ b/administrator/components/com_patchtester/PatchTester/Controller/FetchController.php @@ -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 diff --git a/administrator/components/com_patchtester/PatchTester/Controller/RevertController.php b/administrator/components/com_patchtester/PatchTester/Controller/RevertController.php index e16b872..0fdb6e1 100644 --- a/administrator/components/com_patchtester/PatchTester/Controller/RevertController.php +++ b/administrator/components/com_patchtester/PatchTester/Controller/RevertController.php @@ -15,7 +15,7 @@ use PatchTester\Model\PullModel; * * @since 2.0 */ -class RevertController extends DisplayController +class RevertController extends AbstractController { /** * Execute the controller. diff --git a/administrator/components/com_patchtester/PatchTester/Controller/StartfetchController.php b/administrator/components/com_patchtester/PatchTester/Controller/StartfetchController.php index 3a3f041..24310b8 100644 --- a/administrator/components/com_patchtester/PatchTester/Controller/StartfetchController.php +++ b/administrator/components/com_patchtester/PatchTester/Controller/StartfetchController.php @@ -16,7 +16,7 @@ use PatchTester\Model\PullsModel; * * @since 2.0 */ -class StartfetchController extends DisplayController +class StartfetchController extends AbstractController { /** * Execute the controller. diff --git a/administrator/components/com_patchtester/PatchTester/Model/PullsModel.php b/administrator/components/com_patchtester/PatchTester/Model/PullsModel.php index 1e2a243..bdc4d22 100644 --- a/administrator/components/com_patchtester/PatchTester/Model/PullsModel.php +++ b/administrator/components/com_patchtester/PatchTester/Model/PullsModel.php @@ -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; } /** diff --git a/administrator/components/com_patchtester/script.php b/administrator/components/com_patchtester/script.php index d5d8c16..f378ed2 100644 --- a/administrator/components/com_patchtester/script.php +++ b/administrator/components/com_patchtester/script.php @@ -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 *