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'); }
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'); }
/** * 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)); }
protected function sendMessageToRedis(Message $message) { $message[self::TIME_PLACED] = $message[self::TIME_PLACED]->toDateTimeString(); $message[self::AMOUNT_BUY] = number_format($message[self::AMOUNT_BUY], 2, '.', ''); $message[self::AMOUNT_SELL] = number_format($message[self::AMOUNT_SELL], 2, '.', ''); $message[self::RATE] = number_format($message[self::RATE], 4, '.', ''); $redis = LRedis::connection(); $redis->publish('message', $message->toJson()); }
public function testRuleCamposRequeridosSatisfeitos() { $model = new Message(); $this->assertFalse($model->validate()); $model->author_email = '*****@*****.**'; $model->author_name = 'test'; $model->message = str_repeat('A', 140); $this->assertTrue($model->validate()); }
/** * 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; }
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 actionSaveMasseges() { $model = new Message(); if ($model->load(Yii::$app->request->post())) { $model->file = UploadedFile::getInstance($model, 'file'); if ($model->file && $model->validate()) { $path = 'uploads/' . md5(microtime()) . '.' . $model->file->extension; $model->file->saveAs($path); } } $model->saveMassage($path); return $this->redirect('/site/index'); }
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"; }
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; }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $message = Message::findOrFail($id); $message->viewed = 1; $message->save(); return view('admin.messages.viewOne', ['message' => $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; }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('messages')->delete(); Message::create(['message' => 'Привет. Как дела?', 'user_id' => '1', 'friend_id' => '2']); Message::create(['message' => 'Норм. Поехали в центр', 'user_id' => '2', 'friend_id' => '1']); Message::create(['message' => 'Привет. Как дела?', 'user_id' => '1', 'friend_id' => '3']); Message::create(['message' => 'Завтра едем?', 'user_id' => '3', 'friend_id' => '1']); Message::create(['message' => 'Привет. Как дела?', 'user_id' => '2', 'friend_id' => '4']); Message::create(['message' => 'Привет', 'user_id' => '3', 'friend_id' => '4']); Message::create(['message' => 'эгегей', 'user_id' => '4', 'friend_id' => '3']); Message::create(['message' => 'Купи хлеба домой', 'user_id' => '3', 'friend_id' => '4']); Message::create(['message' => 'Привет. Как дела?', 'user_id' => '4', 'friend_id' => '8']); Message::create(['message' => 'и тебе не хворать', 'user_id' => '8', 'friend_id' => '4']); Message::create(['message' => 'Привет. Как дела?', 'user_id' => '4', 'friend_id' => '10']); Message::create(['message' => 'бедааа, скучно', 'user_id' => '10', 'friend_id' => '4']); Message::create(['message' => 'Скоро зайду - будет весело', 'user_id' => '4', 'friend_id' => '10']); Message::create(['message' => 'Привет. Как дела?', 'user_id' => '5', 'friend_id' => '9']); Message::create(['message' => 'Привет. Как дела?', 'user_id' => '5', 'friend_id' => '6']); Message::create(['message' => 'оригинальное начало беседы', 'user_id' => '6', 'friend_id' => '5']); Message::create(['message' => 'ну а что мне ещё спрашивать то?', 'user_id' => '5', 'friend_id' => '6']); Message::create(['message' => 'Привет. Как дела?', 'user_id' => '6', 'friend_id' => '8']); Message::create(['message' => 'кууу', 'user_id' => '8', 'friend_id' => '6']); Message::create(['message' => 'Привет. Как дела?', 'user_id' => '6', 'friend_id' => '10']); Message::create(['message' => 'Я не дома. позже созвонимся', 'user_id' => '10', 'friend_id' => '6']); Message::create(['message' => 'Привет. Как дела?', 'user_id' => '7', 'friend_id' => '1']); Message::create(['message' => 'как кирпичом по голове :/', 'user_id' => '1', 'friend_id' => '7']); Message::create(['message' => 'Что случилось?', 'user_id' => '7', 'friend_id' => '1']); Message::create(['message' => 'Привет. Как дела?', 'user_id' => '8', 'friend_id' => '2']); Message::create(['message' => 'у меня наушники сломались', 'user_id' => '2', 'friend_id' => '8']); Message::create(['message' => 'так неси, отремонтирую', 'user_id' => '8', 'friend_id' => '2']); Message::create(['message' => 'Привет. Как дела?', 'user_id' => '9', 'friend_id' => '2']); Message::create(['message' => 'отлично', 'user_id' => '2', 'friend_id' => '9']); Message::create(['message' => 'Привет. Как дела?', 'user_id' => '10', 'friend_id' => '5']); }
public function run() { DB::table('messages')->delete(); $collection = [['user_id' => 2, 'sender' => 'Taylor Otwell', 'sender_email' => '*****@*****.**', 'message' => 'I am not sure where the trace documentation has gone. Do you know of a source where I can get another copy?'], ['user_id' => 2, 'sender' => 'Jeffrey Way', 'sender_email' => '*****@*****.**', 'message' => 'I am no longer interested. I have another source for my needs that is much more economic but I hope to do business with you in the very near future.'], ['user_id' => 2, 'sender' => 'Jason Vorhees', 'sender_email' => '*****@*****.**', 'message' => 'I will disassemble YOU with my axe when I meet you.', 'status' => 'received']]; foreach ($collection as $record) { Message::create($record); } }
protected function findModel($id) { if (($model = Message::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function readall() { if (!auth()->check()) { return Response::create('Unauthorized', '401'); } Message::whereTo(auth()->user()->id)->unread()->update(['read' => date('Y-m-d H:i:s')]); return 1; }
public function edit() { $message = Message::find($this->request->id); if ($this->request->data && $message->save($this->request->data)) { return compact('message'); } else { return array('errors' => $message->errors()); } }
public function myMessages() { $user = Auth::user(); $messages = Message::with($this->related)->where('user_id', Auth::id())->get(); foreach ($messages as $message) { $message['gravatar'] = md5(strtolower(trim($message->sender_email))); } return view('pages.allmessages', compact('messages')); }
/** * Store a newly created resource in storage. * * @param Request $request * @param Message $modelMessage * @param Dialog $modelDialog * @param $id * @param $fid * @return $this|\Illuminate\Http\RedirectResponse */ public function store(Request $request, Message $modelMessage, Dialog $modelDialog, $id, $fid) { if (!$request->has('message')) { return redirect()->route('message.create', ['id' => $id, 'fid' => $fid]); } try { if (!$modelDialog->createDialog($id, $fid)) { throw new Exception('Problem with database: cannot create dialog'); } $crt = $modelMessage->create(['message' => $request->get('message'), 'user_id' => $id, 'friend_id' => $fid]); if (!$crt) { throw new Exception('Problem with database: cannot create message'); } } catch (Exception $e) { return redirect()->back()->withErrors([$e->getMessage()]); } return redirect()->route('message.create', ['id' => $id, 'fid' => $fid]); }
private function composeUserbar() { view()->composer('layouts.partials.userbar', function ($view) { $user = Auth::user(); $notifications = Notification::with('type')->where('user_id', Auth::id())->where('status', 'pending')->latest()->get(); $messages = Message::where('user_id', Auth::id())->where('status', 'pending')->latest()->get(); $view->with(['user' => $user, 'notifications' => $notifications, 'messages' => $messages]); }); }
function tweet($userId, $msg) { if (!Auth::check()) { //TODO: Handle Exception } $user = Auth::user(); $ins = ['user_id' => $userId, 'sender' => $user->firstname . ' ' . $user->lastname, 'sender_email' => $user->email, 'message' => $msg]; Message::create($ins); return true; }
public function updateSeen() { $id = Input::get('id'); if ($id) { Message::UpdateSeen($id); $arr = Message::DetailMessage($id); $arr['update_count_message'] = count(Message::CountNewMessage()); return json_encode($arr); } }
public function actionDelete($id, $language) { $model = $this->findModel(Message::className(), ['id' => $id, 'language' => $language]); if ($model->delete()) { Alert::addSuccess(Yii::t('messages', 'Translation has been successfully deleted')); } else { Alert::addError(Yii::t('messages', 'Translation has not been deleted')); } return $this->redirect(Yii::$app->request->referrer); }
public function actionIndex() { $curUser = \Yii::$app->user->id; UserSettingsBlock::sync($curUser); //todo return data model $block = Block::find()->with('links')->where(['hidden' => Block::STATUS_SHOW, 'type' => Block::TYPE_TAB])->orderBy('order')->all(); $model = UserSettingsBlock::find()->with('block')->orderBy('column, order')->where(['{{%user_settings_block}}.user_id' => $curUser])->all(); $msg = Message::find()->where(['status' => Message::STATUS_SHOW])->all(); return $this->render('index', ['model' => $model, 'blocks' => $block, 'messages' => $msg, 'link' => Link::getLinksBlocks()]); }
/** * Display a listing of the resource. * * @return Response */ public function getList($criteria = Null) { //dd("A"); $message_list = Message::orderBy('created_at', 'desc')->paginate($this->show_per_page); //echo "<pre>"; //print_r($message_list->toArray()); //echo "</pre>"; //exit; // return view('admin.message.list', ['message_list' => $message_list]); }
public function actionContact() { $this->layout = 'page'; $model = new ContactForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $message = new Message(); $message->fullname = $model->fullname; $message->subject = $model->subject; $message->email = $model->email; $message->message = $model->message; $message->date = time(); $message->insert(); Yii::$app->session->setFlash('contactFormSubmitted'); return $this->refresh(); } else { $customData = CustomData::find()->where(['key' => 'contact'])->one(); $contactData = json_decode($customData->value, TRUE); return $this->render('contact', ['model' => $model, 'contactData' => $contactData]); } }
public function actionEdit() { $languages = Message::getLanguages(); $model = new Message(); $model->language = $_GET['language']; $model->file = $_GET['file']; $model->messageId = $_GET['message-id']; $model->message = Message::find($_GET['language'], $_GET['file'], $_GET['message-id']); $files = Message::getFiles($_GET['language']); return $this->render('edit', array('languages' => $languages, 'files' => $files, 'language' => $model->language, 'file' => $model->file, 'message' => $model->message, 'messageId' => $model->messageId)); }
public function actionDelMessage() { if (!Yii::$app->user->isGuest && Yii::$app->user->identity->isAdmin()) { $post = Yii::$app->request->post(); if ($post['id']) { $message = Message::find()->where(['id' => $post['id']])->one(); if ($message) { $message->delete(); } } } }