phpDocumentor SpoolTemplate
[ Back ] [ class tree: SpoolTemplate ] [ index: SpoolTemplate ] [ all elements ]

Source for file sptpl_clsRow.php

Documentation is available at sptpl_clsRow.php

  1. <?php
  2. /**
  3. * sptpl_clsRow.php
  4. *
  5. * @copyright sptpl_clsRow.php is part of Sptpl project {@link http://www.andrioli.com/en/sptpl.html} and it is LGPL
  6. * @author Andrioli Darvin <darvin (inside) andrioli (dot) com>
  7. * @version $Header: d:\cvs/classistd/sptpl/sptpl_clsRow.php,v 2.10 2005/03/02 21:00:54 Darvin Exp $
  8. */
  9. /*
  10. * +-------------------------------------------------------------------------+
  11. * | Sptpl |
  12. * +-------------------------------------------------------------------------+
  13. * | Copyright (c) 2003-2005 Andrioli Darvin |
  14. * | Email <darvin (inside) andrioli (dot) com> |
  15. * | Web http://www.andrioli.com/en/sptpl.html |
  16. * | Download http://www.phpclasses.org/browse.html/package/1326.html |
  17. * | |
  18. * +-------------------------------------------------------------------------+
  19. * | This library is free software; you can redistribute it and/or modify |
  20. * | it under the terms of the GNU Lesser General Public License as |
  21. * | published by the Free Software Foundation; either version 2 of the |
  22. * | License, or (at your option) any later version. |
  23. * | |
  24. * | This library is distributed in the hope that it will be useful, but |
  25. * | WITHOUT ANY WARRANTY; without even the implied warranty of |
  26. * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
  27. * | Lesser General Public License for more details. |
  28. * | |
  29. * | You should have received a copy of the GNU Lesser General Public |
  30. * | License along with this library; if not, write to the Free Software |
  31. * | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  32. * +-------------------------------------------------------------------------+
  33. */
  34.  
  35.  
  36.  
  37. class CRow {
  38.  
  39. /**
  40. * Text for this row ready to be evaled
  41. * @var string $RowText
  42. */
  43. var $RowText;
  44. /**
  45. * reference to the instance of DataManager, created by the class sptpl
  46. * @var object DataStorage $DataMgr
  47. */
  48. var $DataMgr;
  49. /**
  50. * Vertical position (optional). Specify the position for
  51. * the current row.
  52. * Values: top,bottom,relative,absolute,newpage
  53. * @var string $VPos
  54. * @see ParseXml()
  55. */
  56. var $VPos;
  57.  
  58. /**
  59. * Row number, it specify the row namuber if the value for $VPos is 'absolute'
  60. * or 'relative'
  61. * @var integer $RowPos
  62. * @see $VPos
  63. */
  64. var $RowPos;
  65. /**
  66. * Orizontal alignment: right, center, left
  67. * Default: left
  68. * @var string $Align
  69. */
  70. var $Align;
  71. /**
  72. * Column where start the row. This value is added to the column calculated
  73. * by the parameter align
  74. * Default: 0
  75. * @var integer $ColPos
  76. */
  77. var $ColPos;
  78. /**
  79. * during row evaluation should I use the current value
  80. * or the oldest (i.e when close one group sometime I need
  81. * the values from the previous row
  82. * Values:
  83. * CURRENTVALUE: use the current value
  84. * OLDVALUE : use the previous value
  85. * Default: CURRENTVALUE
  86. * @var string $ValueType
  87. */
  88. var $ValueType;
  89. /**
  90. * Which font I should be used to print this row
  91. * Default: ''
  92. * @var string $FontId
  93. */
  94. var $FontId;
  95. /**
  96. * Which columnset should be used to print the current row
  97. * Default: NONE, no columnset required.
  98. * @var string
  99. */
  100. var $ColumnSet;
  101. /**
  102. * No. of column where put the text
  103. * Default: 0
  104. * @var integere
  105. */
  106. var $Column;
  107. /**
  108. * Class constructor
  109. * @parameter object DataStorage &$RefToDataMgr Reference to the istance of CDataManeger
  110. * made by the class sptpl.
  111. * @parameter object CXml2Array $Node definition node for the current istance
  112. * @parameter string $ValueType during row evaluation should I use the current value
  113. * or the oldest (i.e when close one group somethime I need
  114. * some value from the previous row
  115. * @access public
  116. */
  117. function CRow(&$RefToDataMgr,$Cfg=NULL,$ValueType=CURRENTVALUE)
  118. {
  119. $this->DataMgr=&$RefToDataMgr;
  120. if(!is_object($this->DataMgr))
  121. trigger_error('Internal error, CRow, first parameter should be an object', E_USER_ERROR);
  122. $this->VPos="";
  123. $this->RowPos=0;
  124. $this->Align='';
  125. $this->ColPos=0;
  126. $this->ValueType=$ValueType;
  127. $this->FontId='';
  128. $this->ColumnSet=NONE;
  129. $this->Column=0;
  130. if($Cfg!=NULL)
  131. $this->ParseXml($Cfg);
  132.  
  133. }
  134.  
  135.  
  136. /**
  137. *
  138. * Parse the row tag and its childs to set the intenal structure
  139. *
  140. * @param object CXml2Array $Node
  141. * @access public
  142. */
  143. function ParseXml($Cfg)
  144. {
  145. // $Cfg->ArrayDump();
  146. // I Must reset the internal pointer. I already done a llop into the attributes
  147. $Cfg->EachAttribute(true);
  148. while(($ret=$Cfg->EachAttribute())!=FALSE)
  149. {
  150. // var_dump($ret);
  151. // echo "<br>";
  152. list($AttribName,$value)=$ret;
  153. switch(strtolower($AttribName))
  154. {
  155. case 'vpos' :
  156. $attr=strtolower($value);
  157. switch($attr) {
  158. case 'top' :
  159. case 'bottom' :
  160. case 'relative' :
  161. case 'absolute' :
  162. case 'newpage' :
  163. $this->VPos=$attr;
  164. break;
  165. default :
  166. trigger_error('Unespected value \''.$attr.'\' for the attribute vpos', E_USER_ERROR);
  167. break;
  168. }
  169. break;
  170. case 'rowpos' :
  171. $this->RowPos=$value;
  172. if(!is_numeric($this->RowPos))
  173. trigger_error('The attribute RowPos should be a number', E_USER_ERROR);
  174. break;
  175. case 'fontid' :
  176. $this->FontId=$value;
  177. break;
  178. case 'align' :
  179. $attr=strtolower($value);
  180. switch($attr) {
  181. case 'left' :
  182. case 'right' :
  183. case 'center' :
  184. $this->Align=$attr;
  185. break;
  186. default :
  187. trigger_error('Unespected value \''.$attr.'\' for the attribute align', E_USER_ERROR);
  188. break;
  189. }
  190. break;
  191. case 'colpos' :
  192. $this->ColPos=$value;
  193. if(!is_numeric($this->ColPos))
  194. trigger_error('The attribute ColPos should be a number', E_USER_ERROR);
  195. break;
  196. case 'columnset' :
  197. $this->ColumnSet=$value;
  198. break;
  199. case 'column' :
  200. $this->Column=$value;
  201. if(!is_numeric($this->Column))
  202. trigger_error('The attribute column should be a number', E_USER_ERROR);
  203. break;
  204. }
  205. }
  206. // var_dump(nl2br(GetDomValue($Node)));
  207. //var_dump($this);
  208. // echo "<hr><br>";
  209. $this->RowText=$this->_ParseRow($Cfg->GetText());
  210. // var_dump(nl2br($this->RowText));
  211. }
  212.  
  213. /**
  214. * Parse the template row from the xml file and convert it into
  215. * internal format suitable to be eval'ed
  216. *
  217. * @param string Row
  218. * @access private
  219. */
  220. function _ParseRow($Row)
  221. {
  222. $outText="";
  223. $Offset=0;
  224. while(($StartPos=strpos($Row,'{',$Offset))!==FALSE)
  225. {
  226. $outText.="\"".substr($Row,$Offset,$StartPos-$Offset)."\"";
  227. // Where is the end
  228. if(($EndPos=strpos($Row,'}',$StartPos))===FALSE)
  229. trigger_error("Open { without the close }",E_USER_ERROR);
  230. $outText.=" . ".$this->_ExtractVar(substr($Row,$StartPos,$EndPos-$StartPos))." . ";
  231. $Offset=$EndPos+1;
  232. }
  233. // Last part of the text
  234. $outText.="\"".substr($Row,$Offset)."\"";
  235. return($outText);
  236. }
  237. /**
  238. * Parse the text and decode the function or the data field from the given text
  239. *
  240. * @param string Text
  241. * @access private
  242. */
  243. function _ExtractVar($Text)
  244. {
  245. $OutText="";
  246. if(preg_match("/^\{(\w+)\(([\.\$\w\][,\'\"-\/ ]+)*\)\}*/",$Text,$var))
  247. {
  248. // Function Type: $var[1] -> Function name
  249. // $var[2] -> parameters
  250. // Is this function defined inside the DataManager class?
  251. // If so, I prepend $this to the function's name
  252. $LocalFunction='';
  253. if(method_exists($this->DataMgr,$var[1]))
  254. {
  255. $LocalFunction='$this->';
  256. }
  257.  
  258. $OutText.='$this->GetEvalValue("'.$var[1].'",'.$LocalFunction.$var[1]."(";
  259. if(array_key_exists(2,$var))
  260. {
  261. $param=explode(",",$var[2]);
  262. $i=0;
  263. foreach($param as $value)
  264. {
  265. if($i) { $OutText.=",";}
  266. $OutText.=$this->_ExtractVar($value);
  267. $i++;
  268. }
  269. }
  270. $OutText.="))";
  271. }
  272. else
  273. {
  274. if(preg_match('/^\{*\$([a-zA-Z0-9]+)((\[[0-9a-zA-Z\'\"_]+\])*)\}*/',$Text,$var)) //'"
  275. {
  276. // Variable Type: $var[1] -> Variable name
  277. // $var[2] -> squares bracket used by array
  278. $FuncGetVal=($this->ValueType==CURRENTVALUE)?'$this->Values':'$this->OldValues';
  279. $OutText.='$this->GetEvalValue("'.$var[1].'",'.$FuncGetVal.'["'.$var[1].'"]'.$var[2].')';
  280. }
  281. else
  282. $OutText=$Text;
  283. }
  284. return($OutText);
  285. }
  286.  
  287. /**
  288. * Write the text for this row. Actualy this function call the DataStorage to eval
  289. * the text, then it pass tha evalued text to the PageManager to perform the real output
  290. * @parameter object CPageMgr &$PageMgr reference to PageManager
  291. * @access public
  292. */
  293. function WriteOut(&$PageMgr)
  294. {
  295. if(!is_object($PageMgr))
  296. trigger_error('Internal error, WriteOut, first parameter should be an object', E_USER_ERROR);
  297. $evaluated=$this->DataMgr->EvalText($this->RowText);
  298. // Should I setup a new column set ?
  299. if($this->ColumnSet!=NONE)
  300. $PageMgr->NewColumnSet($this->ColumnSet);
  301. // Check wheter I need to move the current line.
  302. switch($this->VPos) {
  303. case 'top' :
  304. $PageMgr->MvTop();
  305. break;
  306. case 'bottom' :
  307. $PageMgr->MvBottom();
  308. break;
  309. case 'absolute' :
  310. $PageMgr->MvAbsolutePos($this->RowPos);
  311. break;
  312. case 'relative' :
  313. if(!$PageMgr->MvRelativePos($this->RowPos))
  314. trigger_error('Error in relative move of current line by '.$this->RowPos.' rows',E_USER_ERROR);
  315. break;
  316. case 'newpage' :
  317. $PageMgr->NewPage();
  318. break;
  319. }
  320. // var_dump($this->RowText);
  321. $PageMgr->WriteOut($evaluated,$this->Align,$this->ColPos,$this->Column,$this->FontId);
  322. }
  323.  
  324. /**
  325. * @access public
  326. */
  327. function GetEvaledText()
  328. {
  329. return($this->DataMgr->EvalText($this->RowText));
  330. }
  331.  
  332. }
  333.  
  334.  
  335. /**
  336. * Particular CROw used as header line on the page
  337. */
  338. class CRowHeader extends CRow
  339. {
  340. function CRowHeader(&$RefToDataMgr,$Node=NULL,$ValueType=CURRENTVALUE)
  341. {
  342. parent::CRow($RefToDataMgr,$Node,$ValueType);
  343. }
  344.  
  345. function WriteOut(&$PageMgr)
  346. {
  347. if(!is_object($PageMgr))
  348. trigger_error('Internal error, WriteOut, first parameter should be an object', E_USER_ERROR);
  349. $evaluated=$this->DataMgr->EvalText($this->RowText);
  350. // var_dump($this->RowText);
  351. $PageMgr->WriteOutHeaderRow($evaluated,$this->Align,$this->ColPos,$this->FontId);
  352. }
  353.  
  354. }
  355.  
  356. /**
  357. * Particular CROw used as footer line on the page
  358. */
  359. class CRowFooter extends CRow
  360. {
  361. function CRowFooter(&$RefToDataMgr,$Node=NULL,$ValueType=CURRENTVALUE)
  362. {
  363. parent::CRow($RefToDataMgr,$Node,$ValueType);
  364. }
  365.  
  366. function WriteOut(&$PageMgr)
  367. {
  368. if(!is_object($PageMgr))
  369. trigger_error('Internal error, WriteOut, first parameter should be an object', E_USER_ERROR);
  370. $evaluated=$this->DataMgr->EvalText($this->RowText);
  371. // var_dump($this->RowText);
  372. $PageMgr->WriteOutFooterRow($evaluated,$this->Align,$this->ColPos,$this->FontId);
  373. }
  374.  
  375. }
  376. ?>

Documentation generated on Mon, 28 Mar 2005 15:13:21 +0200 by phpDocumentor 1.3.0RC3