コード例 #1
0
 protected function buildForm($change_mode = false)
 {
     if (!$this->container) {
         throw new \LogicException(Translator::getInstance()->trans("The container should not be null in this form. Please use the FormFactory to get an instance."));
     }
     /** @var TaxEngine $taxEngine */
     $taxEngine = $this->container->get('thelia.taxEngine');
     $types = $taxEngine->getTaxTypeList();
     $typeList = array();
     $requirementList = array();
     foreach ($types as $classname) {
         $instance = new $classname();
         $typeList[Tax::escapeTypeName($classname)] = $instance->getTitle();
         $requirementList[$classname] = $instance->getRequirementsDefinition();
     }
     $this->formBuilder->add("locale", "hidden", ["constraints" => [new NotBlank()]])->add("type", "choice", ["choices" => $typeList, "required" => true, "constraints" => [new Constraints\NotBlank()], "label" => Translator::getInstance()->trans("Type"), "label_attr" => ["for" => "type_field"]]);
     foreach ($requirementList as $name => $requirements) {
         /** @var TaxTypeRequirementDefinition $requirement */
         foreach ($requirements as $requirement) {
             if (!isset(self::$typeList[$requirement->getName()])) {
                 self::$typeList[$requirement->getName()] = $requirement->getType();
             }
             $this->formBuilder->add(Tax::escapeTypeName($name) . ':' . $requirement->getName(), new TheliaType(), ["constraints" => [new Constraints\Callback(["methods" => [[$this, "checkRequirementField"]]])], "attr" => ["tag" => "requirements", "tax_type" => Tax::escapeTypeName($name)], "label_attr" => ["type" => $requirement->getName()], "label" => Translator::getInstance()->trans($requirement->getTitle()), "type" => $requirement->getType()->getFormType(), "options" => $requirement->getType()->getFormOptions()]);
         }
     }
     $this->addStandardDescFields(array('postscriptum', 'chapo', 'locale'));
 }
コード例 #2
0
ファイル: TaxCreationForm.php プロジェクト: badelas/thelia
 protected function buildForm($change_mode = false)
 {
     if ($this->taxEngine == null) {
         throw new \LogicException(Translator::getInstance()->trans("The TaxEngine should be passed to this form before using it."));
     }
     $types = $this->taxEngine->getTaxTypeList();
     $typeList = array();
     $requirementList = array();
     foreach ($types as $classname) {
         $instance = new $classname();
         $typeList[Tax::escapeTypeName($classname)] = $instance->getTitle();
         $requirementList[$classname] = $instance->getRequirementsDefinition();
     }
     $this->formBuilder->add("locale", "text", array("constraints" => array(new NotBlank())))->add("type", "choice", array("choices" => $typeList, "required" => true, "constraints" => array(new Constraints\NotBlank()), "label" => Translator::getInstance()->trans("Type"), "label_attr" => array("for" => "type_field")));
     foreach ($requirementList as $name => $requirements) {
         foreach ($requirements as $requirement) {
             $this->formBuilder->add(Tax::escapeTypeName($name) . ':' . $requirement->getName(), new TheliaType(), array("constraints" => array(new Constraints\Callback(array("methods" => array(array($requirement->getType(), "verifyForm"))))), "attr" => array("tag" => "requirements", "tax_type" => Tax::escapeTypeName($name)), "label" => Translator::getInstance()->trans($requirement->getName()), "type" => $requirement->getType()->getFormType(), "options" => $requirement->getType()->getFormOptions()));
         }
     }
     $this->addStandardDescFields(array('postscriptum', 'chapo', 'locale'));
 }
コード例 #3
0
ファイル: Tax.php プロジェクト: margery/thelia
 public function parseResults(LoopResult $loopResult)
 {
     /** @var TaxModel $tax */
     foreach ($loopResult->getResultDataCollection() as $tax) {
         $loopResultRow = new LoopResultRow($tax);
         $loopResultRow->set("ID", $tax->getId())->set("TYPE", $tax->getType())->set("ESCAPED_TYPE", TaxModel::escapeTypeName($tax->getType()))->set("REQUIREMENTS", $tax->getRequirements())->set("IS_TRANSLATED", $tax->getVirtualColumn('IS_TRANSLATED'))->set("LOCALE", $this->locale)->set("TITLE", $tax->getVirtualColumn('i18n_TITLE'))->set("DESCRIPTION", $tax->getVirtualColumn('i18n_DESCRIPTION'));
         $this->addOutputFields($loopResultRow, $tax);
         $loopResult->addRow($loopResultRow);
     }
     return $loopResult;
 }
コード例 #4
0
 protected function hydrateObjectForm($object)
 {
     $data = array('id' => $object->getId(), 'locale' => $object->getLocale(), 'title' => $object->getTitle(), 'description' => $object->getDescription(), 'type' => Tax::escapeTypeName($object->getType()));
     // Setup the object form
     return $this->createForm(AdminForm::TAX_MODIFICATION, "form", $data);
 }
コード例 #5
0
ファイル: TaxController.php プロジェクト: badelas/thelia
 protected function hydrateObjectForm($object)
 {
     $data = array('id' => $object->getId(), 'locale' => $object->getLocale(), 'title' => $object->getTitle(), 'description' => $object->getDescription(), 'type' => Tax::escapeTypeName($object->getType()));
     // Setup the object form
     return new TaxModificationForm($this->getRequest(), "form", $data, ["tax_engine" => $this->container->get('thelia.taxEngine')]);
 }