Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ModelAttributesImportMappingAdapter.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  {
43  protected $model;
44 
48  public function __construct(RedBeanModel $model)
49  {
50  assert('$model !== null');
51  $this->model = $model;
52  }
53 
60  public function getAttributes()
61  {
62  $attributes = array();
64  $attributes,
65  'id',
66  $this->model->getAttributeLabel('id'),
67  'id',
68  'Id'
69  );
70  foreach ($this->model->getAttributes() as $attributeName => $notUsed)
71  {
72  if (!$this->model->isRelation($attributeName) ||
73  $this->isAttributeAnOwnedCustomFieldRelation($attributeName) ||
75  $this->isAttributeAHasOneNotOwnedRelation($attributeName) ||
77  {
78  $type = ModelAttributeToMixedTypeUtil::getType($this->model, $attributeName);
79  $resolvedType = static::resolveAttributeImportTypeByAttributeName($type, $attributeName);
81  $attributes,
82  $attributeName,
83  $this->model->getAttributeLabel($attributeName),
84  $attributeName,
85  $resolvedType,
86  null,
87  $this->model->isAttributeRequired($attributeName)
88  );
89  }
90  elseif ($this->isAttributeAHasOneOwnedRelation($attributeName))
91  {
92  foreach ($this->model->{$attributeName}->getAttributes() as $relationAttributeName => $notUsed)
93  {
94  if (!$this->model->{$attributeName}->isRelation($relationAttributeName))
95  {
96  $attributeLabel = $this->model->getAttributeLabel($attributeName) .
97  ' - ' .
98  $this->model->{$attributeName}->getAttributeLabel($relationAttributeName);
99  $type = ModelAttributeToMixedTypeUtil::getType($this->model->$attributeName,
100  $relationAttributeName);
101  $resolvedType = static::
102  resolveAttributeImportTypeByAttributeName($type, $relationAttributeName);
104  $attributes,
105  $attributeName . FormModelUtil::DELIMITER . $relationAttributeName,
106  $attributeLabel,
107  $attributeName,
108  $resolvedType,
109  $relationAttributeName,
110  $this->model->{$attributeName}->isAttributeRequired($relationAttributeName)
111  );
112  }
113  }
114  }
115  }
116  return $attributes;
117  }
118 
123  protected function isAttributeAHasOneOwnedRelation($attributeName)
124  {
125  assert('is_string($attributeName)');
126  if ($this->model->isRelation($attributeName) &&
127  $this->model->getRelationType($attributeName) == RedBeanModel::HAS_ONE &&
128  $this->model->isOwnedRelation($attributeName))
129  {
130  return true;
131  }
132  return false;
133  }
134 
139  protected function isAttributeAHasOneNotOwnedRelation($attributeName)
140  {
141  assert('is_string($attributeName)');
142  if ($this->model->isRelation($attributeName) &&
143  ($this->model->getRelationType($attributeName) == RedBeanModel::HAS_ONE ||
144  $this->model->getRelationType($attributeName) == RedBeanModel::HAS_MANY_BELONGS_TO ) &&
145  !$this->model->isOwnedRelation($attributeName))
146  {
147  return true;
148  }
149  return false;
150  }
151 
156  protected function isAttributeAnOwnedCustomFieldRelation($attributeName)
157  {
158  assert('is_string($attributeName)');
159  if ($this->model->isRelation($attributeName) &&
160  $this->model->getRelationType($attributeName) == RedBeanModel::HAS_ONE &&
161  $this->model->isOwnedRelation($attributeName) &&
162  $this->model->{$attributeName} instanceof OwnedCustomField)
163  {
164  return true;
165  }
166  return false;
167  }
168 
173  protected function isAttributeAnOwnedMultipleValuesCustomFieldRelation($attributeName)
174  {
175  assert('is_string($attributeName)');
176  if ($this->model->isRelation($attributeName) &&
177  $this->model->getRelationType($attributeName) == RedBeanModel::HAS_ONE &&
178  $this->model->isOwnedRelation($attributeName) &&
179  $this->model->{$attributeName} instanceof OwnedMultipleValuesCustomField)
180  {
181  return true;
182  }
183  return false;
184  }
185 
192  {
193  assert('is_string($attributeName)');
194  if ($this->model->isRelation($attributeName) &&
195  $this->model->getRelationType($attributeName) == RedBeanModel::HAS_ONE &&
196  $this->model->isOwnedRelation($attributeName) &&
197  in_array($this->model->getRelationModelClassName($attributeName),
198  static::getRelationModelClassNamesToTreatAsNonOwnedRelations()))
199  {
200  return true;
201  }
202  return false;
203  }
204 
213  {
214  return array('CurrencyValue');
215  }
216 
225  protected static function resolveAttributeImportTypeByAttributeName($type, $attributeName)
226  {
227  assert('is_string($type)');
228  assert('is_string($attributeName)');
229  if ($attributeName =='createdByUser')
230  {
231  return 'CreatedByUser';
232  }
233  if ($attributeName =='modifiedByUser')
234  {
235  return 'ModifiedByUser';
236  }
237  if ($attributeName =='createdDateTime')
238  {
239  return 'CreatedDateTime';
240  }
241  if ($attributeName =='modifiedDateTime')
242  {
243  return 'ModifiedDateTime';
244  }
245  if ($attributeName =='latestActivityDateTime')
246  {
247  return 'LatestActivityDateTime';
248  }
249  if ($attributeName =='username')
250  {
251  return 'Username';
252  }
253  if ($attributeName =='name')
254  {
255  return 'Name';
256  }
257  if ($attributeName =='stageModifiedDateTime')
258  {
259  return 'StageModifiedDateTime';
260  }
261  return $type;
262  }
263  }
264 ?>
const HAS_ONE
Definition: BeanModel.php:64
static resolveAttributeImportTypeByAttributeName($type, $attributeName)
static populateCollection(&$collection, $attributeIndex, $attributeLabel, $attributeName, $elementType, $relationAttributeName=null, $isRequired=false)
const HAS_MANY_BELONGS_TO
Definition: BeanModel.php:58
static getType($model, $attributeName)
Generated on Fri Jul 3 2020 07:10:33
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.