PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/application/libraries/doc/fx_data_column.php

http://comet.googlecode.com/
PHP | 414 lines | 336 code | 33 blank | 45 comment | 46 complexity | 88b94b060123ecc9b42aa1453a4bbc07 MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. // L?p Fx_Data_Column chuyęn důng ?? h? tr? cho Fx_Data_Row
  3. class Fx_Data_Column extends Fx_Data_View
  4. {
  5. // Hŕng ch?a c?t
  6. protected $_dataRow = null;
  7. // Tięu ?? c?t
  8. protected $_heading = '';
  9. // Colspan
  10. protected $_colspan = 1;
  11. // Rowspan
  12. protected $_rowspan = 1;
  13. // B? ??nh d?ng hi?n th? c?t
  14. protected $_renderer = null;
  15. // Xác ??nh tr??ng d? li?u trong câu truy v?n b?t k?
  16. protected $_field = '';
  17. // Xác ??nh c?t có ph?i lŕ khóa chính hay không
  18. protected $_isPrimaryKey = false;
  19. // Xác ??nh có cho phép s?p x?p hay không
  20. protected $_sortable = true;
  21. // Xác ??nh có cho phép l?c hay không
  22. protected $_filterable = true;
  23. // B? filter
  24. protected $_filter = null;
  25. // ??i v?i d? li?u d?ng select, giá tr? c?a m?i option có th?
  26. // khác v?i nhăn c?a option ?ó
  27. protected $_valueMember = '';
  28. // Nhăn c?a option ???c l?y theo tr??ng nŕo
  29. protected $_displayMember = '';
  30. // ??i v?i m?t s? column ??c bi?t, value ch? lŕ d?ng id ???c tham chi?u
  31. function __construct($_data = array('id'=>'', 'class'=>'', 'tooltip'=>'', 'heading'=>'', 'renderer'=>null, 'data'=>null, 'field'=>''))
  32. {
  33. $this->__beforeInit();
  34. $this->__init($_data);
  35. $this->__afterInit();
  36. }
  37. // Kh?i t?o các tham s? c?n thi?t
  38. protected function __init($_data)
  39. {
  40. if (!is_array($_data) || count($_data) == 0)
  41. {
  42. return $this;
  43. }
  44. if (isset($_data['id']))
  45. {
  46. $this->setId($_data['id']);
  47. }
  48. if (isset($_data['class']))
  49. {
  50. $this->setClassName($_data['class']);
  51. }
  52. if (isset($_data['tooltip']))
  53. {
  54. $this->setTooltip($_data['tooltip']);
  55. }
  56. if (isset($_data['heading']))
  57. {
  58. $this->setHeading($_data['heading']);
  59. }
  60. if (isset($_data['renderer']))
  61. {
  62. $this->setRenderer($_data['renderer']);
  63. }
  64. if (isset($_data['data']))
  65. {
  66. $this->setData($_data['data']);
  67. }
  68. if (isset($_data['field']))
  69. {
  70. $this->setField($_data['field']);
  71. }
  72. if (isset($_data['colspan']))
  73. {
  74. $this->setColspan($_data['colspan']);
  75. }
  76. if (isset($_data['rowspan']))
  77. {
  78. $this->setRowspan($_data['rowspan']);
  79. }
  80. if (isset($_data['primarykey']))
  81. {
  82. $this->setPrimaryKey($_data['primarykey']);
  83. }
  84. if (isset($_data['sortable']))
  85. {
  86. $this->allowSortable($_data['sortable']);
  87. }
  88. if (isset($_data['filterable']))
  89. {
  90. $this->allowFilterable($_data['filterable']);
  91. }
  92. return $this;
  93. }
  94. protected function __afterInit()
  95. {
  96. if ($this->_renderer === null)
  97. {
  98. $this->_renderer = new Fx_Data_Column_Renderer('text', $this);
  99. }
  100. if ($this->_filterable === true)
  101. {
  102. $this->_filter = new Fx_Data_Column_Filter('text', $this);
  103. }
  104. return $this;
  105. }
  106. // Xác ??nh c?t có ph?i lŕ khóa chính hay không
  107. public function setPrimaryKey($yes = true)
  108. {
  109. $this->_isPrimaryKey = $yes;
  110. $gridView = & $this->getDataRow()->getDataGrid();
  111. foreach ($gridView->getRowCollection() as $row)
  112. {
  113. $column = & $row->getColumn($this->getId());
  114. $column->_isPrimaryKey = $yes;
  115. }
  116. return $this;
  117. }
  118. public function isPrimaryKey()
  119. {
  120. return (boolean)$this->_isPrimaryKey;
  121. }
  122. // Có cho phép ???c s?p x?p hay không
  123. public function allowSortable($sortable = true)
  124. {
  125. $this->_sortable = (boolean)$sortable;
  126. return $this;
  127. }
  128. // Xác ??nh c?t có ???c s?p x?p hay không
  129. public function isSortable()
  130. {
  131. return (boolean)$this->_sortable;
  132. }
  133. // Có cho phép ???c l?c hay không
  134. public function allowFilterable($filterable = true)
  135. {
  136. $this->_filterable = (boolean)$filterable;
  137. if ($this->_filter !== null)
  138. {
  139. $this->_filter->setVisible($filterable);
  140. }
  141. return $this;
  142. }
  143. // Xác ??nh c?t có ???c l?c hay không
  144. public function isFilterable()
  145. {
  146. return (boolean)$this->_filterable;
  147. }
  148. // L?y v? b? filter
  149. public function & getFilter()
  150. {
  151. $filter = & $this->_filter;
  152. if ($filter === null)
  153. {
  154. require_once APP_LIBRARY_PATH . 'doc/fx_data_column_filter.php';
  155. $filter = new Fx_Data_Column_Filter('text', $this);
  156. }
  157. return $filter;
  158. }
  159. // Thi?t l?p value member
  160. function setValueMember($field)
  161. {
  162. if (!is_string($field) || empty($field))
  163. {
  164. return false;
  165. }
  166. $this->_valueMember = $field;
  167. return $this;
  168. }
  169. // L?y v? value member
  170. function getValueMember()
  171. {
  172. return (string)$this->_valueMember;
  173. }
  174. // Thi?t l?p tr??ng hi?n th?
  175. function setDisplayMember($field)
  176. {
  177. if (!is_string($field) || empty($field))
  178. {
  179. return false;
  180. }
  181. $this->_displayMember = $field;
  182. return $this;
  183. }
  184. // L?y v? tr??ng hi?n th?
  185. function getDisplayMember()
  186. {
  187. return (string)$this->_displayMember;
  188. }
  189. // Thi?t l?p b? filter
  190. public function setFilter(Fx_Data_Column_Filter $filter)
  191. {
  192. $this->_filter = & $filter;
  193. return $this;
  194. }
  195. // Thi?t l?p data row ch?a c?t
  196. public function setDataRow(Fx_Data_Row $row)
  197. {
  198. if ($row != null)
  199. {
  200. $this->_dataRow = & $row;
  201. $this->_model = & $this->_dataRow->getModel();
  202. }
  203. return $this;
  204. }
  205. // L?y v? data row c?a c?t ?ó
  206. public function & getDataRow()
  207. {
  208. $row = & $this->_dataRow;
  209. return $row;
  210. }
  211. // Thi?t l?p ID
  212. public function setId($_id = '')
  213. {
  214. if (is_string($_id) && !empty($_id))
  215. {
  216. $this->_id = $_id;
  217. } else {
  218. $this->_id = $this->_field.'_'.sha1(time());
  219. }
  220. return $this;
  221. }
  222. // Thi?t l?p Colspan
  223. public function setColspan($cols = 1)
  224. {
  225. if (is_int($cols) && $cols > 0)
  226. {
  227. $this->_colspan = $cols;
  228. }
  229. return $this;
  230. }
  231. // L?y v? Colspan
  232. public function getColspan()
  233. {
  234. return (int)$this->_colspan;
  235. }
  236. // Thi?t l?p Rowspan
  237. public function setRowspan($rows = 1)
  238. {
  239. if (is_int($rows) && $rows > 0)
  240. {
  241. $this->_rowspan = $rows;
  242. }
  243. return $this;
  244. }
  245. // L?y v? Rowspan
  246. public function getRowspan()
  247. {
  248. return (int)$this->_rowspan;
  249. }
  250. // Thi?t l?p renderer
  251. public function setRenderer(&$_renderer = null)
  252. {
  253. if ($_renderer != null)
  254. {
  255. $_renderer->setColumn($this);
  256. $this->_renderer = & $_renderer;
  257. }
  258. return $this;
  259. }
  260. // L?y v? ki?u render
  261. public function getRenderer($type = 'text')
  262. {
  263. if (null === $this->_renderer) {
  264. $this->setRenderer(new Fx_Data_Column_Renderer($type));
  265. }
  266. return $this->_renderer;
  267. }
  268. // Thi?t l?p render cho c? c?t
  269. public function setRenderType($type = 'text')
  270. {
  271. $this->_renderer->setType($type);
  272. $gridView = & $this->getDataRow()->getDataGrid();
  273. foreach ($gridView->getRowCollection() as $row)
  274. {
  275. $column = & $row->getColumn($this->getId());
  276. $column->_renderer->setType($type);
  277. }
  278. return $this;
  279. }
  280. // Thi?t l?p c?t d? li?u
  281. public function setField($_field = '')
  282. {
  283. if (is_string($_field) && !empty($_field))
  284. {
  285. $this->_field = $_field;
  286. }
  287. return $this;
  288. }
  289. // L?y v? tęn c?t d? li?u
  290. public function getField()
  291. {
  292. return (string)$this->_field;
  293. }
  294. // Thay ??i d? li?u field hi?n th?i thŕnh d? li?u field
  295. // khác trong cůng model
  296. public function changeFieldData($field)
  297. {
  298. if ($this->_model === null || !$this->_model->isLoaded())
  299. {
  300. throw new Exception('Cannot change field '.$this->_field . ' to field ' . $field);
  301. }
  302. $this->drawDataFromModel($this->_model, $field);
  303. return $this;
  304. }
  305. // Thi?t l?p s? hi?n th? c?a column
  306. public function setVisible($visible = true)
  307. {
  308. $this->_visible = $visible;
  309. $gridView = & $this->getDataRow()->getDataGrid();
  310. foreach ($gridView->getRowCollection() as $row)
  311. {
  312. $column = & $row->getColumn($this->getId());
  313. $column->_visible = $visible;
  314. }
  315. return $this;
  316. }
  317. // L?y v? n?i dung nh? m?t c?t c?a header
  318. public function getOutputHeader()
  319. {
  320. if ($this->isVisible()) {
  321. $gridView = $this->getDataRow()->getDataGrid();
  322. $gridId = $gridView->getId();
  323. $actionUrl = base_url() . $gridView->getSortUrl() . '/';
  324. if (empty($gridId) || empty($actionUrl))
  325. {
  326. throw new Exception('DataGridView Id Has Not Set Or Sort Action Url Has Not Set');
  327. }
  328. $output = "<th id=\"colHeaderId_$this->_id\" class=\"columnHeader";
  329. if ($this->_sortable)
  330. {
  331. $output .= " sortable ";
  332. $output .= $this->getClassName();
  333. $output .= "\" onclick=\"sortBy('$gridId', this.id, '$actionUrl')\"";
  334. }
  335. $output .= " title=\"$this->_tooltip\" alt=\"$this->_tooltip\" colspan=\"$this->_colspan\" rowspan=\"$this->_rowspan\" width=\"$this->_width\" height=\"$this->_height\" onmouseover=\"jQuery(this).toggleClass('hoverTitle');\" onmouseout=\"jQuery(this).toggleClass('hoverTitle');\">";
  336. $output .= "<div>\n";
  337. $output .= "<span>" . $this->getHeading() . "</span>\n";
  338. $output .= "</div>";
  339. $output .= "</th>";
  340. return $output;
  341. }
  342. return null;
  343. }
  344. // L?y v? n?i dung html
  345. public function getOutputHtml()
  346. {
  347. if ($this->isVisible())
  348. {
  349. $output = "<td id=\"colId_$this->_id\" class=\"cellDataView\" title=\"$this->_tooltip\" alt=\"$this->_tooltip\" colspan=\"$this->_colspan\" rowspan=\"$this->_rowspan\" width=\"$this->_width\" height=\"$this->_height\"";
  350. if (!$this->_isPrimaryKey) {
  351. $url = $this->getDataRow()->getRowUrl();
  352. $output .= " onclick=\"loadAjaxPage('".$url."', null, 'wrapper')\"";
  353. }
  354. $output .= ">";
  355. $output .= $this->_renderer->renderOutputData();
  356. $output .= '</td>';
  357. return $output;
  358. }
  359. return null;
  360. }
  361. // L?y d? li?u t? m?t model
  362. public function drawDataFromModel(st_model $_model, $_field, $_type = 'text')
  363. {
  364. $this->setHeading($_field);
  365. $this->setClassName($_field);
  366. $this->setTooltip($_field);
  367. $this->setField($_field);
  368. if ($this->_filter != null)
  369. {
  370. $this->_filter->setField($_field);
  371. }
  372. $this->_renderer->setType($_type);
  373. $this->setId($_field);
  374. $_method = 'get' . ucfirst($_field);
  375. $this->setData($_model->$_method());
  376. $this->setModel($_model);
  377. $this->getFilter()->setColumn($this);
  378. return $this;
  379. }
  380. }
  381. ?>