Advertisement
Guest User

unzend.com_282

a guest
Jun 22nd, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 23.10 KB | None | 0 0
  1. <?php
  2. // Ioncube Decoder Unzend.Com Email unzend@gmail.com
  3. // http://www.unzend.com
  4. /**
  5.  * CGridView class file.
  6.  *
  7.  * @author Qiang Xue <qiang.xue@gmail.com>
  8.  * @link http://www.yiiframework.com/
  9.  * @copyright 2008-2013 Yii Software LLC
  10.  * @license http://www.yiiframework.com/license/
  11.  */
  12.  
  13. Yii::import('zii.widgets.CBaseListView');
  14. Yii::import('zii.widgets.grid.CDataColumn');
  15. Yii::import('zii.widgets.grid.CLinkColumn');
  16. Yii::import('zii.widgets.grid.CButtonColumn');
  17. Yii::import('zii.widgets.grid.CCheckBoxColumn');
  18.  
  19. /**
  20.  * CGridView displays a list of data items in terms of a table.
  21.  *
  22.  * Each row of the table represents the data of a single data item, and a column usually represents
  23.  * an attribute of the item (some columns may correspond to complex expression of attributes or static text).
  24.  *
  25.  * CGridView supports both sorting and pagination of the data items. The sorting
  26.  * and pagination can be done in AJAX mode or normal page request. A benefit of using CGridView is that
  27.  * when the user browser disables JavaScript, the sorting and pagination automatically degenerate
  28.  * to normal page requests and are still functioning as expected.
  29.  *
  30.  * CGridView should be used together with a {@link IDataProvider data provider}, preferrably a
  31.  * {@link CActiveDataProvider}.
  32.  *
  33.  * The minimal code needed to use CGridView is as follows:
  34.  *
  35.  * <pre>
  36.  * $dataProvider=new CActiveDataProvider('Post');
  37.  *
  38.  * $this->widget('zii.widgets.grid.CGridView', array(
  39.  *     'dataProvider'=>$dataProvider,
  40.  * ));
  41.  * </pre>
  42.  *
  43.  * The above code first creates a data provider for the <code>Post</code> ActiveRecord class.
  44.  * It then uses CGridView to display every attribute in every <code>Post</code> instance.
  45.  * The displayed table is equiped with sorting and pagination functionality.
  46.  *
  47.  * In order to selectively display attributes with different formats, we may configure the
  48.  * {@link CGridView::columns} property. For example, we may specify only the <code>title</code>
  49.  * and <code>create_time</code> attributes to be displayed, and the <code>create_time</code>
  50.  * should be properly formatted to show as a time. We may also display the attributes of the related
  51.  * objects using the dot-syntax as shown below:
  52.  *
  53.  * <pre>
  54.  * $this->widget('zii.widgets.grid.CGridView', array(
  55.  *     'dataProvider'=>$dataProvider,
  56.  *     'columns'=>array(
  57.  *         'title',          // display the 'title' attribute
  58.  *         'category.name',  // display the 'name' attribute of the 'category' relation
  59.  *         'content:html',   // display the 'content' attribute as purified HTML
  60.  *         array(            // display 'create_time' using an expression
  61.  *             'name'=>'create_time',
  62.  *             'value'=>'date("M j, Y", $data->create_time)',
  63.  *         ),
  64.  *         array(            // display 'author.username' using an expression
  65.  *             'name'=>'authorName',
  66.  *             'value'=>'$data->author->username',
  67.  *         ),
  68.  *         array(            // display a column with "view", "update" and "delete" buttons
  69.  *             'class'=>'CButtonColumn',
  70.  *         ),
  71.  *     ),
  72.  * ));
  73.  * </pre>
  74.  *
  75.  * Please refer to {@link columns} for more details about how to configure this property.
  76.  *
  77.  * @property boolean $hasFooter Whether the table should render a footer.
  78.  * This is true if any of the {@link columns} has a true {@link CGridColumn::hasFooter} value.
  79.  * @property CFormatter $formatter The formatter instance. Defaults to the 'format' application component.
  80.  *
  81.  * @author Qiang Xue <qiang.xue@gmail.com>
  82.  * @package zii.widgets.grid
  83.  * @since 1.1
  84.  */
  85. class CGridView extends CBaseListView
  86. {
  87.     const FILTER_POS_HEADER='header';
  88.     const FILTER_POS_FOOTER='footer';
  89.     const FILTER_POS_BODY='body';
  90.  
  91.     private $_formatter;
  92.     /**
  93.      * @var array grid column configuration. Each array element represents the configuration
  94.      * for one particular grid column which can be either a string or an array.
  95.      *
  96.      * When a column is specified as a string, it should be in the format of "name:type:header",
  97.      * where "type" and "header" are optional. A {@link CDataColumn} instance will be created in this case,
  98.      * whose {@link CDataColumn::name}, {@link CDataColumn::type} and {@link CDataColumn::header}
  99.      * properties will be initialized accordingly.
  100.      *
  101.      * When a column is specified as an array, it will be used to create a grid column instance, where
  102.      * the 'class' element specifies the column class name (defaults to {@link CDataColumn} if absent).
  103.      * Currently, these official column classes are provided: {@link CDataColumn},
  104.      * {@link CLinkColumn}, {@link CButtonColumn} and {@link CCheckBoxColumn}.
  105.      */
  106.     public $columns=array();
  107.     /**
  108.      * @var array the CSS class names for the table body rows. If multiple CSS class names are given,
  109.      * they will be assigned to the rows sequentially and repeatedly. This property is ignored
  110.      * if {@link rowCssClassExpression} is set. Defaults to <code>array('odd', 'even')</code>.
  111.      * @see rowCssClassExpression
  112.      */
  113.     public $rowCssClass=array('odd','even');
  114.     /**
  115.      * @var string a PHP expression that is evaluated for every table body row and whose result
  116.      * is used as the CSS class name for the row. In this expression, you can use the following variables:
  117.      * <ul>
  118.      *   <li><code>$row</code> the row number (zero-based)</li>
  119.      *   <li><code>$data</code> the data model for the row</li>
  120.      *   <li><code>$this</code> the grid view object</li>
  121.      * </ul>
  122.      * The PHP expression will be evaluated using {@link evaluateExpression}.
  123.      *
  124.      * A PHP expression can be any PHP code that has a value. To learn more about what an expression is,
  125.      * please refer to the {@link http://www.php.net/manual/en/language.expressions.php php manual}.
  126.      * @see rowCssClass
  127.      * @deprecated in 1.1.13 in favor of {@link rowHtmlOptionsExpression}
  128.      */
  129.     public $rowCssClassExpression;
  130.     /**
  131.      * @var string a PHP expression that is evaluated for every table body row and whose result
  132.      * is used as additional HTML attributes for the row. The expression should return an
  133.      * array whose key value pairs correspond to html attribute and value.
  134.      * In this expression, you can use the following variables:
  135.      * <ul>
  136.      *   <li><code>$row</code> the row number (zero-based)</li>
  137.      *   <li><code>$data</code> the data model for the row</li>
  138.      *   <li><code>$this</code> the grid view object</li>
  139.      * </ul>
  140.      * The PHP expression will be evaluated using {@link evaluateExpression}.
  141.      *
  142.      * A PHP expression can be any PHP code that has a value. To learn more about what an expression is,
  143.      * please refer to the {@link http://www.php.net/manual/en/language.expressions.php php manual}.
  144.      * @since 1.1.13
  145.      */
  146.     public $rowHtmlOptionsExpression;
  147.     /**
  148.      * @var boolean whether to display the table even when there is no data. Defaults to true.
  149.      * The {@link emptyText} will be displayed to indicate there is no data.
  150.      */
  151.     public $showTableOnEmpty=true;
  152.     /**
  153.      * @var mixed the ID of the container whose content may be updated with an AJAX response.
  154.      * Defaults to null, meaning the container for this grid view instance.
  155.      * If it is set false, it means sorting and pagination will be performed in normal page requests
  156.      * instead of AJAX requests. If the sorting and pagination should trigger the update of multiple
  157.      * containers' content in AJAX fashion, these container IDs may be listed here (separated with comma).
  158.      */
  159.     public $ajaxUpdate;
  160.     /**
  161.      * @var string the jQuery selector of the HTML elements that may trigger AJAX updates when they are clicked.
  162.      * These tokens are recognized: {page} and {sort}. They will be replaced with the pagination and sorting links selectors.
  163.      * Defaults to '{page}, {sort}', that means that the pagination links and the sorting links will trigger AJAX updates.
  164.      * Tokens are available from 1.1.11
  165.      *
  166.      * Note: if this value is empty an exception will be thrown.
  167.      *
  168.      * Example (adding a custom selector to the default ones):
  169.      * <pre>
  170.      *  ...
  171.      *  'updateSelector'=>'{page}, {sort}, #mybutton',
  172.      *  ...
  173.      * </pre>
  174.      * @since 1.1.7
  175.      */
  176.     public $updateSelector='{page}, {sort}';
  177.     /**
  178.      * @var string a javascript function that will be invoked if an AJAX update error occurs.
  179.      *
  180.      * The function signature is <code>function(xhr, textStatus, errorThrown, errorMessage)</code>
  181.      * <ul>
  182.      * <li><code>xhr</code> is the XMLHttpRequest object.</li>
  183.      * <li><code>textStatus</code> is a string describing the type of error that occurred.
  184.      * Possible values (besides null) are "timeout", "error", "notmodified" and "parsererror"</li>
  185.      * <li><code>errorThrown</code> is an optional exception object, if one occurred.</li>
  186.      * <li><code>errorMessage</code> is the CGridView default error message derived from xhr and errorThrown.
  187.      * Usefull if you just want to display this error differently. CGridView by default displays this error with an javascript.alert()</li>
  188.      * </ul>
  189.      * Note: This handler is not called for JSONP requests, because they do not use an XMLHttpRequest.
  190.      *
  191.      * Example (add in a call to CGridView):
  192.      * <pre>
  193.      *  ...
  194.      *  'ajaxUpdateError'=>'function(xhr,ts,et,err){ $("#myerrordiv").text(err); }',
  195.      *  ...
  196.      * </pre>
  197.      */
  198.     public $ajaxUpdateError;
  199.     /**
  200.      * @var string the name of the GET variable that indicates the request is an AJAX request triggered
  201.      * by this widget. Defaults to 'ajax'. This is effective only when {@link ajaxUpdate} is not false.
  202.      */
  203.     public $ajaxVar='ajax';
  204.     /**
  205.      * @var mixed the URL for the AJAX requests should be sent to. {@link CHtml::normalizeUrl()} will be
  206.      * called on this property. If not set, the current page URL will be used for AJAX requests.
  207.      * @since 1.1.8
  208.      */
  209.     public $ajaxUrl;
  210.     /**
  211.      * @var string the type ('GET' or 'POST') of the AJAX requests. If not set, 'GET' will be used.
  212.      * You can set this to 'POST' if you are filtering by many fields at once and have a problem with GET query string length.
  213.      * Note that in POST mode direct links and {@link enableHistory} feature may not work correctly!
  214.      * @since 1.1.14
  215.      */
  216.     public $ajaxType;
  217.     /**
  218.      * @var string a javascript function that will be invoked before an AJAX update occurs.
  219.      * The function signature is <code>function(id,options)</code> where 'id' refers to the ID of the grid view,
  220.      * 'options' the AJAX request options  (see jQuery.ajax api manual).
  221.      */
  222.     public $beforeAjaxUpdate;
  223.     /**
  224.      * @var string a javascript function that will be invoked after a successful AJAX response is received.
  225.      * The function signature is <code>function(id, data)</code> where 'id' refers to the ID of the grid view,
  226.      * 'data' the received ajax response data.
  227.      */
  228.     public $afterAjaxUpdate;
  229.     /**
  230.      * @var string a javascript function that will be invoked after the row selection is changed.
  231.      * The function signature is <code>function(id)</code> where 'id' refers to the ID of the grid view.
  232.      * In this function, you may use <code>$(gridID).yiiGridView('getSelection')</code> to get the key values
  233.      * of the currently selected rows (gridID is the DOM selector of the grid).
  234.      * @see selectableRows
  235.      */
  236.     public $selectionChanged;
  237.     /**
  238.      * @var integer the number of table body rows that can be selected. If 0, it means rows cannot be selected.
  239.      * If 1, only one row can be selected. If 2 or any other number, it means multiple rows can be selected.
  240.      * A selected row will have a CSS class named 'selected'. You may also call the JavaScript function
  241.      * <code>$(gridID).yiiGridView('getSelection')</code> to retrieve the key values of the currently selected
  242.      * rows (gridID is the DOM selector of the grid).
  243.      */
  244.     public $selectableRows=1;
  245.     /**
  246.      * @var string the base script URL for all grid view resources (eg javascript, CSS file, images).
  247.      * Defaults to null, meaning using the integrated grid view resources (which are published as assets).
  248.      */
  249.     public $baseScriptUrl;
  250.     /**
  251.      * @var string the URL of the CSS file used by this grid view. Defaults to null, meaning using the integrated
  252.      * CSS file. If this is set false, you are responsible to explicitly include the necessary CSS file in your page.
  253.      */
  254.     public $cssFile;
  255.     /**
  256.      * @var string the text to be displayed in a data cell when a data value is null. This property will NOT be HTML-encoded
  257.      * when rendering. Defaults to an HTML blank.
  258.      */
  259.     public $nullDisplay='&nbsp;';
  260.     /**
  261.      * @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.
  262.      * This differs from {@link nullDisplay} in that {@link nullDisplay} is only used by {@link CDataColumn} to render
  263.      * null data values.
  264.      * @since 1.1.7
  265.      */
  266.     public $blankDisplay='&nbsp;';
  267.     /**
  268.      * @var string the CSS class name that will be assigned to the widget container element
  269.      * when the widget is updating its content via AJAX. Defaults to 'grid-view-loading'.
  270.      * @since 1.1.1
  271.      */
  272.     public $loadingCssClass='grid-view-loading';
  273.     /**
  274.      * @var string the jQuery selector of filter input fields.
  275.      * The token '{filter}' is recognized and it will be replaced with the grid filters selector.
  276.      * Defaults to '{filter}'.
  277.      *
  278.      * Note: if this value is empty an exception will be thrown.
  279.      *
  280.      * Example (adding a custom selector to the default one):
  281.      * <pre>
  282.      *  ...
  283.      *  'filterSelector'=>'{filter}, #myfilter',
  284.      *  ...
  285.      * </pre>
  286.      * @since 1.1.13
  287.      */
  288.     public $filterSelector='{filter}';
  289.     /**
  290.      * @var string the CSS class name for the table row element containing all filter input fields. Defaults to 'filters'.
  291.      * @see filter
  292.      * @since 1.1.1
  293.      */
  294.     public $filterCssClass='filters';
  295.     /**
  296.      * @var string whether the filters should be displayed in the grid view. Valid values include:
  297.      * <ul>
  298.      *    <li>header: the filters will be displayed on top of each column's header cell.</li>
  299.      *    <li>body: the filters will be displayed right below each column's header cell.</li>
  300.      *    <li>footer: the filters will be displayed below each column's footer cell.</li>
  301.      * </ul>
  302.      * @see filter
  303.      * @since 1.1.1
  304.      */
  305.     public $filterPosition='body';
  306.     /**
  307.      * @var CModel the model instance that keeps the user-entered filter data. When this property is set,
  308.      * the grid view will enable column-based filtering. Each data column by default will display a text field
  309.      * at the top that users can fill in to filter the data.
  310.      * Note that in order to show an input field for filtering, a column must have its {@link CDataColumn::name}
  311.      * property set or have {@link CDataColumn::filter} as the HTML code for the input field.
  312.      * When this property is not set (null) the filtering is disabled.
  313.      * @since 1.1.1
  314.      */
  315.     public $filter;
  316.     /**
  317.      * @var boolean whether to hide the header cells of the grid. When this is true, header cells
  318.      * will not be rendered, which means the grid cannot be sorted anymore since the sort links are located
  319.      * in the header. Defaults to false.
  320.      * @since 1.1.1
  321.      */
  322.     public $hideHeader=false;
  323.     /**
  324.      * @var boolean whether to leverage the {@link https://developer.mozilla.org/en/DOM/window.history DOM history object}.  Set this property to true
  325.      * to persist state of grid across page revisits.  Note, there are two limitations for this feature:
  326.      * <ul>
  327.      *    <li>this feature is only compatible with browsers that support HTML5.</li>
  328.      *    <li>expect unexpected functionality (e.g. multiple ajax calls) if there is more than one grid/list on a single page with enableHistory turned on.</li>
  329.      * </ul>
  330.      * @since 1.1.11
  331.      */
  332.     public $enableHistory=false;
  333.  
  334.  
  335.     /**
  336.      * Initializes the grid view.
  337.      * This method will initialize required property values and instantiate {@link columns} objects.
  338.      */
  339.     public function init()
  340.     {
  341.         parent::init();
  342.  
  343.         if(empty($this->updateSelector))
  344.             throw new CException(Yii::t('zii','The property updateSelector should be defined.'));
  345.         if(empty($this->filterSelector))
  346.             throw new CException(Yii::t('zii','The property filterSelector should be defined.'));
  347.  
  348.         if(!isset($this->htmlOptions['class']))
  349.             $this->htmlOptions['class']='grid-view';
  350.  
  351.         if($this->baseScriptUrl===null)
  352.             $this->baseScriptUrl=Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('zii.widgets.assets')).'/gridview';
  353.  
  354.         if($this->cssFile!==false)
  355.         {
  356.             if($this->cssFile===null)
  357.                 $this->cssFile=$this->baseScriptUrl.'/styles.css';
  358.             Yii::app()->getClientScript()->registerCssFile($this->cssFile);
  359.         }
  360.  
  361.         $this->initColumns();
  362.     }
  363.  
  364.     /**
  365.      * Creates column objects and initializes them.
  366.      */
  367.     protected function initColumns()
  368.     {
  369.         if($this->columns===array())
  370.         {
  371.             if($this->dataProvider instanceof CActiveDataProvider)
  372.                 $this->columns=$this->dataProvider->model->attributeNames();
  373.             elseif($this->dataProvider instanceof IDataProvider)
  374.             {
  375.                 // use the keys of the first row of data as the default columns
  376.                 $data=$this->dataProvider->getData();
  377.                 if(isset($data[0]) && is_array($data[0]))
  378.                     $this->columns=array_keys($data[0]);
  379.             }
  380.         }
  381.         $id=$this->getId();
  382.         foreach($this->columns as $i=>$column)
  383.         {
  384.             if(is_string($column))
  385.                 $column=$this->createDataColumn($column);
  386.             else
  387.             {
  388.                 if(!isset($column['class']))
  389.                     $column['class']='CDataColumn';
  390.                 $column=Yii::createComponent($column, $this);
  391.             }
  392.             if(!$column->visible)
  393.             {
  394.                 unset($this->columns[$i]);
  395.                 continue;
  396.             }
  397.             if($column->id===null)
  398.                 $column->id=$id.'_c'.$i;
  399.             $this->columns[$i]=$column;
  400.         }
  401.  
  402.         foreach($this->columns as $column)
  403.             $column->init();
  404.     }
  405.  
  406.     /**
  407.      * Creates a {@link CDataColumn} based on a shortcut column specification string.
  408.      * @param string $text the column specification string
  409.      * @return CDataColumn the column instance
  410.      */
  411.     protected function createDataColumn($text)
  412.     {
  413.         if(!preg_match('/^([\w\.]+)(:(\w*))?(:(.*))?$/',$text,$matches))
  414.             throw new CException(Yii::t('zii','The column must be specified in the format of "Name:Type:Label", where "Type" and "Label" are optional.'));
  415.         $column=new CDataColumn($this);
  416.         $column->name=$matches[1];
  417.         if(isset($matches[3]) && $matches[3]!=='')
  418.             $column->type=$matches[3];
  419.         if(isset($matches[5]))
  420.             $column->header=$matches[5];
  421.         return $column;
  422.     }
  423.  
  424.     /**
  425.      * Registers necessary client scripts.
  426.      */
  427.     public function registerClientScript()
  428.     {
  429.         $id=$this->getId();
  430.  
  431.         if($this->ajaxUpdate===false)
  432.             $ajaxUpdate=false;
  433.         else
  434.             $ajaxUpdate=array_unique(preg_split('/\s*,\s*/',$this->ajaxUpdate.','.$id,-1,PREG_SPLIT_NO_EMPTY));
  435.         $options=array(
  436.             'ajaxUpdate'=>$ajaxUpdate,
  437.             'ajaxVar'=>$this->ajaxVar,
  438.             'pagerClass'=>$this->pagerCssClass,
  439.             'loadingClass'=>$this->loadingCssClass,
  440.             'filterClass'=>$this->filterCssClass,
  441.             'tableClass'=>$this->itemsCssClass,
  442.             'selectableRows'=>$this->selectableRows,
  443.             'enableHistory'=>$this->enableHistory,
  444.             'updateSelector'=>$this->updateSelector,
  445.             'filterSelector'=>$this->filterSelector
  446.         );
  447.         if($this->ajaxUrl!==null)
  448.             $options['url']=CHtml::normalizeUrl($this->ajaxUrl);
  449.         if($this->ajaxType!==null)
  450.             $options['ajaxType']=strtoupper($this->ajaxType);
  451.         if($this->enablePagination)
  452.             $options['pageVar']=$this->dataProvider->getPagination()->pageVar;
  453.         foreach(array('beforeAjaxUpdate', 'afterAjaxUpdate', 'ajaxUpdateError', 'selectionChanged') as $event)
  454.         {
  455.             if($this->$event!==null)
  456.             {
  457.                 if($this->$event instanceof CJavaScriptExpression)
  458.                     $options[$event]=$this->$event;
  459.                 else
  460.                     $options[$event]=new CJavaScriptExpression($this->$event);
  461.             }
  462.         }
  463.  
  464.         $options=CJavaScript::encode($options);
  465.         $cs=Yii::app()->getClientScript();
  466.         $cs->registerCoreScript('jquery');
  467.         $cs->registerCoreScript('bbq');
  468.         if($this->enableHistory)
  469.             $cs->registerCoreScript('history');
  470.         $cs->registerScriptFile($this->baseScriptUrl.'/jquery.yiigridview.js',CClientScript::POS_END);
  471.         $cs->registerScript(__CLASS__.'#'.$id,"jQuery('#$id').yiiGridView($options);");
  472.     }
  473.  
  474.     /**
  475.      * Renders the data items for the grid view.
  476.      */
  477.     public function renderItems()
  478.     {
  479.         if($this->dataProvider->getItemCount()>0 || $this->showTableOnEmpty)
  480.         {
  481.             echo "<table class=\"{$this->itemsCssClass}\">\n";
  482.             $this->renderTableHeader();
  483.             ob_start();
  484.             $this->renderTableBody();
  485.             $body=ob_get_clean();
  486.             $this->renderTableFooter();
  487.             echo $body; // TFOOT must appear before TBODY according to the standard.
  488.             echo "</table>";
  489.         }
  490.         else
  491.             $this->renderEmptyText();
  492.     }
  493.  
  494.     /**
  495.      * Renders the table header.
  496.      */
  497.     public function renderTableHeader()
  498.     {
  499.         if(!$this->hideHeader)
  500.         {
  501.             echo "<thead>\n";
  502.  
  503.             if($this->filterPosition===self::FILTER_POS_HEADER)
  504.                 $this->renderFilter();
  505.  
  506.             echo "<tr>\n";
  507.             foreach($this->columns as $column)
  508.                 $column->renderHeaderCell();
  509.             echo "</tr>\n";
  510.  
  511.             if($this->filterPosition===self::FILTER_POS_BODY)
  512.                 $this->renderFilter();
  513.  
  514.             echo "</thead>\n";
  515.         }
  516.         elseif($this->filter!==null && ($this->filterPosition===self::FILTER_POS_HEADER || $this->filterPosition===self::FILTER_POS_BODY))
  517.         {
  518.             echo "<thead>\n";
  519.             $this->renderFilter();
  520.             echo "</thead>\n";
  521.         }
  522.     }
  523.  
  524.     /**
  525.      * Renders the filter.
  526.      * @since 1.1.1
  527.      */
  528.     public function renderFilter()
  529.     {
  530.         if($this->filter!==null)
  531.         {
  532.             echo "<tr class=\"{$this->filterCssClass}\">\n";
  533.             foreach($this->columns as $column)
  534.                 $column->renderFilterCell();
  535.             echo "</tr>\n";
  536.         }
  537.     }
  538.  
  539.     /**
  540.      * Renders the table footer.
  541.      */
  542.     public function renderTableFooter()
  543.     {
  544.         $hasFilter=$this->filter!==null && $this->filterPosition===self::FILTER_POS_FOOTER;
  545.         $hasFooter=$this->getHasFooter();
  546.         if($hasFilter || $hasFooter)
  547.         {
  548.             echo "<tfoot>\n";
  549.             if($hasFooter)
  550.             {
  551.                 echo "<tr>\n";
  552.                 foreach($this->columns as $column)
  553.                     $column->renderFooterCell();
  554.                 echo "</tr>\n";
  555.             }
  556.             if($hasFilter)
  557.                 $this->renderFilter();
  558.             echo "</tfoot>\n";
  559.         }
  560.     }
  561.  
  562.     /**
  563.      * Renders the table body.
  564.      */
  565.     public function renderTableBody()
  566.     {
  567.         $data=$this->dataProvider->getData();
  568.         $n=count($data);
  569.         echo "<tbody>\n";
  570.  
  571.         if($n>0)
  572.         {
  573.             for($row=0;$row<$n;++$row)
  574.                 $this->renderTableRow($row);
  575.         }
  576.         else
  577.         {
  578.             echo '<tr><td colspan="'.count($this->columns).'" class="empty">';
  579.             $this->renderEmptyText();
  580.             echo "</td></tr>\n";
  581.         }
  582.         echo "</tbody>\n";
  583.     }
  584.  
  585.     /**
  586.      * Renders a table body row.
  587.      * @param integer $row the row number (zero-based).
  588.      */
  589.     public function renderTableRow($row)
  590.     {
  591.         $htmlOptions=array();
  592.         if($this->rowHtmlOptionsExpression!==null)
  593.         {
  594.             $data=$this->dataProvider->data[$row];
  595.             $options=$this->evaluateExpression($this->rowHtmlOptionsExpression,array('row'=>$row,'data'=>$data));
  596.             if(is_array($options))
  597.                 $htmlOptions = $options;
  598.         }
  599.  
  600.         if($this->rowCssClassExpression!==null)
  601.         {
  602.             $data=$this->dataProvider->data[$row];
  603.             $class=$this->evaluateExpression($this->rowCssClassExpression,array('row'=>$row,'data'=>$data));
  604.         }
  605.         elseif(is_array($this->rowCssClass) && ($n=count($this->rowCssClass))>0)
  606.             $class=$this->rowCssClass[$row%$n];
  607.  
  608.         if(!empty($class))
  609.         {
  610.             if(isset($htmlOptions['class']))
  611.                 $htmlOptions['class'].=' '.$class;
  612.             else
  613.                 $htmlOptions['class']=$class;
  614.         }
  615.  
  616.         echo CHtml::openTag('tr', $htmlOptions)."\n";
  617.         foreach($this->columns as $column)
  618.             $column->renderDataCell($row);
  619.         echo "</tr>\n";
  620.     }
  621.  
  622.     /**
  623.      * @return boolean whether the table should render a footer.
  624.      * This is true if any of the {@link columns} has a true {@link CGridColumn::hasFooter} value.
  625.      */
  626.     public function getHasFooter()
  627.     {
  628.         foreach($this->columns as $column)
  629.             if($column->getHasFooter())
  630.                 return true;
  631.         return false;
  632.     }
  633.  
  634.     /**
  635.      * @return CFormatter the formatter instance. Defaults to the 'format' application component.
  636.      */
  637.     public function getFormatter()
  638.     {
  639.         if($this->_formatter===null)
  640.             $this->_formatter=Yii::app()->format;
  641.         return $this->_formatter;
  642.     }
  643.  
  644.     /**
  645.      * @param CFormatter $value the formatter instance
  646.      */
  647.     public function setFormatter($value)
  648.     {
  649.         $this->_formatter=$value;
  650.     }
  651. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement