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());
 }
 public function testSequentialProcessViewFactory()
 {
     $a = new A();
     $b = new B();
     $sequentialProcess = new TestSequentialProcess($a, $b);
     $sequentialProcess->run(null, array('b' => 'x'));
     $route = 'default/someAction';
     $view = SequentialProcessViewFactory::makeBySequentialProcess($sequentialProcess, $route);
     $content = $view->render();
     $this->assertNotNull($content);
 }
 public function testSequentialProcessViewFactory()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $freezeWhenComplete = false;
     //Unfreeze since the test model is not part of the standard schema.
     if (RedBeanDatabase::isFrozen()) {
         RedBeanDatabase::unfreeze();
         $freezeWhenComplete = true;
     }
     $testModels = ImportModelTestItem::getAll();
     $this->assertEquals(0, count($testModels));
     $import = new Import();
     $mappingData = array('column_0' => array('attributeIndexOrDerivedType' => 'string', 'type' => 'importColumn', 'mappingRulesData' => array('DefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))), 'column_23' => array('attributeIndexOrDerivedType' => 'FullName', 'type' => 'importColumn', 'mappingRulesData' => array('FullNameDefaultValueModelAttributeMappingRuleForm' => array('defaultValue' => null))));
     $serializedData['importRulesType'] = 'ImportModelTestItem';
     $serializedData['mappingData'] = $mappingData;
     $serializedData['firstRowIsHeaderRow'] = true;
     $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 ImportCreateUpdateModelsSequentialProcess($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));
     $this->assertEquals('processRows', $sequentialProcess->getNextStep());
     //Now process the first run. Will process page 0.
     $sequentialProcess = new ImportCreateUpdateModelsSequentialProcess($import, $dataProvider);
     $sequentialProcess->run('processRows', null);
     $route = 'default/someAction';
     $view = SequentialProcessViewFactory::makeBySequentialProcess($sequentialProcess, $route);
     $content = $view->render();
     $this->assertNotNull($content);
     $this->assertEquals('SequentialProcessView', get_class($view));
     $this->assertEquals(array('page' => 1), $sequentialProcess->getNextParams());
     //Confirm 2 models were successfully added.
     $testModels = ImportModelTestItem::getAll();
     $this->assertEquals(2, count($testModels));
     //Re-freeze if needed.
     if ($freezeWhenComplete) {
         RedBeanDatabase::freeze();
     }
 }
 /**
  * Example of a sequential process.
  * @see TestCompleteSequentialProcessView
  * @see TestSequentialProcess
  * @param string $step
  */
 function actionSequentialProcess($step)
 {
     if (isset($_GET['nextParams'])) {
         $nextParams = $_GET['nextParams'];
     } else {
         $nextParams = null;
     }
     Yii::import('application.core.tests.unit.models.*');
     Yii::import('application.core.tests.unit.components.*');
     Yii::import('application.core.tests.unit.views.*');
     assert('$step == null || is_string($step)');
     assert('$nextParams == null || is_array($nextParams)');
     //////Do setup logic here if needed
     $a = new A();
     $b = new B();
     $sequentialProcess = new TestSequentialProcess($a, $b);
     $sequentialProcess->run($step, $nextParams);
     $nextStep = $sequentialProcess->getNextStep();
     $route = $this->getModule()->getId() . '/' . $this->getId() . '/sequentialProcess';
     if ($sequentialProcess->isComplete()) {
         //////Do completion logic here if needed
         $sequenceView = new TestCompleteSequentialProcessView($a, $b);
     } else {
         $sequenceView = SequentialProcessViewFactory::makeBySequentialProcess($sequentialProcess, $route);
     }
     if ($step == null) {
         $gridView = new GridView(2, 1);
         $titleBarView = new TitleBarView('Zurmo', 'Test Sequential Process');
         $wrapperView = new SequentialProcessContainerView($sequenceView, $sequentialProcess->getAllStepsMessage());
         $gridView->setView($titleBarView, 0, 0);
         $gridView->setView($wrapperView, 1, 0);
         $view = new ZurmoConfigurationPageView(ZurmoDefaultViewUtil::makeStandardViewForCurrentUser($this, $gridView));
     } else {
         $view = new AjaxPageView($sequenceView);
     }
     echo $view->render();
 }
 /**
  * Step 6. Sanitize and create/update models using a sequential process.
  * @param integer $id - Import model id
  * @param null|string $step
  * @param null|int $pageSize
  */
 public function actionStep6($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);
     $cs = Yii::app()->getClientScript();
     $cs->registerCoreScript('bbq');
     $unserializedData = unserialize($import->serializedData);
     $passedInPageSize = $pageSize;
     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, (int) $filteredByStatus);
     $sequentialProcess = new ImportCreateUpdateModelsSequentialProcess($import, $dataProvider);
     Yii::app()->gameHelper->muteScoringModelsOnSave();
     $sequentialProcess->run($step, $nextParams);
     Yii::app()->gameHelper->unmuteScoringModelsOnSave();
     $nextStep = $sequentialProcess->getNextStep();
     $route = $this->getModule()->getId() . '/' . $this->getId() . '/step6';
     if ($sequentialProcess->isComplete()) {
         $this->resolveResettingPageOnCompletion($dataProvider);
         $importingIntoModelClassName = $unserializedData['importRulesType'] . 'ImportRules';
         Yii::app()->gameHelper->triggerImportEvent($importingIntoModelClassName::getModelClassName());
         if (isset($getData['ajax']) && $getData['ajax'] == 'import-temp-table-list-view') {
             $resolvedView = new ImportResultsImportTempTableListView($this->getId(), $this->getModule()->getId(), $dataProvider, $unserializedData['mappingData'], $importWizardForm->importRulesType, ImportWizardDataAnalysisCompleteView::resolveConfigurationForm(), new ZurmoActiveForm(), $import->id);
         } else {
             $importCompleteView = $this->makeImportCompleteView($import, $importWizardForm, $dataProvider, true, $passedInPageSize);
             $resolvedView = new ContainedViewCompleteSequentialProcessView($importCompleteView);
         }
     } else {
         $resolvedView = SequentialProcessViewFactory::makeBySequentialProcess($sequentialProcess, $route);
     }
     if ($step == null) {
         $title = Zurmo::t('ImportModule', 'Import Wizard - Import Data');
         $importRulesClassName = ImportRulesUtil::getImportRulesClassNameByType($importWizardForm->importRulesType);
         $stepToUse = ImportStepsAndProgressBarForWizardView::resolveAfterUploadStepByImportClassName(5, $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();
 }
 /**
  * Step 6. Sanitize and create/update models using a sequential process.
  * @param integer id - Import model id
  * @param string $step
  */
 function actionStep6($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);
     $cs = Yii::app()->getClientScript();
     $cs->registerCoreScript('bbq');
     if (isset($_GET['ajax']) && $_GET['ajax'] == 'list-view') {
         $importCompleteView = $this->makeImportCompleteView($import, $importWizardForm);
         $view = new AjaxPageView($importCompleteView);
         echo $view->render();
         Yii::app()->end(0, false);
     }
     $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 ImportCreateUpdateModelsSequentialProcess($import, $dataProvider);
     Yii::app()->gameHelper->muteScoringModelsOnSave();
     $sequentialProcess->run($step, $nextParams);
     Yii::app()->gameHelper->unmuteScoringModelsOnSave();
     $nextStep = $sequentialProcess->getNextStep();
     $route = $this->getModule()->getId() . '/' . $this->getId() . '/step6';
     if ($sequentialProcess->isComplete()) {
         $importingIntoModelClassName = $unserializedData['importRulesType'] . 'ImportRules';
         Yii::app()->gameHelper->triggerImportEvent($importingIntoModelClassName::getModelClassName());
         $importCompleteView = $this->makeImportCompleteView($import, $importWizardForm, true);
         $sequenceView = new ContainedViewCompleteSequentialProcessView($importCompleteView);
     } else {
         $sequenceView = SequentialProcessViewFactory::makeBySequentialProcess($sequentialProcess, $route);
     }
     if ($step == null) {
         $title = Zurmo::t('ImportModule', 'Import Wizard: Step 6 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();
 }