Rajout de la gestion des formulaires dans \Custom
authorSébastien CHAZALLET <s.chazallet@gmail.com>
Fri, 16 Nov 2012 10:22:06 +0000 (11:22 +0100)
committerSébastien CHAZALLET <s.chazallet@gmail.com>
Fri, 16 Nov 2012 10:22:06 +0000 (11:22 +0100)
vendor/zf2biz/Custom/Form/AbstractForm.php [new file with mode: 0644]
vendor/zf2biz/Custom/Model/Entity.php

diff --git a/vendor/zf2biz/Custom/Form/AbstractForm.php b/vendor/zf2biz/Custom/Form/AbstractForm.php
new file mode 100644 (file)
index 0000000..f7f5249
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+
+namespace Custom\Form;
+
+use Zend\Form\Form;
+
+use Zend\I18n\Translator\TranslatorAwareInterface;
+use Zend\I18n\Translator\Translator;
+
+
+class AbstractForm extends Form implements TranslatorAwareInterface
+{
+
+    private $_translator = null;
+    private $_textDomain = 'default';
+    private $_translator_enabled = false; 
+
+
+    abstract public function initialize();
+
+
+
+
+    public function translate($k)
+    {
+        if ($this->_translator && $this->_translator_enabled) {
+            return $this->_translator->translate($k, $this->_textDomain);
+        }
+        return $k;
+    }
+
+
+
+
+    protected function addElement($name, $type='text', $label=null, $attributes=array(), $options=array())
+    {
+        if ($type) {
+            $attributes['type' = $type
+        }
+        if ($label) {
+            $options['label'] = $label;
+        }
+        $params = array('name' => $name);
+        if ($attributes) {
+            $params['attributes'] = $attributes;
+        }
+        if ($options) {
+            $params['options'] = $options;
+        }
+        $this->add($params);
+    }
+
+
+
+
+    public function setTranslator(Translator $translator = null, $textDomain = null)
+    {
+        $this->_translator = $translator;
+       $this->_textDomain = $textDomain;
+    }
+
+    public function getTranslator()
+    {
+        return $this->_translator;
+    }
+
+    public function hasTranslator()
+    {
+        return $this->_translator !== null;
+    }
+
+    public function setTranslatorEnabled($enabled = true)
+    {
+        $this->_translator_enabled = $enabed;
+    }
+
+    public function isTranslatorEnabled()
+    {
+        return $this->_translator_enabled;
+    }
+
+    public function setTranslatorTextDomain($textDomain = 'default')
+    {
+       $this->_textDomain = $textDomain;
+    }
+
+    public function getTranslatorTextDomain()
+    {
+        return $this->_textDomain;
+    }
+
+
+    protected function setMethod($method='post')
+    {
+        $this->setAttribute('method', $method);
+    }
+
+}
index 7788491..f261e5a 100644 (file)
@@ -1,9 +1,19 @@
 <?php
+
 namespace Custom\Model;
 
-class Entity
+
+use Zend\InputFilter\Factory as InputFactory;
+use Zend\InputFilter\InputFilter;
+use Zend\InputFilter\InputFilterInterface;
+use Zend\InputFilter\InputFilterAwareInterface;
+
+
+class Entity implements InputFilterAwareInterface
 {
 
+    protected $inputFilter;
+
     public function exchangeArray($data, $overwrite=true)
     {
         foreach($this->columns as $col) {
@@ -23,6 +33,14 @@ class Entity
         return $result;
     }
 
+    public function getArrayCopy() {
+        $result = array();
+        foreach($this->columns as $col) {
+            $result[$col] = $this->$col;
+        }
+        return $result;
+    }
+
     public function toUpdatableArray() {
         $result = array();
         foreach($this->updatable_columns as $col) {
@@ -38,4 +56,39 @@ class Entity
         }
         return $result;
     }
+
+
+
+    public function setInputFilter(InputFilterInterface $inputfilter)
+    {
+        $this->inputFilter = $inputFilter;
+    }
+
+    public function getInputFilter()
+    {
+        if (!$this->inputFilter) {
+            $this->setDefaultInputFilter();
+        }
+        return $this->inputFilter;
+    }
+
+    protected function setDefaultInputFilter()
+    {
+        $inputFilter = new InputFilter;
+        $factory = new InputFactory;
+
+        for ($this->getDefaultInputFilterArrays() as $params) {
+            $inputFilter->add($factory->createInput($params))
+        }
+        $this->inputFilter = $inputFilter;
+
+        return $this->inputFilter;
+
+    }
+
+    protected function getDefaultInputFilterArrays()
+    {
+        return array();
+    }
+
 }