[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_users/src/Model/ -> NoteModel.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_users
   6   *
   7   * @copyright   (C) 2011 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\Users\Administrator\Model;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\MVC\Model\AdminModel;
  15  use Joomla\CMS\Plugin\PluginHelper;
  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   * User note model.
  24   *
  25   * @since  2.5
  26   */
  27  class NoteModel 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_users.note';
  38  
  39      /**
  40       * Method to get the record form.
  41       *
  42       * @param   array    $data      Data for the form.
  43       * @param   boolean  $loadData  True if the form is to load its own data (default case), false if not.
  44       *
  45       * @return  \Joomla\CMS\Form\Form|bool  A Form object on success, false on failure
  46       *
  47       * @since   2.5
  48       */
  49      public function getForm($data = array(), $loadData = true)
  50      {
  51          // Get the form.
  52          $form = $this->loadForm('com_users.note', 'note', array('control' => 'jform', 'load_data' => $loadData));
  53  
  54          if (empty($form)) {
  55              return false;
  56          }
  57  
  58          return $form;
  59      }
  60  
  61      /**
  62       * Method to get a single record.
  63       *
  64       * @param   integer  $pk  The id of the primary key.
  65       *
  66       * @return  mixed  Object on success, false on failure.
  67       *
  68       * @since   2.5
  69       * @throws  \Exception
  70       */
  71      public function getItem($pk = null)
  72      {
  73          $result = parent::getItem($pk);
  74  
  75          // Get the dispatcher and load the content plugins.
  76          PluginHelper::importPlugin('content');
  77  
  78          // Load the user plugins for backward compatibility (v3.3.3 and earlier).
  79          PluginHelper::importPlugin('user');
  80  
  81          // Trigger the data preparation event.
  82          Factory::getApplication()->triggerEvent('onContentPrepareData', array('com_users.note', $result));
  83  
  84          return $result;
  85      }
  86  
  87      /**
  88       * Method to get the data that should be injected in the form.
  89       *
  90       * @return  mixed  The data for the form.
  91       *
  92       * @since   1.6
  93       * @throws  \Exception
  94       */
  95      protected function loadFormData()
  96      {
  97          // Get the application
  98          $app = Factory::getApplication();
  99  
 100          // Check the session for previously entered form data.
 101          $data = $app->getUserState('com_users.edit.note.data', array());
 102  
 103          if (empty($data)) {
 104              $data = $this->getItem();
 105  
 106              // Prime some default values.
 107              if ($this->getState('note.id') == 0) {
 108                  $data->set('catid', $app->input->get('catid', $app->getUserState('com_users.notes.filter.category_id'), 'int'));
 109              }
 110  
 111              $userId = $app->input->get('u_id', 0, 'int');
 112  
 113              if ($userId != 0) {
 114                  $data->user_id = $userId;
 115              }
 116          }
 117  
 118          $this->preprocessData('com_users.note', $data);
 119  
 120          return $data;
 121      }
 122  
 123      /**
 124       * Method to auto-populate the model state.
 125       *
 126       * Note. Calling getState in this method will result in recursion.
 127       *
 128       * @return  void
 129       *
 130       * @since   2.5
 131       * @throws  \Exception
 132       */
 133      protected function populateState()
 134      {
 135          parent::populateState();
 136  
 137          $userId = Factory::getApplication()->input->get('u_id', 0, 'int');
 138          $this->setState('note.user_id', $userId);
 139      }
 140  }


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