PageRenderTime 147ms CodeModel.GetById 26ms RepoModel.GetById 2ms app.codeStats 0ms

/classes/ag/AgHTML.php

https://github.com/orphee2633/AgFramework
PHP | 125 lines | 88 code | 24 blank | 13 comment | 8 complexity | cec6bbbad6a36b8200a3e399aafb80da MD5 | raw file
  1. <?php
  2. /**
  3. * Descripcion : Objeto de html para imprimir resultados en pantalla desde
  4. *
  5. * un controlador, tiene como objetivo reducir la cantidad de codigo a escribir
  6. *
  7. * en HTML asi como dar un orden o estructura al sistema, puede imprimir tags
  8. *
  9. * de html o bien traer e incluir framentos de html segun sea necesario.
  10. *
  11. *
  12. *
  13. * @author Arnoldo Iglesias Ramos
  14. */
  15. class AgHTML {
  16. public $titulo;
  17. public $css;
  18. public $js;
  19. public $flow;
  20. public $messages;
  21. public $display_data;
  22. function __construct()
  23. {
  24. $this->titulo = "Pagina Ag";
  25. $this->css = array();
  26. $this->js = array();
  27. }
  28. function template($string, $controller = "")
  29. {
  30. if(is_file(VIEW_DIR.$string.".php") && empty($controller))
  31. {
  32. include(VIEW_DIR.$string.".php");
  33. return;
  34. }
  35. elseif(is_file(VIEW_DIR.$controller."/".$string.".php") && !empty($controller))
  36. {
  37. include(VIEW_DIR.$controller."/".$string.".php");
  38. return;
  39. }
  40. }
  41. function set($item, $flag = "titulo")
  42. {
  43. switch($flag)
  44. {
  45. case "titulo":
  46. $this->titulo = $item;
  47. break;
  48. case "css":
  49. $this->css[] = $item;
  50. break;
  51. case "js":
  52. $this->js[] = $item;
  53. break;
  54. case "flow":
  55. $this->flow[] = $item;
  56. break;
  57. default:
  58. $this->titulo = $item;
  59. break;
  60. }
  61. }
  62. function setCSS()
  63. {
  64. foreach($this->css as $file)
  65. {
  66. if(is_file(RESOURCE_DIR."css/".$file))
  67. {
  68. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"".RESOURCE_DIR."css/".$file."\" />\n";
  69. }
  70. }
  71. }
  72. function setJS()
  73. {
  74. foreach($this->js as $file)
  75. {
  76. if(is_file(RESOURCE_DIR."js/".$file))
  77. {
  78. echo "<script type=\"text/javascript\" src=\"".RESOURCE_DIR."js/".$file."\"></script>\n";
  79. }
  80. }
  81. }
  82. public function callview($controlador = "main", $action = "index")
  83. {
  84. foreach($this->flow as $template)
  85. {
  86. if($template == "AgOutput")
  87. {
  88. if(is_file(VIEW_DIR.$controlador."/".$action.".php"))
  89. $this->template($action, $controlador);
  90. }
  91. else
  92. {
  93. $this->template($template);
  94. }
  95. }
  96. }
  97. public function addMessage($message, $type){ $this->messages[] = new AgMessage($message, $type); }
  98. public function a($nombre, $que){$this->display_data[$nombre] = $que;}
  99. public function d($que){return $this->display_data[$que];}
  100. }
  101. ?>