Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
AutoresponderItem.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 
38  {
39  public static function getModuleClassName()
40  {
41  return 'AutorespondersModule';
42  }
43 
48  protected static function getLabel($language = null)
49  {
50  return Zurmo::t('AutorespondersModule', 'Autoresponder Item', array(), null, $language);
51  }
52 
57  protected static function getPluralLabel($language = null)
58  {
59  return Zurmo::t('AutorespondersModule', 'Autoresponder Items', array(), null, $language);
60  }
61 
62  public static function getDefaultMetadata()
63  {
64  $metadata = parent::getDefaultMetadata();
65  $metadata[__CLASS__] = array(
66  'members' => array(
67  'processDateTime',
68  'processed',
69  ),
70  'relations' => array(
71  'contact' => array(static::HAS_ONE, 'Contact', static::NOT_OWNED),
72  'emailMessage' => array(static::HAS_ONE, 'EmailMessage'),
73  'autoresponderItemActivities' => array(static::HAS_MANY, 'AutoresponderItemActivity'),
74  'autoresponder' => array(static::HAS_ONE, 'Autoresponder', static::NOT_OWNED),
75  ),
76  'rules' => array(
77  array('processDateTime', 'required'),
78  array('processDateTime', 'type', 'type' => 'datetime'),
79  array('processed', 'boolean'),
80  array('processed', 'default', 'value' => false),
81  ),
82  'elements' => array(
83  ),
84  'defaultSortAttribute' => 'processDateTime',
85  );
86  return $metadata;
87  }
88 
89  public static function isTypeDeletable()
90  {
91  return true;
92  }
93 
94  public static function canSaveMetadata()
95  {
96  return true;
97  }
98 
99  public static function getByProcessed($processed, $pageSize = null)
100  {
101  assert('is_int($processed)');
102  $searchAttributeData = array();
103  $searchAttributeData['clauses'] = array(
104  1 => array(
105  'attributeName' => 'processed',
106  'operatorType' => 'equals',
107  'value' => intval($processed),
108  ),
109  );
110  $searchAttributeData['structure'] = '1';
111  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter(get_called_class());
112  $where = RedBeanModelDataProvider::makeWhere(get_called_class(), $searchAttributeData, $joinTablesAdapter);
113  return self::getSubset($joinTablesAdapter, null, $pageSize, $where, 'processDateTime');
114  }
115 
116  public static function getByProcessedAndProcessDateTime($processed, $timestamp = null, $pageSize = null,
117  $offset = 0, $inPast = true)
118  {
119  assert('is_int($processed)');
120  assert('is_int($offset)');
121  assert('is_bool($inPast)');
122  if (empty($timestamp))
123  {
124  $timestamp = time();
125  }
126  $dateTime = DateTimeUtil::convertTimestampToDbFormatDateTime($timestamp);
127  if ($inPast)
128  {
129  $processDateTimeOperator = 'lessThan';
130  }
131  else
132  {
133  $processDateTimeOperator = 'greaterThan';
134  }
135  $searchAttributeData = array();
136  $searchAttributeData['clauses'] = array(
137  1 => array(
138  'attributeName' => 'processed',
139  'operatorType' => 'equals',
140  'value' => intval($processed),
141  ),
142  2 => array(
143  'attributeName' => 'processDateTime',
144  'operatorType' => $processDateTimeOperator,
145  'value' => $dateTime,
146  ),
147  );
148  $searchAttributeData['structure'] = '(1 and 2)';
149  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter(get_called_class());
150  $where = RedBeanModelDataProvider::makeWhere(get_called_class(), $searchAttributeData, $joinTablesAdapter);
151  return self::getSubset($joinTablesAdapter, $offset, $pageSize, $where, 'processDateTime');
152  }
153 
159  public static function getByProcessedAndAutoresponderId($processed, $autoresponderId, $pageSize = null)
160  {
161  assert('is_int($processed)');
162  assert('is_int($autoresponderId) || is_string($autoresponderId)');
163  $searchAttributeData = array();
164  $searchAttributeData['clauses'] = array(
165  1 => array(
166  'attributeName' => 'processed',
167  'operatorType' => 'equals',
168  'value' => intval($processed),
169  ),
170  2 => array(
171  'attributeName' => 'autoresponder',
172  'relatedAttributeName' => 'id',
173  'operatorType' => 'equals',
174  'value' => $autoresponderId,
175  ),
176  );
177  $searchAttributeData['structure'] = '(1 and 2)';
178  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter(get_called_class());
179  $where = RedBeanModelDataProvider::makeWhere(get_called_class(), $searchAttributeData, $joinTablesAdapter);
180  return self::getSubset($joinTablesAdapter, null, $pageSize, $where, 'processDateTime');
181  }
182 
189  public static function getByProcessedAndAutoresponderIdWithProcessDateTime($processed, $autoresponderId, $timestamp = null, $pageSize = null)
190  {
191  if (empty($timestamp))
192  {
193  $timestamp = time();
194  }
195  $dateTime = DateTimeUtil::convertTimestampToDbFormatDateTime($timestamp);
196  assert('is_int($processed)');
197  assert('is_int($autoresponderId) || is_string($autoresponderId)');
198  $searchAttributeData = array();
199  $searchAttributeData['clauses'] = array(
200  1 => array(
201  'attributeName' => 'processed',
202  'operatorType' => 'equals',
203  'value' => intval($processed),
204  ),
205  2 => array(
206  'attributeName' => 'processDateTime',
207  'operatorType' => 'lessThan',
208  'value' => $dateTime,
209  ),
210  3 => array(
211  'attributeName' => 'autoresponder',
212  'relatedAttributeName' => 'id',
213  'operatorType' => 'equals',
214  'value' => $autoresponderId,
215  ),
216  );
217  $searchAttributeData['structure'] = '(1 and 2 and 3)';
218  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter(get_called_class());
219  $where = RedBeanModelDataProvider::makeWhere(get_called_class(), $searchAttributeData, $joinTablesAdapter);
220  return self::getSubset($joinTablesAdapter, null, $pageSize, $where, 'processDateTime');
221  }
222 
223  public static function registerAutoresponderItemsByAutoresponderOperation($operation, $marketingListId, $contact)
224  {
225  $autoresponders = Autoresponder::getByOperationTypeAndMarketingListId($operation, $marketingListId);
226  $now = time();
227  foreach ($autoresponders as $autoresponder)
228  {
229  $processTimestamp = $autoresponder->resolveNewTimeStampForDuration($now);
230  $processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime($processTimestamp);
231  $processed = false;
232  static::addNewItem($processed, $processDateTime, $contact, $autoresponder);
233  }
234  }
235 
236  public static function addNewItem($processed, $processDateTime, $contact, $autoresponder)
237  {
238  $autoresponderItem = new self;
239  $autoresponderItem->processed = $processed;
240  $autoresponderItem->processDateTime = $processDateTime;
241  $autoresponderItem->contact = $contact;
242  $autoresponderItem->autoresponder = $autoresponder;
243  $saved = $autoresponderItem->unrestrictedSave();
244  assert('$saved');
245  if (!$saved)
246  {
247  throw new FailedToSaveModelException();
248  }
249  return $saved;
250  }
251 
257  protected function beforeSave()
258  {
259  $this->isNewModel = $this->id < 0;
260  return parent::beforeSave();
261  }
262 
263  protected function afterSave()
264  {
265  Yii::app()->jobQueue->resolveToAddJobTypeByModelByDateTimeAttribute($this, 'processDateTime',
266  'AutoresponderQueueMessagesInOutbox');
267  parent::afterSave();
268  $this->originalAttributeValues = array();
269  $this->isNewModel = false; //reset.
270  }
271 
272  protected function afterDelete()
273  {
274  $this->emailMessage->delete();
275  foreach ($this->autoresponderItemActivities as $activity)
276  {
277  $activity->delete();
278  }
279  return parent::afterDelete();
280  }
281  }
282 ?>
static getByProcessedAndAutoresponderId($processed, $autoresponderId, $pageSize=null)
static makeWhere($modelClassName, array $metadata, &$joinTablesAdapter)
static getLabel($language=null)
static getPluralLabel($language=null)
static getByProcessedAndAutoresponderIdWithProcessDateTime($processed, $autoresponderId, $timestamp=null, $pageSize=null)
Generated on Wed Oct 21 2020 07:10:28
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.