コード例 #1
0
ファイル: Chat.php プロジェクト: locoss/onlinechat
 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
ファイル: User.php プロジェクト: locoss/onlinechat
 public function getLoginResponse()
 {
     $response = array('status' => 1, 'name' => $this->getName(), 'gravatar' => Helper::gravatarFromHash($this->getGravatar()));
     return json_encode($response);
 }
コード例 #3
0
ファイル: Index.php プロジェクト: locoss/onlinechat
 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()));
     }
 }