[ 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_tags 6 * 7 * @copyright (C) 2013 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\Tags\Administrator\Table; 12 13 use Joomla\CMS\Application\ApplicationHelper; 14 use Joomla\CMS\Factory; 15 use Joomla\CMS\Helper\TagsHelper; 16 use Joomla\CMS\Language\Text; 17 use Joomla\CMS\Table\Nested; 18 use Joomla\CMS\Versioning\VersionableTableInterface; 19 use Joomla\Database\DatabaseDriver; 20 use Joomla\String\StringHelper; 21 22 // phpcs:disable PSR1.Files.SideEffects 23 \defined('_JEXEC') or die; 24 // phpcs:enable PSR1.Files.SideEffects 25 26 /** 27 * Tags table 28 * 29 * @since 3.1 30 */ 31 class TagTable extends Nested implements VersionableTableInterface 32 { 33 /** 34 * An array of key names to be json encoded in the bind function 35 * 36 * @var array 37 * @since 4.0.0 38 */ 39 protected $_jsonEncode = ['params', 'metadata', 'urls', 'images']; 40 41 /** 42 * Indicates that columns fully support the NULL value in the database 43 * 44 * @var boolean 45 * @since 4.0.0 46 */ 47 protected $_supportNullValue = true; 48 49 /** 50 * Constructor 51 * 52 * @param DatabaseDriver $db A database connector object 53 */ 54 public function __construct(DatabaseDriver $db) 55 { 56 $this->typeAlias = 'com_tags.tag'; 57 58 parent::__construct('#__tags', 'id', $db); 59 } 60 61 /** 62 * Overloaded check method to ensure data integrity. 63 * 64 * @return boolean True on success. 65 * 66 * @since 3.1 67 * @throws \UnexpectedValueException 68 */ 69 public function check() 70 { 71 try { 72 parent::check(); 73 } catch (\Exception $e) { 74 $this->setError($e->getMessage()); 75 76 return false; 77 } 78 79 // Check for valid name. 80 if (trim($this->title) == '') { 81 throw new \UnexpectedValueException('The title is empty'); 82 } 83 84 if (empty($this->alias)) { 85 $this->alias = $this->title; 86 } 87 88 $this->alias = ApplicationHelper::stringURLSafe($this->alias, $this->language); 89 90 if (trim(str_replace('-', '', $this->alias)) == '') { 91 $this->alias = Factory::getDate()->format('Y-m-d-H-i-s'); 92 } 93 94 // Check the publish down date is not earlier than publish up. 95 if (!empty($this->publish_down) && !empty($this->publish_up) && $this->publish_down < $this->publish_up) { 96 throw new \UnexpectedValueException('End publish date is before start publish date.'); 97 } 98 99 // Clean up description -- eliminate quotes and <> brackets 100 if (!empty($this->metadesc)) { 101 // Only process if not empty 102 $bad_characters = array("\"", '<', '>'); 103 $this->metadesc = StringHelper::str_ireplace($bad_characters, '', $this->metadesc); 104 } 105 106 if (empty($this->path)) { 107 $this->path = ''; 108 } 109 110 if (empty($this->hits)) { 111 $this->hits = 0; 112 } 113 114 if (empty($this->params)) { 115 $this->params = '{}'; 116 } 117 118 if (empty($this->metadesc)) { 119 $this->metadesc = ''; 120 } 121 122 if (empty($this->metakey)) { 123 $this->metakey = ''; 124 } 125 126 if (empty($this->metadata)) { 127 $this->metadata = '{}'; 128 } 129 130 if (empty($this->urls)) { 131 $this->urls = '{}'; 132 } 133 134 if (empty($this->images)) { 135 $this->images = '{}'; 136 } 137 138 if (!(int) $this->checked_out_time) { 139 $this->checked_out_time = null; 140 } 141 142 if (!(int) $this->publish_up) { 143 $this->publish_up = null; 144 } 145 146 if (!(int) $this->publish_down) { 147 $this->publish_down = null; 148 } 149 150 return true; 151 } 152 153 /** 154 * Overridden \JTable::store to set modified data and user id. 155 * 156 * @param boolean $updateNulls True to update fields even if they are null. 157 * 158 * @return boolean True on success. 159 * 160 * @since 3.1 161 */ 162 public function store($updateNulls = true) 163 { 164 $date = Factory::getDate(); 165 $user = Factory::getUser(); 166 167 if ($this->id) { 168 // Existing item 169 $this->modified_user_id = $user->get('id'); 170 $this->modified_time = $date->toSql(); 171 } else { 172 // New tag. A tag created and created_by field can be set by the user, 173 // so we don't touch either of these if they are set. 174 if (!(int) $this->created_time) { 175 $this->created_time = $date->toSql(); 176 } 177 178 if (empty($this->created_user_id)) { 179 $this->created_user_id = $user->get('id'); 180 } 181 182 if (!(int) $this->modified_time) { 183 $this->modified_time = $this->created_time; 184 } 185 186 if (empty($this->modified_user_id)) { 187 $this->modified_user_id = $this->created_user_id; 188 } 189 } 190 191 // Verify that the alias is unique 192 $table = new static($this->getDbo()); 193 194 if ($table->load(array('alias' => $this->alias)) && ($table->id != $this->id || $this->id == 0)) { 195 $this->setError(Text::_('COM_TAGS_ERROR_UNIQUE_ALIAS')); 196 197 return false; 198 } 199 200 return parent::store($updateNulls); 201 } 202 203 /** 204 * Method to delete a node and, optionally, its child nodes from the table. 205 * 206 * @param integer $pk The primary key of the node to delete. 207 * @param boolean $children True to delete child nodes, false to move them up a level. 208 * 209 * @return boolean True on success. 210 * 211 * @since 3.1 212 */ 213 public function delete($pk = null, $children = false) 214 { 215 $return = parent::delete($pk, $children); 216 217 if ($return) { 218 $helper = new TagsHelper(); 219 $helper->tagDeleteInstances($pk); 220 } 221 222 return $return; 223 } 224 225 /** 226 * Get the type alias for the history table 227 * 228 * @return string The alias as described above 229 * 230 * @since 4.0.0 231 */ 232 public function getTypeAlias() 233 { 234 return $this->typeAlias; 235 } 236 }
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 |