Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ImportWizardUtil.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  {
47  private static $importToFormAttributeMap = array('importRulesType',
48  'fileUploadData',
49  'rowColumnDelimiter',
50  'rowColumnEnclosure',
51  'firstRowIsHeaderRow',
52  'mappingData');
53 
59  public static function makeFormByImport($import)
60  {
61  assert('$import instanceof Import');
62  $form = new ImportWizardForm();
63  $form->id = $import->id;
64  if ($import->serializedData != null)
65  {
66  $unserializedData = unserialize($import->serializedData);
67  foreach (self::$importToFormAttributeMap as $attributeName)
68  {
69  if (isset($unserializedData[$attributeName]))
70  {
71  $form->$attributeName = $unserializedData[$attributeName];
72  }
73  }
74  if (isset($unserializedData['explicitReadWriteModelPermissions']))
75  {
76  $form->explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::
78  $unserializedData['explicitReadWriteModelPermissions']);
79  }
80  else
81  {
82  $form->explicitReadWriteModelPermissions = new ExplicitReadWriteModelPermissions();
83  }
84  }
85  return $form;
86  }
87 
95  public static function setFormByPostForStep1($importWizardForm, $postData)
96  {
97  assert('$importWizardForm instanceof ImportWizardForm');
98  assert('is_array($postData) && isset($postData["importRulesType"])');
99  if ($importWizardForm->importRulesType != $postData["importRulesType"])
100  {
101  foreach (self::$importToFormAttributeMap as $attributeName)
102  {
103  $importWizardForm->$attributeName = null;
104  }
105  $importWizardForm->explicitReadWriteModelPermissions = new ExplicitReadWriteModelPermissions();
106  }
107  $importWizardForm->importRulesType = $postData['importRulesType'];
108  }
109 
115  public static function setFormByPostForStep2($importWizardForm, $postData)
116  {
117  assert('$importWizardForm instanceof ImportWizardForm');
118  assert('is_array($postData)');
119  assert('isset($postData["firstRowIsHeaderRow"])');
120  assert('isset($postData["rowColumnDelimiter"])');
121  assert('isset($postData["rowColumnEnclosure"])');
122  $importWizardForm->setAttributes(array('firstRowIsHeaderRow' => $postData['firstRowIsHeaderRow'],
123  'rowColumnDelimiter' => $postData['rowColumnDelimiter'],
124  'rowColumnEnclosure' => $postData['rowColumnEnclosure']));
125  }
126 
132  public static function setFormByPostForStep3($importWizardForm, $postData)
133  {
134  assert('$importWizardForm instanceof ImportWizardForm');
135  assert('is_array($postData) && isset($postData["explicitReadWriteModelPermissions"])');
136  $importWizardForm->explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::
138  $postData['explicitReadWriteModelPermissions']);
139  }
140 
146  public static function setFormByPostForStep4($importWizardForm, $postData)
147  {
148  assert('$importWizardForm instanceof ImportWizardForm');
149  assert('is_array($postData)');
150  $importWizardForm->mappingData = $postData;
151  }
152 
160  public static function setFormByFileUploadDataAndTableName($importWizardForm, $fileUploadData, $tableName)
161  {
162  assert('$importWizardForm instanceof ImportWizardForm');
163  assert('is_array($fileUploadData)');
164  assert('is_string($tableName)');
165  foreach (self::$importToFormAttributeMap as $attributeName)
166  {
167  if ($attributeName != 'importRulesType')
168  {
169  $importWizardForm->$attributeName = null;
170  }
171  }
172  $importWizardForm->explicitReadWriteModelPermissions = new ExplicitReadWriteModelPermissions();
173  $importWizardForm->fileUploadData = $fileUploadData;
174  try
175  {
176  $importWizardForm->mappingData = ImportMappingUtil::makeMappingDataByTableName($tableName);
177  }
178  catch (NoRowsInTableException $e)
179  {
180  throw new FailedFileUploadException(Zurmo::t('ImportModule', 'Import file has no rows to use.'));
181  }
182  }
183 
190  public static function setImportSerializedDataFromForm($importWizardForm, $import)
191  {
192  assert('$importWizardForm instanceof ImportWizardForm');
193  assert('$import instanceof Import');
194  $dataToSerialize = array();
195  foreach (self::$importToFormAttributeMap as $attributeName)
196  {
197  $dataToSerialize[$attributeName] = $importWizardForm->$attributeName;
198  }
199  $dataToSerialize['explicitReadWriteModelPermissions'] =
202  $importWizardForm->explicitReadWriteModelPermissions);
203  $import->serializedData = serialize($dataToSerialize);
204  }
205 
212  public static function clearFileAndRelatedDataFromImport($import)
213  {
214  assert('$import instanceof Import');
215  $unserializedData = unserialize($import->serializedData);
216  $newUnserializedData['importRulesType'] = $unserializedData['importRulesType'];
217  if ($import->save())
218  {
219  ZurmoRedBean::$writer->dropTableByTableName($import->getTempTableName());
220  return true;
221  }
222  return false;
223  }
224 
233  public static function importFileHasAtLeastOneImportRow($importWizardForm, $import)
234  {
235  assert('$importWizardForm instanceof ImportWizardForm');
236  assert('$import instanceof Import');
237  $count = ImportDatabaseUtil::getCount($import->getTempTableName());
238  $minimumRows = 1;
239  if ($importWizardForm->firstRowIsHeaderRow)
240  {
241  $minimumRows = 2;
242  }
243  if ($count >= $minimumRows)
244  {
245  return true;
246  }
247  return false;
248  }
249  }
250 ?>
static getCount($tableName, $where=null)
static clearFileAndRelatedDataFromImport($import)
static importFileHasAtLeastOneImportRow($importWizardForm, $import)
static setImportSerializedDataFromForm($importWizardForm, $import)
static setFormByPostForStep3($importWizardForm, $postData)
static makeFormByImport($import)
static setFormByPostForStep1($importWizardForm, $postData)
static setFormByPostForStep2($importWizardForm, $postData)
static setFormByPostForStep4($importWizardForm, $postData)
static makeMixedPermitablesDataByExplicitReadWriteModelPermissions($explicitReadWriteModelPermissions)
static setFormByFileUploadDataAndTableName($importWizardForm, $fileUploadData, $tableName)
static makeMappingDataByTableName($tableName)
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.