All Data Structures Functions Variables Pages
ModelStateChangesSubscriptionUtil.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo 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 the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo 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
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * 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
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified 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.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
41  {
54  public static function getCreatedModels($serviceName, $modelClassName, $pageSize, $offset, $timestamp,
55  $stateMetadataAdapterClassName = null, $owner = null,
56  $checkIfModelCreationApiSyncUtilIsNull = true)
57  {
58  $where = null;
59  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter($modelClassName);
60  $result = self::makeJoinAdapterAndWhereClauseForGetCreatedModels($serviceName, $modelClassName, $timestamp,
61  $stateMetadataAdapterClassName, $owner,
62  $checkIfModelCreationApiSyncUtilIsNull,
63  $joinTablesAdapter, $where);
64  if ($result === false)
65  {
66  return false;
67  }
68  else
69  {
70  return $modelClassName::getSubset($joinTablesAdapter, $offset, $pageSize, $where);
71  }
72  }
73 
84  public static function getCreatedModelsCount($serviceName, $modelClassName, $timestamp,
85  $stateMetadataAdapterClassName = null, $owner = null,
86  $checkIfModelCreationApiSyncUtilIsNull = true)
87  {
88  $where = null;
89  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter($modelClassName);
90  $result = self::makeJoinAdapterAndWhereClauseForGetCreatedModels($serviceName, $modelClassName, $timestamp,
91  $stateMetadataAdapterClassName, $owner,
92  $checkIfModelCreationApiSyncUtilIsNull,
93  $joinTablesAdapter, $where);
94  if ($result === false)
95  {
96  return 0;
97  }
98  else
99  {
100  return $modelClassName::getCount($joinTablesAdapter, $where, null, true);
101  }
102  }
103 
104  protected static function makeJoinAdapterAndWhereClauseForGetCreatedModels($serviceName, $modelClassName, $timestamp,
105  $stateMetadataAdapterClassName = null, $owner = null,
106  $checkIfModelCreationApiSyncUtilIsNull = true,
107  & $joinTablesAdapter, & $where)
108  {
109  $metadata = array();
110 
112  $serviceName, $modelClassName, $timestamp, ReadPermissionsSubscriptionUtil::TYPE_ADD,
113  Yii::app()->user->userModel, $checkIfModelCreationApiSyncUtilIsNull);
114  if (!is_array($modelIds) || empty($modelIds))
115  {
116  return false;
117  }
118  $metadata['clauses'] = array(
119  1 => array(
120  'attributeName' => 'id',
121  'operatorType' => 'oneOf',
122  'value' => $modelIds
123  ),
124  );
125  if (isset($owner) && $owner instanceof User)
126  {
127  $metadata['clauses'][2] = array(
128  'attributeName' => 'owner',
129  'operatorType' => 'equals',
130  'value' => $owner->id
131  );
132  $metadata['structure'] = "(1 AND 2)";
133  }
134  else
135  {
136  $metadata['structure'] = "1";
137  }
138  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter($modelClassName);
139  if ($stateMetadataAdapterClassName != null)
140  {
141  $stateMetadataAdapter = new $stateMetadataAdapterClassName($metadata);
142  $metadata = $stateMetadataAdapter->getAdaptedDataProviderMetadata();
143  }
144  $where = RedBeanModelDataProvider::makeWhere($modelClassName, $metadata, $joinTablesAdapter);
145  }
146 
157  public static function getDeletedModelIds($serviceName, $modelClassName, $pageSize, $offset, $timestamp,
158  $stateMetadataAdapterClassName = null)
159  {
161  $serviceName, $modelClassName, $timestamp, ReadPermissionsSubscriptionUtil::TYPE_DELETE,
162  Yii::app()->user->userModel);
163  $modelIds = array_slice($modelIds, $offset, $pageSize);
164  return $modelIds;
165  }
166 
175  public static function getDeletedModelsCount($serviceName, $modelClassName, $timestamp,
176  $stateMetadataAdapterClassName = null)
177  {
178  $items = self::getDeletedModelIds($serviceName, $modelClassName, null, 0, $timestamp,
179  $stateMetadataAdapterClassName = null);
180  return count($items);
181  }
182 
193  public static function getUpdatedModels($modelClassName, $pageSize, $offset, $timestamp,
194  $stateMetadataAdapterClassName = null, $owner = null)
195  {
196  if ($timestamp != 0)
197  {
198  $where = null;
199  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter($modelClassName);
200  self::makeJoinAdapterAndWhereClauseForGetUpdatedModels($modelClassName, $timestamp,
201  $stateMetadataAdapterClassName, $owner,
202  $joinTablesAdapter, $where);
203  return $modelClassName::getSubset($joinTablesAdapter, $offset, $pageSize, $where, 'modifiedDateTime asc');
204  }
205  else
206  {
207  return array();
208  }
209  }
210 
219  public static function getUpdatedModelsCount($modelClassName, $timestamp,
220  $stateMetadataAdapterClassName = null, $owner = null)
221  {
222  if ($timestamp != 0)
223  {
224  $where = null;
225  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter($modelClassName);
226  self::makeJoinAdapterAndWhereClauseForGetUpdatedModels($modelClassName, $timestamp,
227  $stateMetadataAdapterClassName, $owner,
228  $joinTablesAdapter, $where);
229  return $modelClassName::getCount($joinTablesAdapter, $where, null, true);
230  }
231  else
232  {
233  return 0;
234  }
235  }
236 
245  protected static function makeJoinAdapterAndWhereClauseForGetUpdatedModels($modelClassName, $timestamp,
246  $stateMetadataAdapterClassName = null, $owner = null,
247  & $joinTablesAdapter, & $where)
248  {
249  $metadata = array();
250  $dateTime = DateTimeUtil::convertTimestampToDbFormatDateTime($timestamp);
251  $metadata['clauses'] = array(
252  1 => array(
253  'attributeName' => 'modifiedDateTime',
254  'operatorType' => 'greaterThan',
255  'value' => $dateTime
256  )
257  );
258 
259  if (isset($owner) && $owner instanceof User)
260  {
261  $metadata['clauses'][2] = array(
262  'attributeName' => 'owner',
263  'operatorType' => 'equals',
264  'value' => $owner->id
265  );
266  $metadata['structure'] = "(1 AND 2) AND (item.modifiedDateTime > (3 + item.createdDateTime))";
267  }
268  else
269  {
270  $metadata['structure'] = "1 AND (item.modifiedDateTime > (3 + item.createdDateTime))";
271  }
272 
273  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter($modelClassName);
274  if ($stateMetadataAdapterClassName != null)
275  {
276  $stateMetadataAdapter = new $stateMetadataAdapterClassName($metadata);
277  $metadata = $stateMetadataAdapter->getAdaptedDataProviderMetadata();
278  }
279  $where = RedBeanModelDataProvider::makeWhere($modelClassName, $metadata, $joinTablesAdapter);
280  }
281  }
282 ?>
static getUpdatedModels($modelClassName, $pageSize, $offset, $timestamp, $stateMetadataAdapterClassName=null, $owner=null)
static getUpdatedModelsCount($modelClassName, $timestamp, $stateMetadataAdapterClassName=null, $owner=null)
static getCreatedModelsCount($serviceName, $modelClassName, $timestamp, $stateMetadataAdapterClassName=null, $owner=null, $checkIfModelCreationApiSyncUtilIsNull=true)
static getAddedOrDeletedModelsFromReadSubscriptionTable($serviceName, $modelClassName, $lastUpdateTimestamp, $type, $user, $checkIfModelCreationApiSyncUtilIsNull=true)
Definition: User.php:37
static getDeletedModelsCount($serviceName, $modelClassName, $timestamp, $stateMetadataAdapterClassName=null)
static makeWhere($modelClassName, array $metadata, &$joinTablesAdapter)
static getDeletedModelIds($serviceName, $modelClassName, $pageSize, $offset, $timestamp, $stateMetadataAdapterClassName=null)
static getCreatedModels($serviceName, $modelClassName, $pageSize, $offset, $timestamp, $stateMetadataAdapterClassName=null, $owner=null, $checkIfModelCreationApiSyncUtilIsNull=true)
static makeJoinAdapterAndWhereClauseForGetUpdatedModels($modelClassName, $timestamp, $stateMetadataAdapterClassName=null, $owner=null, &$joinTablesAdapter, &$where)
Generated on Thu May 28 2020 07:10:36