Formulaire : étape 2, modification du modèle
authorSébastien CHAZALLET <s.chazallet@gmail.com>
Thu, 15 Nov 2012 12:02:09 +0000 (13:02 +0100)
committerSébastien CHAZALLET <s.chazallet@gmail.com>
Thu, 15 Nov 2012 12:02:09 +0000 (13:02 +0100)
module/Galerie/src/Galerie/Model/Galerie.php

index 89a3794..6b46e20 100644 (file)
@@ -2,9 +2,14 @@
 
 namespace Galerie\Model;
 
+use Zend\InputFilter\Factory as InputFactory;
+use Zend\InputFilter\InputFilter;
+use Zend\InputFilter\InputFilterInterface;
+use Zend\InputFilter\InputFilterAwareInterface;
+
 use Custom\Model\Entity;
 
-class Galerie extends Entity
+class Galerie extends Entity implements InputFilterAwareInterface
 {
     public $id;
     public $id_user;
@@ -13,6 +18,8 @@ class Galerie extends Entity
     public $created;
     public $updated;
 
+    protected $inputFilter;
+
 
     protected $columns = array(
         'id',
@@ -27,12 +34,69 @@ class Galerie extends Entity
         'id_user',
         'name',
         'description',
-        'created',
-        'updated',
     );
 
     protected $primary_columns = array(
         'id',
     );
 
+    public function getArrayCopy()
+    {
+        return $this->toArray();
+    }
+
+    public function setInputFilter(InputFilterInterface $inputfilter)
+    {
+        throw new \Exception("This entity does not allow to set Input Filter");
+    }
+
+    public function getInputFilter()
+    {
+        if (!$this->inputFilter) {
+            $inputFilter = new InputFilter;
+            $factory = new InputFactory;
+
+            $inputFilter->add($factory->createInput(array(
+                'name' => 'id',
+                'required' => true,
+                'filters' => array(
+                    array('name' => 'Int'),
+                ),
+            )));
+
+            $inputFilter->add($factory->createInput(array(
+                'name' => 'name',
+                'required' => true,
+                'filters' => array(
+                    array('name' => 'StripTags'),
+                    array('name' => 'StringTrim'),
+                ),
+                'validators' => array(
+                    array(
+                        'name' => 'StringLength',
+                        'options' => array(
+                            'encoding' => 'UTF-8',
+                            'min' => 1,
+                            'max' => 32,
+                        ),
+                    ),
+                ),
+            )));
+
+            $inputFilter->add($factory->createInput(array(
+                'name' => 'description',
+                'required' => true,
+                'filters' => array(
+                    array('name' => 'StripTags'),
+                    array('name' => 'StringTrim'),
+                ),
+            )));
+
+            $this->inputFilter = $inputFilter;
+        }
+
+        return $this->inputFilter;
+
+    }
+
 }