[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_users/src/Table/ -> NoteTable.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\Table;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Table\Table;
  15  use Joomla\CMS\Versioning\VersionableTableInterface;
  16  use Joomla\Database\DatabaseDriver;
  17  
  18  // phpcs:disable PSR1.Files.SideEffects
  19  \defined('_JEXEC') or die;
  20  // phpcs:enable PSR1.Files.SideEffects
  21  
  22  /**
  23   * User notes table class
  24   *
  25   * @since  2.5
  26   */
  27  class NoteTable extends Table implements VersionableTableInterface
  28  {
  29      /**
  30       * Indicates that columns fully support the NULL value in the database
  31       *
  32       * @var    boolean
  33       * @since  4.0.0
  34       */
  35      protected $_supportNullValue = true;
  36  
  37      /**
  38       * Constructor
  39       *
  40       * @param   DatabaseDriver  $db  Database object
  41       *
  42       * @since  2.5
  43       */
  44      public function __construct(DatabaseDriver $db)
  45      {
  46          $this->typeAlias = 'com_users.note';
  47          parent::__construct('#__user_notes', 'id', $db);
  48  
  49          $this->setColumnAlias('published', 'state');
  50      }
  51  
  52      /**
  53       * Overloaded store method for the notes table.
  54       *
  55       * @param   boolean  $updateNulls  Toggle whether null values should be updated.
  56       *
  57       * @return  boolean  True on success, false on failure.
  58       *
  59       * @since   2.5
  60       */
  61      public function store($updateNulls = true)
  62      {
  63          $date = Factory::getDate()->toSql();
  64          $userId = Factory::getUser()->get('id');
  65  
  66          if (!((int) $this->review_time)) {
  67              $this->review_time = null;
  68          }
  69  
  70          if ($this->id) {
  71              // Existing item
  72              $this->modified_time    = $date;
  73              $this->modified_user_id = $userId;
  74          } else {
  75              // New record.
  76              $this->created_time     = $date;
  77              $this->created_user_id  = $userId;
  78              $this->modified_time    = $date;
  79              $this->modified_user_id = $userId;
  80          }
  81  
  82          // Attempt to store the data.
  83          return parent::store($updateNulls);
  84      }
  85  
  86      /**
  87       * Method to perform sanity checks on the Table instance properties to ensure they are safe to store in the database.
  88       *
  89       * @return  boolean  True if the instance is sane and able to be stored in the database.
  90       *
  91       * @since   4.0.0
  92       */
  93      public function check()
  94      {
  95          try {
  96              parent::check();
  97          } catch (\Exception $e) {
  98              $this->setError($e->getMessage());
  99  
 100              return false;
 101          }
 102  
 103          if (empty($this->modified_time)) {
 104              $this->modified_time = $this->created_time;
 105          }
 106  
 107          if (empty($this->modified_user_id)) {
 108              $this->modified_user_id = $this->created_user_id;
 109          }
 110  
 111          return true;
 112      }
 113  
 114      /**
 115       * Get the type alias for the history table
 116       *
 117       * @return  string  The alias as described above
 118       *
 119       * @since   4.0.0
 120       */
 121      public function getTypeAlias()
 122      {
 123          return $this->typeAlias;
 124      }
 125  }


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