Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
MashableUtil.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  {
44  public static function createMashableInboxRulesByModel($modelClassName)
45  {
46  assert('is_string($modelClassName) && $modelClassName != ""');
47  $mashableInboxRulesType = $modelClassName::getMashableInboxRulesType();
48  assert('$mashableInboxRulesType !== null');
49  $mashableInboxRulesClassName = $mashableInboxRulesType . 'MashableInboxRules';
50  $mashableInboxRules = new $mashableInboxRulesClassName();
51  return $mashableInboxRules;
52  }
53 
61  public static function getModelDataForCurrentUserByInterfaceName($interfaceClassName, $includeHavingRelatedItems = true)
62  {
63  assert('is_string($interfaceClassName)');
64  $interfaceModelClassNames = array();
65  $modules = Module::getModuleObjects();
66  foreach ($modules as $module)
67  {
68  $modelClassNames = $module::getModelClassNames();
69  foreach ($modelClassNames as $modelClassName)
70  {
71  $classToEvaluate = new ReflectionClass($modelClassName);
72  if ($classToEvaluate->implementsInterface($interfaceClassName) &&
73  !$classToEvaluate->isAbstract())
74  {
75  if (RightsUtil::canUserAccessModule(get_class($module), Yii::app()->user->userModel))
76  {
77  if (!$includeHavingRelatedItems && !$modelClassName::hasRelatedItems())
78  {
79  continue;
80  }
81  $interfaceModelClassNames[$modelClassName] =
82  $modelClassName::getModelLabelByTypeAndLanguage('Plural');
83  }
84  }
85  }
86  }
87  return $interfaceModelClassNames;
88  }
89 
94  public static function getUnreadCountForCurrentUserByModelClassName($modelClassName)
95  {
96  $mashableInboxRules = static::createMashableInboxRulesByModel($modelClassName);
97  return (int)$mashableInboxRules->getUnreadCountForCurrentUser();
98  }
99 
100  public static function getUnreadCountMashableInboxForCurrentUser()
101  {
102  $unreadCount = 0;
103  $mashableInboxModels = static::getModelDataForCurrentUserByInterfaceName('MashableInboxInterface');
104  foreach ($mashableInboxModels as $modelClassName => $modelLabel)
105  {
106  $unreadCount += static::getUnreadCountForCurrentUserByModelClassName($modelClassName);
107  }
108  return $unreadCount;
109  }
110 
111  public static function renderUnreadCountForDynamicLabelContent()
112  {
113  $unreadCount = self::getUnreadCountMashableInboxForCurrentUser();
114  return ZurmoHtml::wrapLabel($unreadCount, 'unread-inbox-count');
115  }
116 
123  public static function getSearchAttributeMetadataForMashableInboxByModelClassName($modelClassNames, $filteredBy, $searchTerm = '')
124  {
125  $modelClassNamesAndSearchAttributeData = array();
126  foreach ($modelClassNames as $modelClassName)
127  {
128  $mashableActivityRules
129  = static::createMashableInboxRulesByModel($modelClassName);
130  $metadataForMashableInbox
131  = $mashableActivityRules->getMetadataForMashableInbox();
132  $searchAttributesData
133  = $mashableActivityRules->getSearchAttributeData($searchTerm);
134  $metadataForMashableInboxAndSearch
135  = static::mergeMetadata($metadataForMashableInbox, $searchAttributesData);
136  $metadataFilteredBy
137  = $mashableActivityRules->getMetadataFilteredByFilteredBy($filteredBy);
138  $searchAttributesDataAndByFiltered
139  = static::mergeMetadata($metadataForMashableInboxAndSearch, $metadataFilteredBy);
140  $modelClassNamesAndSearchAttributeData[]
141  = array($modelClassName => $searchAttributesDataAndByFiltered);
142  }
143  return $modelClassNamesAndSearchAttributeData;
144  }
145 
150  public static function getSortAttributesByMashableInboxModelClassNames($modelClassNames)
151  {
152  assert('is_array($modelClassNames)');
153  $modelClassNamesAndSortAttributes = array();
154  foreach ($modelClassNames as $modelClassName)
155  {
156  $mashableActivityRules = static::createMashableInboxRulesByModel($modelClassName);
157  $modelClassNamesAndSortAttributes[$modelClassName] =
158  $mashableActivityRules->getMachableInboxOrderByAttributeName();
159  }
160  return $modelClassNamesAndSortAttributes;
161  }
162 
167  public static function renderSummaryContent(RedBeanModel $model)
168  {
169  $mashableInboxRules = static::createMashableInboxRulesByModel(get_class($model));
170  $summaryContentTemplate = $mashableInboxRules->getSummaryContentTemplate();
171  $data = array();
172  $data['modelStringContent'] = static::renderModelStringContent($model, $mashableInboxRules);
173  $data['modelCreationTimeContent'] = static::renderModelCreationTimeContent($model, $mashableInboxRules);
174  $spanForTag = ZurmoHtml::tag(
175  'div',
176  array(
177  "class" => "model-tag " . strtolower($mashableInboxRules->getModelClassName())
178  ),
179  ZurmoHtml::tag('span', array(), $mashableInboxRules->getModelClassName()));
180  $content = ZurmoHtml::tag('div', array('class' => 'inbox-item'), $spanForTag . self::resolveContentTemplate($summaryContentTemplate, $data));
181  return $content;
182  }
183 
184  protected static function renderModelStringContent(RedBeanModel $model, $mashableInboxRules)
185  {
186  return $mashableInboxRules->getModelStringContent($model);
187  }
188 
189  protected static function renderModelCreationTimeContent(RedBeanModel $model, $mashableInboxRules)
190  {
191  return $mashableInboxRules->getModelCreationTimeContent($model);
192  }
193 
199  public static function resolveContentTemplate($template, $data)
200  {
201  assert('is_string($template)');
202  assert('is_array($data)');
203  $preparedContent = array();
204  foreach ($data as $templateVar => $content)
205  {
206  $preparedContent["{" . $templateVar . "}"] = $content;
207  }
208  return strtr($template, $preparedContent);
209  }
210 
217  public static function mergeMetadata($firstMetadata, $secondMetadata, $isAnd = true)
218  {
219  if ($firstMetadata == null && $secondMetadata == null)
220  {
221  $metadata['clauses'] = array();
222  $metadata['structure'] = null;
223  return $metadata;
224  }
225  if ($firstMetadata == null)
226  {
227  return $secondMetadata;
228  }
229  if ($secondMetadata == null)
230  {
231  return $firstMetadata;
232  }
233  $firstMetadataClausesCount = count($firstMetadata['clauses']);
234  foreach ($secondMetadata['clauses'] as $clauseNumber => $clause)
235  {
236  $firstMetadata['clauses'][$clauseNumber + $firstMetadataClausesCount] = $clause;
237  }
238  if ($isAnd)
239  {
240  $operator = ' and ';
241  }
242  else
243  {
244  $operator = ' or ';
245  }
246  $callback = function($match) use ($firstMetadataClausesCount)
247  {
248  return (($match[0] + $firstMetadataClausesCount));
249  };
250  $firstMetadata['structure'] = '(' . $firstMetadata['structure'] . ')' . $operator .
251  '(' . preg_replace_callback("/(\\d+)/", $callback, $secondMetadata['structure']) . ')'; // Not Coding Standard
252  return $firstMetadata;
253  }
254 
259  public static function saveSelectedOptionsAsStickyData(MashableInboxForm $mashableInboxForm, $modelClassName)
260  {
261  assert('strlen($modelClassName) > 0 || ($modelClassName === null)');
262  $key = self::resolveKeyByModuleAndModel('MashableInboxModule', $modelClassName);
263  StickyUtil::setDataByKeyAndData($key, $mashableInboxForm->getAttributes(
264  array('optionForModel', 'filteredBy', 'searchTerm')));
265  }
266 
271  public static function restoreSelectedOptionsAsStickyData($modelClassName)
272  {
273  assert('strlen($modelClassName) > 0 || ($modelClassName === null)');
274  $key = self::resolveKeyByModuleAndModel('MashableInboxModule', $modelClassName);
275  $data = StickyUtil::getDataByKey($key);
276  $mashableInboxForm = new MashableInboxForm();
277  $mashableInboxForm->attributes = $data;
278  return $mashableInboxForm;
279  }
280 
286  public static function resolveKeyByModuleAndModel($moduleClassName, $modelClassName)
287  {
288  assert('strlen($moduleClassName) > 0');
289  if ($modelClassName == null)
290  {
291  $modelClassName = 'default';
292  }
293  return $moduleClassName . '_' . $modelClassName;
294  }
295  }
296 ?>
static getSortAttributesByMashableInboxModelClassNames($modelClassNames)
static wrapLabel($label, $class= 'z-label')
Definition: ZurmoHtml.php:656
static resolveKeyByModuleAndModel($moduleClassName, $modelClassName)
static getSearchAttributeMetadataForMashableInboxByModelClassName($modelClassNames, $filteredBy, $searchTerm= '')
static resolveContentTemplate($template, $data)
static mergeMetadata($firstMetadata, $secondMetadata, $isAnd=true)
static getModuleObjects()
Definition: Module.php:51
static renderSummaryContent(RedBeanModel $model)
static getModelDataForCurrentUserByInterfaceName($interfaceClassName, $includeHavingRelatedItems=true)
static canUserAccessModule($moduleClassName, $user)
Definition: RightsUtil.php:103
static createMashableInboxRulesByModel($modelClassName)
static saveSelectedOptionsAsStickyData(MashableInboxForm $mashableInboxForm, $modelClassName)
static getUnreadCountForCurrentUserByModelClassName($modelClassName)
static restoreSelectedOptionsAsStickyData($modelClassName)
Generated on Thu Aug 6 2020 07:10:32
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.