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