33
0
mirror of https://github.com/joomla-extensions/patchtester.git synced 2024-12-27 12:43:04 +00:00
patchtester/administrator/components/com_patchtester/PatchTester/View/Pulls/PullsHtmlView.php

202 lines
4.3 KiB
PHP
Raw Normal View History

<?php
/**
* Patch testing component for the Joomla! CMS
*
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later
*/
namespace PatchTester\View\Pulls;
use Joomla\CMS\Factory;
2019-08-28 01:20:49 +00:00
use Joomla\CMS\Language\Text;
use Joomla\CMS\Pagination\Pagination;
use Joomla\CMS\Toolbar\Toolbar;
2019-08-28 01:20:49 +00:00
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Registry\Registry;
use PatchTester\TrackerHelper;
use PatchTester\View\DefaultHtmlView;
/**
* View class for a list of pull requests.
*
* @since 2.0
2015-12-05 17:43:54 +00:00
*
* @property-read \PatchTester\Model\PullsModel $model The model object.
*/
class PullsHtmlView extends DefaultHtmlView
{
/**
* Array containing the list of branches
*
* @var array
2017-05-31 08:06:00 +00:00
* @since 3.0.0
*/
protected $branches = array();
/**
* Array containing environment errors
*
* @var array
* @since 2.0
*/
protected $envErrors = array();
/**
* Array of open pull requests
*
* @var array
* @since 2.0
*/
protected $items;
/**
* Pagination object
*
* @var Pagination
* @since 2.0
*/
protected $pagination;
/**
* The model state
*
* @var Registry
* @since 2.0
*/
protected $state;
/**
* The issue tracker project alias
*
* @var string|boolean
* @since 2.0
*/
protected $trackerAlias;
/**
* Method to render the view.
*
* @return string The rendered view.
*
* @since 2.0
*/
public function render()
{
if (!extension_loaded('openssl'))
{
2019-08-28 01:20:49 +00:00
$this->envErrors[] = Text::_('COM_PATCHTESTER_REQUIREMENT_OPENSSL');
}
2020-03-31 18:19:05 +00:00
if (!in_array('https', stream_get_wrappers(), true))
{
2019-08-28 01:20:49 +00:00
$this->envErrors[] = Text::_('COM_PATCHTESTER_REQUIREMENT_HTTPS');
}
// Only process the data if there are no environment errors
if (!count($this->envErrors))
{
$this->state = $this->model->getState();
$this->items = $this->model->getItems();
$this->pagination = $this->model->getPagination();
$this->trackerAlias = TrackerHelper::getTrackerAlias($this->state->get('github_user'), $this->state->get('github_repo'));
$this->branches = $this->model->getBranches();
}
2017-01-21 19:52:15 +00:00
// Change the layout if there are environment errors
if (count($this->envErrors))
{
$this->setLayout('errors');
}
$this->addToolbar();
// Make text strings available in the JavaScript API
2019-08-28 01:20:49 +00:00
Text::script('COM_PATCHTESTER_CONFIRM_RESET');
// Set a warning on 4.0 branch
if (version_compare(JVERSION, '4.0', 'ge'))
{
Factory::getApplication()->enqueueMessage(Text::_('COM_PATCHTESTER_40_WARNING'), 'warning');
}
return parent::render();
}
/**
* Add the page title and toolbar.
*
* @return void
*
* @since 2.0
*/
2020-03-31 18:19:05 +00:00
protected function addToolbar(): void
{
2020-07-09 18:15:09 +00:00
ToolbarHelper::title(Text::_('COM_PATCHTESTER'), 'patchtester fas fa-save');
if (!count($this->envErrors))
{
$toolbar = Toolbar::getInstance('toolbar');
$toolbar->appendButton(
'Popup',
'sync',
'COM_PATCHTESTER_TOOLBAR_FETCH_DATA',
'index.php?option=com_patchtester&view=fetch&tmpl=component',
500,
210,
0,
0,
'window.parent.location.reload()',
Text::_('COM_PATCHTESTER_HEADING_FETCH_DATA')
);
// Add a reset button.
$toolbar->appendButton('Standard', 'expired', 'COM_PATCHTESTER_TOOLBAR_RESET', 'reset', false);
}
2019-08-28 01:20:49 +00:00
ToolbarHelper::preferences('com_patchtester');
}
/**
* Returns an array of values to be used for pagination limits
*
* @return array
*
* @since 4.0.0
*/
protected function getLimitOptions()
{
return array(
2019-08-28 01:20:49 +00:00
5 => Text::_('J5'),
10 => Text::_('J10'),
15 => Text::_('J15'),
20 => Text::_('J20'),
25 => Text::_('J25'),
30 => Text::_('J30'),
50 => Text::_('J50'),
100 => Text::_('J100'),
200 => Text::_('J200'),
500 => Text::_('J500'),
0 => Text::_('JALL'),
);
}
/**
* Returns an array of fields the table can be sorted by
*
* @return array
*
* @since 2.0
*/
protected function getSortFields()
{
return array(
2019-08-28 01:20:49 +00:00
'a.title ASC' => Text::_('JGLOBAL_TITLE_ASC'),
'a.title DESC' => Text::_('JGLOBAL_TITLE_DESC'),
'a.pull_id ASC' => Text::_('COM_PATCHTESTER_PULL_ID_ASC'),
'a.pull_id DESC' => Text::_('COM_PATCHTESTER_PULL_ID_DESC'),
);
}
}