group.php
4.45 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/**
* @package Joomla.Administrator
* @subpackage com_fields
*
* @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;
/**
* Groups Table
*
* @since 3.7.0
*/
class FieldsTableGroup extends JTable
{
/**
* Class constructor.
*
* @param JDatabaseDriver $db JDatabaseDriver object.
*
* @since 3.7.0
*/
public function __construct($db = null)
{
parent::__construct('#__fields_groups', 'id', $db);
$this->setColumnAlias('published', 'state');
}
/**
* Method to bind an associative array or object to the JTable instance.This
* method only binds properties that are publicly accessible and optionally
* takes an array of properties to ignore when binding.
*
* @param mixed $src An associative array or object to bind to the JTable instance.
* @param mixed $ignore An optional array or space separated list of properties to ignore while binding.
*
* @return boolean True on success.
*
* @since 3.7.0
* @throws InvalidArgumentException
*/
public function bind($src, $ignore = '')
{
if (isset($src['params']) && is_array($src['params']))
{
$registry = new Registry;
$registry->loadArray($src['params']);
$src['params'] = (string) $registry;
}
// Bind the rules.
if (isset($src['rules']) && is_array($src['rules']))
{
$rules = new JAccessRules($src['rules']);
$this->setRules($rules);
}
return parent::bind($src, $ignore);
}
/**
* Method to perform sanity checks on the JTable instance properties to ensure
* they are safe to store in the database. Child classes should override this
* method to make sure the data they are storing in the database is safe and
* as expected before storage.
*
* @return boolean True if the instance is sane and able to be stored in the database.
*
* @link https://docs.joomla.org/Special:MyLanguage/JTable/check
* @since 3.7.0
*/
public function check()
{
// Check for a title.
if (trim($this->title) == '')
{
$this->setError(JText::_('COM_FIELDS_MUSTCONTAIN_A_TITLE_GROUP'));
return false;
}
$date = JFactory::getDate();
$user = JFactory::getUser();
if ($this->id)
{
$this->modified = $date->toSql();
$this->modified_by = $user->get('id');
}
else
{
if (!(int) $this->created)
{
$this->created = $date->toSql();
}
if (empty($this->created_by))
{
$this->created_by = $user->get('id');
}
}
return true;
}
/**
* Method to compute the default name of the asset.
* The default name is in the form table_name.id
* where id is the value of the primary key of the table.
*
* @return string
*
* @since 3.7.0
*/
protected function _getAssetName()
{
$component = explode('.', $this->context);
return $component[0] . '.fieldgroup.' . (int) $this->id;
}
/**
* Method to return the title to use for the asset table. In
* tracking the assets a title is kept for each asset so that there is some
* context available in a unified access manager. Usually this would just
* return $this->title or $this->name or whatever is being used for the
* primary name of the row. If this method is not overridden, the asset name is used.
*
* @return string The string to use as the title in the asset table.
*
* @link https://docs.joomla.org/Special:MyLanguage/JTable/getAssetTitle
* @since 3.7.0
*/
protected function _getAssetTitle()
{
return $this->title;
}
/**
* Method to get the parent asset under which to register this one.
* By default, all assets are registered to the ROOT node with ID,
* which will default to 1 if none exists.
* The extended class can define a table and id to lookup. If the
* asset does not exist it will be created.
*
* @param JTable $table A JTable object for the asset parent.
* @param integer $id Id to look up
*
* @return integer
*
* @since 3.7.0
*/
protected function _getAssetParentId(JTable $table = null, $id = null)
{
$component = explode('.', $this->context);
$db = $this->getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__assets'))
->where($db->quoteName('name') . ' = ' . $db->quote($component[0]));
$db->setQuery($query);
if ($assetId = (int) $db->loadResult())
{
return $assetId;
}
return parent::_getAssetParentId($table, $id);
}
}