Joomla-Sermon-Distributor/admin/src/View/Local_listings/HtmlView.php
Robot 60e9e3b32d
Release of v5.0.0-beta2
First release of Sermon Distributor towards Joomla 5. Add PHP check to install/update class. Add Database check and fix to install/update class.
2024-05-03 07:46:28 +02:00

235 lines
7.8 KiB
PHP

<?php
/*-------------------------------------------------------------------------------------------------------------| www.vdm.io |------/
____ ____ __ __ __
/\ _`\ /\ _`\ __ /\ \__ __/\ \ /\ \__
\ \,\L\_\ __ _ __ ___ ___ ___ ___ \ \ \/\ \/\_\ ____\ \ ,_\ _ __ /\_\ \ \____ __ __\ \ ,_\ ___ _ __
\/_\__ \ /'__`\/\`'__\/' __` __`\ / __`\ /' _ `\ \ \ \ \ \/\ \ /',__\\ \ \/ /\`'__\/\ \ \ '__`\/\ \/\ \\ \ \/ / __`\/\`'__\
/\ \L\ \/\ __/\ \ \/ /\ \/\ \/\ \/\ \L\ \/\ \/\ \ \ \ \_\ \ \ \/\__, `\\ \ \_\ \ \/ \ \ \ \ \L\ \ \ \_\ \\ \ \_/\ \L\ \ \ \/
\ `\____\ \____\\ \_\ \ \_\ \_\ \_\ \____/\ \_\ \_\ \ \____/\ \_\/\____/ \ \__\\ \_\ \ \_\ \_,__/\ \____/ \ \__\ \____/\ \_\
\/_____/\/____/ \/_/ \/_/\/_/\/_/\/___/ \/_/\/_/ \/___/ \/_/\/___/ \/__/ \/_/ \/_/\/___/ \/___/ \/__/\/___/ \/_/
/------------------------------------------------------------------------------------------------------------------------------------/
@version 5.0.x
@created 22nd October, 2015
@package Sermon Distributor
@subpackage HtmlView.php
@author Llewellyn van der Merwe <https://www.vdm.io/>
@copyright Copyright (C) 2015. All Rights Reserved
@license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
A sermon distributor that links to Dropbox.
/----------------------------------------------------------------------------------------------------------------------------------*/
namespace TrueChristianChurch\Component\Sermondistributor\Administrator\View\Local_listings;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Form\FormHelper;
use Joomla\CMS\Session\Session;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\HTML\HTMLHelper as Html;
use Joomla\CMS\Layout\FileLayout;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\CMS\Document\Document;
use TrueChristianChurch\Component\Sermondistributor\Administrator\Helper\SermondistributorHelper;
use TrueChristianChurch\Joomla\Utilities\ArrayHelper;
use TrueChristianChurch\Joomla\Utilities\StringHelper;
// No direct access to this file
\defined('_JEXEC') or die;
/**
* Sermondistributor Html View class for the Local_listings
*
* @since 1.6
*/
class HtmlView extends BaseHtmlView
{
/**
* Local_listings view display method
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
* @since 1.6
*/
public function display($tpl = null)
{
// Assign data to the view
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->state = $this->get('State');
$this->styles = $this->get('Styles');
$this->scripts = $this->get('Scripts');
$this->user ??= Factory::getApplication()->getIdentity();
// Load the filter form from xml.
$this->filterForm = $this->get('FilterForm');
// Load the active filters.
$this->activeFilters = $this->get('ActiveFilters');
// Add the list ordering clause.
$this->listOrder = $this->escape($this->state->get('list.ordering', 'a.id'));
$this->listDirn = $this->escape($this->state->get('list.direction', 'DESC'));
$this->saveOrder = $this->listOrder == 'a.ordering';
// set the return here value
$this->return_here = urlencode(base64_encode((string) Uri::getInstance()));
// get global action permissions
$this->canDo = SermondistributorHelper::getActions('local_listing');
$this->canEdit = $this->canDo->get('local_listing.edit');
$this->canState = $this->canDo->get('local_listing.edit.state');
$this->canCreate = $this->canDo->get('local_listing.create');
$this->canDelete = $this->canDo->get('local_listing.delete');
$this->canBatch = ($this->canDo->get('local_listing.batch') && $this->canDo->get('core.batch'));
// If we don't have items we load the empty state
if (is_array($this->items) && !count((array) $this->items) && $this->isEmptyState = $this->get('IsEmptyState'))
{
$this->setLayout('emptystate');
}
// We don't need toolbar in the modal window.
if ($this->getLayout() !== 'modal')
{
$this->addToolbar();
}
// Check for errors.
if (count($errors = $this->get('Errors')))
{
throw new \Exception(implode("\n", $errors), 500);
}
// Set the html view document stuff
$this->_prepareDocument();
// Display the template
parent::display($tpl);
}
/**
* Add the page title and toolbar.
*
* @return void
* @since 1.6
*/
protected function addToolbar(): void
{
ToolbarHelper::title(Text::_('COM_SERMONDISTRIBUTOR_LOCAL_LISTINGS'), 'link');
if ($this->canCreate)
{
ToolbarHelper::addNew('local_listing.add');
}
// Only load if there are items
if (ArrayHelper::check($this->items))
{
if ($this->canEdit)
{
ToolbarHelper::editList('local_listing.edit');
}
if ($this->canState)
{
ToolbarHelper::publishList('local_listings.publish');
ToolbarHelper::unpublishList('local_listings.unpublish');
ToolbarHelper::archiveList('local_listings.archive');
if ($this->canDo->get('core.admin'))
{
ToolbarHelper::checkin('local_listings.checkin');
}
}
if ($this->state->get('filter.published') == -2 && ($this->canState && $this->canDelete))
{
ToolbarHelper::deleteList('', 'local_listings.delete', 'JTOOLBAR_EMPTY_TRASH');
}
elseif ($this->canState && $this->canDelete)
{
ToolbarHelper::trash('local_listings.trash');
}
}
// set help url for this view if found
$this->help_url = SermondistributorHelper::getHelpUrl('local_listings');
if (StringHelper::check($this->help_url))
{
ToolbarHelper::help('COM_SERMONDISTRIBUTOR_HELP_MANAGER', false, $this->help_url);
}
// add the options comp button
if ($this->canDo->get('core.admin') || $this->canDo->get('core.options'))
{
ToolbarHelper::preferences('com_sermondistributor');
}
}
/**
* Prepare some document related stuff.
*
* @return void
* @since 1.6
*/
protected function _prepareDocument(): void
{
// Load jQuery
Html::_('jquery.framework');
$this->getDocument()->setTitle(Text::_('COM_SERMONDISTRIBUTOR_LOCAL_LISTINGS'));
// add styles
foreach ($this->styles as $style)
{
Html::_('stylesheet', $style, ['version' => 'auto']);
}
// add scripts
foreach ($this->scripts as $script)
{
Html::_('script', $script, ['version' => 'auto']);
}
}
/**
* Escapes a value for output in a view script.
*
* @param mixed $var The output to escape.
* @param bool $shorten The switch to shorten.
* @param int $length The shorting length.
*
* @return mixed The escaped value.
* @since 1.6
*/
public function escape($var, bool $shorten = true, int $length = 50)
{
if (!is_string($var))
{
return $var;
}
return StringHelper::html($var, $this->_charset ?? 'UTF-8', $shorten, $length);
}
/**
* Returns an array of fields the table can be sorted by
*
* @return array containing the field name to sort by as the key and display text as value
* @since 1.6
*/
protected function getSortFields()
{
return array(
'a.ordering' => Text::_('JGRID_HEADING_ORDERING'),
'a.published' => Text::_('JSTATUS'),
'a.name' => Text::_('COM_SERMONDISTRIBUTOR_LOCAL_LISTING_NAME_LABEL'),
'a.build' => Text::_('COM_SERMONDISTRIBUTOR_LOCAL_LISTING_BUILD_LABEL'),
'a.size' => Text::_('COM_SERMONDISTRIBUTOR_LOCAL_LISTING_SIZE_LABEL'),
'g.description' => Text::_('COM_SERMONDISTRIBUTOR_LOCAL_LISTING_EXTERNAL_SOURCE_LABEL'),
'a.key' => Text::_('COM_SERMONDISTRIBUTOR_LOCAL_LISTING_KEY_LABEL'),
'a.id' => Text::_('JGRID_HEADING_ID')
);
}
}