[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_finder 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\Finder\Administrator\Table; 12 13 use Joomla\CMS\Application\ApplicationHelper; 14 use Joomla\CMS\Factory; 15 use Joomla\CMS\Language\Text; 16 use Joomla\CMS\Table\Table; 17 use Joomla\Database\DatabaseDriver; 18 use Joomla\Registry\Registry; 19 20 // phpcs:disable PSR1.Files.SideEffects 21 \defined('_JEXEC') or die; 22 // phpcs:enable PSR1.Files.SideEffects 23 24 /** 25 * Filter table class for the Finder package. 26 * 27 * @since 2.5 28 */ 29 class FilterTable extends Table 30 { 31 /** 32 * Indicates that columns fully support the NULL value in the database 33 * 34 * @var boolean 35 * @since 4.0.0 36 */ 37 protected $_supportNullValue = true; 38 39 /** 40 * Ensure the params are json encoded in the bind method 41 * 42 * @var array 43 * @since 4.0.0 44 */ 45 protected $_jsonEncode = array('params'); 46 47 /** 48 * Constructor 49 * 50 * @param DatabaseDriver $db Database Driver connector object. 51 * 52 * @since 2.5 53 */ 54 public function __construct(DatabaseDriver $db) 55 { 56 parent::__construct('#__finder_filters', 'filter_id', $db); 57 58 $this->setColumnAlias('published', 'state'); 59 } 60 61 /** 62 * Method to perform sanity checks on the \JTable instance properties to ensure 63 * they are safe to store in the database. Child classes should override this 64 * method to make sure the data they are storing in the database is safe and 65 * as expected before storage. 66 * 67 * @return boolean True if the instance is sane and able to be stored in the database. 68 * 69 * @since 2.5 70 */ 71 public function check() 72 { 73 try { 74 parent::check(); 75 } catch (\Exception $e) { 76 $this->setError($e->getMessage()); 77 78 return false; 79 } 80 81 if (trim($this->alias) === '') { 82 $this->alias = $this->title; 83 } 84 85 $this->alias = ApplicationHelper::stringURLSafe($this->alias); 86 87 if (trim(str_replace('-', '', $this->alias)) === '') { 88 $this->alias = Factory::getDate()->format('Y-m-d-H-i-s'); 89 } 90 91 $params = new Registry($this->params); 92 93 $d1 = $params->get('d1', ''); 94 $d2 = $params->get('d2', ''); 95 96 // Check the end date is not earlier than the start date. 97 if (!empty($d1) && !empty($d2) && $d2 < $d1) { 98 // Swap the dates. 99 $params->set('d1', $d2); 100 $params->set('d2', $d1); 101 $this->params = (string) $params; 102 } 103 104 return true; 105 } 106 107 /** 108 * Method to store a row in the database from the \JTable instance properties. 109 * If a primary key value is set the row with that primary key value will be 110 * updated with the instance property values. If no primary key value is set 111 * a new row will be inserted into the database with the properties from the 112 * \JTable instance. 113 * 114 * @param boolean $updateNulls True to update fields even if they are null. [optional] 115 * 116 * @return boolean True on success. 117 * 118 * @since 2.5 119 */ 120 public function store($updateNulls = true) 121 { 122 $date = Factory::getDate()->toSql(); 123 $userId = Factory::getUser()->id; 124 125 // Set created date if not set. 126 if (!(int) $this->created) { 127 $this->created = $date; 128 } 129 130 if ($this->filter_id) { 131 // Existing item 132 $this->modified_by = $userId; 133 $this->modified = $date; 134 } else { 135 if (empty($this->created_by)) { 136 $this->created_by = $userId; 137 } 138 139 if (!(int) $this->modified) { 140 $this->modified = $this->created; 141 } 142 143 if (empty($this->modified_by)) { 144 $this->modified_by = $this->created_by; 145 } 146 } 147 148 if (is_array($this->data)) { 149 $this->map_count = count($this->data); 150 $this->data = implode(',', $this->data); 151 } else { 152 $this->map_count = 0; 153 $this->data = implode(',', array()); 154 } 155 156 // Verify that the alias is unique 157 $table = new static($this->getDbo()); 158 159 if ($table->load(array('alias' => $this->alias)) && ($table->filter_id != $this->filter_id || $this->filter_id == 0)) { 160 $this->setError(Text::_('JLIB_DATABASE_ERROR_ARTICLE_UNIQUE_ALIAS')); 161 162 return false; 163 } 164 165 return parent::store($updateNulls); 166 } 167 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |