All Data Structures Functions Variables Pages
ByTimeWorkflowInQueue.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 
43  {
47  public static function canSaveMetadata()
48  {
49  return true;
50  }
51 
55  public static function getDefaultMetadata()
56  {
57  $metadata = parent::getDefaultMetadata();
58  $metadata[__CLASS__] = array(
59  'members' => array(
60  'modelClassName',
61  'processDateTime',
62  ),
63  'relations' => array(
64  'modelItem' => array(static::HAS_ONE, 'Item', static::NOT_OWNED,
65  static::LINK_TYPE_SPECIFIC, 'modelItem'),
66  'savedWorkflow' => array(static::HAS_ONE, 'SavedWorkflow', static::NOT_OWNED),
67  ),
68  'rules' => array(
69  array('modelClassName', 'required'),
70  array('modelClassName', 'type', 'type' => 'string'),
71  array('modelClassName', 'length', 'max' => 64),
72  array('modelItem', 'required'),
73  array('processDateTime', 'required'),
74  array('processDateTime', 'type', 'type' => 'datetime'),
75  array('savedWorkflow', 'required'),
76  ),
77  'elements' => array(
78  'processDateTime' => 'DateTime'
79  ),
80  'defaultSortAttribute' => 'processDateTime',
81  );
82  return $metadata;
83  }
84 
88  public static function isTypeDeletable()
89  {
90  return true;
91  }
92 
98  protected static function getLabel($language = null)
99  {
100  return Zurmo::t('WorkflowsModule', 'Time Queue Item', array(), null, $language);
101  }
102 
108  protected static function getPluralLabel($language = null)
109  {
110  return Zurmo::t('WorkflowsModule', 'Time Queue Items', array(), null, $language);
111  }
112 
116  public static function getModuleClassName()
117  {
118  return 'WorkflowsModule';
119  }
120 
127  public static function resolveByWorkflowIdAndModel(SavedWorkflow $savedWorkflow, RedBeanModel $model)
128  {
129  $searchAttributeData = array();
130  $searchAttributeData['clauses'] = array(
131  1 => array(
132  'attributeName' => 'modelItem',
133  'operatorType' => 'equals',
134  'value' => $model->getClassId('Item')
135  ),
136  2 => array(
137  'attributeName' => 'savedWorkflow',
138  'operatorType' => 'equals',
139  'value' => $savedWorkflow->id
140  ),
141  3 => array(
142  'attributeName' => 'modelClassName',
143  'operatorType' => 'equals',
144  'value' => get_class($model)
145  ),
146  );
147  $searchAttributeData['structure'] = '1 and 2 and 3';
148  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('ByTimeWorkflowInQueue');
149  $where = RedBeanModelDataProvider::makeWhere('ByTimeWorkflowInQueue', $searchAttributeData,
150  $joinTablesAdapter);
151  $models = self::getSubset($joinTablesAdapter, null, null, $where, null);
152  if (count($models) > 1)
153  {
154  throw new NotSupportedException();
155  }
156  elseif (count($models) == 1)
157  {
158  return $models[0];
159  }
160  else
161  {
162  $byTimeWorkflowInQueue = new ByTimeWorkflowInQueue();
163  $byTimeWorkflowInQueue->modelClassName = get_class($model);
164  $byTimeWorkflowInQueue->modelItem = $model;
165  $byTimeWorkflowInQueue->savedWorkflow = $savedWorkflow;
166  return $byTimeWorkflowInQueue;
167  }
168  }
169 
174  public static function getModelsToProcess($pageSize)
175  {
176  assert('is_int($pageSize) || $pageSize == null');
177  $timeStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
178  $searchAttributeData = array();
179  $searchAttributeData['clauses'] = array(
180  1 => array(
181  'attributeName' => 'processDateTime',
182  'operatorType' => 'lessThan',
183  'value' => $timeStamp,
184  ),
185  );
186  $searchAttributeData['structure'] = '1';
187  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('ByTimeWorkflowInQueue');
188  $where = RedBeanModelDataProvider::makeWhere('ByTimeWorkflowInQueue', $searchAttributeData, $joinTablesAdapter);
189  return self::getSubset($joinTablesAdapter, null, $pageSize, $where, null);
190  }
191 
192  protected function afterSave()
193  {
194  InQueueUtil::resolveToAddJobToQueueAfterSaveOfModel($this, 'ByTimeWorkflowInQueue');
195  parent::afterSave();
196  }
197  }
198 ?>
static getPluralLabel($language=null)
getClassId($modelClassName)
static makeWhere($modelClassName, array $metadata, &$joinTablesAdapter)
static getLabel($language=null)
static resolveByWorkflowIdAndModel(SavedWorkflow $savedWorkflow, RedBeanModel $model)
Definition: Item.php:37
static getModelsToProcess($pageSize)
Generated on Wed Apr 8 2020 07:10:44