Héritage, Overload et/ou ?
Bonjour,
Soucis de compréhension de classes PÈRE, ENFANT et de ce qui est hérité de 'l'un vers l'autre...
Je suis entrain de réécrire un script, juste pour l'exercice.. avec pour idée bien sur de le récupérer...
Bref, je définis une class HTML enfant de TBDesigner
TBD... instanties HTML et appelle des méthodes de cette dernière.
Il y a souci car je n'obtiens ce que je souhate avoir...
Voici le code de la classe HTML
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
class html {
private $class_tbdesigner;
private $class_td;
private $class_tr;
private $class_table;
function __construct($css) {
// print("hrml __construct" . CRLF) ;
$this->class_tbdesigner = $css[0] ; // $class_tbdesigner;
$this->class_td = $css[1] ; // $class_td;
$this->class_tr = $css[2] ; // $class_tr;
$this->class_table = $css[3] ; // $class_table;
}
function getClassTag($node) {
// $this->getHtmlTag($node) ;
switch($node) {
case "tbdesigner": {
if($this->class_tbdesigner!="")
return " class=\"".$this->class_tbdesigner."\"";
else
return "";
}
break;
case "td": {
if($this->class_td!="")
return " class=\"".$this->class_td."\"";
else
return "";
}
break;
case "tr": {
if($this->class_tr!="")
return " class=\"".$this->class_tr."\"";
else
return "";
}
break;
case "table": {
if($this->class_table!="")
return " class=\"".$this->class_table."\"";
else
return "";
}
break;
default: user_error("getClassTag[".$node."] undefined !" , E_USER_NOTICE) ;
return "";
break;
}
}
} |
Celui de la classe TBDesigner
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
class tableDesigner extends html{
private $tbdesigner;
private $data;
private $id_container;
private $table_title;
private $id_title;
private $html ;
function __construct( $tbdesigner,
$data,
$id_container = "",
$id_title = "Click Me to toggle",
$table_title = "Table Title",
$css = array("","","","")
)
{
$this->tbdesigner = $tbdesigner;
$this->data = $data;
$this->id_container = $id_container;
$this->id_title = $id_title;
$this->table_title = $table_title;
$this->html = new html($css) ;
}
function printTable($return=FALSE) {
$tb = "";
$close_container = ($this->id_container!="") ? TRUE : FALSE;
$tb .= "<div id=\"".$this->id_title."\">".$this->id_title."</div>\n";
if ($close_container)
$tb .= "<div id=\"".$this->id_container."\">\n";
$tb .= "<table".$this->getClassTag("table").">\n";
$tb .= "<tr".$this->getClassTag("tr").">\n";
// for($i=0;$i<count($this->tbdesigner);$i++) {
foreach ($this->tbdesigner as $key => $value) {
// $tb .= "<td".$this->getClassTag("td")."><span".$this->getClassTag("tbdesigner").">".$this->tbdesigner[$key]."</span></td>\n";
$tb .= "<td".$this->getClassTag("td")."><span".$this->getClassTag("tbdesigner").">".$value."</span></td>\n";
}
$tb .= "</tr>\n";
//$i=0;
// for($i=0;$i<count($this->data);$i++) {
foreach ($this->data as $key => $value) {
// print_r($this->data[$key] . CRLF) ;
$tb .= "<tr".$this->getClassTag("tr").">\n";
//$j=0;
// for($j=0;$j<count($this->tbdesigner);$j++) {
foreach($this->tbdesigner as $css => $cssvalue) {
if ($this->data[$key][''.$this->tbdesigner[$css].'']=="")
$this->data[$key][''.$this->tbdesigner[$css].'']=" ";
$tb .= "<td".$this->getClassTag("td").">".$this->data[$key][''.$this->tbdesigner[$css].'']."</td>\n";
//$j++;
}
$tb .= "</tr>\n";
//$i++;
}
$tb .= "</table>\n";
if ($close_container)
$tb .= "</div>\n";
$tb .= "\n";
if ($return)
return $tb;
else
echo $tb;
}
/* DEBUG METHOD */
function printAllData()
{
$in = print_r($this->tbdesigner,true);
$dt = print_r($this->data,true);
echo "tbdesigner:<br />\n";
echo "<pre>".$in."</pre>\n";
echo "<br />\n<br />\n";
echo "DATA:<br />\n";
echo "<pre>".$dt."</pre>\n";
}
} |
Avant de sortir les parties de code de TBDesigner vers HTML, les résultats du script étaient corrects, le simple fait de bouger ces parties de code me rendent perplexe...
Un p'tit coup d'oeil... merci de votre support...:P