From 39c002e83cc4f327577a303ba86faddd6c585144 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Mon, 26 Aug 2013 15:23:49 +0200 Subject: [PATCH] Refactored DataColumn::renderHeaderCellContent() --- framework/yii/grid/DataColumn.php | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/framework/yii/grid/DataColumn.php b/framework/yii/grid/DataColumn.php index afb2fba..82b8641 100644 --- a/framework/yii/grid/DataColumn.php +++ b/framework/yii/grid/DataColumn.php @@ -72,36 +72,36 @@ class DataColumn extends Column protected function renderHeaderCellContent() { - if ($this->header === null) { - $provider = $this->grid->dataProvider; + if ($this->header !== null || $this->label === null && $this->attribute === null) { + return parent::renderHeaderCellContent(); + } + + $provider = $this->grid->dataProvider; - if ($this->label === null) { - if ($provider instanceof ActiveDataProvider && $provider->query instanceof ActiveQuery) { + if ($this->label === null) { + if ($provider instanceof ActiveDataProvider && $provider->query instanceof ActiveQuery) { + /** @var Model $model */ + $model = new $provider->query->modelClass; + $label = $model->getAttributeLabel($this->attribute); + } else { + $models = $provider->getModels(); + if (($model = reset($models)) instanceof Model) { /** @var Model $model */ - $model = new $provider->query->modelClass; $label = $model->getAttributeLabel($this->attribute); } else { - $models = $provider->getModels(); - if (($model = reset($models)) instanceof Model) { - /** @var Model $model */ - $label = $model->getAttributeLabel($this->attribute); - } else { - $label = Inflector::camel2words($this->attribute); - } + $label = Inflector::camel2words($this->attribute); } - } else { - $label = $this->label; } + } else { + $label = $this->label; + } - if ($this->attribute !== null && $this->enableSorting && - ($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) { + if ($this->attribute !== null && $this->enableSorting && + ($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) { - return $sort->link($this->attribute, Html::encode($label), $this->sortLinkOptions); - } else { - return Html::encode($label); - } + return $sort->link($this->attribute, Html::encode($label), $this->sortLinkOptions); } else { - return parent::renderHeaderCellContent(); + return Html::encode($label); } }