Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed Jun 20, 2018
1 parent 0de1316 commit bf5dfc1
Showing 1 changed file with 25 additions and 37 deletions.
62 changes: 25 additions & 37 deletions src/widgets/GridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
use skeeks\yii2\config\ConfigBehavior;
use skeeks\yii2\config\ConfigTrait;
use skeeks\yii2\form\fields\FieldSet;
use skeeks\yii2\form\fields\SelectField;
use skeeks\yii2\form\fields\WidgetField;
use yii\base\Component;
use yii\base\Event;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yii\data\ArrayDataProvider;
Expand All @@ -27,7 +25,6 @@
use yii\db\ActiveQueryInterface;
use yii\grid\DataColumn;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Inflector;

/**
Expand Down Expand Up @@ -73,7 +70,6 @@ class GridView extends \yii\grid\GridView
public $configBehaviorData = [];



/**
* @var string name of the parameter storing the current page index.
* @see params
Expand Down Expand Up @@ -133,7 +129,7 @@ public function behaviors()
'widgetClass' => DualSelect::class,
'widgetConfig' => [
'visibleLabel' => \Yii::t('skeeks/cms', 'Display columns'),
'hiddenLabel' => \Yii::t('skeeks/cms', 'Hidden columns'),
'hiddenLabel' => \Yii::t('skeeks/cms', 'Hidden columns'),
],
//'multiple' => true,
'on beforeRender' => function ($e) {
Expand Down Expand Up @@ -207,13 +203,13 @@ public function behaviors()
],
'attributeLabels' => [
'visibleColumns' => 'Отображаемые колонки',
'caption' => 'Заголовок таблицы',
'caption' => 'Заголовок таблицы',

'pageParam' => \Yii::t('skeeks/cms', 'Parameter name pages, pagination'),
'defaultPageSize' => \Yii::t('skeeks/cms', 'Number of records on one page'),
'pageSizeLimitMin' => \Yii::t('skeeks/cms', 'The minimum allowable value for pagination'),
'pageSizeLimitMax' => \Yii::t('skeeks/cms', 'The maximum allowable value for pagination'),
'pageSizeParam' => \Yii::t('skeeks/cms', 'pageSizeParam'),
'pageSizeParam' => \Yii::t('skeeks/cms', 'pageSizeParam'),

'defaultOrder' => 'Сортировка',
],
Expand All @@ -230,7 +226,7 @@ public function behaviors()
['pageSizeLimitMax', 'integer'],
],
],
], (array) $this->configBehaviorData),
], (array)$this->configBehaviorData),
]);
}

Expand Down Expand Up @@ -303,7 +299,6 @@ public function getColumnsKeyLabels()
}*/



/**
*
*/
Expand Down Expand Up @@ -335,8 +330,7 @@ public function init()
$this->_initSort();

//Если удалили колонки
foreach ($this->columns as $key => $column)
{
foreach ($this->columns as $key => $column) {
if (!is_object($column)) {
unset($this->columns[$key]);
}
Expand All @@ -361,12 +355,11 @@ public function run()
fputcsv($out, $cells, ";");

if (isset($this->dataProvider->query)) {
foreach ($this->dataProvider->query->each(10) as $key => $model)
{
foreach ($this->dataProvider->query->each(10) as $key => $model) {
$cells = [];

foreach ($this->columns as $column) {
$cells[] = iconv("UTF-8", "windows-1251", strip_tags( $column->renderDataCell($model, $key, $key) ));
$cells[] = iconv("UTF-8", "windows-1251", strip_tags($column->renderDataCell($model, $key, $key)));
}

fputcsv($out, $cells, ";");
Expand All @@ -376,7 +369,7 @@ public function run()

fclose($out);
$filename = "export.csv";
header( 'Content-Type: text/csv' );
header('Content-Type: text/csv');

// disable caching
$now = gmdate("D, d M Y H:i:s");
Expand All @@ -390,7 +383,7 @@ public function run()
header("Content-Type: application/download");

header("Content-Transfer-Encoding: binary");
header( 'Content-Disposition: attachment;filename='.$filename);
header('Content-Disposition: attachment;filename='.$filename);

\Yii::$app->end();
}
Expand All @@ -400,7 +393,8 @@ public function run()
return parent::run();
}

protected function _initDialogCallbackData() {
protected function _initDialogCallbackData()
{

if ($callbackEventName = BackendUrlHelper::createByParams()->setBackendParamsByCurrentRequest()->callbackEventName) {
$this->view->registerJs(<<<JS
Expand Down Expand Up @@ -640,8 +634,7 @@ protected function _preInitColumns()
$resultColumns = [];

if ($columnsTmp) {
foreach ($columnsTmp as $key => $column)
{
foreach ($columnsTmp as $key => $column) {
if (isset($columns[$key])) {
$resultColumns[$key] = $columns[$key];
unset($columns[$key]);
Expand All @@ -650,7 +643,7 @@ protected function _preInitColumns()
}

if ($resultColumns) {
$resultColumns = ArrayHelper::merge((array) $resultColumns, (array) $columns);
$resultColumns = ArrayHelper::merge((array)$resultColumns, (array)$columns);
$columns = $resultColumns;
}

Expand Down Expand Up @@ -681,7 +674,6 @@ protected function _applyColumns()
}



return $this;
}
/**
Expand Down Expand Up @@ -721,23 +713,19 @@ public function getEditData()
{
$sort = [];
if ($this->dataProvider->getSort()->attributes) {
foreach ($this->dataProvider->getSort()->attributes as $key => $value)
{
foreach ($this->dataProvider->getSort()->attributes as $key => $value) {
$sort[$key] = ArrayHelper::getValue($value, 'label');
}
}

return [
'callAttributes' => $this->callAttributes,
'callAttributes' => $this->callAttributes,
'availableColumns' => $this->getColumnsKeyLabels(),
'sortAttributes' => $sort,
'sortAttributes' => $sort,
];
}





protected $_dialogCallbackDataColumn = null;

/**
Expand All @@ -755,8 +743,8 @@ public function getDialogCallbackDataColumn()
{
if ($this->_dialogCallbackDataColumn === null) {
$this->_dialogCallbackDataColumn = [
'class' => \yii\grid\DataColumn::className(),
'value' => function ($model) {
'class' => \yii\grid\DataColumn::className(),
'value' => function ($model) {
$data = $model->toArray();

if ($this->dialogCallbackData && is_callable($this->dialogCallbackData)) {
Expand All @@ -765,21 +753,21 @@ public function getDialogCallbackDataColumn()
} else {
if ($model instanceof ActiveRecord) {
$data = ArrayHelper::merge($model->toArray(), [
'asText' => $model->asText
'asText' => $model->asText,
]);
}

}

return \yii\helpers\Html::a('<i class="glyphicon glyphicon-circle-arrow-left"></i> ' . \Yii::t('skeeks/cms',
return \yii\helpers\Html::a('<i class="glyphicon glyphicon-circle-arrow-left"></i> '.\Yii::t('skeeks/cms',
'Choose'), '#', [
'class' => 'btn btn-primary sx-row-action',
'onclick' => 'sx.SelectCmsElement.submit(' . \yii\helpers\Json::encode($data) . '); return false;',
'data-pjax' => 0
'class' => 'btn btn-primary sx-row-action',
'onclick' => 'sx.SelectCmsElement.submit('.\yii\helpers\Json::encode($data).'); return false;',
'data-pjax' => 0,
]);
},
'label' => '',
'format' => 'raw'
'label' => '',
'format' => 'raw',
];
}
return $this->_dialogCallbackDataColumn;
Expand Down

0 comments on commit bf5dfc1

Please sign in to comment.