示例#1
0
 /**
  * {@inheritdoc}
  */
 protected function update()
 {
     $this->session->open();
     if (isset($this->session['jtk-notifications'])) {
         $notifications = $this->session['jtk-notifications'];
         if (is_array($notifications) and count($notifications) > 0) {
             unset($this->session['jtk-notifications']);
             $this->session->close();
             return Json::encodeResponse($notifications);
         }
     }
     $this->session->close();
     return null;
 }
示例#2
0
 public function post($data)
 {
     if (!$this->request->accepts('json')) {
         return $this->invalid();
     }
     $message = $this->Message->create($data, array('message'));
     if (preg_match('/^\\/name (.+)/i', $message->message, $matches) === 1) {
         $this->session['name'] = trim($matches[1]);
         return Json::encodeResponse('success');
     }
     if (isset($this->session['name'])) {
         $message->author = $this->session['name'];
     }
     if ($message->save()) {
         return Json::encodeResponse('success');
     }
     return Json::encodeResponse($message->getErors());
 }
示例#3
0
 protected function update()
 {
     if (isset($this->request->query['lastMessage'])) {
         $messages = $this->Message->where('id > %i', $this->request->query['lastMessage'])->orderBy('id');
         $response = array();
         foreach ($messages as $message) {
             $response[] = array('id' => $message->id, 'author' => $message->author, 'message' => $message->message);
         }
         if (count($response) > 0) {
             return Json::encodeResponse($response);
         }
     } else {
         $messages = $this->Message->orderByDescending('id')->limit(10);
         $response = array();
         foreach ($messages as $message) {
             $response[] = array('id' => $message->id, 'author' => $message->author, 'message' => $message->message);
         }
         $response = array_reverse($response);
         return Json::encodeResponse($response);
     }
     return null;
 }