[ 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_templates 6 * 7 * @copyright (C) 2009 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\Templates\Administrator\Table; 12 13 use Joomla\CMS\Language\Text; 14 use Joomla\CMS\Table\Table; 15 use Joomla\Database\DatabaseDriver; 16 use Joomla\Database\ParameterType; 17 use Joomla\Registry\Registry; 18 19 // phpcs:disable PSR1.Files.SideEffects 20 \defined('_JEXEC') or die; 21 // phpcs:enable PSR1.Files.SideEffects 22 23 /** 24 * Template style table class. 25 * 26 * @since 1.6 27 */ 28 class StyleTable extends Table 29 { 30 /** 31 * Constructor 32 * 33 * @param DatabaseDriver $db A database connector object 34 * 35 * @since 1.6 36 */ 37 public function __construct(DatabaseDriver $db) 38 { 39 parent::__construct('#__template_styles', 'id', $db); 40 } 41 42 /** 43 * Overloaded bind function to pre-process the params. 44 * 45 * @param array $array Named array 46 * @param mixed $ignore An optional array or space separated list of properties to ignore while binding. 47 * 48 * @return null|string null if operation was satisfactory, otherwise returns an error 49 * 50 * @since 1.6 51 */ 52 public function bind($array, $ignore = '') 53 { 54 if (isset($array['params']) && is_array($array['params'])) { 55 $registry = new Registry($array['params']); 56 $array['params'] = (string) $registry; 57 } 58 59 // Verify that the default style is not unset 60 if ($array['home'] == '0' && $this->home == '1') { 61 $this->setError(Text::_('COM_TEMPLATES_ERROR_CANNOT_UNSET_DEFAULT_STYLE')); 62 63 return false; 64 } 65 66 return parent::bind($array, $ignore); 67 } 68 69 /** 70 * Overloaded check method to ensure data integrity. 71 * 72 * @return boolean True on success. 73 * 74 * @since 1.6 75 */ 76 public function check() 77 { 78 try { 79 parent::check(); 80 } catch (\Exception $e) { 81 $this->setError($e->getMessage()); 82 83 return false; 84 } 85 86 if (empty($this->title)) { 87 $this->setError(Text::_('COM_TEMPLATES_ERROR_STYLE_REQUIRES_TITLE')); 88 89 return false; 90 } 91 92 return true; 93 } 94 95 /** 96 * Overloaded store method to ensure unicity of default style. 97 * 98 * @param boolean $updateNulls True to update fields even if they are null. 99 * 100 * @return boolean True on success. 101 * 102 * @since 1.6 103 */ 104 public function store($updateNulls = false) 105 { 106 if ($this->home != '0') { 107 $clientId = (int) $this->client_id; 108 $query = $this->_db->getQuery(true) 109 ->update($this->_db->quoteName('#__template_styles')) 110 ->set($this->_db->quoteName('home') . ' = ' . $this->_db->quote('0')) 111 ->where($this->_db->quoteName('client_id') . ' = :clientid') 112 ->where($this->_db->quoteName('home') . ' = :home') 113 ->bind(':clientid', $clientId, ParameterType::INTEGER) 114 ->bind(':home', $this->home); 115 $this->_db->setQuery($query); 116 $this->_db->execute(); 117 } 118 119 return parent::store($updateNulls); 120 } 121 122 /** 123 * Overloaded store method to unsure existence of a default style for a template. 124 * 125 * @param mixed $pk An optional primary key value to delete. If not set the instance property value is used. 126 * 127 * @return boolean True on success. 128 * 129 * @since 1.6 130 */ 131 public function delete($pk = null) 132 { 133 $k = $this->_tbl_key; 134 $pk = is_null($pk) ? $this->$k : $pk; 135 136 if (!is_null($pk)) { 137 $clientId = (int) $this->client_id; 138 $query = $this->_db->getQuery(true) 139 ->select($this->_db->quoteName('id')) 140 ->from($this->_db->quoteName('#__template_styles')) 141 ->where($this->_db->quoteName('client_id') . ' = :clientid') 142 ->where($this->_db->quoteName('template') . ' = :template') 143 ->bind(':template', $this->template) 144 ->bind(':clientid', $clientId, ParameterType::INTEGER); 145 $this->_db->setQuery($query); 146 $results = $this->_db->loadColumn(); 147 148 if (count($results) == 1 && $results[0] == $pk) { 149 $this->setError(Text::_('COM_TEMPLATES_ERROR_CANNOT_DELETE_LAST_STYLE')); 150 151 return false; 152 } 153 } 154 155 return parent::delete($pk); 156 } 157 }
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 |