Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
PathUtil.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 
37  abstract class PathUtil
38  {
39  public static function getAllClassNamesByPathAlias($alias)
40  {
41  assert('is_string($alias)');
42  try
43  {
44  // not using default value to save cpu cycles on requests that follow the first exception.
45  $classNames = GeneralCache::getEntry($alias . '.ClassNames');
46  }
47  catch (NotFoundException $e)
48  {
49  $classNames = array();
50  $pathOfAlias = Yii::getPathOfAlias($alias . '.*');
51  if (is_dir($pathOfAlias))
52  {
53  $directoryFiles = ZurmoFileHelper::findFiles($pathOfAlias);
54  $classNames = array();
55  foreach ($directoryFiles as $filePath)
56  {
57  $filePathInfo = pathinfo($filePath);
58  if ($filePathInfo['extension'] == 'php')
59  {
60  $classNames[] = $filePathInfo['filename'];
61  }
62  }
63  }
64  GeneralCache::cacheEntry($alias, $classNames);
65  }
66  return $classNames;
67  }
68 
69  public static function getAllPrimaryModelClassNames($filter = null)
70  {
71  try
72  {
73  $allPrimaryModelClasses = GeneralCache::getEntry('allPrimaryModelClassNames');
74  }
75  catch (NotFoundException $e)
76  {
77  $allPrimaryModelClasses = array();
78  $modules = Module::getModuleObjects();
79  foreach ($modules as $module)
80  {
81  $modelClass = $module::getPrimaryModelName();
82  if (!empty($modelClasses))
83  {
84  $allPrimaryModelClasses[] = $modelClass;
85  }
86  }
87  GeneralCache::cacheEntry('allPrimaryModelClassNames', $allPrimaryModelClasses);
88  }
89  if ($filter && is_callable($filter))
90  {
91  $allPrimaryModelClasses = array_filter($allPrimaryModelClasses, $filter);
92  }
93  $allPrimaryModelClasses = array_unique($allPrimaryModelClasses);
94  return $allPrimaryModelClasses;
95  }
96 
97  public static function getAllModelClassNames($filter = null)
98  {
99  try
100  {
101  $allModelClasses = GeneralCache::getEntry('allModelClassNames');
102  }
103  catch (NotFoundException $e)
104  {
105  $allModelClasses = array();
106  $nonModuleModelPathAliases = Yii::app()->additionalModelsConfig->resolvePathAliases();
107  $modules = Module::getModuleObjects();
108  foreach ($modules as $module)
109  {
110  $modelClasses = $module::getModelClassNames();
111  if (!empty($modelClasses))
112  {
113  $allModelClasses = CMap::mergeArray($allModelClasses, array_values($modelClasses));
114  }
115  }
116  foreach ($nonModuleModelPathAliases as $alias)
117  {
118  $models = array_values(static::getAllClassNamesByPathAlias($alias));
119  $allModelClasses = CMap::mergeArray($allModelClasses, $models);
120  }
121  GeneralCache::cacheEntry('allModelClassNames', $allModelClasses);
122  }
123  if ($filter && is_callable($filter))
124  {
125  $allModelClasses = array_filter($allModelClasses, $filter);
126  }
127  $allModelClasses = array_unique(array_values($allModelClasses));
128  return $allModelClasses;
129  }
130 
131  public static function getAllCanHaveBeanModelClassNames()
132  {
133  return static::getAllModelClassNamesWithFilterFromCache('canHaveBeanModelClassNames',
134  'static::filterCanHaveBeanModels');
135  }
136 
137  public static function getAllReadSubscriptionModelClassNames()
138  {
139  return static::getAllModelClassNamesWithFilterFromCache('readPermissionsSubscriptionModelClassNames',
140  'static::filterReadSubscriptionModels');
141  }
142 
143  public static function getAllMungableModelClassNames()
144  {
145  return static::getAllModelClassNamesWithFilterFromCache('mungableModelClassNames',
146  'static::filterMungableModels');
147  }
148 
149  public static function getAllEmailTemplateElementClassNames($filter = null)
150  {
151  $emailTemplatePathAliases = 'application.modules.emailTemplates.elements';
152  $elements = array_values(static::getAllClassNamesByPathAlias($emailTemplatePathAliases));
153  if ($filter && is_callable($filter))
154  {
155  $elements = array_filter($elements, $filter);
156  }
157  $elements = array_unique(array_values($elements));
158  return $elements;
159  }
160 
161  public static function getAllUIAccessibleBuilderElementClassNames()
162  {
163  return static::getAllEmailTemplateElementClassNamesWithFilterFromCache(
164  'uiAccessibleBuilderElementClassNames',
165  'static::filterUIAccessibleBuilderElementClassNames');
166  }
167 
168  protected static function getAllModelClassNamesWithFilterFromCache($identifier, $filter)
169  {
170  try
171  {
172  $filteredModelClassNames = GeneralCache::getEntry($identifier);
173  }
174  catch (NotFoundException $e)
175  {
176  $filteredModelClassNames = static::getAllModelClassNames($filter);
177  GeneralCache::cacheEntry($identifier, $filteredModelClassNames);
178  }
179  return $filteredModelClassNames;
180  }
181 
182  protected static function filterCanHaveBeanModels($model)
183  {
184  return (is_subclass_of($model, 'RedBeanModel') && $model::getCanHaveBean());
185  }
186 
187  protected static function filterReadSubscriptionModels($model)
188  {
189  return (is_subclass_of($model, 'OwnedSecurableItem') && $model::hasReadPermissionsSubscriptionOptimization());
190  }
191 
192  protected static function filterMungableModels($model)
193  {
194  return (is_subclass_of($model, 'SecurableItem') && $model::hasReadPermissionsOptimization());
195  }
196 
197  protected static function getAllEmailTemplateElementClassNamesWithFilterFromCache($identifier, $filter)
198  {
199  try
200  {
201  $filteredElementClassNames = GeneralCache::getEntry($identifier);
202  }
203  catch (NotFoundException $e)
204  {
205  $filteredElementClassNames = static::getAllEmailTemplateElementClassNames($filter);
206  GeneralCache::cacheEntry($identifier, $filteredElementClassNames);
207  }
208  return $filteredElementClassNames;
209  }
210 
211  protected static function filterUIAccessibleBuilderElementClassNames($className)
212  {
213  return (is_subclass_of($className, 'BaseBuilderElement') && $className::isUIAccessible());
214  }
215  }
216 ?>
static getModuleObjects()
Definition: Module.php:51
Generated on Tue Jul 7 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.