30
1
mirror of https://github.com/joomla-extensions/weblinks.git synced 2024-06-09 01:32:22 +00:00
weblinks/src/administrator/components/com_weblinks/src/View/Weblinks/HtmlView.php
2021-06-19 21:17:09 +07:00

203 lines
5.5 KiB
PHP

<?php
/**
* @package Joomla.Administrator
* @subpackage Weblinks
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Weblinks\Administrator\View\Weblinks;
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\FileLayout;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;
/**
* View class for a list of weblinks.
*
* @since 1.5
*/
class HtmlView extends BaseHtmlView
{
/**
* An array of items
*
* @var array
*/
protected $items;
/**
* The pagination object
*
* @var \JPagination
*/
protected $pagination;
/**
* The model state
*
* @var \JObject
*/
protected $state;
/**
* Form object for search filters
*
* @var \JForm
*/
public $filterForm;
/**
* The active search filters
*
* @var array
*/
public $activeFilters;
/**
* Display the view.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return mixed A string if successful, otherwise an Error object.
*/
public function display($tpl = null)
{
$this->state = $this->get('State');
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
// Check for errors.
if (count($errors = $this->get('Errors')))
{
throw new GenericDataException(implode("\n", $errors), 500);
return false;
}
// We don't need toolbar in the modal layout.
if ($this->getLayout() !== 'modal')
{
$this->addToolbar();
}
else
{
// In article associations modal we need to remove language filter if forcing a language.
// We also need to change the category filter to show show categories with All or the forced language.
if ($forcedLanguage = Factory::getApplication()->input->get('forcedLanguage', '', 'CMD'))
{
// If the language is forced we can't allow to select the language, so transform the language selector filter into an hidden field.
$languageXml = new \SimpleXMLElement('<field name="language" type="hidden" default="' . $forcedLanguage . '" />');
$this->filterForm->setField($languageXml, 'filter', true);
// Also, unset the active language filter so the search tools is not open by default with this filter.
unset($this->activeFilters['language']);
// One last changes needed is to change the category filter to just show categories with All language or with the forced language.
$this->filterForm->setFieldAttribute('category_id', 'language', '*,' . $forcedLanguage, 'filter');
}
}
parent::display($tpl);
}
/**
* Add the page title and toolbar.
*
* @return void
*
* @since 1.6
*/
protected function addToolbar()
{
$state = $this->get('State');
$canDo = ContentHelper::getActions('com_weblinks', 'category', $state->get('filter.category_id'));
$user = Factory::getUser();
// Get the toolbar object instance
$bar = Toolbar::getInstance('toolbar');
ToolbarHelper::title(\JText::_('COM_WEBLINKS_MANAGER_WEBLINKS'), 'link weblinks');
if (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0)
{
ToolbarHelper::addNew('weblink.add');
}
if ($canDo->get('core.edit') || $canDo->get('core.edit.own'))
{
ToolbarHelper::editList('weblink.edit');
}
if ($canDo->get('core.edit.state'))
{
ToolbarHelper::publish('weblinks.publish', 'JTOOLBAR_PUBLISH', true);
ToolbarHelper::unpublish('weblinks.unpublish', 'JTOOLBAR_UNPUBLISH', true);
ToolbarHelper::archiveList('weblinks.archive');
ToolbarHelper::checkin('weblinks.checkin');
}
if ($state->get('filter.published') == -2 && $canDo->get('core.delete'))
{
ToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'weblinks.delete', 'JTOOLBAR_EMPTY_TRASH');
}
elseif ($canDo->get('core.edit.state'))
{
ToolbarHelper::trash('weblinks.trash');
}
// Add a batch button
if ($user->authorise('core.create', 'com_weblinks') && $user->authorise('core.edit', 'com_weblinks')
&& $user->authorise('core.edit.state', 'com_weblinks'))
{
HTMLHelper::_('bootstrap.renderModal', 'collapseModal');
$title = Text::_('JTOOLBAR_BATCH');
// Instantiate a new JLayoutFile instance and render the batch button
$layout = new FileLayout('joomla.toolbar.batch');
$dhtml = $layout->render(array('title' => $title));
$bar->appendButton('Custom', $dhtml, 'batch');
}
if ($user->authorise('core.admin', 'com_weblinks') || $user->authorise('core.options', 'com_weblinks'))
{
ToolbarHelper::preferences('com_weblinks');
}
ToolbarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS');
}
/**
* Returns an array of fields the table can be sorted by
*
* @return array Array containing the field name to sort by as the key and display text as value
*
* @since 3.0
*/
protected function getSortFields()
{
return array(
'a.ordering' => \JText::_('JGRID_HEADING_ORDERING'),
'a.state' => \JText::_('JSTATUS'),
'a.title' => \JText::_('JGLOBAL_TITLE'),
'a.access' => \JText::_('JGRID_HEADING_ACCESS'),
'a.hits' => \JText::_('JGLOBAL_HITS'),
'a.language' => \JText::_('JGRID_HEADING_LANGUAGE'),
'a.id' => \JText::_('JGRID_HEADING_ID'),
);
}
}