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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| <?php
/**
* Class Menu
*
* @version 0.1
* @copyright 2006 - Xavier VALENTIN
*/
class Menu {
public $db; // base de données - class d'abstraction PDO
public $table; // table contenant les informations du menu
/**
* Menu::__construct()
*
* @param mixed $z_table
* @param mixed $z_db
**/
function __construct($z_table,$z_db){
$this->db = $z_db;
$this->table = $z_table;
}
/**
* Menu::get_title()
*
* @param mixed $id
* @return - string - donne le title pour $id
**/
function get_title($id){
$title = $this->db->query("SELECT title FROM $this->table
WHERE id = '$id'");
$result = $title->fetch(PDO::FETCH_BOTH);
return $result[0];
}
/**
* Menu::get_parentID()
*
* @param mixed $id
* @return - string - donne le parentID pour $id
**/
function get_parentID($id){
$parentID = $this->db->query("SELECT parentID FROM $this->table
WHERE id = '$id'");
$result = $parentID->fetch(PDO::FETCH_BOTH);
return $result[0];
}
/**
* Menu::create_node()
*
* @param mixed $title
* @param mixed $position
* @param mixed $parentID
* @return
**/
function create_node($title,$position,$parentID){
$this->db->query("INSERT INTO $this->table (title,position,parentID)
VALUES ('$title','$position','$parentID')");
}
/**
* Menu::delete_node()
*
* @param mixed $id
* @return
**/
function delete_node($id){
$this->db->query("DELETE FROM $this->table WHERE id = '$id'");
}
/**
* Menu::update_node()
*
* @param mixed $id
* @param mixed $title
* @param mixed $position
* @param mixed $parentID
* @return
**/
function update_node($id,$title,$position,$parentID){
$this->db->query("UPDATE $this->table SET
title = '$title',
position = '$position',
parentID = '$parentID'
WHERE id = '$id';");
}
/**
* Menu::create_menu()
*
* @param mixed $parentID
* @return
**/
function create_menu($parentID){
global $i;
global $req;
if ($parentID == 0) {$i=0;}
$i = $i + 1 ;
$req = $this->db->query("SELECT * FROM $this->table
WHERE parentID = '$parentID'");
print "<ul id=\"menu\">\n";
while($myrow = $req->fetch()) {
print '<li><a href="'.$myrow['id'].'">'.$myrow['title'].'</a>';
$this->create_menu($myrow['id']);
print "</li>\n";
}
print "</ul>\n";
}
}
?> |
Partager