2
/*********************************************************************************
3
* TimeTrex is a Workforce Management program developed by
4
* TimeTrex Software Inc. Copyright (C) 2003 - 2017 TimeTrex Software Inc.
6
* This program is free software; you can redistribute it and/or modify it under
7
* the terms of the GNU Affero General Public License version 3 as published by
8
* the Free Software Foundation with the addition of the following permission
9
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
10
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
11
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13
* This program is distributed in the hope that it will be useful, but WITHOUT
14
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18
* You should have received a copy of the GNU Affero General Public License along
19
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
20
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
24
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
26
* The interactive user interfaces in modified source and object code versions
27
* of this program must display Appropriate Legal Notices, as required under
28
* Section 5 of the GNU Affero General Public License version 3.
30
* In accordance with Section 7(b) of the GNU Affero General Public License
31
* version 3, these Appropriate Legal Notices must retain the display of the
32
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
33
* feasible for technical reasons, the Appropriate Legal Notices must display
34
* the words "Powered by TimeTrex".
35
********************************************************************************/
41
class PermissionListFactory extends PermissionFactory implements IteratorAggregate {
42
function getAll($limit = NULL, $page = NULL, $where = NULL, $order = NULL) {
45
from '. $this->getTable() .'
47
$query .= $this->getWhereSQL( $where );
48
$query .= $this->getSortSQL( $order );
50
$this->ExecuteSQL( $query, NULL, $limit, $page );
55
function getById($id, $where = NULL, $order = NULL) {
67
from '. $this->getTable() .'
70
$query .= $this->getWhereSQL( $where );
71
$query .= $this->getSortSQL( $order );
73
$this->ExecuteSQL( $query, $ph );
78
function getByCompanyId($company_id, $where = NULL, $order = NULL) {
79
if ( $company_id == '') {
84
'company_id' => (int)$company_id,
87
$pcf = new PermissionControlFactory();
91
from '. $this->getTable() .' as a,
92
'. $pcf->getTable() .' as b
93
where b.id = a.permission_control_id
95
AND ( a.deleted = 0 AND b.deleted = 0 )';
96
$query .= $this->getWhereSQL( $where );
97
$query .= $this->getSortSQL( $order );
99
$this->ExecuteSQL( $query, $ph );
104
function getByCompanyIdAndPermissionControlId($company_id, $permission_control_id, $where = NULL, $order = NULL) {
105
if ( $company_id == '') {
109
if ( $permission_control_id == '') {
114
'company_id' => (int)$company_id,
115
'permission_control_id' => (int)$permission_control_id,
118
$pcf = new PermissionControlFactory();
122
from '. $this->getTable() .' as a,
123
'. $pcf->getTable() .' as b
124
where b.id = a.permission_control_id
126
AND a.permission_control_id = ?
127
AND ( a.deleted = 0 AND b.deleted = 0 )';
128
$query .= $this->getWhereSQL( $where );
129
$query .= $this->getSortSQL( $order );
131
$this->ExecuteSQL( $query, $ph );
136
function getByCompanyIdAndPermissionControlIdAndSectionAndName($company_id, $permission_control_id, $section, $name, $where = NULL, $order = NULL) {
137
if ( $company_id == '') {
141
if ( $permission_control_id == '') {
145
if ( $section == '') {
154
'company_id' => (int)$company_id,
155
'permission_control_id' => (int)$permission_control_id,
156
'section' => $section,
157
//'name' => $name, //Allow a list of names.
160
$pcf = new PermissionControlFactory();
164
from '. $this->getTable() .' as a,
165
'. $pcf->getTable() .' as b
166
where b.id = a.permission_control_id
168
AND a.permission_control_id = ?
170
AND a.name in ('. $this->getListSQL($name, $ph) .')
171
AND ( a.deleted = 0 AND b.deleted = 0)';
172
$query .= $this->getWhereSQL( $where );
173
$query .= $this->getSortSQL( $order );
175
$this->ExecuteSQL( $query, $ph );
180
function getByCompanyIdAndPermissionControlIdAndSectionAndNameAndValue($company_id, $permission_control_id, $section, $name, $value, $where = NULL, $order = NULL) {
181
if ( $company_id == '') {
185
if ( $permission_control_id == '') {
189
if ( $section == '') {
198
'company_id' => (int)$company_id,
199
'permission_control_id' => (int)$permission_control_id,
200
'section' => $section,
201
'value' => (int)$value,
202
//'name' => $name, //Allow a list of names.
205
$pcf = new PermissionControlFactory();
209
from '. $this->getTable() .' as a,
210
'. $pcf->getTable() .' as b
211
where b.id = a.permission_control_id
213
AND a.permission_control_id = ?
216
AND a.name in ('. $this->getListSQL($name, $ph) .')
217
AND ( a.deleted = 0 AND b.deleted = 0)';
218
$query .= $this->getWhereSQL( $where );
219
$query .= $this->getSortSQL( $order );
221
$this->ExecuteSQL( $query, $ph );
226
function getByCompanyIdAndSectionAndDateAndValidIDs($company_id, $section, $date = NULL, $valid_ids = array(), $where = NULL, $order = NULL) {
227
if ( $company_id == '') {
231
if ( $section == '') {
240
'company_id' => (int)$company_id,
243
$pcf = new PermissionControlFactory();
247
from '. $this->getTable() .' as a,
248
'. $pcf->getTable() .' as b
249
where b.id = a.permission_control_id
253
a.section in ('. $this->getListSQL($section, $ph) .') ';
255
//When the Mobile App/TimeClock are doing a reload database, $date should always be 0. That forces the query to just send data for $valid_user_ids.
256
// All other cases it will send data for all current users always, or records that were recently created/updated.
257
if ( isset($date) AND $date > 0 ) {
258
//Append the same date twice for created and updated.
261
$query .= ' AND ( a.created_date >= ? OR a.updated_date >= ? ) ) ';
266
if ( isset($valid_ids) AND is_array($valid_ids) AND count($valid_ids) > 0 ) {
267
$query .= ' OR a.id in ('. $this->getListSQL( $valid_ids, $ph, 'int' ) .') ';
271
AND ( a.deleted = 0 AND b.deleted = 0)';
272
$query .= $this->getWhereSQL( $where );
273
$query .= $this->getSortSQL( $order );
275
$this->ExecuteSQL( $query, $ph );
280
function getAllPermissionsByCompanyIdAndUserId($company_id, $user_id) {
281
if ( $company_id == '') {
285
if ( $user_id == '') {
290
'company_id' => (int)$company_id,
291
'user_id' => (int)$user_id,
294
$pcf = new PermissionControlFactory();
295
$puf = new PermissionUserFactory();
300
from '. $this->getTable() .' as a,
301
'. $pcf->getTable() .' as b,
302
'. $puf->getTable() .' as c
303
where b.id = a.permission_control_id
304
AND b.id = c.permission_control_id
307
AND ( a.deleted = 0 AND b.deleted = 0 )
310
$this->ExecuteSQL( $query, $ph );
315
function getIsModifiedByCompanyIdAndDate($company_id, $date, $where = NULL, $order = NULL) {
316
if ( $company_id == '') {
325
'company_id' => (int)$company_id,
326
'created_date' => $date,
327
'updated_date' => $date,
328
'deleted_date' => $date,
331
$pcf = new PermissionControlFactory();
333
//INCLUDE Deleted rows in this query.
336
from '. $this->getTable() .' as a,
337
'. $pcf->getTable() .' as b
341
( a.created_date >= ? OR a.updated_date >= ? OR ( a.deleted = 1 AND a.deleted_date >= ? ) )
343
$query .= $this->getWhereSQL( $where );
344
$query .= $this->getSortSQL( $order );
346
$this->rs = $this->db->SelectLimit($query, 1, -1, $ph);
347
if ( $this->getRecordCount() > 0 ) {
348
Debug::text('Rows have been modified: '. $this->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
352
Debug::text('Rows have NOT been modified', __FILE__, __LINE__, __METHOD__, 10);