controller.class.inc.php 3.2 KB

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