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 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); } }