use yii\grid\GridView; use bariew\yii2Tools\helpers\GridHelper; use app\modules\poll\models\Question; use app\modules\code\models\PullRequest; /* @var $this yii\web\View */ /* @var $searchModel app\modules\poll\models\QuestionSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('modules/poll', 'Questions'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="question-index"> <h1> <?php echo Html::encode($this->title); ?> <span class="pull-right"><?php echo \bariew\yii2Tools\helpers\HtmlHelper::linkDropdown(Yii::t('modules/poll', 'Create Question'), array_map(function (&$v) { return $v = ['/poll/question/create', 'type' => $v]; }, array_flip($searchModel::typeList()))); ?> </span> </h1> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'summary' => false, 'columns' => ['title', GridHelper::listFormat($searchModel, 'type'), 'created_at:date', 'url:url', ['attribute' => 'status', 'format' => 'raw', 'value' => function ($data) { return $data->link; }, 'filter' => $searchModel::statusList()]]]); ?> </div>
/** * Runs access methods for view event. * @param Event $event view event. * @return bool */ public function responseAfterPrepare(Event $event) { if (!Yii::$app instanceof Application) { return true; } $doc = \phpQuery::newDocumentHTML($event->sender->content); foreach ($doc->find('a') as $el) { $link = pq($el); if (!($rule = HtmlHelper::urlToPath($link->attr('href')))) { continue; } if (!$this->checkAccess(Yii::$app->user->id, implode('/', $rule))) { $link->remove(); } } foreach ($doc->find('ul.dropdown-menu') as $el) { $ul = pq($el); if (!$ul->find('a[href!="#"]')->length) { $ul->parent('li.dropdown')->addClass('hide'); } } $event->sender->content = $doc; }
public function prettyPrint($attribute) { return HtmlHelper::arrayPrettyPrint($this->labeledAttribute($attribute)); }