sources.php
3.43 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
<?php
// namespace administrator\components\com_jmap\tables;
/**
*
* @package JMAP::SOURCES::administrator::components::com_jmap
* @subpackage tables
* @author Joomla! Extensions Store
* @copyright (C) 2015 - Joomla! Extensions Store
* @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
*/
// no direct access
defined ( '_JEXEC' ) or die ( 'Restricted access' );
/**
* ORM Table for sitemap sources
*
* @package JMAP::SOURCES::administrator::components::com_jmap
* @subpackage tables
* @since 1.0
*/
class TableSources extends JTable {
/**
* @var int
*/
public $id = null;
/**
* @var string
*/
public $type = 'user';
/**
* @var string
*/
public $name = '';
/**
* @var string
*/
public $description = '';
/**
* @var int
*/
public $checked_out = 0;
/**
* @var datetime
*/
public $checked_out_time = 0;
/**
* @var int
*/
public $published = 1;
/**
* @var int
*/
public $ordering = null;
/**
* @var string
*/
public $sqlquery = '';
/**
* @var string
*/
public $sqlquery_managed = '{}';
/**
* @var string
*/
public $params = null;
/**
* Bind Table override
* @override
*
* @see JTable::bind()
*/
public function bind($fromArray, $saveTask = false, $sessionTask = false) {
parent::bind ( $fromArray );
if ($saveTask) {
$registry = new JRegistry ();
$registry->loadArray ( $this->params );
$this->params = $registry->toString ();
if (is_array ( $this->sqlquery_managed )) {
$this->sqlquery_managed = json_encode ( $this->sqlquery_managed );
}
}
// Manage complex attributes during session recovering bind/load
if($sessionTask) {
$registry = new JRegistry ( $this->params );
$this->params = $registry;
// By default convert to plain object this json serialized field, later convertable in JRegistry if needed
if ($this->sqlquery_managed) {
$this->sqlquery_managed = (object) ( $this->sqlquery_managed );
}
}
return true;
}
/**
* Load Table override
* @override
*
* @see JTable::load()
*/
public function load($idEntity = null, $reset = true) {
// If not $idEntity set return empty object
if($idEntity) {
if(!parent::load ( $idEntity )) {
return false;
}
}
$registry = new JRegistry ();
$registry->loadString( $this->params );
$this->params = $registry;
// By default convert to plain object this json serialized field, later convertable in JRegistry if needed
if ($this->sqlquery_managed) {
$this->sqlquery_managed = json_decode ( $this->sqlquery_managed );
}
return true;
}
/**
* Check Table override
* @override
*
* @see JTable::check()
*/
public function check() {
// Name required
if (! $this->name) {
$this->setError ( JText::_('COM_JMAP_VALIDATION_ERROR' ) );
return false;
}
// Validate sql query managed chunks
if($this->type == 'user') {
if(isset($this->sqlquery_managed)) {
$sqlQuerymanagedObject = json_decode($this->sqlquery_managed);
if( !($sqlQuerymanagedObject->option) ||
!($sqlQuerymanagedObject->table_maintable) ||
!($sqlQuerymanagedObject->titlefield) ||
!($sqlQuerymanagedObject->id)) {
$this->setError ( JText::_('COM_JMAP_ERROR_DATASOURCE_VALIDATION' ) );
return false;
}
}
}
return true;
}
/**
* Class constructor
* @param Object& $_db
*
* return Object&
*/
public function __construct(&$_db) {
parent::__construct ( '#__jmap', 'id', $_db );
}
}