Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
MarketingList.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 getByName($name)
40  {
41  return self::getByNameOrEquivalent('name', $name);
42  }
43 
44  public static function getModuleClassName()
45  {
46  return 'MarketingListsModule';
47  }
48 
49  public function __toString()
50  {
51  try
52  {
53  if (trim($this->name) == '')
54  {
55  return Zurmo::t('Core', '(Unnamed)');
56  }
57  return $this->name;
58  }
60  {
61  return '';
62  }
63  }
64 
65  protected static function getLabel($language = null)
66  {
67  return Zurmo::t('MarketingListsModule', 'Marketing List', array(), null, $language);
68  }
69 
74  protected static function getPluralLabel($language = null)
75  {
76  return Zurmo::t('MarketingListsModule', 'Marketing Lists', array(), null, $language);
77  }
78 
79  public static function canSaveMetadata()
80  {
81  return true;
82  }
83 
84  public static function isTypeDeletable()
85  {
86  return true;
87  }
88 
89  public static function getDefaultMetadata()
90  {
91  $metadata = parent::getDefaultMetadata();
92  $metadata[__CLASS__] = array(
93  'members' => array(
94  'name',
95  'description',
96  'fromName',
97  'fromAddress',
98  'anyoneCanSubscribe',
99  ),
100  'relations' => array(
101  'marketingListMembers' => array(static::HAS_MANY, 'MarketingListMember', static::OWNED),
102  'autoresponders' => array(static::HAS_MANY, 'Autoresponder', static::OWNED),
103  'campaigns' => array(static::HAS_MANY, 'Campaign', static::OWNED),
104  ),
105  'rules' => array(
106  array('name', 'required'),
107  array('name', 'type', 'type' => 'string'),
108  array('name', 'length', 'min' => 1, 'max' => 64),
109  array('description', 'type', 'type' => 'string'),
110  array('fromName', 'type', 'type' => 'string'),
111  array('fromName', 'length', 'min' => 1, 'max' => 64),
112  array('fromAddress', 'type', 'type' => 'string'),
113  array('fromAddress', 'length', 'min' => 6, 'max' => 64),
114  array('fromAddress', 'email'),
115  array('anyoneCanSubscribe', 'boolean'),
116  array('anyoneCanSubscribe', 'default', 'value' => false),
117  ),
118  'elements' => array(
119  'anyoneCanSubscribe' => 'CheckBox',
120  'description' => 'TextArea',
121  ),
122  'defaultSortAttribute' => 'name',
123  );
124  return $metadata;
125  }
126 
127  public static function hasReadPermissionsOptimization()
128  {
129  return true;
130  }
131 
132  public static function getGamificationRulesType()
133  {
134  return 'MarketingListGamification';
135  }
136 
137  public function addNewMember($contactId, $unsubscribed = false, $contact = null, $scenario = null)
138  {
139  $member = new MarketingListMember();
140  if (empty($contact))
141  {
142  $contact = Contact::getById($contactId);
143  }
144  if ($this->memberAlreadyExists($contact->id))
145  {
146  return false;
147  }
148  $member->contact = $contact;
149  $member->unsubscribed = $unsubscribed;
150  $member->marketingList = $this;
151  if (isset($scenario))
152  {
153  $member->setScenario($scenario);
154  }
155  return $member->unrestrictedSave();
156  }
157 
158  public function memberAlreadyExists($contactId)
159  {
160  $sql = "SELECT COUNT(*) FROM " . MarketingListMember::getTableName();
161  $sql .= " WHERE contact_id={$contactId} AND marketinglist_id={$this->id}"; // Not Coding Standard
162  return (int) ZurmoRedBean::getCell($sql);
163  }
164 
165  public static function getByAnyoneCanSubscribe($anyoneCanSubscribe, $pageSize = null)
166  {
167  assert('is_int($anyoneCanSubscribe) || is_string($anyoneCanSubscribe)');
168  assert('intval($anyoneCanSubscribe) == 0 || intval($anyoneCanSubscribe) == 1');
169  $searchAttributeData = array();
170  $searchAttributeData['clauses'] = array(
171  1 => array(
172  'attributeName' => 'anyoneCanSubscribe',
173  'operatorType' => 'equals',
174  'value' => intval($anyoneCanSubscribe)
175  ),
176  );
177  $searchAttributeData['structure'] = '1';
178  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter(get_called_class());
179  $where = RedBeanModelDataProvider::makeWhere(get_called_class(), $searchAttributeData, $joinTablesAdapter);
180  return self::getSubset($joinTablesAdapter, null, $pageSize, $where, null);
181  }
182 
183  protected static function getIdsByAnyOneCanSubscribe($anyoneCanSubscribe, $pageSize = null)
184  {
185  assert('is_int($anyoneCanSubscribe) || is_string($anyoneCanSubscribe)');
186  assert('$anyoneCanSubscribe == 0 || $anyoneCanSubscribe == 1');
187  $searchAttributeData = array();
188  $searchAttributeData['clauses'] = array(
189  1 => array(
190  'attributeName' => 'anyoneCanSubscribe',
191  'operatorType' => 'equals',
192  'value' => intval($anyoneCanSubscribe)
193  ),
194  );
195  $searchAttributeData['structure'] = '1';
196  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter(get_called_class());
197  $where = RedBeanModelDataProvider::makeWhere(get_called_class(), $searchAttributeData, $joinTablesAdapter);
198  return self::getSubsetIds($joinTablesAdapter, null, $pageSize, $where, null);
199  }
200 
201  protected static function getIdsByUnsubscribed($contactId, $unsubscribed = 0, $pageSize = null)
202  {
203  assert('is_int($unsubscribed) || is_string($unsubscribed)');
204  assert('intval($unsubscribed) == 0 || intval($unsubscribed) == 1');
205  $searchAttributeData = array();
206  $searchAttributeData['clauses'] = array(
207  1 => array(
208  'attributeName' => 'marketingListMembers',
209  'relatedModelData' => array(
210  'attributeName' => 'contact',
211  'relatedAttributeName' => 'id',
212  'operatorType' => 'equals',
213  'value' => intval($contactId)
214  ),
215  ),
216  2 => array(
217  'attributeName' => 'marketingListMembers',
218  'relatedModelData' => array(
219  'attributeName' => 'unsubscribed',
220  'operatorType' => 'equals',
221  'value' => intval($unsubscribed)
222  ),
223  ),
224  );
225  $searchAttributeData['structure'] = '1 and 2';
226  $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter(get_called_class());
227  $where = RedBeanModelDataProvider::makeWhere(get_called_class(), $searchAttributeData, $joinTablesAdapter);
228  return self::getSubsetIds($joinTablesAdapter, null, $pageSize, $where, null);
229  }
230 
231  public static function getByUnsubscribedAndAnyoneCanSubscribe($contactId, $unsubscribed = 0,
232  $anyoneCanSubscribe = 1, $pageSize = null)
233  {
234  // TODO: @Shoaibi: Critical: Add Tests to cover:
235  $marketingListModels = array();
236  $subscribedMarketingListIds = static::getIdsByUnsubscribed($contactId, $unsubscribed, $pageSize);
237  $anyoneCanSubscribeMarketingListIds = static::getIdsByAnyOneCanSubscribe($anyoneCanSubscribe, $pageSize);
238  $marketingListIds = CMap::mergeArray($subscribedMarketingListIds,
239  $anyoneCanSubscribeMarketingListIds);
240  $marketingListIds = array_unique($marketingListIds);
241  foreach ($marketingListIds as $marketingListId)
242  {
243  $marketingListModelArray = array();
244  $marketingListModelArray['model'] = static::getById(intval($marketingListId));
245  $marketingListModelArray['subscribed'] = false;
246  if (in_array($marketingListId, $subscribedMarketingListIds))
247  {
248  $marketingListModelArray['subscribed'] = true;
249  }
250  $marketingListModels[] = $marketingListModelArray;
251  }
252  return $marketingListModels;
253  }
254  }
255 ?>
static makeWhere($modelClassName, array $metadata, &$joinTablesAdapter)
static getPluralLabel($language=null)
static getById($id, $modelClassName=null)
static getTableName()
Generated on Thu Jul 2 2020 07:10:35
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.