Browse Source

Refactored DataColumn::renderHeaderCellContent()

tags/2.0.0-beta
Carsten Brandt 11 years ago
parent
commit
39c002e83c
  1. 42
      framework/yii/grid/DataColumn.php

42
framework/yii/grid/DataColumn.php

@ -72,36 +72,36 @@ class DataColumn extends Column
protected function renderHeaderCellContent() protected function renderHeaderCellContent()
{ {
if ($this->header === null) { if ($this->header !== null || $this->label === null && $this->attribute === null) {
$provider = $this->grid->dataProvider; return parent::renderHeaderCellContent();
}
$provider = $this->grid->dataProvider;
if ($this->label === null) { if ($this->label === null) {
if ($provider instanceof ActiveDataProvider && $provider->query instanceof ActiveQuery) { 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 */ /** @var Model $model */
$model = new $provider->query->modelClass;
$label = $model->getAttributeLabel($this->attribute); $label = $model->getAttributeLabel($this->attribute);
} else { } else {
$models = $provider->getModels(); $label = Inflector::camel2words($this->attribute);
if (($model = reset($models)) instanceof Model) {
/** @var Model $model */
$label = $model->getAttributeLabel($this->attribute);
} else {
$label = Inflector::camel2words($this->attribute);
}
} }
} else {
$label = $this->label;
} }
} else {
$label = $this->label;
}
if ($this->attribute !== null && $this->enableSorting && if ($this->attribute !== null && $this->enableSorting &&
($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) { ($sort = $provider->getSort()) !== false && $sort->hasAttribute($this->attribute)) {
return $sort->link($this->attribute, Html::encode($label), $this->sortLinkOptions); return $sort->link($this->attribute, Html::encode($label), $this->sortLinkOptions);
} else {
return Html::encode($label);
}
} else { } else {
return parent::renderHeaderCellContent(); return Html::encode($label);
} }
} }

Loading…
Cancel
Save