Esempio n. 1
0
 /**
  * Construct a new model filter view
  * @param zibo\orm\builder\form\ModelFilterForm $filterForm
  * @return null
  */
 public function __construct(BuilderWizard $wizard)
 {
     parent::__construct(self::TEMPLATE);
     $translator = I18n::getInstance()->getTranslator();
     $modelTable = $wizard->getModelTable();
     $currentStep = $wizard->getCurrentStep();
     $steps = array();
     if ($modelTable) {
         $generalStep = $translator->translate(self::TRANSLATION_STEP_GENERAL_MODEL, array('model' => $modelTable->getName()));
     } else {
         $generalStep = $translator->translate(self::TRANSLATION_STEP_GENERAL);
     }
     $fieldNewStep = $translator->translate(self::TRANSLATION_STEP_FIELD_NEW);
     $dataFormatStep = $translator->translate(self::TRANSLATION_STEP_DATA_FORMAT);
     $indexStep = $translator->translate(self::TRANSLATION_STEP_INDEX);
     $finishStep = $translator->translate(self::TRANSLATION_STEP_FINISH);
     switch ($currentStep) {
         case ModelGeneralStep::NAME:
             $currentStep = $generalStep;
             break;
         case DataFormatStep::NAME:
             $currentStep = $dataFormatStep;
             break;
         case IndexStep::NAME:
             $currentStep = $indexStep;
             break;
         case FinishStep::NAME:
             $currentStep = $finishStep;
             break;
     }
     if ($wizard->isLimitedToModel()) {
         $steps[$generalStep] = false;
     } elseif ($wizard->isLimitedToDataFormats()) {
         $steps[$dataFormatStep] = false;
     } elseif ($wizard->isLimitedToIndex()) {
         $steps[$indexStep] = false;
     } else {
         $limitField = $wizard->getLimitField();
         if (!$limitField) {
             $steps[$generalStep] = false;
         }
         if ($limitField && $limitField !== true) {
             $step = $translator->translate(self::TRANSLATION_STEP_FIELD, array('field' => $limitField));
             if ($currentStep == FieldStep::NAME) {
                 $currentStep = $step;
             }
             $steps[$step] = false;
         } else {
             $isFieldStep = $currentStep == FieldStep::NAME;
             $currentFieldName = null;
             if ($isFieldStep) {
                 $currentFieldName = $wizard->getVariable(BuilderWizard::VARIABLE_FIELD);
                 $currentStep = null;
             }
             if ($modelTable) {
                 $fields = $modelTable->getFields();
                 foreach ($fields as $fieldName => $field) {
                     if ($fieldName == ModelTable::PRIMARY_KEY) {
                         continue;
                     }
                     $step = $translator->translate(self::TRANSLATION_STEP_FIELD, array('field' => $fieldName));
                     if ($fieldName == $currentFieldName) {
                         $currentStep = $step;
                     }
                     $steps[$step] = false;
                 }
             }
             if (!$currentStep) {
                 $currentStep = $fieldNewStep;
             }
             $steps[$fieldNewStep] = false;
         }
         if (!$limitField) {
             $steps[$dataFormatStep] = false;
             $steps[$indexStep] = false;
         }
     }
     $steps[$finishStep] = false;
     $this->set('currentStep', $currentStep);
     $this->set('steps', $steps);
 }