public static function notification($template, $recipient, $variables) { $variables['recipient'] = $recipient; if ($recipient instanceof User) { $recipient = array($recipient); } foreach ($recipient as $user) { $messageParts = View::make('messenger.templates.' . $template, $variables)->renderSections(); $thread = Thread::create(['subject' => $messageParts['subject']]); // Message Message::create(['thread_id' => $thread->id, 'user_id' => $user->id, 'body' => $messageParts['body'] . $messageParts['footer'], 'type' => 'notification']); // Sender Participant::create(['thread_id' => $thread->id, 'user_id' => $user->id]); // Recipients $thread->addParticipants(array($user->id)); } }
public function createThread($data) { $res = preg_match('#^\\[(?P<date>.*)\\]\\s(?P<challenge_index>\\w+\\s.*)\\s*\\[(?P<difficulty>\\w+)\\]\\s*(?P<title>.*)\\z#', $data['title'], $matches); if ($res) { $this->info($data['title'] . ' matches pattern'); $title = trim($matches['challenge_index']) . ' - ' . trim($matches['title']); $difficulty = strtolower($matches['difficulty']); $url = $data['url']; $thread_already_stored = Thread::where(['title' => $title, 'difficulty' => $difficulty, 'url' => $url])->count() > 0; if (!$thread_already_stored) { Thread::create(['title' => $title, 'difficulty' => $difficulty, 'url' => $data['url'], 'published_at' => $data['published_at'], 'content' => $data['content'], 'html_content' => $data['html_content']]); } } else { $this->warn($data['title'] . ' failed to match pattern'); } }
/** * Stores a new message thread * * @return mixed */ public function store() { $input = Input::all(); $thread = Thread::create(['subject' => $input['subject']]); // Message $message = Message::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'body' => strip_tags($input['message'])]); // Sender Participant::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'last_read' => new Carbon()]); // Recipients if (Input::has('recipients')) { $recipients = array_filter(explode(',', trim($input['recipients']))); $recipientsAllowed = array(); foreach ($recipients as $recipient) { // Until further notice, remove the check to see if the participant is allowed to message each other // if (UserRepository::canMessage($recipient)) { $recipientsAllowed[] = $recipient; // } } $thread->addParticipants($recipientsAllowed); } $participants = $message->thread->participants; foreach ($participants as $participant) { if ($participant->user->id != $message->user->id) { Event::fire('App.Events.NewMessage', [new NewMessage($participant)]); } } return Redirect::to('messages'); }