public function run() { switch ($this->model instanceof RepliesModel) { case true: switch (empty($this->parentId)) { /** * This issue model was initialed through a model * We need to set the parentId and parentType from the constraints values */ case true: //$this->parentId = $this->model->constraints['parent_id']; //$this->parentType = $this->model->constrain['parent_type']; break; } $searchModel = new RepliesSearch(); $this->model->queryOptions['with'][] = 'replyTo'; $searchModel->addWith($this->model->queryOptions['with']); $get = \Yii::$app->request->getQueryParams(); $params = array_merge($get, $this->model->constraints); unset($params['type']); unset($params['id']); switch (\Yii::$app->user->identity->isAdmin()) { case false: $params['hidden'] = 0; break; } $dataProvider = $searchModel->search($params); $dataProvider->setSort(['defaultOrder' => ['id' => SORT_DESC]]); $this->options['id'] .= $this->parentId; $replies = $this->getView()->render('@nitm/widgets/views/chat/index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'widget' => $this]); //RepliesAsset::register($this->getView()); break; default: //$replies = Html::tag('h3', "No comments", ['class' => 'text-error']); $replies = 'No Replies'; break; } $this->options['id'] .= $this->parentId; return $replies; }
public function run() { $dataProvider = null; switch (isset($this->items) && is_array($this->items)) { case true: $dataProvider = new \yii\data\ArrayDataProvider(["allModels" => $this->items]); break; default: switch ($this->model instanceof RepliesModel) { case true: $get = \Yii::$app->request->getQueryParams(); $params = array_merge($get, $this->model->getConstraints()); unset($params['type']); unset($params['id']); if (!\Yii::$app->user->identity->isAdmin()) { $params['hidden'] = false; } $searchModel = new RepliesSearch(['queryOptions' => ['with' => ['author', 'replyTo', 'count', 'last']]]); $dataProvider = $searchModel->search($params); $dataProvider->setSort(['defaultOrder' => ['id' => SORT_DESC]]); break; } break; } switch (isset($dataProvider)) { case true: $defaultOptions = ['parentId' => $this->parentId, 'parentType' => $this->parentType, 'uniqid' => $this->uniqid, 'model' => $this->model]; $this->formOptions = array_merge($defaultOptions, $this->formOptions); $viewOptions = array_merge($defaultOptions, ['dataProvider' => $dataProvider, 'widget' => $this]); $replies = $this->getView()->render('@nitm/widgets/views/replies/index', $viewOptions); break; default: //$replies = Html::tag('h3', "No comments", ['class' => 'text-error']); $replies = ''; break; } return $replies; }