Skip to content
Snippets Groups Projects
Commit c3efa82c authored by clement's avatar clement
Browse files

Merge branch 'master' of gitlab.utc.fr:nf17-camp-p14/clivi

parents fb3854aa b2d20689
No related branches found
No related tags found
No related merge requests found
<?php
class ForeignField {
protected $name;
protected $value;
protected $primary;
protected $choices;
public function __construct($name, &$value, $primary=false) {
$this->name = $name;
$this->value =& $value;
$this->primary = $primary;
$cl = ucfirst($name);
$this->choices = $cl::getAll();
}
public function html($form) {
// Todo, if isset($_POST[$this->name]) && !$this->validate() => Show a error msg explanation for this line.
$disabled = "";
if($this->primary && $form->action == "Ajouter") { return ""; }
if($this->primary && $form->action == "Modifier") { $disabled = "disabled"; }
$html = '<div class="form-group">
<label for="form'.$this->name.'">'.ucfirst($this->name).'</label>
<select class="form-control" name="'.$this->name.'">';
foreach ($this->choices as $value) {
if($this->value == $value->{$value->$_primaryAttr}()) { $selected = "selected"; } else { $selected = ""; }
$html .= "<option value=".$value->{$value->$_primaryAttr}()." ".$selected." >".$value->str()."</option>";
}
$html.= '</select>
</div>';
return $html;
}
/*
Load the data from $_POST
and return false, if data is not valid !
*/
public function validate() {
// On ne peut pas changer la valeur de la clef primaire
if($this->primary && $this->value) {
return true;
}
$this->value = $_POST[$this->name];
return true;
}
}
......@@ -136,4 +136,8 @@ class Objet
$ligne = $requete_prepare->fetch(PDO::FETCH_ASSOC);
$this->fromDb($ligne);
}
public function str() {
return self::dbName()." #".$this->{$this->_primaryAttr};
}
}
\ No newline at end of file
......@@ -6,6 +6,10 @@ class Race extends Objet
protected $nom;
protected $espece;
protected $prix_intervention;
public $_specialFields = array(
"espece" => array(
"t" => "ForeignField"
));
public function id()
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment