From d07240432b7ae913227f90bcc4d9822aef1d0e79 Mon Sep 17 00:00:00 2001
From: Matthieu Guffroy <mattgu74@gmail.com>
Date: Wed, 18 Jun 2014 21:57:27 +0200
Subject: [PATCH] improvment

---
 class/employe.php |  6 +++++-
 class/field.php   |  4 +++-
 class/objet.php   | 11 ++++++++---
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/class/employe.php b/class/employe.php
index be84cec..9809200 100644
--- a/class/employe.php
+++ b/class/employe.php
@@ -6,7 +6,11 @@ class Employe extends Personne
     protected $is_veterinaire;
     public $_specialFields = array(
         "is_veterinaire" => array(
-            "t" => "BoolField"
+            "t" => "BoolField",
+            "label" => "Veterinaire"
+        ),
+        "id_national" => array(
+            "label" => "Identifiant national"
         ));
 
     public function id_national()
diff --git a/class/field.php b/class/field.php
index 55356cb..497637e 100644
--- a/class/field.php
+++ b/class/field.php
@@ -4,11 +4,13 @@ class Field {
 	protected $name;
 	protected $value;
 	protected $primary;
+	public $label;
 
 	public function __construct($name, &$value, $primary=false) {
 		$this->name = $name;
 		$this->value =& $value;
 		$this->primary = $primary;
+		$this->label = ucfirst($name);
 	}
 
 	public function html($form) {
@@ -44,7 +46,7 @@ class Field {
 	}
 
 	public function getLabel() {
-		return ucfirst($this->name);
+		return $this->label;
 	}
 
 }
diff --git a/class/objet.php b/class/objet.php
index 7512c16..76c0f2e 100644
--- a/class/objet.php
+++ b/class/objet.php
@@ -52,13 +52,18 @@ class Objet
     {
         $ret = array();
         foreach(array_keys(get_object_vars($this)) as $keyName) {
+            $field = null;
             if($keyName[0] == "_") { continue; }
             if($keyName == $this->_primaryAttr && $this->_primaryAttr == "id") { $ret[] = new Field($keyName, $this->$keyName, true); continue; }
-            if(in_array($keyName, array_keys($this->_specialFields))) {
-                $ret[] = new $this->_specialFields[$keyName]["t"]($keyName, $this->$keyName);
+            if(isset($this->_specialFields[$keyName]["t"])) {
+                $field = new $this->_specialFields[$keyName]["t"]($keyName, $this->$keyName);
             } else {
-                $ret[] = new Field($keyName, $this->$keyName);
+                $field = new Field($keyName, $this->$keyName);
             }
+            if(isset($this->_specialFields[$keyName]["label"])) {
+                $field->label = $this->_specialFields[$keyName]["label"];
+            }
+            $ret[] = $field;
         }
         return $ret;
     }
-- 
GitLab