Example #1
0
 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();
     }
 }
Example #2
0
 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);
     }
 }