public function testSequentialProcessViewFactory()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $import = new Import();
     $mappingData = array('column_0' => array('attributeIndexOrDerivedType' => 'string', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_1' => array('attributeIndexOrDerivedType' => 'phone', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))));
     $serializedData['importRulesType'] = 'ImportModelTestItem';
     $serializedData['mappingData'] = $mappingData;
     $import->serializedData = serialize($serializedData);
     $this->assertTrue($import->save());
     ImportTestHelper::createTempTableByFileNameAndTableName('importAnalyzerTest.csv', $import->getTempTableName());
     $config = array('pagination' => array('pageSize' => 2));
     $dataProvider = new ImportDataProvider($import->getTempTableName(), true, $config);
     $sequentialProcess = new ImportDataAnalysisSequentialProcess($import, $dataProvider);
     $sequentialProcess->run(null, null);
     $route = 'default/someAction';
     $view = SequentialProcessViewFactory::makeBySequentialProcess($sequentialProcess, $route);
     $content = $view->render();
     $this->assertNotNull($content);
     $this->assertEquals('SequentialProcessView', get_class($view));
     //Now process the first run. Will process page 0.
     $sequentialProcess = new ImportDataAnalysisSequentialProcess($import, $dataProvider);
     $sequentialProcess->run('processColumns', null);
     $route = 'default/someAction';
     $view = SequentialProcessViewFactory::makeBySequentialProcess($sequentialProcess, $route);
     $content = $view->render();
     $this->assertNotNull($content);
     $this->assertEquals('SequentialProcessView', get_class($view));
     $this->assertEquals(array('columnNameToProcess' => 'column_1'), $sequentialProcess->getNextParams());
 }
 /**
  * Step 5. Analyze data in a sequential process.
  * @param integer id - Import model id
  * @param string $step
  */
 public function actionStep5($id, $step = null, $pageSize = null)
 {
     $getData = GetUtil::getData();
     if (isset($getData['nextParams'])) {
         $nextParams = $getData['nextParams'];
     } else {
         $nextParams = null;
     }
     assert('$step == null || is_string($step)');
     assert('$nextParams == null || is_array($nextParams)');
     $import = Import::getById((int) $id);
     $importWizardForm = ImportWizardUtil::makeFormByImport($import);
     $unserializedData = unserialize($import->serializedData);
     if ($pageSize == null) {
         $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType('importPageSize');
     }
     $config = array('pagination' => array('pageSize' => $pageSize));
     $filteredByStatus = $this->resolveFilteredByStatus();
     $dataProvider = new ImportDataProvider($import->getTempTableName(), (bool) $importWizardForm->firstRowIsHeaderRow, $config, null, $filteredByStatus);
     $sequentialProcess = new ImportDataAnalysisSequentialProcess($import, $dataProvider);
     $sequentialProcess->run($step, $nextParams);
     $route = $this->getModule()->getId() . '/' . $this->getId() . '/step5';
     if ($sequentialProcess->isComplete()) {
         $this->resolveResettingPageOnCompletion($dataProvider);
         $columnNamesAndAttributeIndexOrDerivedTypeLabels = ImportMappingUtil::makeColumnNamesAndAttributeIndexOrDerivedTypeLabels($unserializedData['mappingData'], $unserializedData['importRulesType']);
         if (isset($getData['ajax']) && $getData['ajax'] == 'import-temp-table-list-view') {
             $resolvedView = new AnalysisResultsImportTempTableListView($this->getId(), $this->getModule()->getId(), $dataProvider, $unserializedData['mappingData'], $importWizardForm->importRulesType, ImportWizardDataAnalysisCompleteView::resolveConfigurationForm(), new ZurmoActiveForm(), $import->id);
         } else {
             $dataAnalysisCompleteView = new ImportWizardDataAnalysisCompleteView($this->getId(), $this->getModule()->getId(), $importWizardForm, $columnNamesAndAttributeIndexOrDerivedTypeLabels, $dataProvider, $unserializedData['mappingData']);
             $resolvedView = new ContainedViewCompleteSequentialProcessView($dataAnalysisCompleteView);
         }
     } else {
         $resolvedView = SequentialProcessViewFactory::makeBySequentialProcess($sequentialProcess, $route);
     }
     if ($step == null) {
         $title = Zurmo::t('ImportModule', 'Import Wizard - Analyze Data');
         $importRulesClassName = ImportRulesUtil::getImportRulesClassNameByType($importWizardForm->importRulesType);
         $stepToUse = ImportStepsAndProgressBarForWizardView::resolveAfterUploadStepByImportClassName(4, $importRulesClassName);
         $progressBarAndStepsView = new ImportStepsAndProgressBarForWizardView($importRulesClassName, $stepToUse);
         $wrapperView = new ImportSequentialProcessContainerView($resolvedView, $sequentialProcess->getAllStepsMessage(), $title);
         $wrapperView->setCssClasses(array('DetailsView'));
         $view = $this->getImportPageView($progressBarAndStepsView, $wrapperView);
     } else {
         $view = new AjaxPageView($resolvedView);
     }
     echo $view->render();
 }
Example #3
0
 /**
  * Step 5. Analyze data in a sequential process.
  * @param integer id - Import model id
  * @param string $step
  */
 function actionStep5($id, $step = null)
 {
     if (isset($_GET['nextParams'])) {
         $nextParams = $_GET['nextParams'];
     } else {
         $nextParams = null;
     }
     assert('$step == null || is_string($step)');
     assert('$nextParams == null || is_array($nextParams)');
     $import = Import::getById((int) $id);
     $importWizardForm = ImportWizardUtil::makeFormByImport($import);
     $unserializedData = unserialize($import->serializedData);
     $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType('importPageSize');
     $config = array('pagination' => array('pageSize' => $pageSize));
     $dataProvider = new ImportDataProvider($import->getTempTableName(), (bool) $importWizardForm->firstRowIsHeaderRow, $config);
     $sequentialProcess = new ImportDataAnalysisSequentialProcess($import, $dataProvider);
     $sequentialProcess->run($step, $nextParams);
     $nextStep = $sequentialProcess->getNextStep();
     $route = $this->getModule()->getId() . '/' . $this->getId() . '/step5';
     if ($sequentialProcess->isComplete()) {
         $columnNamesAndAttributeIndexOrDerivedTypeLabels = ImportMappingUtil::makeColumnNamesAndAttributeIndexOrDerivedTypeLabels($unserializedData['mappingData'], $unserializedData['importRulesType']);
         $dataAnalysisCompleteView = new ImportWizardDataAnalysisCompleteView($this->getId(), $this->getModule()->getId(), $importWizardForm, $columnNamesAndAttributeIndexOrDerivedTypeLabels);
         $sequenceView = new ContainedViewCompleteSequentialProcessView($dataAnalysisCompleteView);
     } else {
         $sequenceView = SequentialProcessViewFactory::makeBySequentialProcess($sequentialProcess, $route);
     }
     if ($step == null) {
         $title = Zurmo::t('ImportModule', 'Import Wizard: Step 5 of 6');
         $wrapperView = new ImportSequentialProcessContainerView($sequenceView, $sequentialProcess->getAllStepsMessage(), $title);
         $wrapperView->setCssClasses(array('DetailsView'));
         $view = new ImportPageView(ZurmoDefaultAdminViewUtil::makeStandardViewForCurrentUser($this, $wrapperView));
     } else {
         $view = new AjaxPageView($sequenceView);
     }
     echo $view->render();
 }