public function getTestdata() { for ($i = 0; $i < 5; $i++) { $post = new Message(); $post->sender_id = 1; $post->receiver_id = 2; $post->content = '1 - 2: ' . md5(time() * rand()); $post->save(); $post = new Message(); $post->sender_id = 2; $post->receiver_id = 1; $post->content = '2 - 1: ' . md5(time() * rand()); $post->save(); $post = new Message(); $post->sender_id = 1; $post->receiver_id = 3; $post->content = '1 - 3: ' . md5(time() * rand()); $post->save(); $post = new Message(); $post->sender_id = 3; $post->receiver_id = 1; $post->content = '3 - 1: ' . md5(time() * rand()); $post->save(); } }
public function actionIncoming($id) { $user_id = NULL; $from = Yii::$app->request->post('From'); $body = Yii::$app->request->post('Body'); // Lookup user based on a few different methods // First, check with basic number with +1 removed $number = str_replace('+1', '', $from); $person = Person::find()->where(['phone' => $number])->one(); // If no results, add hyphens if (!$person) { $formatted_number = preg_replace("/^(\\d{3})(\\d{3})(\\d{4})\$/", "\$1-\$2-\$3", $number); $person = Person::find()->where(['phone' => $formatted_number])->one(); } if ($person) { $user_id = $person->id; } if ($from) { $message = new Message(); $message->message = $body; $message->project_id = $id; $message->time = time(); $message->user_id = $user_id; $message->status = 2; $message->type = 'text'; $message->number = $from; $message->save(); } }
/** * Show the application dashboard. * * @param $id * @param MessagesRequest $request * @return \Illuminate\Http\Response */ public function store($id, MessagesRequest $request) { try { if (count($request->get('messages'))) { foreach ($request->get('messages') as $locale => $text) { if ($text) { $message = Message::whereTranslateId($id)->whereLocaleId($locale)->first(); if (!$message) { $message = new Message(); $message->locale_id = $locale; $message->translate_id = $id; } $message->message = $text; $message->save(); } } } $request->session()->flash('message', 'Translates was successful!'); $request->session()->flash('alert', 'success'); } catch (\Exception $e) { $request->session()->flash('message', 'Translates error!'); $request->session()->flash('alert', 'danger'); } return redirect('/translates'); }
/** * Create parts of message common to all 3 types * * @param $fields * @return Message|null */ protected function createBasic(array $fields) { $message = new Message(); collect($this->common)->map(function ($name) use($message, $fields) { $message->{$name} = $fields[ucfirst($name)]; }); $message->save(); return $message; }
/** * Creates a new Message model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $message = new Message(); if ($message->load(Yii::$app->request->post()) && $message->save()) { return $this->redirect(['index']); } else { return $this->render('create', ['message' => $message]); } }
public function actionSendMessage() { if (!Yii::$app->user->isGuest) { $post = Yii::$app->request->post(); $message = new Message(); $message->parse($post); $message->save(); } }
/** * Creates a new Message model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Message(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id, 'User_id' => $model->User_id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Store a newly created resource in storage. * * @param StoreMessageRequest $request * * @return \Illuminate\Http\Response */ public function store(StoreMessageRequest $request) { $message = new Message(); $message->content = $request->get('content'); $message->author = $request->get('author'); $message->save(); session()->put('nickname', $request->get('author')); event(new MessageWasSent($message)); }
public function postContact(SendContactRequest $request) { $message = new Message(); $message->fill($request->all()); $message->type = 'contact'; $message->save(); \Flash::success(trans('BaseTheme::messages.envoy_success', ['ref' => $message->id])); return redirect()->route('contact'); }
public function sendMessage(Request $request) { $redis = LRedis::connection(); $data = ['message' => $request->input('message'), 'user' => $request->input('user'), 'user_id' => $request->input('id'), 'createdAt' => new \DateTime()]; $message = new Message(); $message->fill($data); $message->save(); $redis->publish('message', json_encode($data)); return response()->json([]); }
public function postMessage($conversation) { $postValue = \Input::get('Message'); $message = new Message(); $message->setAttribute('body', $postValue['body']); $message->setAttribute('file', $this->getUploadedFile()); if ($message->save()) { return redirect(route('message.conversation', $conversation)); } else { return view('message.errorPost'); } }
public function actionSave() { $languages = Message::getLanguages(); $model = new Message(); $model->language = $_POST['language']; $model->file = $_POST['file']; $model->messageId = $_POST['message-id']; $model->message = $_POST['message-content']; $model->save(); $files = Message::getFiles($_POST['language']); Yii::$app->getSession()->setFlash('success', Yii::t('messages', 'common.changessaved')); return $this->render('edit', array('languages' => $languages, 'files' => $files, 'language' => $model->language, 'file' => $model->file, 'message' => $model->message, 'messageId' => $model->messageId)); }
public function onMessage(ConnectionInterface $from, $msg) { $model = new Message(); $model->message = $msg; $model->date = time(); $model->steamid = $from->User->steamid; $model->save(); foreach ($this->clients as $client) { $client->send(json_encode(['username' => $from->User->username, 'steamid' => $from->User->steamid, 'avatar' => $from->User->avatar_md, 'profile_url' => $from->User->profile_url, 'message' => $msg, 'id' => $model->id])); } Yii::info('Message: steamID: "' . $from->User->steamid . '", message: "' . $msg . '", IP: ' . $from->remoteAddress, 'chat'); echo 'Message: steamID: "' . $from->User->steamid . '", message: "' . $msg . '", IP: ' . $from->remoteAddress . "\n"; }
/** * Show the messages view to the user. * * @return Response */ public function create(Request $request) { //Validate the Request $this->validate($request, ['message' => 'required']); $message = new Message(); $message->sender_id = Auth::user()->id; $message->receiver_id = $request->receiverId; $message->message = $request->message; $message->is_read = 0; $message->save(); Event::fire(new MessageSent($message)); return ['status' => 'success']; }
public static function saveMessage($text, $receiver_id) { $message = new Message(); $sender_id = Auth::user()->user_id; $channel = $message->getChannel($sender_id, $receiver_id); $message->sender_id = $sender_id; $message->receiver_id = $receiver_id; $message->text = $text; $message->TID = $channel; $pusher = App::make('pusher'); $pusher->trigger($channel, 'messages:onsend', ['message' => $text, 'sender_id' => $sender_id]); $message->save(); return $message; }
/** * @param Translate $translate * @param Locale $locale * @return Message */ private function getMessage(Translate $translate, Locale $locale) { $message = Message::whereTranslateId($translate->id)->whereLocaleId($locale->id)->first(); if (!$message) { $record = Message::whereTranslateId($translate->id)->whereLocaleId($this->defaultLocale->id)->first(); if (!$record) { $record = new Message(); $record->locale_id = $this->defaultLocale->id; $record->translate_id = $translate->id; $record->message = Request::get('key'); $record->save(); } return $record; } return $message; }
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()); }
/** * Store a newly created resource in storage. * POST /messages * * @return Response */ public function store() { $data = Input::all(); if (!Auth::check() && isset($data['email'])) { $result = $this->registerUser($data, Config::get('constants.ROLE_BROKER')); Log::info($result); if (is_array($result)) { return View::make('users.fastcomposer')->withErrors($result); } } if (Auth::check()) { $data['sender_id'] = Auth::user()->id; $msg = new Message(); if ($msg->validate($data)) { $msg->fill($data); $msg->last_reply = Carbon::now()->toDateTimeString(); $msg->save(); if (Request::ajax()) { return Response::json($msg); } return Redirect::intended("inbox/{$msg->id}"); } if (Request::ajax()) { return Response::json($msg->getValidator, 400); } return View::make(Auth::user()->role->name . '.messages.create')->withErrors($msg->getValidator()); } }
private function send($message) { $data = array_only($message->toArray(), ['message_id', 'type', 'app_id', 'author_id', 'all_receiver_ids', 'title', 'content']); $allReceiverIds = []; $receiverIdString = $message['all_receiver_ids']; if (!empty($receiverIdString)) { $allReceiverIds = explode(',', $receiverIdString); } $failedList = []; foreach ($allReceiverIds as $receiverId) { if (!is_numeric($receiverId)) { array_push($failedList, $receiverId); continue; } $user = User::find($receiverId); if (!$user) { array_push($failedList, $receiverId); continue; } $data['receiver_id'] = $receiverId; $data['status'] = 1; $message = new Message($data); $message->save(); } return $failedList; }
public function actionAddmessage() { $model = new Message(); $data = Yii::$app->request->post(); $model->from = $data['usid']; $model->to = $data['frid']; $model->message = $data['msg']; $model->save(); if (empty($data['lastmsg'])) { $sql = 'SELECT * FROM `message` WHERE `from`=' . $data['usid'] . ' and `to`=' . $data['frid'] . ' or `to`=' . $data['usid'] . ' and `from`=' . $data['frid'] . ''; Message::updateAll(['status' => 1], '`from`=' . $data['frid'] . ' and `to`=' . $data['usid'] . ''); } else { $sql = 'SELECT * FROM `message` WHERE `message_id`>' . $data['lastmsg'] . ' and `from`=' . $data['usid'] . ' and `to`=' . $data['frid'] . ' or `message_id`>' . $data['lastmsg'] . ' and `to`=' . $data['usid'] . ' and `from`=' . $data['frid'] . ''; Message::updateAll(['status' => 1], '`from`=' . $data['frid'] . ' and `to`=' . $data['usid'] . ''); } $msg = $model->findBySql($sql)->asArray()->all(); return json_encode($msg); }
/** * @return mixed */ public function actionNewMessage() { Yii::$app->response->format = Response::FORMAT_JSON; $msg = Yii::$app->request->post(); $message = new Message(); $message->content = $msg['content']; $message->user_name = $msg['user_name']; $message->save(); return ['id' => $message->id, 'created_at' => date("d M H:i", strtotime($message->created_at)), 'owner' => true]; }
public function sendText($selection, $message) { if (!$message) { return false; } $numbers = array(); // Initiate Twilio $sid = Yii::$app->params['twilioId']; $token = Yii::$app->params['twilioToken']; $client = new Twilio\Rest\Client($sid, $token); foreach ($selection as $user_id) { $person = Person::find()->where(['id' => $user_id])->one(); $number = preg_replace("/[^0-9]/", "", $person->phone); if (is_numeric($number) && $number >= 1000000000 && $number <= 9999999999) { try { $sms[] = $client->messages->create('+1' . $number, array('from' => $this->twilio_number, 'body' => $message)); $messageModel = new Message(); $messageModel->message = $message; $messageModel->user_id = $person->id; $messageModel->project_id = $this->id; $messageModel->time = time(); $messageModel->type = 'text'; $messageModel->status = 1; $messageModel->save(); } catch (Exception $e) { echo "Error: " . $e->getMessage(); } } //end if not 10 digit number } // echo '<pre>'; // var_dump($sms); // echo '</pre>'; }
/** * Creates a new Message model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionAjaxSendMessage() { Yii::$app->response->format = Response::FORMAT_JSON; $model = new Message(); $model->sender_id = Yii::$app->user->id; if ($model->load(Yii::$app->request->get()) && $model->save()) { return ['status' => 1, 'message' => 'message sent successfully to ' . $model->receiver->full_name]; } else { /* return $this->render('create', [ 'model' => $model, 'new_messages' => 10 ]);*/ return ['status' => 0, 'message' => 'request error : ' . print_r($model->getErrors())]; } }
public function message_send() { $mes = Input::get('message', ''); $to_id = Input::get('to_id', 0); $from_id = Auth::user()->id; $user = User::find($to_id); if (!$user) { abort(404); } $message = new Message(); $message->from_id = $from_id; $message->to_id = $to_id; $message->message = $mes; $message->save(); return redirect()->back()->with('success', trans('message.message_success_send')); }