style.php
3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
* @package Joomla.Administrator
* @subpackage com_templates
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\Registry\Registry;
/**
* Template style table class.
*
* @since 1.6
*/
class TemplatesTableStyle extends JTable
{
/**
* Constructor
*
* @param JDatabaseDriver &$db A database connector object
*
* @since 1.6
*/
public function __construct(&$db)
{
parent::__construct('#__template_styles', 'id', $db);
}
/**
* Overloaded bind function to pre-process the params.
*
* @param array $array Named array
* @param mixed $ignore An optional array or space separated list of properties to ignore while binding.
*
* @return null|string null if operation was satisfactory, otherwise returns an error
*
* @since 1.6
*/
public function bind($array, $ignore = '')
{
if (isset($array['params']) && is_array($array['params']))
{
$registry = new Registry($array['params']);
$array['params'] = (string) $registry;
}
// Verify that the default style is not unset
if ($array['home'] == '0' && $this->home == '1')
{
$this->setError(JText::_('COM_TEMPLATES_ERROR_CANNOT_UNSET_DEFAULT_STYLE'));
return false;
}
return parent::bind($array, $ignore);
}
/**
* Overloaded check method to ensure data integrity.
*
* @return boolean True on success.
*
* @since 1.6
*/
public function check()
{
if (empty($this->title))
{
$this->setError(JText::_('COM_TEMPLATES_ERROR_STYLE_REQUIRES_TITLE'));
return false;
}
return true;
}
/**
* Overloaded store method to ensure unicity of default style.
*
* @param boolean $updateNulls True to update fields even if they are null.
*
* @return boolean True on success.
*
* @since 1.6
*/
public function store($updateNulls = false)
{
if ($this->home != '0')
{
$query = $this->_db->getQuery(true)
->update('#__template_styles')
->set('home=\'0\'')
->where('client_id=' . (int) $this->client_id)
->where('home=' . $this->_db->quote($this->home));
$this->_db->setQuery($query);
$this->_db->execute();
}
return parent::store($updateNulls);
}
/**
* Overloaded store method to unsure existence of a default style for a template.
*
* @param mixed $pk An optional primary key value to delete. If not set the instance property value is used.
*
* @return boolean True on success.
*
* @since 1.6
*/
public function delete($pk = null)
{
$k = $this->_tbl_key;
$pk = is_null($pk) ? $this->$k : $pk;
if (!is_null($pk))
{
$query = $this->_db->getQuery(true)
->from('#__template_styles')
->select('id')
->where('client_id=' . (int) $this->client_id)
->where('template=' . $this->_db->quote($this->template));
$this->_db->setQuery($query);
$results = $this->_db->loadColumn();
if (count($results) == 1 && $results[0] == $pk)
{
$this->setError(JText::_('COM_TEMPLATES_ERROR_CANNOT_DELETE_LAST_STYLE'));
return false;
}
}
return parent::delete($pk);
}
}