public static function sendChat($post) { if (isset($post['message'])) $message = $post['message']; if (isset($post['userfield'])) $userField = $post['userfield']; if (isset($post['model'])) $userModel = $post['model']; else $userModel = Yii::$app->getUser()->identityClass; $model = new \sintret\chat\models\Chat; $model->userModel = $userModel; if ($userField) $model->userField = $userField; if ($message) { $model->message = $message; $model->userId = Yii::$app->user->id; if ($model->save()) { echo $model->data(); } else { print_r($model->getErrors()); exit(0); } } else { echo $model->data(); } }
public function run() { parent::init(); ChatJs::register($this->view); $model = new Chat(); $model->userModel = $this->userModel; $model->userField = $this->userField; $data = $model->data(); return $this->render('index', ['data' => $data, 'url' => $this->url, 'userModel' => $this->userModel, 'userField' => $this->userField, 'loading' => $this->loadingImage]); }
public function data() { $userField = $this->userField; $output = ''; $models = Chat::records(); if ($models) foreach ($models as $model) { if (isset($model->user->$userField)) { $avatar = $model->user->$userField; } else{ $avatar = Yii::$app->assetManager->getPublishedUrl("@vendor/sintret/yii2-chat-adminlte/assets/img/avatar.png"); } $output .= '<div class="item"> <img class="online" alt="user image" src="' . $avatar . '"> <p class="message"> <a class="name" href="#"> <small class="text-muted pull-right" style="color:green"><i class="fa fa-clock-o"></i> ' . \kartik\helpers\Enum::timeElapsed($model->updateDate) . '</small> ' . $model->user->user_name . ' </a> ' . $model->message . ' </p> </div>'; } return $output; }
public static function sendChat($post) { if (isset($post['message'])) { $message = $post['message']; } if (isset($post['userfield'])) { $userField = $post['userfield']; } if (isset($post['idRequest'])) { $idRequest = $post['idRequest']; } if (isset($post['userName'])) { $userName = $post['userName']; } if (isset($post['model'])) { $userModel = $post['model']; } else { $userModel = Yii::$app->getUser()->identityClass; } $model = new \sintret\chat\models\Chat(); $model->userModel = $userModel; if ($userField) { $model->userField = $userField; } if ($message) { $model->message = $message; $model->request_id = $idRequest; if (!Yii::$app->user->isGuest) { $model->userId = Yii::$app->user->id; $user = User::findIdUserName(Yii::$app->user->id); $model->user_name = $user->user_name; } else { $model->userId = Yii::$app->user->id; $model->user_name = $userName; } if ($model->save()) { echo $model->data($idRequest); } else { print_r($model->getErrors()); exit(0); } } else { echo $model->data($idRequest); } }