[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_scheduler/src/View/Tasks/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_scheduler
   6   *
   7   * @copyright   (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Component\Scheduler\Administrator\View\Tasks;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Form\Form;
  15  use Joomla\CMS\Helper\ContentHelper;
  16  use Joomla\CMS\Language\Text;
  17  use Joomla\CMS\MVC\View\GenericDataException;
  18  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  19  use Joomla\CMS\Object\CMSObject;
  20  use Joomla\CMS\Pagination\Pagination;
  21  use Joomla\CMS\Toolbar\Button\DropdownButton;
  22  use Joomla\CMS\Toolbar\Toolbar;
  23  use Joomla\CMS\Toolbar\ToolbarHelper;
  24  
  25  // phpcs:disable PSR1.Files.SideEffects
  26  \defined('_JEXEC') or die;
  27  // phpcs:enable PSR1.Files.SideEffects
  28  
  29  /**
  30   * MVC View for the Tasks list page.
  31   *
  32   * @since  4.1.0
  33   */
  34  class HtmlView extends BaseHtmlView
  35  {
  36      /**
  37       * Array of task items.
  38       *
  39       * @var    array
  40       * @since  4.1.0
  41       */
  42      protected $items;
  43  
  44      /**
  45       * The pagination object.
  46       *
  47       * @var    Pagination
  48       * @since  4.1.0
  49       * @todo   Test pagination.
  50       */
  51      protected $pagination;
  52  
  53      /**
  54       * The model state.
  55       *
  56       * @var    CMSObject
  57       * @since  4.1.0
  58       */
  59      protected $state;
  60  
  61      /**
  62       * A Form object for search filters.
  63       *
  64       * @var    Form
  65       * @since  4.1.0
  66       */
  67      public $filterForm;
  68  
  69      /**
  70       * The active search filters.
  71       *
  72       * @var    array
  73       * @since  4.1.0
  74       */
  75      public $activeFilters;
  76  
  77      /**
  78       * Is this view in an empty state?
  79       *
  80       * @var    boolean
  81       * @since  4.1.0
  82       */
  83      private $isEmptyState = false;
  84  
  85      /**
  86       * @inheritDoc
  87       *
  88       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  89       *
  90       * @return  void
  91       *
  92       * @since   4.1.0
  93       * @throws  \Exception
  94       */
  95      public function display($tpl = null): void
  96      {
  97          $this->items         = $this->get('Items');
  98          $this->pagination    = $this->get('Pagination');
  99          $this->state         = $this->get('State');
 100          $this->filterForm    = $this->get('FilterForm');
 101          $this->activeFilters = $this->get('ActiveFilters');
 102  
 103          if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) {
 104              $this->setLayout('empty_state');
 105          }
 106  
 107          // Check for errors.
 108          if (\count($errors = $this->get('Errors'))) {
 109              throw new GenericDataException(implode("\n", $errors), 500);
 110          }
 111  
 112          // We don't need toolbar in the modal window.
 113          if ($this->getLayout() !== 'modal') {
 114              $this->addToolbar();
 115          }
 116  
 117          parent::display($tpl);
 118      }
 119  
 120      /**
 121       * Add the page title and toolbar.
 122       *
 123       * @return  void
 124       *
 125       * @since  4.1.0
 126       * @throws  \Exception
 127       */
 128      protected function addToolbar(): void
 129      {
 130          $canDo = ContentHelper::getActions('com_scheduler');
 131          $user  = Factory::getApplication()->getIdentity();
 132  
 133          /*
 134          * Get the toolbar object instance
 135          * !! @todo : Replace usage with ToolbarFactoryInterface
 136          */
 137          $toolbar = Toolbar::getInstance();
 138  
 139          ToolbarHelper::title(Text::_('COM_SCHEDULER_MANAGER_TASKS'), 'clock');
 140  
 141          if ($canDo->get('core.create')) {
 142              $toolbar->linkButton('new', 'JTOOLBAR_NEW')
 143                  ->url('index.php?option=com_scheduler&view=select&layout=default')
 144                  ->buttonClass('btn btn-success')
 145                  ->icon('icon-new');
 146          }
 147  
 148          if (!$this->isEmptyState && ($canDo->get('core.edit.state') || $user->authorise('core.admin'))) {
 149              /** @var  DropdownButton $dropdown */
 150              $dropdown = $toolbar->dropdownButton('status-group')
 151                  ->toggleSplit(false)
 152                  ->text('JTOOLBAR_CHANGE_STATUS')
 153                  ->icon('icon-ellipsis-h')
 154                  ->buttonClass('btn btn-action')
 155                  ->listCheck(true);
 156  
 157              $childBar = $dropdown->getChildToolbar();
 158  
 159              // Add the batch Enable, Disable and Trash buttons if privileged
 160              if ($canDo->get('core.edit.state')) {
 161                  $childBar->publish('tasks.publish', 'JTOOLBAR_ENABLE')->listCheck(true);
 162                  $childBar->unpublish('tasks.unpublish', 'JTOOLBAR_DISABLE')->listCheck(true);
 163  
 164                  if ($canDo->get('core.admin')) {
 165                      $childBar->checkin('tasks.checkin')->listCheck(true);
 166                  }
 167  
 168                  $childBar->checkin('tasks.unlock', 'COM_SCHEDULER_TOOLBAR_UNLOCK')->listCheck(true)->icon('icon-unlock');
 169  
 170                  // We don't want the batch Trash button if displayed entries are all trashed
 171                  if ($this->state->get('filter.state') != -2) {
 172                      $childBar->trash('tasks.trash')->listCheck(true);
 173                  }
 174              }
 175          }
 176  
 177          // Add "Empty Trash" button if filtering by trashed.
 178          if ($this->state->get('filter.state') == -2 && $canDo->get('core.delete')) {
 179              $toolbar->delete('tasks.delete')
 180                  ->message('JGLOBAL_CONFIRM_DELETE')
 181                  ->text('JTOOLBAR_EMPTY_TRASH')
 182                  ->listCheck(true);
 183          }
 184  
 185          // Link to component preferences if user has admin privileges
 186          if ($canDo->get('core.admin') || $canDo->get('core.options')) {
 187              $toolbar->preferences('com_scheduler');
 188          }
 189  
 190          $toolbar->help('Scheduled_Tasks');
 191      }
 192  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer