Source for file SimpleTableHeader.php

Documentation is available at SimpleTableHeader.php

  1. <?php
  2. /*
  3. * This file is part of Sylar.
  4. *
  5. * Sylar is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * Sylar is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with Sylar. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * @copyright Copyright Sylar Development Team
  19. * @license http://www.gnu.org/licenses/ GNU Public License V2.0
  20. * @see https://launchpad.net/sylar/
  21. * @see http://www.giano-solutions.com
  22. */
  23.  
  24. import('sylar.common.system.ExceptionInSylar');
  25. import('sylar.common.system.ConfigBox');
  26. import('sylar.common.system.Logger');
  27. import('sylar.common.data.DataContainer');
  28.  
  29.  
  30. /**
  31. * SimpleTableHeader
  32. * It is the header of the table. It contains informations about:
  33. *
  34. * @see Sylar_SimpleTable
  35. * @see Sylar_SimpleTableHeaderColumn
  36. *
  37. * @package Sylar
  38. * @version 1.0
  39. * @since 03/2008
  40. *
  41. * @author Gianluca Giusti [brdp] <g.giusti@giano-solutions.com>
  42. * @copyright Sylar Development Team
  43. */
  44. class Sylar_SimpleTableHeader{
  45. private $arrayData;
  46. private $columns;
  47. /**
  48. * Constructor
  49. * reset data and set the number of columns defined
  50. *
  51. * @since 22/feb/08
  52. * @author Gianluca Giusti [brdp] <g.giusti@giano-solutions.com>
  53. *
  54. * @param array $arrayDataRow
  55. * @param int $columns specify number of columns of the row, if false then it calculates it from dataArray
  56. */
  57. function __construct($columns=false){
  58. // If not specified set columns to 0 and refresh every add
  59. if(!$columns){
  60. $columns = 0;
  61. }
  62. $this->reset();
  63. $this->setColumns($columns);
  64. }
  65. function __destruct(){
  66. // nothing to do at the moment
  67. }
  68. // Getter and Setter
  69. // --------------------------------
  70. public function setColumns($iColumns){
  71. $this->columns = $iColumns;
  72. }
  73. public function getColumns(){
  74. return $this->columns;
  75. }
  76. /**
  77. * Return the list of the columns defined in the header
  78. *
  79. * @see Sylar_SimpleTableHeaderColumn
  80. *
  81. * @return array that contains object Sylar_SimpleTableHeaderColumn
  82. */
  83. private function getColumnsList(){
  84. return $this->arrayData;
  85. }
  86. // Public methods
  87. // --------------------------------
  88. /**
  89. * add a column to Table header object
  90. *
  91. * @since 22/feb/08
  92. * @author Gianluca Giusti [brdp] <g.giusti@giano-solutions.com>
  93. *
  94. * @see Sylar_SimpleTableHeaderColumn
  95. *
  96. * @param Sylar_SimpleTableHeaderColumn $columnBean
  97. * @return boolean
  98. */
  99. public function addColumn(Sylar_SimpleTableHeaderColumn $columnBean){
  100. //TODO Controls on Column before insert
  101. $this->arrayData[] = $columnBean;
  102. $this->setColumns(count($this->getColumnsList()));
  103. }
  104. /**
  105. * it return Column number $columnId
  106. *
  107. * @see Sylar_SimpleTableHeaderColumn
  108. *
  109. * @since 22/feb/08
  110. * @author Gianluca Giusti [brdp] <g.giusti@giano-solutions.com>
  111. *
  112. * @param int $columnId
  113. * @return Sylar_SimpleTableHeaderColumn
  114. */
  115. public function getColumnById($columnId){
  116. //TODO Controls on lenght of array and column number
  117. return $this->arrayData[$columnId];
  118. }
  119. /**
  120. * Check if header has columns
  121. * verify if the table header has at least one column. Return false if there are no column.
  122. *
  123. * @since 22/feb/08
  124. * @author Gianluca Giusti [brdp] <g.giusti@giano-solutions.com>
  125. *
  126. * @return boolean
  127. */
  128. public function hasColumns(){
  129. if($this->getColumns()>0){
  130. return true;
  131. }else{
  132. return false;
  133. }
  134. }
  135. // Private Methods
  136. // --------------------------------
  137. /**
  138. * reset header
  139. * If is set destroy and reset the header information
  140. *
  141. * @since 22/feb/08
  142. * @author Gianluca Giusti [brdp] <g.giusti@giano-solutions.com>
  143. *
  144. * @return void
  145. */
  146. private function reset(){
  147. if(isset($this->arrayData)){
  148. unset($this->arrayData);
  149. }
  150. $this->arrayData = array();
  151. $this->setColumns(0);
  152. }
  153. /**
  154. * Check if Column exists
  155. * verify if a specified column num exists in the table header
  156. *
  157. * @param int $columnNum
  158. * @return boolean
  159. */
  160. private function columnExists($columnNum){
  161. try{
  162. if(!$this->hasColumns()){
  163. throw new ExceptionInSylar("Header has no columns. [Sylar_SimpleTable::columnExists]");
  164. return false;
  165. }
  166. if( !array_key_exists($columnNum, $this->getColumnsList()) ){
  167. throw new ExceptionInSylar("Column number does not exists in table header (Request Column: ".$columnNum." Header Columns Tot: ".count($this->getColumnsList())."). [Sylar_SimpleTable::columnExists]");
  168. return false;
  169. }
  170. return true;
  171. }catch (ExceptionInSylar $ex){
  172. throw $ex;
  173. return false;
  174. }
  175. }
  176. }
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184. /**
  185. * Header Single Column
  186. * It is information about a single column header. It contains informations about:
  187. * Column name
  188. * Column code
  189. * Column type
  190. * Column format type
  191. * Column description
  192. *
  193. * @see Sylar_SimpleTableHeader
  194. *
  195. * @package Sylar
  196. * @version 1.0
  197. * @since 03/2008
  198. *
  199. * @author Gianluca Giusti [brdp] <g.giusti@giano-solutions.com>
  200. * @copyright Sylar Development Team
  201. */
  202. class Sylar_SimpleTableHeaderColumn{
  203. /**Unique code for column for example 'user_id' may be the same sql column name from query */
  204.  
  205. private $columnCode;
  206. /** type of data contained in the column, for example: int, string, etc... */
  207.  
  208. private $columnType;
  209. /** How the data must be format in the column. For example: valute, tel, mobile, email, web */
  210.  
  211. private $columnFormatType;
  212. /** It's the name showed on the table header */
  213.  
  214. private $columnName;
  215. /** The description ov column that may be displayed on tooltip for example */
  216.  
  217. private $columnDesc;
  218.  
  219.  
  220.  
  221. function __construct($columnCode){
  222. // nothing to do at the moment
  223. if(!$columnCode){
  224. //TODO Exception ! Code must be set!
  225. }
  226. $this->setColumnCode($columnCode);
  227. }
  228. function __destruct(){
  229. // nothing to do at the moment
  230. }
  231. // Getter and Setter
  232. // --------------------------------
  233. public function setColumnCode($columnCode){
  234. $this->columnCode = $columnCode;
  235. }
  236. public function getColumnCode(){
  237. return $this->columnCode;
  238. }
  239. public function setColumnType($columnType){
  240. $this->columnType = $columnType;
  241. }
  242. public function getColumnType(){
  243. return $this->columnType;
  244. }
  245. public function setColumnFormatType($columnFormatType){
  246. $this->columnFormatType = $columnFormatType;
  247. }
  248. public function getColumnFormatType(){
  249. return $this->columnFormatType;
  250. }
  251. public function setColumnName($columnName){
  252. $this->columnName = $columnName;
  253. }
  254. public function getColumnName(){
  255. return $this->columnName;
  256. }
  257. public function setColumnDesc($columnDesc){
  258. $this->columnDesc = $columnDesc;
  259. }
  260. public function getColumnDesc(){
  261. return $this->columnDesc;
  262. }
  263.  
  264.  
  265. // Public methods
  266. // --------------------------------
  267.  
  268. }
  269.  
  270.  
  271. ?>

Documentation generated on Thu, 24 Apr 2008 16:14:21 +0200 by phpDocumentor 1.3.0RC3