protected function privateMessage(User $user, $forId, $data) { $message = new Message(); $message->user = $user; $message->for = User::find($forId); $message->datetime = new \DateTime(); $message->data = $data; $message->save(); $this->sendToUser($forId, Protocol::message($message)); return $message; }
/** * @Route("/", name="chat") */ public function index() { $em = $this->app->entityManager(); if (!$this->app->isAuthenticated()) { return $this->render('index.twig'); } else { $user = $this->app->user(); // Recent messages $recent = array(); foreach (Message::getLastMessages($user->id) as $message) { $recent[] = $message->exportWithUser(); } // Reverse array of messages $recent = array_reverse($recent); // Language $lang = array(); $translator = $this->app['translator']; if ($translator instanceof Translator) { $lang = $translator->getCatalogue()->all('browser'); } return $this->render('chat/chat.twig', array('user' => $user->export(), 'recent' => $recent, 'lang' => $lang)); } }
public static function message(Message $message) { return self::data(self::MESSAGE, $message->exportWithUser()); }