All Data Structures Functions Variables Pages
ImportWizardForm.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 
44  {
49  public $id;
50 
54  public $importRulesType;
55 
60  public $fileUploadData;
61 
66  public $rowColumnDelimiter = ','; // Not Coding Standard
67 
72  public $rowColumnEnclosure = '"';
73 
78  public $firstRowIsHeaderRow;
79 
86  protected $explicitReadWriteModelPermissions;
87 
93  public $mappingData;
94 
95  public function rules()
96  {
97  return array(
98  //default validators must come before the required validators
99  array('rowColumnDelimiter', 'default', 'value' => ',', 'setOnEmpty' => true), // Not Coding Standard
100  array('rowColumnEnclosure', 'default', 'value' => '"', 'setOnEmpty' => true),
101  array('importRulesType', 'required'),
102  array('rowColumnDelimiter', 'required'),
103  array('rowColumnEnclosure', 'required'),
104  array('fileUploadData', 'type', 'type' => 'array'),
105  array('rowColumnDelimiter', 'type', 'type' => 'string'),
106  array('rowColumnEnclosure', 'type', 'type' => 'string'),
107 
108  array('firstRowIsHeaderRow', 'boolean'),
109  array('mappingData', 'type', 'type' => 'array'),
110  array('newPassword', 'validateMappingData', 'on' => 'saveMappingData'),
111  );
112  }
113 
114  public function attributeLabels()
115  {
116  return array(
117  'importRulesType' => Zurmo::t('ImportModule', 'Module To Import To'),
118  'fileUploadData' => Zurmo::t('ImportModule', 'File Upload Data'),
119  'rowColumnDelimiter' => Zurmo::t('ImportModule', 'Delimiter'),
120  'rowColumnEnclosure' => Zurmo::t('ImportModule', 'Qualifier'),
121  'firstRowIsHeaderRow' => Zurmo::t('ImportModule', 'First Row is Header Row'),
122  'explicitReadWriteModelPermissions' => Zurmo::t('ImportModule', 'Model Permissions'),
123  'mappingData' => Zurmo::t('ImportModule', 'Mapping Data'),
124  );
125  }
126 
127  public function getExplicitReadWriteModelPermissions()
128  {
129  return $this->explicitReadWriteModelPermissions;
130  }
131 
132  public function setExplicitReadWriteModelPermissions($explicitReadWriteModelPermissions)
133  {
134  assert($explicitReadWriteModelPermissions instanceof ExplicitReadWriteModelPermissions); // Not Coding Standard
135  $this->explicitReadWriteModelPermissions = $explicitReadWriteModelPermissions;
136  }
137 
146  public function validateMappingData($attribute, $params)
147  {
148  assert('$this->importRulesType != null');
149  assert('$this->mappingData != null');
150  $atLeastOneAttributeMappedOrHasRules = false;
151  $attributeMappedOrHasRulesMoreThanOnce = false;
152  $mappedAttributes = array();
153  $importRulesClassName = ImportRulesUtil::
154  getImportRulesClassNameByType($this->importRulesType);
155  foreach ($this->mappingData as $columnName => $data)
156  {
157  if ($data['attributeIndexOrDerivedType'] != null)
158  {
159  $atLeastOneAttributeMappedOrHasRules = true;
160  if (in_array($data['attributeIndexOrDerivedType'], $mappedAttributes))
161  {
162  $attributeMappedOrHasRulesMoreThanOnce = true;
163  }
164  else
165  {
166  $mappedAttributes[] = $data['attributeIndexOrDerivedType'];
167  }
168  }
169  }
170  if ($attributeMappedOrHasRulesMoreThanOnce)
171  {
172  $this->addError('mappingData', Zurmo::t('ImportModule', 'You can only map each field once.'));
173  }
174  if (!$atLeastOneAttributeMappedOrHasRules)
175  {
176  $this->addError('mappingData', Zurmo::t('ImportModule', 'You must map at least one of your import columns.'));
177  }
178  $mappedAttributeIndicesOrDerivedAttributeTypes = ImportMappingUtil::
180  $this->mappingData);
181  $requiredAttributeCollection = $importRulesClassName::
182  getRequiredAttributesCollectionNotIncludingReadOnly();
183  $mappedAttributeImportRulesCollection = AttributeImportRulesFactory::makeCollection(
184  $this->importRulesType,
185  $mappedAttributeIndicesOrDerivedAttributeTypes);
186  if (!ImportRulesUtil::areAllRequiredAttributesMappedOrHaveRules($requiredAttributeCollection,
187  $mappedAttributeImportRulesCollection))
188  {
189  $attributesLabelContent = null;
190  foreach ($requiredAttributeCollection as $noteUsed => $attributeData)
191  {
192  if ($attributesLabelContent != null)
193  {
194  $attributesLabelContent .= ', ';
195  }
196  $attributesLabelContent .= $attributeData['attributeLabel'];
197  }
198  $this->addError('mappingData', Zurmo::t('ImportModule', 'All required fields must be mapped or added: {attributesLabelContent}',
199  array('{attributesLabelContent}' => $attributesLabelContent)));
200  }
201  try
202  {
203  ImportRulesUtil::checkIfAnyAttributesAreDoubleMapped($mappedAttributeImportRulesCollection);
204  }
206  {
207  $this->addError('mappingData', Zurmo::t('ImportModule', 'The following field is mapped more than once. {message}',
208  array('{message}' => $e->getMessage())));
209  }
210  }
211 
218  {
219  if (empty($this->rowColumnDelimiter))
220  {
221  return false;
222  }
223  return true;
224  }
225 
232  {
233  if (empty($this->rowColumnEnclosure))
234  {
235  return false;
236  }
237  return true;
238  }
239  }
240 ?>
static areAllRequiredAttributesMappedOrHaveRules(&$requiredAttributeCollection, $mappedAttributeImportRulesCollection)
validateMappingData($attribute, $params)
static getImportRulesClassNameByType($importRulesType)
static checkIfAnyAttributesAreDoubleMapped($mappedAttributeImportRulesCollection)
static makeCollection($importRulesType, $attributeIndicesOrDerivedTypes)
static getMappedAttributeIndicesOrDerivedAttributeTypesByMappingData($mappingData)
Generated on Sun Feb 23 2020 07:10:32