protected function renderDataCellContent($model, $key, $index) { $dropdownId = $this->grid->getId() . '-dropdown2-menu-' . $index; $this->template = implode(' ', array_keys(array_filter(['<li>{view}</li>' => ModelHelper::canRead($model), '<li>{update}</li>' => ModelHelper::canUpdate($model), '<li>{delete}</li>' => ModelHelper::canDelete($model)]))); $fix = ['~(glyphicon\\-eye\\-open"\\>\\</span\\>)(\\</a\\>)~i' => '$1 ' . Yii::t('mozayka', 'View') . '$2', '~(glyphicon\\-pencil"\\>\\</span\\>)(\\</a\\>)~i' => '$1 ' . Yii::t('mozayka', 'Update') . '$2', '~(glyphicon\\-trash"\\>\\</span\\>)(\\</a\\>)~i' => '$1 ' . Yii::t('mozayka', 'Delete') . '$2', '~\\s+title\\="[^"]*"~i' => '', '~\\s+data\\-confirm\\="[^"]*"~i' => '', '~\\s+data\\-method\\="[^"]*"~i' => '']; $cellContent = preg_replace(array_keys($fix), array_values($fix), parent::renderDataCellContent($model, $key, $index)); // dropdown2-menu if ($cellContent && $cellContent != $this->grid->emptyCell) { $cellContent = Html::button('<span class="glyphicon glyphicon-cog"></span>', ['title' => Yii::t('mozayka', 'Actions'), 'class' => 'btn btn-default btn-xs', 'data-dropdown2' => '#' . $dropdownId]) . Html::tag('div', Html::tag('ul', $cellContent, ['class' => 'dropdown2-menu']), ['id' => $dropdownId, 'class' => 'dropdown2 dropdown2-tip' . (array_search($this, $this->grid->columns) + 1 > count($this->grid->columns) / 2 ? ' dropdown2-anchor-right' : '')]); } return $cellContent; }
public function checkAccess($action, $model = null, $params = []) { $newModel = null; if (array_key_exists('newModel', $params)) { $newModel = $params['newModel']; unset($params['newModel']); } $query = null; if (array_key_exists('query', $params)) { $query = $params['query']; unset($params['query']); } switch ($action) { case 'create': case 'create-form': $allowed = ModelHelper::canCreate($this->modelClass, $params, $newModel); break; case 'view': case 'read-form': $allowed = ModelHelper::canRead($model); break; case 'update': case 'update-form': $allowed = ModelHelper::canUpdate($model); break; case 'delete': case 'delete-form': $allowed = ModelHelper::canDelete($model); break; case 'index': case 'list': $allowed = ModelHelper::canList($this->modelClass, $params, $query); break; case 'change-position': $allowed = ModelHelper::canChangePosition($model); break; default: $allowed = false; } if (!$allowed) { $user = Yii::$app->getUser(); throw new ForbiddenHttpException(Yii::t('mozayka', 'Permission denied for user "{user}" to perform action "{action}".', ['user' => $user->getIsGuest() ? Yii::t('mozayka', 'Guest') : $user->getIdentity()->username, 'action' => $this->id . '/' . $action])); } }