示例#1
0
 public function getChatsResponse()
 {
     $chats = array();
     if (is_array($this->getResource())) {
         foreach ($this->getResource() as $chat) {
             $chat->time = array('hours' => gmdate('H', strtotime($chat->ts)), 'minutes' => gmdate('i', strtotime($chat->ts)));
             $chat->gravatar = Helper::gravatarFromHash($chat->gravatar);
             $chats[] = $chat;
         }
         $response = array('chats' => $chats);
         return json_encode($response);
     }
     return json_encode(array('chats' => $chats));
 }
示例#2
0
 public function getLoginResponse()
 {
     $response = array('status' => 1, 'name' => $this->getName(), 'gravatar' => Helper::gravatarFromHash($this->getGravatar()));
     return json_encode($response);
 }
示例#3
0
 public function submitchatAction()
 {
     $chatText = $_POST['chatText'];
     $file = $_POST['file'];
     try {
         if (!$_SESSION['user']) {
             throw new \Exception('You are not logged in');
         }
         if (!$chatText) {
             throw new \Exception('You haven\' entered a chat message.');
         }
         $chatText = Helper::clean($chatText);
         $chat = new \Chat\App\Core\Model\Chat();
         $chat->setFilename($file);
         $chat->setAuthor($_SESSION['user']['name']);
         $chat->setGravatar($_SESSION['user']['gravatar']);
         $chat->setText($chatText);
         $chat->save();
         $chat->getChatSubmitResponse();
         $this->response = $chat->getChatSubmitResponse();
         return $this->response;
     } catch (\Exception $e) {
         $this->response = json_encode(array('error' => $e->getMessage()));
     }
 }