/application/libraries/doc/fx_data_column.php
PHP | 414 lines | 336 code | 33 blank | 45 comment | 46 complexity | 88b94b060123ecc9b42aa1453a4bbc07 MD5 | raw file
Possible License(s): AGPL-3.0
- <?php
- // L?p Fx_Data_Column chuyęn důng ?? h? tr? cho Fx_Data_Row
- class Fx_Data_Column extends Fx_Data_View
- {
- // Hŕng ch?a c?t
- protected $_dataRow = null;
- // Tięu ?? c?t
- protected $_heading = '';
- // Colspan
- protected $_colspan = 1;
- // Rowspan
- protected $_rowspan = 1;
- // B? ??nh d?ng hi?n th? c?t
- protected $_renderer = null;
- // Xác ??nh tr??ng d? li?u trong câu truy v?n b?t k?
- protected $_field = '';
- // Xác ??nh c?t có ph?i lŕ khóa chính hay không
- protected $_isPrimaryKey = false;
- // Xác ??nh có cho phép s?p x?p hay không
- protected $_sortable = true;
- // Xác ??nh có cho phép l?c hay không
- protected $_filterable = true;
- // B? filter
- protected $_filter = null;
- // ??i v?i d? li?u d?ng select, giá tr? c?a m?i option có th?
- // khác v?i nhăn c?a option ?ó
- protected $_valueMember = '';
- // Nhăn c?a option ???c l?y theo tr??ng nŕo
- protected $_displayMember = '';
- // ??i v?i m?t s? column ??c bi?t, value ch? lŕ d?ng id ???c tham chi?u
-
- function __construct($_data = array('id'=>'', 'class'=>'', 'tooltip'=>'', 'heading'=>'', 'renderer'=>null, 'data'=>null, 'field'=>''))
- {
- $this->__beforeInit();
- $this->__init($_data);
- $this->__afterInit();
- }
-
- // Kh?i t?o các tham s? c?n thi?t
- protected function __init($_data)
- {
- if (!is_array($_data) || count($_data) == 0)
- {
- return $this;
- }
- if (isset($_data['id']))
- {
- $this->setId($_data['id']);
- }
- if (isset($_data['class']))
- {
- $this->setClassName($_data['class']);
- }
- if (isset($_data['tooltip']))
- {
- $this->setTooltip($_data['tooltip']);
- }
- if (isset($_data['heading']))
- {
- $this->setHeading($_data['heading']);
- }
- if (isset($_data['renderer']))
- {
- $this->setRenderer($_data['renderer']);
- }
- if (isset($_data['data']))
- {
- $this->setData($_data['data']);
- }
- if (isset($_data['field']))
- {
- $this->setField($_data['field']);
- }
- if (isset($_data['colspan']))
- {
- $this->setColspan($_data['colspan']);
- }
- if (isset($_data['rowspan']))
- {
- $this->setRowspan($_data['rowspan']);
- }
- if (isset($_data['primarykey']))
- {
- $this->setPrimaryKey($_data['primarykey']);
- }
- if (isset($_data['sortable']))
- {
- $this->allowSortable($_data['sortable']);
- }
- if (isset($_data['filterable']))
- {
- $this->allowFilterable($_data['filterable']);
- }
- return $this;
- }
-
- protected function __afterInit()
- {
- if ($this->_renderer === null)
- {
- $this->_renderer = new Fx_Data_Column_Renderer('text', $this);
- }
- if ($this->_filterable === true)
- {
- $this->_filter = new Fx_Data_Column_Filter('text', $this);
- }
- return $this;
- }
-
- // Xác ??nh c?t có ph?i lŕ khóa chính hay không
- public function setPrimaryKey($yes = true)
- {
- $this->_isPrimaryKey = $yes;
- $gridView = & $this->getDataRow()->getDataGrid();
- foreach ($gridView->getRowCollection() as $row)
- {
- $column = & $row->getColumn($this->getId());
- $column->_isPrimaryKey = $yes;
- }
- return $this;
- }
-
- public function isPrimaryKey()
- {
- return (boolean)$this->_isPrimaryKey;
- }
-
- // Có cho phép ???c s?p x?p hay không
- public function allowSortable($sortable = true)
- {
- $this->_sortable = (boolean)$sortable;
- return $this;
- }
-
- // Xác ??nh c?t có ???c s?p x?p hay không
- public function isSortable()
- {
- return (boolean)$this->_sortable;
- }
-
- // Có cho phép ???c l?c hay không
- public function allowFilterable($filterable = true)
- {
- $this->_filterable = (boolean)$filterable;
- if ($this->_filter !== null)
- {
- $this->_filter->setVisible($filterable);
- }
- return $this;
- }
-
- // Xác ??nh c?t có ???c l?c hay không
- public function isFilterable()
- {
- return (boolean)$this->_filterable;
- }
-
- // L?y v? b? filter
- public function & getFilter()
- {
- $filter = & $this->_filter;
- if ($filter === null)
- {
- require_once APP_LIBRARY_PATH . 'doc/fx_data_column_filter.php';
- $filter = new Fx_Data_Column_Filter('text', $this);
- }
- return $filter;
- }
-
- // Thi?t l?p value member
- function setValueMember($field)
- {
- if (!is_string($field) || empty($field))
- {
- return false;
- }
- $this->_valueMember = $field;
- return $this;
- }
-
- // L?y v? value member
- function getValueMember()
- {
- return (string)$this->_valueMember;
- }
-
- // Thi?t l?p tr??ng hi?n th?
- function setDisplayMember($field)
- {
- if (!is_string($field) || empty($field))
- {
- return false;
- }
- $this->_displayMember = $field;
- return $this;
- }
-
- // L?y v? tr??ng hi?n th?
- function getDisplayMember()
- {
- return (string)$this->_displayMember;
- }
-
- // Thi?t l?p b? filter
- public function setFilter(Fx_Data_Column_Filter $filter)
- {
- $this->_filter = & $filter;
- return $this;
- }
-
- // Thi?t l?p data row ch?a c?t
- public function setDataRow(Fx_Data_Row $row)
- {
- if ($row != null)
- {
- $this->_dataRow = & $row;
- $this->_model = & $this->_dataRow->getModel();
- }
- return $this;
- }
-
- // L?y v? data row c?a c?t ?ó
- public function & getDataRow()
- {
- $row = & $this->_dataRow;
- return $row;
- }
-
- // Thi?t l?p ID
- public function setId($_id = '')
- {
- if (is_string($_id) && !empty($_id))
- {
- $this->_id = $_id;
- } else {
- $this->_id = $this->_field.'_'.sha1(time());
- }
- return $this;
- }
-
- // Thi?t l?p Colspan
- public function setColspan($cols = 1)
- {
- if (is_int($cols) && $cols > 0)
- {
- $this->_colspan = $cols;
- }
- return $this;
- }
-
- // L?y v? Colspan
- public function getColspan()
- {
- return (int)$this->_colspan;
- }
-
- // Thi?t l?p Rowspan
- public function setRowspan($rows = 1)
- {
- if (is_int($rows) && $rows > 0)
- {
- $this->_rowspan = $rows;
- }
- return $this;
- }
-
- // L?y v? Rowspan
- public function getRowspan()
- {
- return (int)$this->_rowspan;
- }
-
- // Thi?t l?p renderer
- public function setRenderer(&$_renderer = null)
- {
- if ($_renderer != null)
- {
- $_renderer->setColumn($this);
- $this->_renderer = & $_renderer;
- }
- return $this;
- }
-
- // L?y v? ki?u render
- public function getRenderer($type = 'text')
- {
- if (null === $this->_renderer) {
- $this->setRenderer(new Fx_Data_Column_Renderer($type));
- }
- return $this->_renderer;
- }
-
- // Thi?t l?p render cho c? c?t
- public function setRenderType($type = 'text')
- {
- $this->_renderer->setType($type);
- $gridView = & $this->getDataRow()->getDataGrid();
- foreach ($gridView->getRowCollection() as $row)
- {
- $column = & $row->getColumn($this->getId());
- $column->_renderer->setType($type);
- }
- return $this;
- }
-
- // Thi?t l?p c?t d? li?u
- public function setField($_field = '')
- {
- if (is_string($_field) && !empty($_field))
- {
- $this->_field = $_field;
- }
- return $this;
- }
-
- // L?y v? tęn c?t d? li?u
- public function getField()
- {
- return (string)$this->_field;
- }
-
- // Thay ??i d? li?u field hi?n th?i thŕnh d? li?u field
- // khác trong cůng model
- public function changeFieldData($field)
- {
- if ($this->_model === null || !$this->_model->isLoaded())
- {
- throw new Exception('Cannot change field '.$this->_field . ' to field ' . $field);
- }
- $this->drawDataFromModel($this->_model, $field);
- return $this;
- }
-
- // Thi?t l?p s? hi?n th? c?a column
- public function setVisible($visible = true)
- {
- $this->_visible = $visible;
- $gridView = & $this->getDataRow()->getDataGrid();
- foreach ($gridView->getRowCollection() as $row)
- {
- $column = & $row->getColumn($this->getId());
- $column->_visible = $visible;
- }
- return $this;
- }
-
- // L?y v? n?i dung nh? m?t c?t c?a header
- public function getOutputHeader()
- {
- if ($this->isVisible()) {
- $gridView = $this->getDataRow()->getDataGrid();
- $gridId = $gridView->getId();
- $actionUrl = base_url() . $gridView->getSortUrl() . '/';
- if (empty($gridId) || empty($actionUrl))
- {
- throw new Exception('DataGridView Id Has Not Set Or Sort Action Url Has Not Set');
- }
- $output = "<th id=\"colHeaderId_$this->_id\" class=\"columnHeader";
- if ($this->_sortable)
- {
- $output .= " sortable ";
- $output .= $this->getClassName();
- $output .= "\" onclick=\"sortBy('$gridId', this.id, '$actionUrl')\"";
- }
- $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');\">";
- $output .= "<div>\n";
- $output .= "<span>" . $this->getHeading() . "</span>\n";
- $output .= "</div>";
- $output .= "</th>";
- return $output;
- }
- return null;
- }
-
- // L?y v? n?i dung html
- public function getOutputHtml()
- {
- if ($this->isVisible())
- {
- $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\"";
- if (!$this->_isPrimaryKey) {
- $url = $this->getDataRow()->getRowUrl();
- $output .= " onclick=\"loadAjaxPage('".$url."', null, 'wrapper')\"";
- }
- $output .= ">";
- $output .= $this->_renderer->renderOutputData();
- $output .= '</td>';
- return $output;
- }
- return null;
- }
-
- // L?y d? li?u t? m?t model
- public function drawDataFromModel(st_model $_model, $_field, $_type = 'text')
- {
- $this->setHeading($_field);
- $this->setClassName($_field);
- $this->setTooltip($_field);
- $this->setField($_field);
- if ($this->_filter != null)
- {
- $this->_filter->setField($_field);
- }
- $this->_renderer->setType($_type);
- $this->setId($_field);
- $_method = 'get' . ucfirst($_field);
- $this->setData($_model->$_method());
- $this->setModel($_model);
- $this->getFilter()->setColumn($this);
- return $this;
- }
- }
-
- ?>