controller.class.inc.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. /**
  3. * Gestion controller
  4. * @author mathieu
  5. * @package db_object
  6. *
  7. */
  8. class controller_manager extends db_object_manager{
  9. public $DB_DEBUG = false;
  10. public $FILE_DEBUG = false;
  11. public $_fields = array(
  12. "ref" => array("label"=>"Référence courte", "type"=>"string", "readonly"=>true),
  13. "titre" => array("label"=>"Titre", "type"=>"string"),
  14. "description" => array("label"=>"Description", "type"=>"text"),
  15. "template_layout" => array("label"=>"Layout", "type"=>"string"),
  16. //"template_left_id" => array("label"=>"Template gauche", "type"=>"object", 'object_type'=>'template'),
  17. //"template_right_id" => array("label"=>"Template droit", "type"=>"object", 'object_type'=>'template'),
  18. "template_id" => array("label"=>"Template central", "type"=>"object", 'object_type'=>'template'),
  19. "fields" => array("label"=>"Champs supplémentaires", "type"=>""),
  20. );
  21. public $_field_disp_list = array("ref", "titre");
  22. /**
  23. * Select en base de donnée
  24. * @param [] $params
  25. * @param int $limit
  26. * @param string $order
  27. * @return []
  28. */
  29. public function select($params=null, $limit=null, $order=null)
  30. {
  31. $list = array();
  32. foreach ($this->db_retrieve($params, $limit, $order) as $row)
  33. {
  34. if (!isset($this->list[$row["id"]])){
  35. $classname = $row['ref'].'_controller';
  36. $this->list[$row["id"]] = $object = new $classname(null, $row);
  37. }
  38. else
  39. $object = $this->list[$row["id"]];
  40. $list[] = $object;
  41. }
  42. return $list;
  43. }
  44. protected function db_retrieve_more($list_id=null)
  45. {
  46. if (!is_array($list_id))
  47. return array();
  48. $list = array();
  49. $sql = "SELECT * FROM `controller_params` WHERE `controller_id` IN (".implode(',', $list_id).")";
  50. $q = mysql_query($sql);
  51. while($row = mysql_fetch_assoc($q))
  52. $list[$row['controller_id']]['fields'][$row['name']] = $row;
  53. //var_dump($list);
  54. return $list;
  55. }
  56. }
  57. class controller extends db_object{
  58. public $_name = 'controller';
  59. public $fields = array();
  60. //public $values = array();
  61. public $page = null;
  62. public $params = array();
  63. public $header = array();
  64. function __tostring(){
  65. return $this->titre;
  66. }
  67. function template(){
  68. return $this->object('template_id');
  69. }
  70. function param_url($id){
  71. return "paramurl-$id";
  72. }
  73. function param_title($id){
  74. return "paramtitle-$id";
  75. }
  76. /**
  77. * Mise en place des éléments communs au template
  78. */
  79. function view_before(){
  80. // Header
  81. $this->header = array(
  82. "title"=>$this->page->header_title,
  83. "description"=>$this->page->header_description,
  84. "url"=>$this->page->url(),
  85. );
  86. }
  87. /**
  88. * Mise en place des éléments du template
  89. * A surcharger
  90. */
  91. function view(){
  92. }
  93. /**
  94. * Mise en place des éléments communs au template
  95. */
  96. function view_after(){
  97. }
  98. /**
  99. * Affichage de la page
  100. */
  101. function display(){
  102. $this->params = $this->page->params;
  103. $this->view_before();
  104. $this->view();
  105. $this->view_after();
  106. //var_dump($this->template_id);
  107. $template = $this->template();
  108. $template->controller = $this;
  109. $template->page = $this->page;
  110. $template->params = array_merge($template->params, $this->params);
  111. $template->layout = $this->template_layout;
  112. $template->header = array_merge($template->header, $this->header);
  113. //var_dump($template);
  114. $template->display();
  115. }
  116. }