Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from 2amigos/fix_column_mapper
Browse files Browse the repository at this point in the history
fix column mapper
  • Loading branch information
tonydspaniard committed Aug 14, 2017
2 parents a14092e + 21a3729 commit b2153ee
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/mappers/ColumnValueMapper.php
Expand Up @@ -10,6 +10,7 @@
namespace dosamigos\exportable\mappers;

use yii\base\Model;
use yii\base\Object;
use yii\db\ActiveRecordInterface;
use yii\grid\ActionColumn;
use yii\grid\CheckboxColumn;
Expand Down Expand Up @@ -64,18 +65,26 @@ public function map($model, $index)
? $model->getPrimaryKey()
: $model[$column->attribute];

$value = $this->isHtml
? $column->renderDataCell($model, $key, $index)
: ArrayHelper::getValue($model, $column->attribute);
$value = $this->getColumnValue($column, $model, $key, $index);

$header = $this->getColumnHeader($column, $model);
$header = $this->getColumnHeader($column);
$row[$header] = $value;
}
}

return $row;
}

protected function getColumnValue($column, $model, $key, $index)
{
$value = $column->renderDataCell($model, $key, $index);
if (!$this->isHtml) {
$value = strip_tags($value);
}

return $value;
}

/**
* Returns column headers
*
Expand All @@ -88,9 +97,9 @@ public function getHeaders($model)
$headers = [];
/** @var Column $column */
foreach ($this->columns as $column) {
$headers[] = $this->isHtml
? $column->renderHeaderCell()
: $this->getColumnHeader($column, $model);
if ($this->isColumnExportable($column)) {
$headers[] = $this->getColumnHeader($column);
}
}

return $headers;
Expand All @@ -105,7 +114,7 @@ public function getHeaders($model)
*/
protected function isColumnExportable($column)
{
if (!($column instanceof DataColumn) || $column instanceof ActionColumn || $column instanceof CheckboxColumn) {
if ($column instanceof ActionColumn || $column instanceof CheckboxColumn) {
return false;
}

Expand All @@ -124,16 +133,13 @@ protected function isColumnExportable($column)
*
* @return string
*/
protected function getColumnHeader($column, $model)
protected function getColumnHeader($column)
{
if (!($column instanceof DataColumn)) {
return $column->header;
$header = $column->renderHeaderCell();
if (!$this->isHtml) {
$header = strip_tags($header);
}

return $column->label !== null
? $column->label
: (!empty($model) && $model instanceof Model
? $model->getAttributeLabel($column->attribute)
: $column->attribute);
return $header;
}
}

0 comments on commit b2153ee

Please sign in to comment.