Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ImportMappingUtil.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 
41  {
49  public static function makeMappingDataByTableName($tableName)
50  {
51  assert('is_string($tableName)');
52  $firstRowData = ZurmoRedBean::$writer->getFirstRowByTableName($tableName);
53 
54  if (count($firstRowData) == 1 || count($firstRowData) == 0)
55  {
56  throw new NoRowsInTableException();
57  }
58  //Handle scenario where every column is null. Similiar to scenario below it with no data in file but
59  //making a row anyways.
60  $allValuesAreNull = true;
61  foreach ($firstRowData as $columnName => $value)
62  {
63  if ($value != null && $columnName != 'id')
64  {
65  $allValuesAreNull = false;
66  break;
67  }
68  }
69  if ($allValuesAreNull)
70  {
71  throw new NoRowsInTableException();
72  }
73  //handles scenario where there is no data in the file, but because there are a few bytes,
74  //it creates a single row.
75  if (count($firstRowData) == 2)
76  {
77  foreach ($firstRowData as $columnName => $value)
78  {
79  if (!in_array($columnName, ImportDatabaseUtil::getReservedColumnNames()) && $value == null)
80  {
81  if (ImportDatabaseUtil::getCount($tableName) == 1)
82  {
83  throw new NoRowsInTableException();
84  }
85  }
86  }
87  }
88  $mappingData = array();
89  foreach ($firstRowData as $columnName => $notUsed)
90  {
91  if (!in_array($columnName, ImportDatabaseUtil::getReservedColumnNames()))
92  {
93  $mappingData[$columnName] = array('type' => 'importColumn',
94  'attributeIndexOrDerivedType' => null,
95  'mappingRulesData' => null);
96  }
97  }
98  return $mappingData;
99  }
100 
109  {
110  assert('is_array($mappingData)');
111  $mappedAttributeIndicesOrDerivedAttributeTypes = null;
112  foreach ($mappingData as $data)
113  {
114  if ($data['attributeIndexOrDerivedType'] != null)
115  {
116  $mappedAttributeIndicesOrDerivedAttributeTypes[] = $data['attributeIndexOrDerivedType'];
117  }
118  }
119  return $mappedAttributeIndicesOrDerivedAttributeTypes;
120  }
121 
128  public static function makeExtraColumnNameByColumnCount($columnCount)
129  {
130  assert('is_int($columnCount)');
131  return 'column_' . ($columnCount + 1);
132  }
133 
140  public static function reIndexExtraColumnNamesByPostData($postData)
141  {
142  assert('is_array($postData)');
143  $reIndexedData = array();
144  $importColumnCount = 0;
145  $tempData = array();
146  foreach ($postData as $columnName => $data)
147  {
148  assert('$data["type"] == "importColumn" || $data["type"] == "extraColumn"');
149  if ($data['type'] == 'extraColumn')
150  {
151  $tempData[] = $data;
152  }
153  else
154  {
155  $reIndexedData[$columnName] = $data;
156  $importColumnCount++;
157  }
158  }
159  $extraColumnStartingCount = $importColumnCount - 1;
160  foreach ($tempData as $data)
161  {
162  $reIndexedData[self::makeExtraColumnNameByColumnCount($extraColumnStartingCount)] = $data;
163  $extraColumnStartingCount++;
164  }
165  return $reIndexedData;
166  }
167 
174  public static function makeColumnNamesAndAttributeIndexOrDerivedTypeLabels($mappingData, $importRulesType)
175  {
176  assert('is_array($mappingData)');
177  assert('is_string($importRulesType)');
178  $columnNamesAndAttributeIndexOrDerivedTypeLabels = array();
179  foreach ($mappingData as $columnName => $columnData)
180  {
181  if ($columnData['attributeIndexOrDerivedType'] != null)
182  {
183  $attributeImportRules = AttributeImportRulesFactory::
185  $importRulesType, $columnData['attributeIndexOrDerivedType']);
186  $columnNamesAndAttributeIndexOrDerivedTypeLabels[$columnName] = $attributeImportRules->getDisplayLabel();
187  }
188  else
189  {
190  $columnNamesAndAttributeIndexOrDerivedTypeLabels[$columnName] = null;
191  }
192  }
193  return $columnNamesAndAttributeIndexOrDerivedTypeLabels;
194  }
195 
196  public static function makeBooleanColumnMappingData($attributeName)
197  {
198  return array('attributeIndexOrDerivedType' => $attributeName,
199  'type' => 'importColumn');
200  }
201 
209  public static function makeCurrencyColumnMappingData($attributeName, $currency, $defaultValue = null, $rateToBase = 1)
210  {
211  return array('attributeIndexOrDerivedType' => $attributeName,
212  'type' => 'importColumn',
213  'mappingRulesData' => array(
214  'DefaultValueModelAttributeMappingRuleForm' =>
215  array('defaultValue' => $defaultValue),
216  'CurrencyRateToBaseModelAttributeMappingRuleForm' =>
217  array('rateToBase' => $rateToBase),
218  'CurrencyIdModelAttributeMappingRuleForm' =>
219  array('id' => $currency->id)));
220  }
221 
228  public static function makeDateColumnMappingData($attributeName, $defaultValue = null,
229  $format = 'MM-dd-yyyy')
230  {
231  return array('attributeIndexOrDerivedType' => $attributeName,
232  'type' => 'importColumn',
233  'mappingRulesData' => array(
234  'DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => $defaultValue),
235  'ValueFormatMappingRuleForm' => array('format' => $format)));
236  }
237 
244  public static function makeDateTimeColumnMappingData($attributeName, $defaultValue = null,
245  $format = 'MM-dd-yyyy hh:mm')
246  {
247  return array('attributeIndexOrDerivedType' => $attributeName,
248  'type' => 'importColumn',
249  'mappingRulesData' => array(
250  'DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => $defaultValue),
251  'ValueFormatMappingRuleForm' => array('format' => $format)));
252  }
253 
260  public static function makeDropDownColumnMappingData($attributeName, $defaultValue = null,
261  $customFieldsInstructionData = null)
262  {
263  if ($customFieldsInstructionData == null)
264  {
265  $customFieldsInstructionData = array(CustomFieldsInstructionData::ADD_MISSING_VALUES => array());
266  }
267  return array('attributeIndexOrDerivedType' => $attributeName,
268  'type' => 'importColumn',
269  'mappingRulesData' => array('DefaultValueDropDownModelAttributeMappingRuleForm' =>
270  array('defaultValue' => $defaultValue)),
271  'customFieldsInstructionData' => $customFieldsInstructionData);
272  }
273 
280  public static function makeMultiSelectDropDownColumnMappingData($attributeName, $defaultValue = null,
281  $customFieldsInstructionData = null)
282  {
283  if ($customFieldsInstructionData == null)
284  {
285  $customFieldsInstructionData = array(CustomFieldsInstructionData::ADD_MISSING_VALUES => array());
286  }
287  return array('attributeIndexOrDerivedType' => $attributeName,
288  'type' => 'importColumn',
289  'mappingRulesData' => array('DefaultValueMultiSelectDropDownModelAttributeMappingRuleForm' =>
290  array('defaultValue' => $defaultValue)),
291  'customFieldsInstructionData' => $customFieldsInstructionData);
292  }
293 
300  public static function makeTagCloudColumnMappingData($attributeName, $defaultValue = null,
301  $customFieldsInstructionData = null)
302  {
303  if ($customFieldsInstructionData == null)
304  {
305  $customFieldsInstructionData = array(CustomFieldsInstructionData::ADD_MISSING_VALUES => array());
306  }
307  return array('attributeIndexOrDerivedType' => $attributeName,
308  'type' => 'importColumn',
309  'mappingRulesData' => array('DefaultValueMultiSelectDropDownModelAttributeMappingRuleForm' =>
310  array('defaultValue' => $defaultValue)),
311  'customFieldsInstructionData' => $customFieldsInstructionData);
312  }
313 
319  public static function makeEmailColumnMappingData($attributeName, $defaultValue = null)
320  {
321  return array('attributeIndexOrDerivedType' => $attributeName,
322  'type' => 'importColumn',
323  'mappingRulesData' => array(
324  'DefaultValueModelAttributeMappingRuleForm' =>
325  array('defaultValue' => $defaultValue)));
326  }
327 
333  public static function makeFloatColumnMappingData($attributeName, $defaultValue = null)
334  {
335  return array('attributeIndexOrDerivedType' => $attributeName,
336  'type' => 'importColumn',
337  'mappingRulesData' => array(
338  'DefaultValueModelAttributeMappingRuleForm' =>
339  array('defaultValue' => $defaultValue)));
340  }
341 
342  public static function makeIntegerColumnMappingData($attributeName, $defaultValue = null)
343  {
344  return array('attributeIndexOrDerivedType' => $attributeName,
345  'type' => 'importColumn',
346  'mappingRulesData' => array(
347  'DefaultValueModelAttributeMappingRuleForm' =>
348  array('defaultValue' => $defaultValue)));
349  }
350 
356  public static function makeHasOneColumnMappingData($attributeName,
357  $type = RelatedModelValueTypeMappingRuleForm::ZURMO_MODEL_ID)
358  {
359  return array('attributeIndexOrDerivedType' => $attributeName,
360  'type' => 'importColumn',
361  'mappingRulesData' => array(
362  'RelatedModelValueTypeMappingRuleForm' => array('type' => $type)));
363  }
364 
370  public static function makeModelDerivedColumnMappingData($derivedAttributeName,
371  $type = IdValueTypeMappingRuleForm::EXTERNAL_SYSTEM_ID)
372  {
373  return array('attributeIndexOrDerivedType' => $derivedAttributeName,
374  'type' => 'importColumn',
375  'mappingRulesData' => array(
376  'IdValueTypeMappingRuleForm' => array('type' => $type),
377  'DefaultModelNameIdDerivedAttributeMappingRuleForm' => array('defaultModelId' => null)));
378  }
379 
385  public static function makeStringColumnMappingData($attributeName, $defaultValue = null)
386  {
387  return array('attributeIndexOrDerivedType' => $attributeName,
388  'type' => 'importColumn',
389  'mappingRulesData' => array(
390  'DefaultValueModelAttributeMappingRuleForm' =>
391  array('defaultValue' => $defaultValue)));
392  }
393 
398  public static function makeTextAreaColumnMappingData($attributeName)
399  {
400  return array('attributeIndexOrDerivedType' => $attributeName,
401  'type' => 'importColumn');
402  }
403 
409  public static function makeUrlColumnMappingData($attributeName, $defaultValue = null)
410  {
411  return array('attributeIndexOrDerivedType' => $attributeName,
412  'type' => 'importColumn',
413  'mappingRulesData' => array(
414  'DefaultValueModelAttributeMappingRuleForm' =>
415  array('defaultValue' => $defaultValue)));
416  }
417  }
418 ?>
static makeEmailColumnMappingData($attributeName, $defaultValue=null)
static makeCurrencyColumnMappingData($attributeName, $currency, $defaultValue=null, $rateToBase=1)
static makeDateTimeColumnMappingData($attributeName, $defaultValue=null, $format= 'MM-dd-yyyy hh:mm')
static getCount($tableName, $where=null)
static makeFloatColumnMappingData($attributeName, $defaultValue=null)
static makeByImportRulesTypeAndAttributeIndexOrDerivedType($importRulesType, $attributeIndexOrDerivedType, $penultimateModelClassName=null, $explicitReadWriteModelPermissions=null)
static makeStringColumnMappingData($attributeName, $defaultValue=null)
static makeDropDownColumnMappingData($attributeName, $defaultValue=null, $customFieldsInstructionData=null)
static makeMultiSelectDropDownColumnMappingData($attributeName, $defaultValue=null, $customFieldsInstructionData=null)
static makeHasOneColumnMappingData($attributeName, $type=RelatedModelValueTypeMappingRuleForm::ZURMO_MODEL_ID)
static reIndexExtraColumnNamesByPostData($postData)
static makeModelDerivedColumnMappingData($derivedAttributeName, $type=IdValueTypeMappingRuleForm::EXTERNAL_SYSTEM_ID)
static makeTextAreaColumnMappingData($attributeName)
static makeMappingDataByTableName($tableName)
static makeUrlColumnMappingData($attributeName, $defaultValue=null)
static makeExtraColumnNameByColumnCount($columnCount)
static makeDateColumnMappingData($attributeName, $defaultValue=null, $format= 'MM-dd-yyyy')
static makeTagCloudColumnMappingData($attributeName, $defaultValue=null, $customFieldsInstructionData=null)
static getMappedAttributeIndicesOrDerivedAttributeTypesByMappingData($mappingData)
static makeColumnNamesAndAttributeIndexOrDerivedTypeLabels($mappingData, $importRulesType)
Generated on Mon Jul 6 2020 07:10:34
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.