[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_banners/src/Model/ -> ClientModel.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_banners
   6   *
   7   * @copyright   (C) 2008 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\Banners\Administrator\Model;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\MVC\Model\AdminModel;
  15  use Joomla\CMS\Table\Table;
  16  use Joomla\CMS\Versioning\VersionableModelTrait;
  17  
  18  // phpcs:disable PSR1.Files.SideEffects
  19  \defined('_JEXEC') or die;
  20  // phpcs:enable PSR1.Files.SideEffects
  21  
  22  /**
  23   * Client model.
  24   *
  25   * @since  1.6
  26   */
  27  class ClientModel extends AdminModel
  28  {
  29      use VersionableModelTrait;
  30  
  31      /**
  32       * The type alias for this content type.
  33       *
  34       * @var    string
  35       * @since  3.2
  36       */
  37      public $typeAlias = 'com_banners.client';
  38  
  39      /**
  40       * Method to test whether a record can be deleted.
  41       *
  42       * @param   object  $record  A record object.
  43       *
  44       * @return  boolean  True if allowed to delete the record. Defaults to the permission set in the component.
  45       *
  46       * @since   1.6
  47       */
  48      protected function canDelete($record)
  49      {
  50          if (empty($record->id) || $record->state != -2) {
  51              return false;
  52          }
  53  
  54          if (!empty($record->catid)) {
  55              return Factory::getUser()->authorise('core.delete', 'com_banners.category.' . (int) $record->catid);
  56          }
  57  
  58          return parent::canDelete($record);
  59      }
  60  
  61      /**
  62       * Method to test whether a record can have its state changed.
  63       *
  64       * @param   object  $record  A record object.
  65       *
  66       * @return  boolean  True if allowed to change the state of the record.
  67       *                   Defaults to the permission set in the component.
  68       *
  69       * @since   1.6
  70       */
  71      protected function canEditState($record)
  72      {
  73          $user = Factory::getUser();
  74  
  75          if (!empty($record->catid)) {
  76              return $user->authorise('core.edit.state', 'com_banners.category.' . (int) $record->catid);
  77          }
  78  
  79          return $user->authorise('core.edit.state', 'com_banners');
  80      }
  81  
  82      /**
  83       * Method to get the record form.
  84       *
  85       * @param   array    $data      Data for the form.
  86       * @param   boolean  $loadData  True if the form is to load its own data (default case), false if not.
  87       *
  88       * @return  \Joomla\CMS\Form\Form|boolean  A Form object on success, false on failure
  89       *
  90       * @since   1.6
  91       */
  92      public function getForm($data = array(), $loadData = true)
  93      {
  94          // Get the form.
  95          $form = $this->loadForm('com_banners.client', 'client', array('control' => 'jform', 'load_data' => $loadData));
  96  
  97          if (empty($form)) {
  98              return false;
  99          }
 100  
 101          return $form;
 102      }
 103  
 104      /**
 105       * Method to get the data that should be injected in the form.
 106       *
 107       * @return  mixed  The data for the form.
 108       *
 109       * @since   1.6
 110       */
 111      protected function loadFormData()
 112      {
 113          // Check the session for previously entered form data.
 114          $data = Factory::getApplication()->getUserState('com_banners.edit.client.data', array());
 115  
 116          if (empty($data)) {
 117              $data = $this->getItem();
 118          }
 119  
 120          $this->preprocessData('com_banners.client', $data);
 121  
 122          return $data;
 123      }
 124  
 125      /**
 126       * Prepare and sanitise the table prior to saving.
 127       *
 128       * @param   Table  $table  A Table object.
 129       *
 130       * @return  void
 131       *
 132       * @since   1.6
 133       */
 134      protected function prepareTable($table)
 135      {
 136          $table->name = htmlspecialchars_decode($table->name, ENT_QUOTES);
 137      }
 138  }


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