public function actionIndex($contactId) { if (\Yii::$app->request->isPost) { $this->setUser(\Yii::$app->request->get('userId')); return \Yii::$app->getResponse()->redirect(Url::current(['userId' => null])); } $user = $this->user; if ($contactId == $user->id) { throw new ForbiddenHttpException('You cannot open this conversation'); } $contact = User::findIdentity(['id' => $contactId]); if (empty($contact)) { throw new NotFoundHttpException(); } $this->view->title = $contact->name; $conversationDataProvider = call_user_func([$this->modelClass, 'loadConversations'], $user->id, [$this, 'formatConversation'], 8); $messageDataProvider = call_user_func([$this->modelClass, 'loadMessages'], $user->id, $contact->id, [$this, 'formatMessage'], 10); $users = []; foreach (User::getAll() as $userItem) { $users[] = ['label' => $userItem->name, 'url' => Url::current(['userId' => $userItem->id]), 'options' => ['class' => in_array($userItem->id, [$user->id, $contact->id]) ? 'disabled' : ''], 'linkOptions' => ['data-method' => 'post']]; } return $this->render('index.twig', compact('conversationDataProvider', 'messageDataProvider', 'users', 'user', 'contact')); }
public function getUsers(array $except = []) { $users = []; foreach (User::getAll() as $userItem) { $users[] = ['label' => $userItem->name, 'url' => Url::to(['login-as', 'userId' => $userItem->id]), 'options' => ['class' => in_array($userItem->id, $except) ? 'disabled' : ''], 'linkOptions' => ['data-method' => 'post']]; } return $users; }