[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_privacy/src/Controller/ -> DisplayController.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_privacy
   6   *
   7   * @copyright   (C) 2018 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\Privacy\Administrator\Controller;
  12  
  13  use Joomla\CMS\Language\Text;
  14  use Joomla\CMS\MVC\Controller\BaseController;
  15  use Joomla\CMS\Response\JsonResponse;
  16  use Joomla\CMS\Router\Route;
  17  use Joomla\CMS\Session\Session;
  18  use Joomla\Component\Privacy\Administrator\Model\RequestsModel;
  19  
  20  // phpcs:disable PSR1.Files.SideEffects
  21  \defined('_JEXEC') or die;
  22  // phpcs:enable PSR1.Files.SideEffects
  23  
  24  /**
  25   * Privacy Controller
  26   *
  27   * @since  3.9.0
  28   */
  29  class DisplayController extends BaseController
  30  {
  31      /**
  32       * The default view.
  33       *
  34       * @var    string
  35       * @since  3.9.0
  36       */
  37      protected $default_view = 'requests';
  38  
  39      /**
  40       * Method to display a view.
  41       *
  42       * @param   boolean  $cachable   If true, the view output will be cached
  43       * @param   array    $urlparams  An array of safe URL parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
  44       *
  45       * @return  $this
  46       *
  47       * @since   3.9.0
  48       */
  49      public function display($cachable = false, $urlparams = [])
  50      {
  51          // Get the document object.
  52          $document = $this->app->getDocument();
  53  
  54          // Set the default view name and format from the Request.
  55          $vName   = $this->input->get('view', $this->default_view);
  56          $vFormat = $document->getType();
  57          $lName   = $this->input->get('layout', 'default', 'string');
  58  
  59          // Get and render the view.
  60          if ($view = $this->getView($vName, $vFormat)) {
  61              $model = $this->getModel($vName);
  62              $view->setModel($model, true);
  63  
  64              if ($vName === 'request') {
  65                  // For the default layout, we need to also push the action logs model into the view
  66                  if ($lName === 'default') {
  67                      $logsModel = $this->app->bootComponent('com_actionlogs')
  68                          ->getMVCFactory()->createModel('Actionlogs', 'Administrator', ['ignore_request' => true]);
  69  
  70                      // Set default ordering for the context
  71                      $logsModel->setState('list.fullordering', 'a.log_date DESC');
  72  
  73                      // And push the model into the view
  74                      $view->setModel($logsModel, false);
  75                  }
  76  
  77                  // For the edit layout, if mail sending is disabled then redirect back to the list view as the form is unusable in this state
  78                  if ($lName === 'edit' && !$this->app->get('mailonline', 1)) {
  79                      $this->setRedirect(
  80                          Route::_('index.php?option=com_privacy&view=requests', false),
  81                          Text::_('COM_PRIVACY_WARNING_CANNOT_CREATE_REQUEST_WHEN_SENDMAIL_DISABLED'),
  82                          'warning'
  83                      );
  84  
  85                      return $this;
  86                  }
  87              }
  88  
  89              $view->setLayout($lName);
  90  
  91              // Push document object into the view.
  92              $view->document = $document;
  93  
  94              $view->display();
  95          }
  96  
  97          return $this;
  98      }
  99  
 100      /**
 101       * Fetch and report number urgent privacy requests in JSON format, for AJAX requests
 102       *
 103       * @return  void
 104       *
 105       * @since   3.9.0
 106       */
 107      public function getNumberUrgentRequests()
 108      {
 109          // Check for a valid token. If invalid, send a 403 with the error message.
 110          if (!Session::checkToken('get')) {
 111              $this->app->setHeader('status', 403, true);
 112              $this->app->sendHeaders();
 113              echo new JsonResponse(new \Exception(Text::_('JINVALID_TOKEN'), 403));
 114              $this->app->close();
 115          }
 116  
 117          /** @var RequestsModel $model */
 118          $model                = $this->getModel('requests');
 119          $numberUrgentRequests = $model->getNumberUrgentRequests();
 120  
 121          echo new JsonResponse(['number_urgent_requests' => $numberUrgentRequests]);
 122      }
 123  }


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