Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
DemoController.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 
37  Yii::import('application.modules.import.controllers.DefaultController', true);
39  {
40  public function actionCreateDemoImportForAnalysis($firstRowIsHeaderRow = true)
41  {
42  if (!Group::isUserASuperAdministrator(Yii::app()->user->userModel))
43  {
44  throw new NotSupportedException();
45  }
46  $import = new Import();
47  $serializedData['importRulesType'] = 'Accounts';
48  $mappingData = array(
49  'column_0' => array('attributeIndexOrDerivedType' => 'name', 'type' => 'importColumn',
50  'mappingRulesData' => array(
51  'DefaultValueModelAttributeMappingRuleForm' =>
52  array('defaultValue' => null))),
53  'column_1' => array('attributeIndexOrDerivedType' => 'officePhone', 'type' => 'importColumn',
54  'mappingRulesData' => array(
55  'DefaultValueModelAttributeMappingRuleForm' =>
56  array('defaultValue' => null))),
57  'column_2' => array('attributeIndexOrDerivedType' => 'officeFax', 'type' => 'importColumn',
58  'mappingRulesData' => array(
59  'DefaultValueModelAttributeMappingRuleForm' =>
60  array('defaultValue' => null))),
61  'column_3' => array('attributeIndexOrDerivedType' => 'employees', 'type' => 'importColumn',
62  'mappingRulesData' => array(
63  'DefaultValueModelAttributeMappingRuleForm' =>
64  array('defaultValue' => null))),
65  'column_4' => array('attributeIndexOrDerivedType' => 'annualRevenue', 'type' => 'importColumn',
66  'mappingRulesData' => array(
67  'DefaultValueModelAttributeMappingRuleForm' =>
68  array('defaultValue' => null))),
69  'column_5' => array('attributeIndexOrDerivedType' => 'description', 'type' => 'importColumn',
70  'mappingRulesData' => array(
71  'DefaultValueModelAttributeMappingRuleForm' =>
72  array('defaultValue' => null))),
73  'column_6' => array('attributeIndexOrDerivedType' => 'website', 'type' => 'importColumn',
74  'mappingRulesData' => array(
75  'DefaultValueModelAttributeMappingRuleForm' =>
76  array('defaultValue' => null))),
77  'column_7' => array('attributeIndexOrDerivedType' => null, 'type' => 'importColumn',
78  'mappingRulesData' => array()),
79  );
80  $serializedData['mappingData'] = $mappingData;
81  $serializedData['rowColumnDelimiter'] = ','; // Not Coding Standard
82  $serializedData['rowColumnEnclosure'] = '"';
83  $serializedData['firstRowIsHeaderRow'] = $firstRowIsHeaderRow;
84  $import->serializedData = serialize($serializedData);
85  $saved = $import->save();
86  if (!$saved)
87  {
88  throw new FailedToSaveModelException();
89  }
90  $this->createImportTempTable(8, $import->getTempTableName());
91 
92  //Make header row
93  if ($firstRowIsHeaderRow)
94  {
95  $newBean = ZurmoRedBean::dispense($import->getTempTableName());
96  $newBean->column_0 = 'Header #1';
97  $newBean->column_1 = 'Header #2';
98  $newBean->column_2 = 'Header #3';
99  $newBean->column_3 = 'Header #4';
100  $newBean->column_4 = 'Header #5';
101  $newBean->column_5 = 'Header #6';
102  $newBean->column_6 = 'Header #7';
103  $newBean->column_7 = 'Header #8';
104  ZurmoRedBean::store($newBean);
105  }
106 
107  //Make data rows that are clean
108  for ($i = 0; $i < 3; $i++)
109  {
110  $newBean = ZurmoRedBean::dispense($import->getTempTableName());
111  $newBean->column_0 = 'aa1' . $i;
112  $newBean->column_1 = 'aa2' . $i;
113  $newBean->column_2 = 'aa3' . $i;
114  $newBean->column_3 = 'aa4' . $i;
115  $newBean->column_4 = 'aa5' . $i;
116  $newBean->column_5 = 'aa6' . $i;
117  $newBean->column_6 = 'aa7' . $i;
118  $newBean->column_7 = 'aa8' . $i;
119  $newBean->analysisStatus = ImportDataAnalyzer::STATUS_CLEAN;
120  $analysisData = array();
121  $analysisData['column_0'] = array();
122  $analysisData['column_0'][] = 'a test message 1';
123  $analysisData['column_0'][] = 'a test message 2';
124  $analysisData['column_2'] = array();
125  $analysisData['column_2'][] = 'a test message 1';
126  $analysisData['column_2'][] = 'a test message 2';
127  $newBean->serializedAnalysisMessages = serialize($analysisData);
128  ZurmoRedBean::store($newBean);
129  }
130 
131  //Make data rows that have a warning
132  for ($i = 0; $i < 3; $i++)
133  {
134  $newBean = ZurmoRedBean::dispense($import->getTempTableName());
135  $newBean->column_0 = 'ba1' . $i;
136  $newBean->column_1 = 'ba2' . $i;
137  $newBean->column_2 = 'ba3' . $i;
138  $newBean->column_3 = 'ba4' . $i;
139  $newBean->column_4 = 'ba5' . $i;
140  $newBean->column_5 = 'ba6' . $i;
141  $newBean->column_6 = 'ba7' . $i;
142  $newBean->column_7 = 'ba8' . $i;
143  $newBean->analysisStatus = ImportDataAnalyzer::STATUS_WARN;
144  $analysisData = array();
145  $analysisData['column_0'] = array();
146  $analysisData['column_0'][] = 'a test message 1';
147  $analysisData['column_0'][] = 'a test message 2';
148  $analysisData['column_2'] = array();
149  $analysisData['column_2'][] = 'a test message 1';
150  $analysisData['column_2'][] = 'a test message 2';
151  $newBean->serializedAnalysisMessages = serialize($analysisData);
152  ZurmoRedBean::store($newBean);
153  }
154 
155  //Make data rows that are skipped
156  for ($i = 0; $i < 10; $i++)
157  {
158  $newBean = ZurmoRedBean::dispense($import->getTempTableName());
159  $newBean->column_0 = 'ca1' . $i;
160  $newBean->column_1 = 'ca2' . $i;
161  $newBean->column_2 = 'ca3' . $i;
162  $newBean->column_3 = 'ca4' . $i;
163  $newBean->column_4 = 'ca5' . $i;
164  $newBean->column_5 = 'ca6' . $i;
165  $newBean->column_6 = 'ca7' . $i;
166  $newBean->column_7 = 'ca8' . $i;
167  $newBean->analysisStatus = ImportDataAnalyzer::STATUS_SKIP;
168  $analysisData = array();
169  $analysisData['column_0'] = array();
170  $analysisData['column_0'][] = 'a test message 1';
171  $analysisData['column_0'][] = 'a test message 2';
172  $analysisData['column_2'] = array();
173  $analysisData['column_2'][] = 'a test message 1';
174  $analysisData['column_2'][] = 'a test message 2';
175  $newBean->serializedAnalysisMessages = serialize($analysisData);
176  ZurmoRedBean::store($newBean);
177  }
178 
179  ZurmoRedBean::store($newBean);
180  echo 'the import id is: ' . $import->id;
181  }
182 
183  protected function createImportTempTable($columnCount, $tableName)
184  {
185  $importColumns = array();
186  for ($i = 0; $i < $columnCount; $i++)
187  {
188  $columnName = 'column_' . $i;
189  $importColumns[] = RedBeanModelMemberToColumnUtil::resolveColumnMetadataByHintType($columnName,
190  'string',
191  50);
192  }
194  }
195  }
196 ?>
static createTableByTableNameAndImportColumns($tableName, array $columns)
Generated on Thu Jul 2 2020 07:10:31
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.