public function run() { if ($this->controller->checkAccessInActions && !Yii::app()->user->checkAccess('read ' . $this->controller->authModelClass)) { throw new CHttpException(403, Yii::t('yii', 'You are not authorized to perform this action.')); } // set some defaults $widgetDefaults = array('class' => 'ext.exporter.CsvView', 'dataColumnClass' => 'edt.EDataColumn', 'columns' => $this->columns); if ($this->widget === null) { $this->widget = array(); } elseif (is_string($this->widget)) { $this->widget = array('class' => $this->widget); } $this->widget = array_merge($widgetDefaults, $this->widget); // as this could be expensive, create a dataProvider only if one wasn't provided if (!isset($this->widget['dataProvider'])) { $c = $this->controller; $model = NetActiveRecord::model($c->modelClass); if ($this->criteria === null) { $this->criteria = new CDbCriteria(); } if (is_array($this->criteria)) { $this->criteria = new CDbCriteria($this->criteria); } $filterId = $c->getId() . '-filter'; $filterForm = $c->loadFilterForm($c->getId(), $c->modelClass . 'Filter', $filterId, '_filterForm'); //! @todo how to configure from which action a default query should be used? check out second argument below: $columns = $this->widget['columns']; list($query, $criteria, $columns, $grouping) = $c->loadQuery($c->getId(), 'index', $c->modelClass, $columns, $filterForm); if ($this->columns_from_query) { $this->widget['columns'] = $columns; } $this->criteria->mergeWith($criteria); if (isset($_GET['mode']) && isset($_GET['selected'])) { $pks = array_map('intval', explode(',', $_GET['selected'])); if ($_GET['mode'] === '' || $_GET['mode'] === 'deselect') { $this->criteria->addInCondition('"t".' . $model->tableSchema->primaryKey, $pks); } else { $this->criteria->addNotInCondition('"t".' . $model->tableSchema->primaryKey, $pks); } } $this->widget['dataProvider'] = $model->search($_GET, $this->criteria, $this->widget['columns'], null, false); $filterModel = $filterForm->getModel(); $filterModel->format(null, true); $this->widget['filter'] = $filterModel; } // set timer to 5 minutes set_time_limit(3600); $widget = $this->widget['class']; unset($this->widget['class']); $this->controller->widget($widget, $this->widget); }
protected function renderDataCellContent($row, $data) { if (is_string($this->visible)) { $visible = $this->evaluateExpression($this->visible, array('data' => $data, 'row' => $row)); } else { $visible = $this->visible; } if (!$visible) { return; } if (is_string($this->enabled)) { $enabled = $this->evaluateExpression($this->enabled, array('data' => $data, 'row' => $row)); } else { $enabled = $this->enabled; } if (is_string($this->dynamicType)) { $this->type = $this->evaluateExpression($this->dynamicType, array('data' => $data, 'row' => $row)); } if (substr($this->type, 0, 8) === 'readonly') { $this->type = lcfirst(substr($this->type, 8)); echo parent::renderDataCellContent($row, $data); return; } if ($this->value !== null) { $value = $this->evaluateExpression($this->value, array('data' => $data, 'row' => $row)); } elseif ($this->name !== null) { $value = CHtml::value($data, $this->name); } // not using $this->grid->nullDisplay here because it's a by default $unformattedValue = $value; $value = $value === null ? '' : $this->grid->getFormatter()->format($value, $this->type); //! @todo check type, set different controls or attributes for input tag //! @todo use a different formatter? ex. an image type /* * @todo in views we use pre-generated controls, the dev can choose * from different ones - here we generate them * on the fly - is this the best way? * We COULD provide separate view for every attribute, but * wouldn't it be an overkill? */ $id = str_replace('.', '_', $this->name) . '_row' . $row; $options = $this->htmlOptions; if (!$enabled) { $options['disabled'] = 'disabled'; } $options['class'] = empty($options['class']) ? 'editable' : $options['class'] . ' editable'; switch ($this->type) { default: case 'readonly': echo parent::renderDataCellContent($row, $data); break; case 'text': echo CHtml::tag('input', array_merge(array('type' => 'text', 'id' => $id, 'value' => $value), $options)); break; case 'password': echo CHtml::tag('input', array_merge(array('type' => 'password', 'id' => $id), $options)); break; case 'integer': case 'double': case 'dec2': case 'dec3': case 'dec5': $options['class'] .= ' span1'; echo CHtml::tag('input', array_merge(array('type' => 'text', 'id' => $id, 'value' => $value, 'size' => 6, 'maxlength' => 9), $options)); break; case 'flags': case 'set': case 'object': $relations = $data->relations(); if (($pos = strpos($this->name, '.')) !== false) { $pivotRelationName = substr($this->name, 0, $pos); // withShops $pivotRelation = $relations[$pivotRelationName]; $model = $data->{$pivotRelationName}; $staticModel = NetActiveRecord::model($pivotRelation[1]); // change id and name properties to fk column instead of relation name $id_parts = explode('.', $this->name); $relationName = array_pop($id_parts); $pivotRelations = $staticModel->relations(); $relation = $pivotRelations[$relationName]; $id = implode('_', $id_parts) . '_' . $relation[2] . '_row' . $row; $name = $relation[2]; } else { $relation = $relations[$this->name]; $model = $data; $name = $this->name; } $options['data-placeholder'] = Yii::t('EDataTables.edt', 'Choose') . ' ' . NetActiveRecord::model($relation[1])->label(2) . '...'; $controller = lcfirst($relation[1]); echo $this->grid->owner->widget('ext.select2.ESelect2', array('options' => Select2Helper::filterDefaults(CHtml::normalizeUrl('/' . $controller . '/autocomplete'), '', true, array('width' => '15em')), 'htmlOptions' => array_merge(array('id' => $id, 'name' => $name), $options), 'value' => $model !== null ? isset($relationName) ? $model->{$relationName} !== null ? $model->{$relationName}->getPrimaryKey() : null : ($model->{$this->name} !== null ? $model->{$this->name}->getPrimaryKey() : null) : null), true); break; case 'array': throw new Exception('Editable column not implemented for type ' . $this->type . ' (' . var_export($value, true) . ')'); break; case 'boolean': echo CHtml::tag('input', array_merge(array('type' => 'checkbox', 'id' => $id, 'value' => 1), $unformattedValue ? array('checked' => 'checked') : array(), $options)); //echo '<input type="hidden" value="1"/>'; break; case 'date': case 'time': case 'datetime': $options['class'] .= ' ' . $this->grid->id . '_datepickers'; $options['class'] .= ' span2'; echo $this->grid->owner->widget('Datepicker', array('htmlOptions' => array_merge(array('id' => $id, 'name' => $this->name, 'value' => $value, 'size' => 8, 'maxlength' => 17, 'style' => 'width: 6em;'), $options)), true); break; case 'image': throw new Exception('Editable column not implemented for type ' . $this->type . ' (' . var_export($value, true) . ')'); break; } }