Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ModelToComponentRules.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 
42  abstract class ModelToComponentRules
43  {
47  protected $modelClassName;
48 
53  public static function getRulesName()
54  {
55  throw new NotImplementedException();
56  }
57 
62  public static function makeByModuleClassName($moduleClassName)
63  {
64  assert('is_string($moduleClassName)');
65  $rulesClassName = Yii::app()->custom->resolveComponentRulesClassNameByModule($moduleClassName, static::getRulesName());
66  return new $rulesClassName();
67  }
68 
72  public static function getMetadata()
73  {
74  $className = get_called_class();
75  try
76  {
77  // not using default value to save cpu cycles on requests that follow the first exception.
78  return GeneralCache::getEntry($className . 'Metadata');
79  }
80  catch (NotFoundException $e)
81  {
82  }
83  $metadata = MetadataUtil::getMetadata($className);
84  if (YII_DEBUG)
85  {
86  $className::assertMetadataIsValid($metadata);
87  }
88  GeneralCache::cacheEntry($className . 'Metadata', $metadata);
89  return $metadata;
90  }
91 
95  public static function setMetadata(array $metadata)
96  {
97  $className = get_called_class();
98  if (YII_DEBUG)
99  {
100  $className::assertMetadataIsValid($metadata);
101  }
102  MetadataUtil::setMetadata($className, $metadata);
103  GeneralCache::cacheEntry($className . 'Metadata', $metadata);
104  }
105 
109  public static function getDefaultMetadata()
110  {
111  return array();
112  }
113 
119  {
120  $derivedAttributeTypesData = array();
121  $metadata = static::getMetadata();
122  foreach (array_reverse(RuntimeUtil::getClassHierarchy(
123  get_class($model), $model::getLastClassInBeanHeirarchy())) as $modelClassName)
124  {
125  if (isset($metadata[$modelClassName]) && isset($metadata[$modelClassName]['derivedAttributeTypes']))
126  {
127  foreach ($metadata[$modelClassName]['derivedAttributeTypes'] as $derivedAttributeType)
128  {
129  $elementClassName = $derivedAttributeType . 'Element';
130  $derivedAttributeTypesData
131  [$derivedAttributeType] = array('label' => $elementClassName::getDisplayName(),
132  'derivedAttributeType' => $derivedAttributeType);
133  }
134  }
135  }
136  return $derivedAttributeTypesData;
137  }
138 
144  public function getAvailableOperatorsTypes(RedBeanModel $model, $attribute)
145  {
146  assert('is_string($attribute)');
147  $modelClassName = $model->getAttributeModelClassName($attribute);
148  $metadata = static::getMetadata();
149  if (isset($metadata[$modelClassName]) && isset($metadata[$modelClassName]['availableOperatorsTypes']) &&
150  isset($attribute, $metadata[$modelClassName]['availableOperatorsTypes'][$attribute]))
151  {
152  return $metadata[$modelClassName]['availableOperatorsTypes'][$attribute];
153  }
154  return null;
155  }
156 
162  public static function getVariableStateModuleLabel(User $user)
163  {
164  assert('$user->id > 0');
165  throw new NotImplementedException();
166  }
167 
173  public static function canUserAccessModuleInAVariableState(User $user)
174  {
175  assert('$user->id > 0');
176  throw new NotImplementedException();
177  }
178 
184  public static function resolveStateAdapterUserHasAccessTo(User $user)
185  {
186  assert('$user->id > 0');
187  throw new NotImplementedException();
188  }
189 
195  public static function getVariableStateValuesForUser($modelClassName, User $user)
196  {
197  assert('is_string($modelClassName)');
198  assert('$user->id > 0');
199  }
200 
205  protected static function assertMetadataIsValid(array $metadata)
206  {
207  }
208  }
209 ?>
static setMetadata(array $metadata)
Definition: User.php:37
getAvailableOperatorsTypes(RedBeanModel $model, $attribute)
static resolveStateAdapterUserHasAccessTo(User $user)
static getAttributeModelClassName($attributeName)
Definition: BeanModel.php:208
static assertMetadataIsValid(array $metadata)
static setMetadata($className, array $metadata, User $user=null)
static canUserAccessModuleInAVariableState(User $user)
static getClassHierarchy($className, $upToAndNotIncludingClassName)
Definition: RuntimeUtil.php:54
static getVariableStateModuleLabel(User $user)
static makeByModuleClassName($moduleClassName)
static getMetadata($className, User $user=null)
static getVariableStateValuesForUser($modelClassName, User $user)
getDerivedAttributeTypesData(RedBeanModel $model)
Generated on Sat Jul 11 2020 07:10:35
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.