From 7d4b027fcda0859dc9b591f2778953c33ed9e072 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 15 Apr 2014 14:41:07 +0200 Subject: [PATCH] add missing file --- local/modules/Colissimo/Form/Export.php | 112 ++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 local/modules/Colissimo/Form/Export.php diff --git a/local/modules/Colissimo/Form/Export.php b/local/modules/Colissimo/Form/Export.php new file mode 100644 index 000000000..cdbbc364a --- /dev/null +++ b/local/modules/Colissimo/Form/Export.php @@ -0,0 +1,112 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Colissimo\Form; + +use Colissimo\Colissimo; +use Colissimo\Model\ColissimoQuery; +use Propel\Runtime\ActiveQuery\Criteria; +use Symfony\Component\Validator\Constraints\Callback; +use Symfony\Component\Validator\Constraints\NotBlank; +use Symfony\Component\Validator\ExecutionContextInterface; +use Thelia\Core\Translation\Translator; +use Thelia\Form\BaseForm; +use Thelia\Model\OrderQuery; +use Thelia\Model\OrderStatus; +use Thelia\Model\OrderStatusQuery; + + +/** + * Class Export + * @package Colissimo\Form + * @author Manuel Raynaud + */ +class Export extends BaseForm +{ + + /** + * + * in this function you add all the fields you need for your Form. + * Form this you have to call add method on $this->formBuilder attribute : + * + * $this->formBuilder->add("name", "text") + * ->add("email", "email", array( + * "attr" => array( + * "class" => "field" + * ), + * "label" => "email", + * "constraints" => array( + * new \Symfony\Component\Validator\Constraints\NotBlank() + * ) + * ) + * ) + * ->add('age', 'integer'); + * + * @return null + */ + protected function buildForm() + { + $orders = ColissimoQuery::getOrders() + ->find(); + + $this->formBuilder + ->add('status_id', 'text',[ + 'constraints' => [ + new NotBlank(), + new Callback(array( + "methods" => array( + array($this, + "verifyValue") + ) + )) + ], + 'label' => Translator::getInstance()->trans('Modify status export after export'), + 'label_attr' => [ + 'for' => 'status_id' + ] + ]); + + /** @var \Thelia\Model\Order $order */ + foreach ($orders as $order) { + $this->formBuilder->add("order_".$order->getId(), "checkbox", array( + 'label'=>$order->getRef(), + 'label_attr'=>array('for'=>'export_'.$order->getId()) + )); + } + } + + public function verifyValue($value, ExecutionContextInterface $context) + { + if (!preg_match("#^nochange|processing|sent$#",$value)) { + $context->addViolation(Translator::getInstance()->trans('select a valid status')); + } + } + + /** + * @return string the name of you form. This name must be unique + */ + public function getName() + { + return "colissimo_export"; + } +} \ No newline at end of file