summaryrefslogtreecommitdiff
path: root/framework/zii/widgets/grid
diff options
context:
space:
mode:
Diffstat (limited to 'framework/zii/widgets/grid')
-rw-r--r--framework/zii/widgets/grid/CButtonColumn.php323
-rw-r--r--framework/zii/widgets/grid/CCheckBoxColumn.php187
-rw-r--r--framework/zii/widgets/grid/CDataColumn.php144
-rw-r--r--framework/zii/widgets/grid/CGridColumn.php193
-rw-r--r--framework/zii/widgets/grid/CGridView.php550
-rw-r--r--framework/zii/widgets/grid/CLinkColumn.php96
6 files changed, 1493 insertions, 0 deletions
diff --git a/framework/zii/widgets/grid/CButtonColumn.php b/framework/zii/widgets/grid/CButtonColumn.php
new file mode 100644
index 0000000..7774103
--- /dev/null
+++ b/framework/zii/widgets/grid/CButtonColumn.php
@@ -0,0 +1,323 @@
+<?php
+/**
+ * CButtonColumn class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright &copy; 2008-2011 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ */
+
+Yii::import('zii.widgets.grid.CGridColumn');
+
+/**
+ * CButtonColumn represents a grid view column that renders one or several buttons.
+ *
+ * By default, it will display three buttons, "view", "update" and "delete", which triggers the corresponding
+ * actions on the model of the row.
+ *
+ * By configuring {@link buttons} and {@link template} properties, the column can display other buttons
+ * and customize the display order of the buttons.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id: CButtonColumn.php 3424 2011-10-24 20:13:19Z mdomba $
+ * @package zii.widgets.grid
+ * @since 1.1
+ */
+class CButtonColumn extends CGridColumn
+{
+ /**
+ * @var array the HTML options for the data cell tags.
+ */
+ public $htmlOptions=array('class'=>'button-column');
+ /**
+ * @var array the HTML options for the header cell tag.
+ */
+ public $headerHtmlOptions=array('class'=>'button-column');
+ /**
+ * @var array the HTML options for the footer cell tag.
+ */
+ public $footerHtmlOptions=array('class'=>'button-column');
+ /**
+ * @var string the template that is used to render the content in each data cell.
+ * These default tokens are recognized: {view}, {update} and {delete}. If the {@link buttons} property
+ * defines additional buttons, their IDs are also recognized here. For example, if a button named 'preview'
+ * is declared in {@link buttons}, we can use the token '{preview}' here to specify where to display the button.
+ */
+ public $template='{view} {update} {delete}';
+ /**
+ * @var string the label for the view button. Defaults to "View".
+ * Note that the label will not be HTML-encoded when rendering.
+ */
+ public $viewButtonLabel;
+ /**
+ * @var string the image URL for the view button. If not set, an integrated image will be used.
+ * You may set this property to be false to render a text link instead.
+ */
+ public $viewButtonImageUrl;
+ /**
+ * @var string a PHP expression that is evaluated for every view button and whose result is used
+ * as the URL for the view button. In this expression, the variable
+ * <code>$row</code> the row number (zero-based); <code>$data</code> the data model for the row;
+ * and <code>$this</code> the column object.
+ */
+ public $viewButtonUrl='Yii::app()->controller->createUrl("view",array("id"=>$data->primaryKey))';
+ /**
+ * @var array the HTML options for the view button tag.
+ */
+ public $viewButtonOptions=array('class'=>'view');
+
+ /**
+ * @var string the label for the update button. Defaults to "Update".
+ * Note that the label will not be HTML-encoded when rendering.
+ */
+ public $updateButtonLabel;
+ /**
+ * @var string the image URL for the update button. If not set, an integrated image will be used.
+ * You may set this property to be false to render a text link instead.
+ */
+ public $updateButtonImageUrl;
+ /**
+ * @var string a PHP expression that is evaluated for every update button and whose result is used
+ * as the URL for the update button. In this expression, the variable
+ * <code>$row</code> the row number (zero-based); <code>$data</code> the data model for the row;
+ * and <code>$this</code> the column object.
+ */
+ public $updateButtonUrl='Yii::app()->controller->createUrl("update",array("id"=>$data->primaryKey))';
+ /**
+ * @var array the HTML options for the update button tag.
+ */
+ public $updateButtonOptions=array('class'=>'update');
+
+ /**
+ * @var string the label for the delete button. Defaults to "Delete".
+ * Note that the label will not be HTML-encoded when rendering.
+ */
+ public $deleteButtonLabel;
+ /**
+ * @var string the image URL for the delete button. If not set, an integrated image will be used.
+ * You may set this property to be false to render a text link instead.
+ */
+ public $deleteButtonImageUrl;
+ /**
+ * @var string a PHP expression that is evaluated for every delete button and whose result is used
+ * as the URL for the delete button. In this expression, the variable
+ * <code>$row</code> the row number (zero-based); <code>$data</code> the data model for the row;
+ * and <code>$this</code> the column object.
+ */
+ public $deleteButtonUrl='Yii::app()->controller->createUrl("delete",array("id"=>$data->primaryKey))';
+ /**
+ * @var array the HTML options for the view button tag.
+ */
+ public $deleteButtonOptions=array('class'=>'delete');
+ /**
+ * @var string the confirmation message to be displayed when delete button is clicked.
+ * By setting this property to be false, no confirmation message will be displayed.
+ * This property is used only if <code>$this->buttons['delete']['click']</code> is not set.
+ */
+ public $deleteConfirmation;
+ /**
+ * @var string a javascript function that will be invoked after the delete ajax call.
+ * This property is used only if <code>$this->buttons['delete']['click']</code> is not set.
+ *
+ * The function signature is <code>function(link, success, data)</code>
+ * <ul>
+ * <li><code>link</code> references the delete link.</li>
+ * <li><code>success</code> status of the ajax call, true if the ajax call was successful, false if the ajax call failed.
+ * <li><code>data</code> the data returned by the server in case of a successful call or XHR object in case of error.
+ * </ul>
+ * Note that if success is true it does not mean that the delete was successful, it only means that the ajax call was successful.
+ *
+ * Example:
+ * <pre>
+ * array(
+ * class'=>'CButtonColumn',
+ * 'afterDelete'=>'function(link,success,data){ if(success) alert("Delete completed successfuly"); }',
+ * ),
+ * </pre>
+ */
+ public $afterDelete;
+ /**
+ * @var array the configuration for additional buttons. Each array element specifies a single button
+ * which has the following format:
+ * <pre>
+ * 'buttonID' => array(
+ * 'label'=>'...', // text label of the button
+ * 'url'=>'...', // a PHP expression for generating the URL of the button
+ * 'imageUrl'=>'...', // image URL of the button. If not set or false, a text link is used
+ * 'options'=>array(...), // HTML options for the button tag
+ * 'click'=>'...', // a JS function to be invoked when the button is clicked
+ * 'visible'=>'...', // a PHP expression for determining whether the button is visible
+ * )
+ * </pre>
+ * In the PHP expression for the 'url' option and/or 'visible' option, the variable <code>$row</code>
+ * refers to the current row number (zero-based), and <code>$data</code> refers to the data model for
+ * the row.
+ *
+ * Note that in order to display these additional buttons, the {@link template} property needs to
+ * be configured so that the corresponding button IDs appear as tokens in the template.
+ */
+ public $buttons=array();
+
+ /**
+ * Initializes the column.
+ * This method registers necessary client script for the button column.
+ */
+ public function init()
+ {
+ $this->initDefaultButtons();
+
+ foreach($this->buttons as $id=>$button)
+ {
+ if(strpos($this->template,'{'.$id.'}')===false)
+ unset($this->buttons[$id]);
+ else if(isset($button['click']))
+ {
+ if(!isset($button['options']['class']))
+ $this->buttons[$id]['options']['class']=$id;
+ if(strpos($button['click'],'js:')!==0)
+ $this->buttons[$id]['click']='js:'.$button['click'];
+ }
+ }
+
+ $this->registerClientScript();
+ }
+
+ /**
+ * Initializes the default buttons (view, update and delete).
+ */
+ protected function initDefaultButtons()
+ {
+ if($this->viewButtonLabel===null)
+ $this->viewButtonLabel=Yii::t('zii','View');
+ if($this->updateButtonLabel===null)
+ $this->updateButtonLabel=Yii::t('zii','Update');
+ if($this->deleteButtonLabel===null)
+ $this->deleteButtonLabel=Yii::t('zii','Delete');
+ if($this->viewButtonImageUrl===null)
+ $this->viewButtonImageUrl=$this->grid->baseScriptUrl.'/view.png';
+ if($this->updateButtonImageUrl===null)
+ $this->updateButtonImageUrl=$this->grid->baseScriptUrl.'/update.png';
+ if($this->deleteButtonImageUrl===null)
+ $this->deleteButtonImageUrl=$this->grid->baseScriptUrl.'/delete.png';
+ if($this->deleteConfirmation===null)
+ $this->deleteConfirmation=Yii::t('zii','Are you sure you want to delete this item?');
+
+ foreach(array('view','update','delete') as $id)
+ {
+ $button=array(
+ 'label'=>$this->{$id.'ButtonLabel'},
+ 'url'=>$this->{$id.'ButtonUrl'},
+ 'imageUrl'=>$this->{$id.'ButtonImageUrl'},
+ 'options'=>$this->{$id.'ButtonOptions'},
+ );
+ if(isset($this->buttons[$id]))
+ $this->buttons[$id]=array_merge($button,$this->buttons[$id]);
+ else
+ $this->buttons[$id]=$button;
+ }
+
+ if(!isset($this->buttons['delete']['click']))
+ {
+ if(is_string($this->deleteConfirmation))
+ $confirmation="if(!confirm(".CJavaScript::encode($this->deleteConfirmation).")) return false;";
+ else
+ $confirmation='';
+
+ if(Yii::app()->request->enableCsrfValidation)
+ {
+ $csrfTokenName = Yii::app()->request->csrfTokenName;
+ $csrfToken = Yii::app()->request->csrfToken;
+ $csrf = "\n\t\tdata:{ '$csrfTokenName':'$csrfToken' },";
+ }
+ else
+ $csrf = '';
+
+ if($this->afterDelete===null)
+ $this->afterDelete='function(){}';
+
+ $this->buttons['delete']['click']=<<<EOD
+function() {
+ $confirmation
+ var th=this;
+ var afterDelete=$this->afterDelete;
+ $.fn.yiiGridView.update('{$this->grid->id}', {
+ type:'POST',
+ url:$(this).attr('href'),$csrf
+ success:function(data) {
+ $.fn.yiiGridView.update('{$this->grid->id}');
+ afterDelete(th,true,data);
+ },
+ error:function(XHR) {
+ return afterDelete(th,false,XHR);
+ }
+ });
+ return false;
+}
+EOD;
+ }
+ }
+
+ /**
+ * Registers the client scripts for the button column.
+ */
+ protected function registerClientScript()
+ {
+ $js=array();
+ foreach($this->buttons as $id=>$button)
+ {
+ if(isset($button['click']))
+ {
+ $function=CJavaScript::encode($button['click']);
+ $class=preg_replace('/\s+/','.',$button['options']['class']);
+ $js[]="jQuery('#{$this->grid->id} a.{$class}').live('click',$function);";
+ }
+ }
+
+ if($js!==array())
+ Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$this->id, implode("\n",$js));
+ }
+
+ /**
+ * Renders the data cell content.
+ * This method renders the view, update and delete buttons in the data cell.
+ * @param integer $row the row number (zero-based)
+ * @param mixed $data the data associated with the row
+ */
+ protected function renderDataCellContent($row,$data)
+ {
+ $tr=array();
+ ob_start();
+ foreach($this->buttons as $id=>$button)
+ {
+ $this->renderButton($id,$button,$row,$data);
+ $tr['{'.$id.'}']=ob_get_contents();
+ ob_clean();
+ }
+ ob_end_clean();
+ echo strtr($this->template,$tr);
+ }
+
+ /**
+ * Renders a link button.
+ * @param string $id the ID of the button
+ * @param array $button the button configuration which may contain 'label', 'url', 'imageUrl' and 'options' elements.
+ * See {@link buttons} for more details.
+ * @param integer $row the row number (zero-based)
+ * @param mixed $data the data object associated with the row
+ */
+ protected function renderButton($id,$button,$row,$data)
+ {
+ if (isset($button['visible']) && !$this->evaluateExpression($button['visible'],array('row'=>$row,'data'=>$data)))
+ return;
+ $label=isset($button['label']) ? $button['label'] : $id;
+ $url=isset($button['url']) ? $this->evaluateExpression($button['url'],array('data'=>$data,'row'=>$row)) : '#';
+ $options=isset($button['options']) ? $button['options'] : array();
+ if(!isset($options['title']))
+ $options['title']=$label;
+ if(isset($button['imageUrl']) && is_string($button['imageUrl']))
+ echo CHtml::link(CHtml::image($button['imageUrl'],$label),$url,$options);
+ else
+ echo CHtml::link($label,$url,$options);
+ }
+}
diff --git a/framework/zii/widgets/grid/CCheckBoxColumn.php b/framework/zii/widgets/grid/CCheckBoxColumn.php
new file mode 100644
index 0000000..24356ac
--- /dev/null
+++ b/framework/zii/widgets/grid/CCheckBoxColumn.php
@@ -0,0 +1,187 @@
+<?php
+/**
+ * CCheckBoxColumn class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright &copy; 2008-2011 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ */
+
+Yii::import('zii.widgets.grid.CGridColumn');
+
+/**
+ * CCheckBoxColumn represents a grid view column of checkboxes.
+ *
+ * CCheckBoxColumn supports no selection (read-only), single selection and multiple selection.
+ * The mode is determined according to {@link selectableRows}. When in multiple selection mode, the header cell will display
+ * an additional checkbox, clicking on which will check or uncheck all of the checkboxes in the data cells.
+ *
+ * Additionally selecting a checkbox can select a grid view row (depending on {@link CGridView::selectableRows} value) if
+ * {@link selectableRows} is null (default).
+ *
+ * By default, the checkboxes rendered in data cells will have the values that are the same as
+ * the key values of the data model. One may change this by setting either {@link name} or
+ * {@link value}.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id: CCheckBoxColumn.php 3437 2011-11-07 15:03:58Z mdomba $
+ * @package zii.widgets.grid
+ * @since 1.1
+ */
+class CCheckBoxColumn extends CGridColumn
+{
+ /**
+ * @var string the attribute name of the data model. The corresponding attribute value will be rendered
+ * in each data cell as the checkbox value. Note that if {@link value} is specified, this property will be ignored.
+ * @see value
+ */
+ public $name;
+ /**
+ * @var string a PHP expression that will be evaluated for every data cell and whose result will be rendered
+ * in each data cell as the checkbox value. In this expression, the variable
+ * <code>$row</code> the row number (zero-based); <code>$data</code> the data model for the row;
+ * and <code>$this</code> the column object.
+ */
+ public $value;
+ /**
+ * @var string a PHP expression that will be evaluated for every data cell and whose result will
+ * determine if checkbox for each data cell is checked. In this expression, the variable
+ * <code>$row</code> the row number (zero-based); <code>$data</code> the data model for the row;
+ * and <code>$this</code> the column object.
+ * @since 1.1.4
+ */
+ public $checked;
+ /**
+ * @var array the HTML options for the data cell tags.
+ */
+ public $htmlOptions=array('class'=>'checkbox-column');
+ /**
+ * @var array the HTML options for the header cell tag.
+ */
+ public $headerHtmlOptions=array('class'=>'checkbox-column');
+ /**
+ * @var array the HTML options for the footer cell tag.
+ */
+ public $footerHtmlOptions=array('class'=>'checkbox-column');
+ /**
+ * @var array the HTML options for the checkboxes.
+ */
+ public $checkBoxHtmlOptions=array();
+ /**
+ * @var integer the number of rows that can be checked.
+ * Possible values:
+ * <ul>
+ * <li>0 - the state of the checkbox cannot be changed (read-only mode)</li>
+ * <li>1 - only one row can be checked. Checking a checkbox has nothing to do with selecting the row</li>
+ * <li>2 or more - multiple checkboxes can be checked. Checking a checkbox has nothing to do with selecting the row</li>
+ * <li>null - {@link CGridView::selectableRows} is used to control how many checkboxes can be checked.
+ * Cheking a checkbox will also select the row.</li>
+ * </ul>
+ * You may also call the JavaScript function <code>$.fn.yiiGridView.getChecked(containerID,columnID)</code>
+ * to retrieve the key values of the checked rows.
+ * @since 1.1.6
+ */
+ public $selectableRows=null;
+
+ /**
+ * Initializes the column.
+ * This method registers necessary client script for the checkbox column.
+ */
+ public function init()
+ {
+ if(isset($this->checkBoxHtmlOptions['name']))
+ $name=$this->checkBoxHtmlOptions['name'];
+ else
+ {
+ $name=$this->id;
+ if(substr($name,-2)!=='[]')
+ $name.='[]';
+ $this->checkBoxHtmlOptions['name']=$name;
+ }
+ $name=strtr($name,array('['=>"\\[",']'=>"\\]"));
+
+ if($this->selectableRows===null)
+ {
+ if(isset($this->checkBoxHtmlOptions['class']))
+ $this->checkBoxHtmlOptions['class'].=' select-on-check';
+ else
+ $this->checkBoxHtmlOptions['class']='select-on-check';
+ return;
+ }
+
+ $cball=$cbcode='';
+ if($this->selectableRows==0)
+ {
+ //.. read only
+ $cbcode="return false;";
+ }
+ elseif($this->selectableRows==1)
+ {
+ //.. only one can be checked, uncheck all other
+ $cbcode="$(\"input:not(#\"+this.id+\")[name='$name']\").prop('checked',false);";
+ }
+ else
+ {
+ //.. process check/uncheck all
+ $cball=<<<CBALL
+$('#{$this->id}_all').live('click',function() {
+ var checked=this.checked;
+ $("input[name='$name']").each(function() {this.checked=checked;});
+});
+
+CBALL;
+ $cbcode="$('#{$this->id}_all').prop('checked', $(\"input[name='$name']\").length==$(\"input[name='$name']:checked\").length);";
+ }
+
+ $js=$cball;
+ $js.=<<<EOD
+$("input[name='$name']").live('click', function() {
+ $cbcode
+});
+EOD;
+ Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$this->id,$js);
+ }
+
+ /**
+ * Renders the header cell content.
+ * This method will render a checkbox in the header when {@link selectableRows} is greater than 1
+ * or in case {@link selectableRows} is null when {@link CGridView::selectableRows} is greater than 1.
+ */
+ protected function renderHeaderCellContent()
+ {
+ if($this->selectableRows===null && $this->grid->selectableRows>1)
+ echo CHtml::checkBox($this->id.'_all',false,array('class'=>'select-on-check-all'));
+ else if($this->selectableRows>1)
+ echo CHtml::checkBox($this->id.'_all',false);
+ else
+ parent::renderHeaderCellContent();
+ }
+
+ /**
+ * Renders the data cell content.
+ * This method renders a checkbox in the data cell.
+ * @param integer $row the row number (zero-based)
+ * @param mixed $data the data associated with the row
+ */
+ protected function renderDataCellContent($row,$data)
+ {
+ if($this->value!==null)
+ $value=$this->evaluateExpression($this->value,array('data'=>$data,'row'=>$row));
+ else if($this->name!==null)
+ $value=CHtml::value($data,$this->name);
+ else
+ $value=$this->grid->dataProvider->keys[$row];
+
+ $checked = false;
+ if($this->checked!==null)
+ $checked=$this->evaluateExpression($this->checked,array('data'=>$data,'row'=>$row));
+
+ $options=$this->checkBoxHtmlOptions;
+ $name=$options['name'];
+ unset($options['name']);
+ $options['value']=$value;
+ $options['id']=$this->id.'_'.$row;
+ echo CHtml::checkBox($name,$checked,$options);
+ }
+}
diff --git a/framework/zii/widgets/grid/CDataColumn.php b/framework/zii/widgets/grid/CDataColumn.php
new file mode 100644
index 0000000..74c13fe
--- /dev/null
+++ b/framework/zii/widgets/grid/CDataColumn.php
@@ -0,0 +1,144 @@
+<?php
+/**
+ * CDataColumn class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright &copy; 2008-2011 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ */
+
+Yii::import('zii.widgets.grid.CGridColumn');
+
+/**
+ * CDataColumn represents a grid view column that is associated with a data attribute or expression.
+ *
+ * Either {@link name} or {@link value} should be specified. The former specifies
+ * a data attribute name, while the latter a PHP expression whose value should be rendered instead.
+ *
+ * The property {@link sortable} determines whether the grid view can be sorted according to this column.
+ * Note that the {@link name} should always be set if the column needs to be sortable. The {@link name}
+ * value will be used by {@link CSort} to render a clickable link in the header cell to trigger the sorting.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id: CDataColumn.php 3448 2011-11-18 10:21:42Z mdomba $
+ * @package zii.widgets.grid
+ * @since 1.1
+ */
+class CDataColumn extends CGridColumn
+{
+ /**
+ * @var string the attribute name of the data model. The corresponding attribute value will be rendered
+ * in each data cell. If {@link value} is specified, this property will be ignored
+ * unless the column needs to be sortable or filtered.
+ * @see value
+ * @see sortable
+ */
+ /**
+ * @var string the attribute name of the data model. Used for column sorting, filtering and to render the corresponding
+ * attribute value in each data cell. If {@link value} is specified it will be used to rendered the data cell instead of the attribute value.
+ * @see value
+ * @see sortable
+ */
+ public $name;
+ /**
+ * @var string a PHP expression that will be evaluated for every data cell and whose result will be rendered
+ * as the content of the data cells. In this expression, the variable
+ * <code>$row</code> the row number (zero-based); <code>$data</code> the data model for the row;
+ * and <code>$this</code> the column object.
+ */
+ public $value;
+ /**
+ * @var string the type of the attribute value. This determines how the attribute value is formatted for display.
+ * Valid values include those recognizable by {@link CGridView::formatter}, such as: raw, text, ntext, html, date, time,
+ * datetime, boolean, number, email, image, url. For more details, please refer to {@link CFormatter}.
+ * Defaults to 'text' which means the attribute value will be HTML-encoded.
+ */
+ public $type='text';
+ /**
+ * @var boolean whether the column is sortable. If so, the header cell will contain a link that may trigger the sorting.
+ * Defaults to true. Note that if {@link name} is not set, or if {@link name} is not allowed by {@link CSort},
+ * this property will be treated as false.
+ * @see name
+ */
+ public $sortable=true;
+ /**
+ * @var mixed the HTML code representing a filter input (eg a text field, a dropdown list)
+ * that is used for this data column. This property is effective only when
+ * {@link CGridView::filter} is set.
+ * If this property is not set, a text field will be generated as the filter input;
+ * If this property is an array, a dropdown list will be generated that uses this property value as
+ * the list options.
+ * If you don't want a filter for this data column, set this value to false.
+ * @since 1.1.1
+ */
+ public $filter;
+
+ /**
+ * Initializes the column.
+ */
+ public function init()
+ {
+ parent::init();
+ if($this->name===null)
+ $this->sortable=false;
+ if($this->name===null && $this->value===null)
+ throw new CException(Yii::t('zii','Either "name" or "value" must be specified for CDataColumn.'));
+ }
+
+ /**
+ * Renders the filter cell content.
+ * This method will render the {@link filter} as is if it is a string.
+ * If {@link filter} is an array, it is assumed to be a list of options, and a dropdown selector will be rendered.
+ * Otherwise if {@link filter} is not false, a text field is rendered.
+ * @since 1.1.1
+ */
+ protected function renderFilterCellContent()
+ {
+ if(is_string($this->filter))
+ echo $this->filter;
+ else if($this->filter!==false && $this->grid->filter!==null && $this->name!==null && strpos($this->name,'.')===false)
+ {
+ if(is_array($this->filter))
+ echo CHtml::activeDropDownList($this->grid->filter, $this->name, $this->filter, array('id'=>false,'prompt'=>''));
+ else if($this->filter===null)
+ echo CHtml::activeTextField($this->grid->filter, $this->name, array('id'=>false));
+ }
+ else
+ parent::renderFilterCellContent();
+ }
+
+ /**
+ * Renders the header cell content.
+ * This method will render a link that can trigger the sorting if the column is sortable.
+ */
+ protected function renderHeaderCellContent()
+ {
+ if($this->grid->enableSorting && $this->sortable && $this->name!==null)
+ echo $this->grid->dataProvider->getSort()->link($this->name,$this->header);
+ else if($this->name!==null && $this->header===null)
+ {
+ if($this->grid->dataProvider instanceof CActiveDataProvider)
+ echo CHtml::encode($this->grid->dataProvider->model->getAttributeLabel($this->name));
+ else
+ echo CHtml::encode($this->name);
+ }
+ else
+ parent::renderHeaderCellContent();
+ }
+
+ /**
+ * Renders the data cell content.
+ * This method evaluates {@link value} or {@link name} and renders the result.
+ * @param integer $row the row number (zero-based)
+ * @param mixed $data the data associated with the row
+ */
+ protected function renderDataCellContent($row,$data)
+ {
+ if($this->value!==null)
+ $value=$this->evaluateExpression($this->value,array('data'=>$data,'row'=>$row));
+ else if($this->name!==null)
+ $value=CHtml::value($data,$this->name);
+ echo $value===null ? $this->grid->nullDisplay : $this->grid->getFormatter()->format($value,$this->type);
+ }
+}
diff --git a/framework/zii/widgets/grid/CGridColumn.php b/framework/zii/widgets/grid/CGridColumn.php
new file mode 100644
index 0000000..b66e51e
--- /dev/null
+++ b/framework/zii/widgets/grid/CGridColumn.php
@@ -0,0 +1,193 @@
+<?php
+/**
+ * CGridColumn class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright &copy; 2008-2011 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ */
+
+/**
+ * CGridColumn is the base class for all grid view column classes.
+ *
+ * A CGridColumn object represents the specification for rendering the cells in
+ * a particular grid view column.
+ *
+ * In a column, there is one header cell, multiple data cells, and an optional footer cell.
+ * Child classes may override {@link renderHeaderCellContent}, {@link renderDataCellContent}
+ * and {@link renderFooterCellContent} to customize how these cells are rendered.
+ *
+ * @property boolean $hasFooter Whether this column has a footer cell.
+ * This is determined based on whether {@link footer} is set.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id: CGridColumn.php 3426 2011-10-25 00:01:09Z alexander.makarow $
+ * @package zii.widgets.grid
+ * @since 1.1
+ */
+abstract class CGridColumn extends CComponent
+{
+ /**
+ * @var string the ID of this column. This value should be unique among all grid view columns.
+ * If this is set, it will be assigned one automatically.
+ */
+ public $id;
+ /**
+ * @var CGridView the grid view object that owns this column.
+ */
+ public $grid;
+ /**
+ * @var string the header cell text. Note that it will not be HTML-encoded.
+ */
+ public $header;
+ /**
+ * @var string the footer cell text. Note that it will not be HTML-encoded.
+ */
+ public $footer;
+ /**
+ * @var boolean whether this column is visible. Defaults to true.
+ */
+ public $visible=true;
+ /**
+ * @var string a PHP expression that is evaluated for every data cell and whose result
+ * is used as the CSS class name for the data cell. In this expression, the variable
+ * <code>$row</code> the row number (zero-based); <code>$data</code> the data model for the row;
+ * and <code>$this</code> the column object.
+ */
+ public $cssClassExpression;
+ /**
+ * @var array the HTML options for the data cell tags.
+ */
+ public $htmlOptions=array();
+ /**
+ * @var array the HTML options for the header cell tag.
+ */
+ public $headerHtmlOptions=array();
+ /**
+ * @var array the HTML options for the footer cell tag.
+ */
+ public $footerHtmlOptions=array();
+
+ /**
+ * Constructor.
+ * @param CGridView $grid the grid view that owns this column.
+ */
+ public function __construct($grid)
+ {
+ $this->grid=$grid;
+ }
+
+ /**
+ * Initializes the column.
+ * This method is invoked by the grid view when it initializes itself before rendering.
+ * You may override this method to prepare the column for rendering.
+ */
+ public function init()
+ {
+ }
+
+ /**
+ * @return boolean whether this column has a footer cell.
+ * This is determined based on whether {@link footer} is set.
+ */
+ public function getHasFooter()
+ {
+ return $this->footer!==null;
+ }
+
+ /**
+ * Renders the filter cell.
+ * @since 1.1.1
+ */
+ public function renderFilterCell()
+ {
+ echo "<td>";
+ $this->renderFilterCellContent();
+ echo "</td>";
+ }
+
+ /**
+ * Renders the header cell.
+ */
+ public function renderHeaderCell()
+ {
+ $this->headerHtmlOptions['id']=$this->id;
+ echo CHtml::openTag('th',$this->headerHtmlOptions);
+ $this->renderHeaderCellContent();
+ echo "</th>";
+ }
+
+ /**
+ * Renders a data cell.
+ * @param integer $row the row number (zero-based)
+ */
+ public function renderDataCell($row)
+ {
+ $data=$this->grid->dataProvider->data[$row];
+ $options=$this->htmlOptions;
+ if($this->cssClassExpression!==null)
+ {
+ $class=$this->evaluateExpression($this->cssClassExpression,array('row'=>$row,'data'=>$data));
+ if(isset($options['class']))
+ $options['class'].=' '.$class;
+ else
+ $options['class']=$class;
+ }
+ echo CHtml::openTag('td',$options);
+ $this->renderDataCellContent($row,$data);
+ echo '</td>';
+ }
+
+ /**
+ * Renders the footer cell.
+ */
+ public function renderFooterCell()
+ {
+ echo CHtml::openTag('td',$this->footerHtmlOptions);
+ $this->renderFooterCellContent();
+ echo '</td>';
+ }
+
+ /**
+ * Renders the header cell content.
+ * The default implementation simply renders {@link header}.
+ * This method may be overridden to customize the rendering of the header cell.
+ */
+ protected function renderHeaderCellContent()
+ {
+ echo trim($this->header)!=='' ? $this->header : $this->grid->blankDisplay;
+ }
+
+ /**
+ * Renders the footer cell content.
+ * The default implementation simply renders {@link footer}.
+ * This method may be overridden to customize the rendering of the footer cell.
+ */
+ protected function renderFooterCellContent()
+ {
+ echo trim($this->footer)!=='' ? $this->footer : $this->grid->blankDisplay;
+ }
+
+ /**
+ * Renders the data cell content.
+ * This method SHOULD be overridden to customize the rendering of the data cell.
+ * @param integer $row the row number (zero-based)
+ * @param mixed $data the data associated with the row
+ */
+ protected function renderDataCellContent($row,$data)
+ {
+ echo $this->grid->blankDisplay;
+ }
+
+ /**
+ * Renders the filter cell content.
+ * The default implementation simply renders a space.
+ * This method may be overridden to customize the rendering of the filter cell (if any).
+ * @since 1.1.1
+ */
+ protected function renderFilterCellContent()
+ {
+ echo $this->grid->blankDisplay;
+ }
+}
diff --git a/framework/zii/widgets/grid/CGridView.php b/framework/zii/widgets/grid/CGridView.php
new file mode 100644
index 0000000..d334c10
--- /dev/null
+++ b/framework/zii/widgets/grid/CGridView.php
@@ -0,0 +1,550 @@
+<?php
+/**
+ * CGridView class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright &copy; 2008-2011 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ */
+
+Yii::import('zii.widgets.CBaseListView');
+Yii::import('zii.widgets.grid.CDataColumn');
+Yii::import('zii.widgets.grid.CLinkColumn');
+Yii::import('zii.widgets.grid.CButtonColumn');
+Yii::import('zii.widgets.grid.CCheckBoxColumn');
+
+/**
+ * CGridView displays a list of data items in terms of a table.
+ *
+ * Each row of the table represents the data of a single data item, and a column usually represents
+ * an attribute of the item (some columns may correspond to complex expression of attributes or static text).
+ *
+ * CGridView supports both sorting and pagination of the data items. The sorting
+ * and pagination can be done in AJAX mode or normal page request. A benefit of using CGridView is that
+ * when the user browser disables JavaScript, the sorting and pagination automatically degenerate
+ * to normal page requests and are still functioning as expected.
+ *
+ * CGridView should be used together with a {@link IDataProvider data provider}, preferrably a
+ * {@link CActiveDataProvider}.
+ *
+ * The minimal code needed to use CGridView is as follows:
+ *
+ * <pre>
+ * $dataProvider=new CActiveDataProvider('Post');
+ *
+ * $this->widget('zii.widgets.grid.CGridView', array(
+ * 'dataProvider'=>$dataProvider,
+ * ));
+ * </pre>
+ *
+ * The above code first creates a data provider for the <code>Post</code> ActiveRecord class.
+ * It then uses CGridView to display every attribute in every <code>Post</code> instance.
+ * The displayed table is equiped with sorting and pagination functionality.
+ *
+ * In order to selectively display attributes with different formats, we may configure the
+ * {@link CGridView::columns} property. For example, we may specify only the <code>title</code>
+ * and <code>create_time</code> attributes to be displayed, and the <code>create_time</code>
+ * should be properly formatted to show as a time. We may also display the attributes of the related
+ * objects using the dot-syntax as shown below:
+ *
+ * <pre>
+ * $this->widget('zii.widgets.grid.CGridView', array(
+ * 'dataProvider'=>$dataProvider,
+ * 'columns'=>array(
+ * 'title', // display the 'title' attribute
+ * 'category.name', // display the 'name' attribute of the 'category' relation
+ * 'content:html', // display the 'content' attribute as purified HTML
+ * array( // display 'create_time' using an expression
+ * 'name'=>'create_time',
+ * 'value'=>'date("M j, Y", $data->create_time)',
+ * ),
+ * array( // display 'author.username' using an expression
+ * 'name'=>'authorName',
+ * 'value'=>'$data->author->username',
+ * ),
+ * array( // display a column with "view", "update" and "delete" buttons
+ * 'class'=>'CButtonColumn',
+ * ),
+ * ),
+ * ));
+ * </pre>
+ *
+ * Please refer to {@link columns} for more details about how to configure this property.
+ *
+ * @property boolean $hasFooter Whether the table should render a footer.
+ * This is true if any of the {@link columns} has a true {@link CGridColumn::hasFooter} value.
+ * @property CFormatter $formatter The formatter instance. Defaults to the 'format' application component.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id: CGridView.php 3551 2012-02-02 12:45:25Z mdomba $
+ * @package zii.widgets.grid
+ * @since 1.1
+ */
+class CGridView extends CBaseListView
+{
+ const FILTER_POS_HEADER='header';
+ const FILTER_POS_FOOTER='footer';
+ const FILTER_POS_BODY='body';
+
+ private $_formatter;
+ /**
+ * @var array grid column configuration. Each array element represents the configuration
+ * for one particular grid column which can be either a string or an array.
+ *
+ * When a column is specified as a string, it should be in the format of "name:type:header",
+ * where "type" and "header" are optional. A {@link CDataColumn} instance will be created in this case,
+ * whose {@link CDataColumn::name}, {@link CDataColumn::type} and {@link CDataColumn::header}
+ * properties will be initialized accordingly.
+ *
+ * When a column is specified as an array, it will be used to create a grid column instance, where
+ * the 'class' element specifies the column class name (defaults to {@link CDataColumn} if absent).
+ * Currently, these official column classes are provided: {@link CDataColumn},
+ * {@link CLinkColumn}, {@link CButtonColumn} and {@link CCheckBoxColumn}.
+ */
+ public $columns=array();
+ /**
+ * @var array the CSS class names for the table body rows. If multiple CSS class names are given,
+ * they will be assigned to the rows sequentially and repeatedly. This property is ignored
+ * if {@link rowCssClassExpression} is set. Defaults to <code>array('odd', 'even')</code>.
+ * @see rowCssClassExpression
+ */
+ public $rowCssClass=array('odd','even');
+ /**
+ * @var string a PHP expression that is evaluated for every table body row and whose result
+ * is used as the CSS class name for the row. In this expression, the variable <code>$row</code>
+ * stands for the row number (zero-based), <code>$data</code> is the data model associated with
+ * the row, and <code>$this</code> is the grid object.
+ * @see rowCssClass
+ */
+ public $rowCssClassExpression;
+ /**
+ * @var boolean whether to display the table even when there is no data. Defaults to true.
+ * The {@link emptyText} will be displayed to indicate there is no data.
+ */
+ public $showTableOnEmpty=true;
+ /**
+ * @var mixed the ID of the container whose content may be updated with an AJAX response.
+ * Defaults to null, meaning the container for this grid view instance.
+ * If it is set false, it means sorting and pagination will be performed in normal page requests
+ * instead of AJAX requests. If the sorting and pagination should trigger the update of multiple
+ * containers' content in AJAX fashion, these container IDs may be listed here (separated with comma).
+ */
+ public $ajaxUpdate;
+ /**
+ * @var string the jQuery selector of the HTML elements that may trigger AJAX updates when they are clicked.
+ * If not set, the pagination links and the sorting links will trigger AJAX updates.
+ * @since 1.1.7
+ */
+ public $updateSelector;
+ /**
+ * @var string a javascript function that will be invoked if an AJAX update error occurs.
+ *
+ * The function signature is <code>function(xhr, textStatus, errorThrown, errorMessage)</code>
+ * <ul>
+ * <li><code>xhr</code> is the XMLHttpRequest object.</li>
+ * <li><code>textStatus</code> is a string describing the type of error that occurred.
+ * Possible values (besides null) are "timeout", "error", "notmodified" and "parsererror"</li>
+ * <li><code>errorThrown</code> is an optional exception object, if one occurred.</li>
+ * <li><code>errorMessage</code> is the CGridView default error message derived from xhr and errorThrown.
+ * Usefull if you just want to display this error differently. CGridView by default displays this error with an javascript.alert()</li>
+ * </ul>
+ * Note: This handler is not called for JSONP requests, because they do not use an XMLHttpRequest.
+ *
+ * Example (add in a call to CGridView):
+ * <pre>
+ * ...
+ * 'ajaxUpdateError'=>'function(xhr,ts,et,err){ $("#myerrordiv").text(err); }',
+ * ...
+ * </pre>
+ */
+ public $ajaxUpdateError;
+ /**
+ * @var string the name of the GET variable that indicates the request is an AJAX request triggered
+ * by this widget. Defaults to 'ajax'. This is effective only when {@link ajaxUpdate} is not false.
+ */
+ public $ajaxVar='ajax';
+ /**
+ * @var mixed the URL for the AJAX requests should be sent to. {@link CHtml::normalizeUrl()} will be
+ * called on this property. If not set, the current page URL will be used for AJAX requests.
+ * @since 1.1.8
+ */
+ public $ajaxUrl;
+ /**
+ * @var string a javascript function that will be invoked before an AJAX update occurs.
+ * The function signature is <code>function(id,options)</code> where 'id' refers to the ID of the grid view,
+ * 'options' the AJAX request options (see jQuery.ajax api manual).
+ */
+ public $beforeAjaxUpdate;
+ /**
+ * @var string a javascript function that will be invoked after a successful AJAX response is received.
+ * The function signature is <code>function(id, data)</code> where 'id' refers to the ID of the grid view,
+ * 'data' the received ajax response data.
+ */
+ public $afterAjaxUpdate;
+ /**
+ * @var string a javascript function that will be invoked after the row selection is changed.
+ * The function signature is <code>function(id)</code> where 'id' refers to the ID of the grid view.
+ * In this function, you may use <code>$.fn.yiiGridView.getSelection(id)</code> to get the key values
+ * of the currently selected rows.
+ * @see selectableRows
+ */
+ public $selectionChanged;
+ /**
+ * @var integer the number of table body rows that can be selected. If 0, it means rows cannot be selected.
+ * If 1, only one row can be selected. If 2 or any other number, it means multiple rows can be selected.
+ * A selected row will have a CSS class named 'selected'. You may also call the JavaScript function
+ * <code>$.fn.yiiGridView.getSelection(containerID)</code> to retrieve the key values of the selected rows.
+ */
+ public $selectableRows=1;
+ /**
+ * @var string the base script URL for all grid view resources (eg javascript, CSS file, images).
+ * Defaults to null, meaning using the integrated grid view resources (which are published as assets).
+ */
+ public $baseScriptUrl;
+ /**
+ * @var string the URL of the CSS file used by this grid view. Defaults to null, meaning using the integrated
+ * CSS file. If this is set false, you are responsible to explicitly include the necessary CSS file in your page.
+ */
+ public $cssFile;
+ /**
+ * @var string the text to be displayed in a data cell when a data value is null. This property will NOT be HTML-encoded
+ * when rendering. Defaults to an HTML blank.
+ */
+ public $nullDisplay='&nbsp;';
+ /**
+ * @var string the text to be displayed in an empty grid cell. This property will NOT be HTML-encoded when rendering. Defaults to an HTML blank.
+ * This differs from {@link nullDisplay} in that {@link nullDisplay} is only used by {@link CDataColumn} to render
+ * null data values.
+ * @since 1.1.7
+ */
+ public $blankDisplay='&nbsp;';
+ /**
+ * @var string the CSS class name that will be assigned to the widget container element
+ * when the widget is updating its content via AJAX. Defaults to 'grid-view-loading'.
+ * @since 1.1.1
+ */
+ public $loadingCssClass='grid-view-loading';
+ /**
+ * @var string the CSS class name for the table row element containing all filter input fields. Defaults to 'filters'.
+ * @see filter
+ * @since 1.1.1
+ */
+ public $filterCssClass='filters';
+ /**
+ * @var string whether the filters should be displayed in the grid view. Valid values include:
+ * <ul>
+ * <li>header: the filters will be displayed on top of each column's header cell.</li>
+ * <li>body: the filters will be displayed right below each column's header cell.</li>
+ * <li>footer: the filters will be displayed below each column's footer cell.</li>
+ * </ul>
+ * @see filter
+ * @since 1.1.1
+ */
+ public $filterPosition='body';
+ /**
+ * @var CModel the model instance that keeps the user-entered filter data. When this property is set,
+ * the grid view will enable column-based filtering. Each data column by default will display a text field
+ * at the top that users can fill in to filter the data.
+ * Note that in order to show an input field for filtering, a column must have its {@link CDataColumn::name}
+ * property set or have {@link CDataColumn::filter} as the HTML code for the input field.
+ * When this property is not set (null) the filtering is disabled.
+ * @since 1.1.1
+ */
+ public $filter;
+ /**
+ * @var boolean whether to hide the header cells of the grid. When this is true, header cells
+ * will not be rendered, which means the grid cannot be sorted anymore since the sort links are located
+ * in the header. Defaults to false.
+ * @since 1.1.1
+ */
+ public $hideHeader=false;
+
+ /**
+ * Initializes the grid view.
+ * This method will initialize required property values and instantiate {@link columns} objects.
+ */
+ public function init()
+ {
+ parent::init();
+
+ if(!isset($this->htmlOptions['class']))
+ $this->htmlOptions['class']='grid-view';
+
+ if($this->baseScriptUrl===null)
+ $this->baseScriptUrl=Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('zii.widgets.assets')).'/gridview';
+
+ if($this->cssFile!==false)
+ {
+ if($this->cssFile===null)
+ $this->cssFile=$this->baseScriptUrl.'/styles.css';
+ Yii::app()->getClientScript()->registerCssFile($this->cssFile);
+ }
+
+ $this->initColumns();
+ }
+
+ /**
+ * Creates column objects and initializes them.
+ */
+ protected function initColumns()
+ {
+ if($this->columns===array())
+ {
+ if($this->dataProvider instanceof CActiveDataProvider)
+ $this->columns=$this->dataProvider->model->attributeNames();
+ else if($this->dataProvider instanceof IDataProvider)
+ {
+ // use the keys of the first row of data as the default columns
+ $data=$this->dataProvider->getData();
+ if(isset($data[0]) && is_array($data[0]))
+ $this->columns=array_keys($data[0]);
+ }
+ }
+ $id=$this->getId();
+ foreach($this->columns as $i=>$column)
+ {
+ if(is_string($column))
+ $column=$this->createDataColumn($column);
+ else
+ {
+ if(!isset($column['class']))
+ $column['class']='CDataColumn';
+ $column=Yii::createComponent($column, $this);
+ }
+ if(!$column->visible)
+ {
+ unset($this->columns[$i]);
+ continue;
+ }
+ if($column->id===null)
+ $column->id=$id.'_c'.$i;
+ $this->columns[$i]=$column;
+ }
+
+ foreach($this->columns as $column)
+ $column->init();
+ }
+
+ /**
+ * Creates a {@link CDataColumn} based on a shortcut column specification string.
+ * @param string $text the column specification string
+ * @return CDataColumn the column instance
+ */
+ protected function createDataColumn($text)
+ {
+ if(!preg_match('/^([\w\.]+)(:(\w*))?(:(.*))?$/',$text,$matches))
+ throw new CException(Yii::t('zii','The column must be specified in the format of "Name:Type:Label", where "Type" and "Label" are optional.'));
+ $column=new CDataColumn($this);
+ $column->name=$matches[1];
+ if(isset($matches[3]) && $matches[3]!=='')
+ $column->type=$matches[3];
+ if(isset($matches[5]))
+ $column->header=$matches[5];
+ return $column;
+ }
+
+ /**
+ * Registers necessary client scripts.
+ */
+ public function registerClientScript()
+ {
+ $id=$this->getId();
+
+ if($this->ajaxUpdate===false)
+ $ajaxUpdate=false;
+ else
+ $ajaxUpdate=array_unique(preg_split('/\s*,\s*/',$this->ajaxUpdate.','.$id,-1,PREG_SPLIT_NO_EMPTY));
+ $options=array(
+ 'ajaxUpdate'=>$ajaxUpdate,
+ 'ajaxVar'=>$this->ajaxVar,
+ 'pagerClass'=>$this->pagerCssClass,
+ 'loadingClass'=>$this->loadingCssClass,
+ 'filterClass'=>$this->filterCssClass,
+ 'tableClass'=>$this->itemsCssClass,
+ 'selectableRows'=>$this->selectableRows,
+ );
+ if($this->ajaxUrl!==null)
+ $options['url']=CHtml::normalizeUrl($this->ajaxUrl);
+ if($this->updateSelector!==null)
+ $options['updateSelector']=$this->updateSelector;
+ if($this->enablePagination)
+ $options['pageVar']=$this->dataProvider->getPagination()->pageVar;
+ if($this->beforeAjaxUpdate!==null)
+ $options['beforeAjaxUpdate']=(strpos($this->beforeAjaxUpdate,'js:')!==0 ? 'js:' : '').$this->beforeAjaxUpdate;
+ if($this->afterAjaxUpdate!==null)
+ $options['afterAjaxUpdate']=(strpos($this->afterAjaxUpdate,'js:')!==0 ? 'js:' : '').$this->afterAjaxUpdate;
+ if($this->ajaxUpdateError!==null)
+ $options['ajaxUpdateError']=(strpos($this->ajaxUpdateError,'js:')!==0 ? 'js:' : '').$this->ajaxUpdateError;
+ if($this->selectionChanged!==null)
+ $options['selectionChanged']=(strpos($this->selectionChanged,'js:')!==0 ? 'js:' : '').$this->selectionChanged;
+
+ $options=CJavaScript::encode($options);
+ $cs=Yii::app()->getClientScript();
+ $cs->registerCoreScript('jquery');
+ $cs->registerCoreScript('bbq');
+ $cs->registerScriptFile($this->baseScriptUrl.'/jquery.yiigridview.js',CClientScript::POS_END);
+ $cs->registerScript(__CLASS__.'#'.$id,"jQuery('#$id').yiiGridView($options);");
+ }
+
+ /**
+ * Renders the data items for the grid view.
+ */
+ public function renderItems()
+ {
+ if($this->dataProvider->getItemCount()>0 || $this->showTableOnEmpty)
+ {
+ echo "<table class=\"{$this->itemsCssClass}\">\n";
+ $this->renderTableHeader();
+ ob_start();
+ $this->renderTableBody();
+ $body=ob_get_clean();
+ $this->renderTableFooter();
+ echo $body; // TFOOT must appear before TBODY according to the standard.
+ echo "</table>";
+ }
+ else
+ $this->renderEmptyText();
+ }
+
+ /**
+ * Renders the table header.
+ */
+ public function renderTableHeader()
+ {
+ if(!$this->hideHeader)
+ {
+ echo "<thead>\n";
+
+ if($this->filterPosition===self::FILTER_POS_HEADER)
+ $this->renderFilter();
+
+ echo "<tr>\n";
+ foreach($this->columns as $column)
+ $column->renderHeaderCell();
+ echo "</tr>\n";
+
+ if($this->filterPosition===self::FILTER_POS_BODY)
+ $this->renderFilter();
+
+ echo "</thead>\n";
+ }
+ else if($this->filter!==null && ($this->filterPosition===self::FILTER_POS_HEADER || $this->filterPosition===self::FILTER_POS_BODY))
+ {
+ echo "<thead>\n";
+ $this->renderFilter();
+ echo "</thead>\n";
+ }
+ }
+
+ /**
+ * Renders the filter.
+ * @since 1.1.1
+ */
+ public function renderFilter()
+ {
+ if($this->filter!==null)
+ {
+ echo "<tr class=\"{$this->filterCssClass}\">\n";
+ foreach($this->columns as $column)
+ $column->renderFilterCell();
+ echo "</tr>\n";
+ }
+ }
+
+ /**
+ * Renders the table footer.
+ */
+ public function renderTableFooter()
+ {
+ $hasFilter=$this->filter!==null && $this->filterPosition===self::FILTER_POS_FOOTER;
+ $hasFooter=$this->getHasFooter();
+ if($hasFilter || $hasFooter)
+ {
+ echo "<tfoot>\n";
+ if($hasFooter)
+ {
+ echo "<tr>\n";
+ foreach($this->columns as $column)
+ $column->renderFooterCell();
+ echo "</tr>\n";
+ }
+ if($hasFilter)
+ $this->renderFilter();
+ echo "</tfoot>\n";
+ }
+ }
+
+ /**
+ * Renders the table body.
+ */
+ public function renderTableBody()
+ {
+ $data=$this->dataProvider->getData();
+ $n=count($data);
+ echo "<tbody>\n";
+
+ if($n>0)
+ {
+ for($row=0;$row<$n;++$row)
+ $this->renderTableRow($row);
+ }
+ else
+ {
+ echo '<tr><td colspan="'.count($this->columns).'">';
+ $this->renderEmptyText();
+ echo "</td></tr>\n";
+ }
+ echo "</tbody>\n";
+ }
+
+ /**
+ * Renders a table body row.
+ * @param integer $row the row number (zero-based).
+ */
+ public function renderTableRow($row)
+ {
+ if($this->rowCssClassExpression!==null)
+ {
+ $data=$this->dataProvider->data[$row];
+ echo '<tr class="'.$this->evaluateExpression($this->rowCssClassExpression,array('row'=>$row,'data'=>$data)).'">';
+ }
+ else if(is_array($this->rowCssClass) && ($n=count($this->rowCssClass))>0)
+ echo '<tr class="'.$this->rowCssClass[$row%$n].'">';
+ else
+ echo '<tr>';
+ foreach($this->columns as $column)
+ $column->renderDataCell($row);
+ echo "</tr>\n";
+ }
+
+ /**
+ * @return boolean whether the table should render a footer.
+ * This is true if any of the {@link columns} has a true {@link CGridColumn::hasFooter} value.
+ */
+ public function getHasFooter()
+ {
+ foreach($this->columns as $column)
+ if($column->getHasFooter())
+ return true;
+ return false;
+ }
+
+ /**
+ * @return CFormatter the formatter instance. Defaults to the 'format' application component.
+ */
+ public function getFormatter()
+ {
+ if($this->_formatter===null)
+ $this->_formatter=Yii::app()->format;
+ return $this->_formatter;
+ }
+
+ /**
+ * @param CFormatter $value the formatter instance
+ */
+ public function setFormatter($value)
+ {
+ $this->_formatter=$value;
+ }
+}
diff --git a/framework/zii/widgets/grid/CLinkColumn.php b/framework/zii/widgets/grid/CLinkColumn.php
new file mode 100644
index 0000000..2dd6c22
--- /dev/null
+++ b/framework/zii/widgets/grid/CLinkColumn.php
@@ -0,0 +1,96 @@
+<?php
+/**
+ * CLinkColumn class file.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright &copy; 2008-2011 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ */
+
+Yii::import('zii.widgets.grid.CGridColumn');
+
+/**
+ * CLinkColumn represents a grid view column that renders a hyperlink in each of its data cells.
+ *
+ * The {@link label} and {@link url} properties determine how each hyperlink will be rendered.
+ * The {@link labelExpression}, {@link urlExpression} properties may be used instead if they are available.
+ * In addition, if {@link imageUrl} is set, an image link will be rendered.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Id: CLinkColumn.php 3424 2011-10-24 20:13:19Z mdomba $
+ * @package zii.widgets.grid
+ * @since 1.1
+ */
+class CLinkColumn extends CGridColumn
+{
+ /**
+ * @var string the label to the hyperlinks in the data cells. Note that the label will not
+ * be HTML-encoded when rendering. This property is ignored if {@link labelExpression} is set.
+ * @see labelExpression
+ */
+ public $label='Link';
+ /**
+ * @var string a PHP expression that will be evaluated for every data cell and whose result will be rendered
+ * as the label of the hyperlink of the data cells. In this expression, the variable
+ * <code>$row</code> the row number (zero-based); <code>$data</code> the data model for the row;
+ * and <code>$this</code> the column object.
+ */
+ public $labelExpression;
+ /**
+ * @var string the URL to the image. If this is set, an image link will be rendered.
+ */
+ public $imageUrl;
+ /**
+ * @var string the URL of the hyperlinks in the data cells.
+ * This property is ignored if {@link urlExpression} is set.
+ * @see urlExpression
+ */
+ public $url='javascript:void(0)';
+ /**
+ * @var string a PHP expression that will be evaluated for every data cell and whose result will be rendered
+ * as the URL of the hyperlink of the data cells. In this expression, the variable
+ * <code>$row</code> the row number (zero-based); <code>$data</code> the data model for the row;
+ * and <code>$this</code> the column object.
+ */
+ public $urlExpression;
+ /**
+ * @var array the HTML options for the data cell tags.
+ */
+ public $htmlOptions=array('class'=>'link-column');
+ /**
+ * @var array the HTML options for the header cell tag.
+ */
+ public $headerHtmlOptions=array('class'=>'link-column');
+ /**
+ * @var array the HTML options for the footer cell tag.
+ */
+ public $footerHtmlOptions=array('class'=>'link-column');
+ /**
+ * @var array the HTML options for the hyperlinks
+ */
+ public $linkHtmlOptions=array();
+
+ /**
+ * Renders the data cell content.
+ * This method renders a hyperlink in the data cell.
+ * @param integer $row the row number (zero-based)
+ * @param mixed $data the data associated with the row
+ */
+ protected function renderDataCellContent($row,$data)
+ {
+ if($this->urlExpression!==null)
+ $url=$this->evaluateExpression($this->urlExpression,array('data'=>$data,'row'=>$row));
+ else
+ $url=$this->url;
+ if($this->labelExpression!==null)
+ $label=$this->evaluateExpression($this->labelExpression,array('data'=>$data,'row'=>$row));
+ else
+ $label=$this->label;
+ $options=$this->linkHtmlOptions;
+ if(is_string($this->imageUrl))
+ echo CHtml::link(CHtml::image($this->imageUrl,$label),$url,$options);
+ else
+ echo CHtml::link($label,$url,$options);
+ }
+}