Пример #1
0
 protected function findModel($id)
 {
     if (($model = Message::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #2
0
 public function afterSave($insert)
 {
     $this->activeAttributes();
     if ($insert) {
         $message = new Message();
     } else {
         $message = Message::findOne(['id' => $this->id, 'language' => $this->language]);
         if (!$message instanceof Message) {
             $message = new Message();
         }
     }
     $message->id = $this->id;
     $message->language = $this->language;
     $message->translation = $this->messageTranslation;
     if ($message->save()) {
         Alert::addSuccess(Yii::t('messages', 'Translation has been saved'));
         self::commitLocalTransaction();
         return true;
     }
     Alert::addError(Yii::t('messages', 'Translation has not been saved'), $message->errors);
     self::rollbackLocalTransaction();
     throw new BadRequestHttpException(Alert::popError());
 }
Пример #3
0
 public function actionView($id)
 {
     $message = Message::findOne($id);
     $messages = Message::find()->where(['number' => $message->number])->all();
     $model = Project::findOne($message->project_id);
     $reply = new Message();
     foreach ($messages as $item) {
         $item->status = 4;
         $item->save();
     }
     if ($reply->load(Yii::$app->request->post()) && $reply->validate()) {
         // $reply->user_id =
         $reply->project_id = $message->project_id;
         $reply->status = 1;
         $reply->time = time();
         $reply->type = 'text';
         $reply->save();
         // Send twilio Text through project model
         $model->sendText([$message->user_id], $reply->message);
         Yii::$app->session->setFlash('success', 'Message Sent');
         $this->redirect(['/project/messages', 'id' => $message->project_id]);
     }
     return $this->render('view', ['message' => $message, 'messages' => $messages, 'model' => $model, 'reply' => $reply]);
 }
Пример #4
0
 /**
  * @return bool
  */
 public function actionDeleteMessage()
 {
     $msg = Yii::$app->request->post();
     $user = Message::findOne($msg['message_id']);
     if ($user->user_name === $this->current_user) {
         $user->delete();
         return true;
     } else {
         return false;
     }
 }