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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
| <?php
Zend_Loader::loadClass('Fast_View');
/**
*
* Evaluation des modèles de vue via le moteur de templates Easy Templates System.
*
* @author Patrick Dubois
* @author Jean Yves Terrien
*
*/
class Fast_View_Ets extends Fast_View
{
/* arbre interne des données de la vue. */
protected $_ets = null;
/* suffixe des fichers templates */
protected $_suffix = 'html';
/**
* Constructeur
*/
public function __construct()
{
parent::__construct();
$this->_ets = new stdClass();
#Fastidf_Debug::show('Fastidf_Ets', $this);
$this->_ets->_mainTemplate = null;
$this->_ets->_content = null;
$path = dirname(dirname(dirname(dirname(__FILE__)))) . '/application/default/views/ets/';
$this->setScriptPath($path);
$this->_ets->_templatesDir = $path;
}
/**
@function getSuffix()
@return string le suffixe des fichier de templates
*/
public function getSuffix() {
return $this->_suffix;
}
/**
* Assign a variable to the view
*
* @param string $key The variable name.
* @param mixed $val The variable value.
* @return void
*/
public function __set($key, $val) {
if ('_' != substr($key, 0, 1)) {
#Fastidf_Debug::show('__set '. $key, $val);
$this->_ets->$key = $val;
return;
}
throw new Zend_View_Exception('Setting private or protected class members is not allowed', $this);
}
/**
* E_NOTICE for nonexistent values
*
* @param string $key
* @return null|mixed $key value
*/
public function __get($key)
{
if ($this->__isset($key)) {
return $this->_ets->$key;
} else {
Zend_Loader::loadClass('Fast_Exception_View');
throw new Fast_Exception_View('Template\'s key "' . $key . '" does not exist');
}
return null;
}
/**
* @function __isset()
* is set $key data var
* @param string $key key name
* @return boolean
*/
public function __isset($key)
{
return isset($this->_ets->$key);
}
/**
* @function __unset()
* unset $key data var
* @param string $key key name
* @return void
*/
public function __unset($key)
{
unset($this->_ets->$key);
}
/**
* @function clearVars()
* unset all data vars
* @return void
*/
public function clearVars()
{
$this->_ets = new stdClass();
}
/**
* Assign variables
*
*/
public function assign($spec, $value = null) {
if (!is_array($spec)) {
$spec = array($spec=>$value);
}
foreach ($spec as $key=>$val) {
if ('_' == substr($key, 0, 1)) {
throw new Zend_View_Exception('Setting private var is not allowed', $this);
}
if ($this->_ets == null) {
throw new Zend_View_Exception('ETS not defined', $this);
}
$this->_ets->$key = $val;
}
return;
}
public function setMainTemplate($tpl)
{
$this->_ets->_mainTemplate = $tpl;
}
public function setScriptPath($path)
{
parent::setScriptPath($path);
}
/**
* Includes the view script in a scope with only public $this variables.
*
* @param string The view script to execute.
*/
protected function _run()
{
// récupère le chemin complet du template demandé
$name = func_get_arg(0);
// le template principal est considéré à la racine des templates de l'application (ou du module).
if (!isset($this->_ets->_mainTemplate))
$this->setMainTemplate(str_replace(chr(92), '/', dirname(dirname($name)) . '/main.html'));
// initialiser ets
require_once("TemplatesEngines/Ets/Ets.php");
// on indique à l'arbre de données d'Ets quel est le template à inclure
$this->_ets->_content = str_replace(chr(92), '/', $name);
$this->_ets->_templatesDir = dirname(dirname($name)) . '/';
// rendu de la page
printt($this->_ets, $this->_ets->_mainTemplate);
}
} |
Partager