public function saveMessage() { foreach (ChatUserRecord::finder()->findAll() as $user) { $message = new self(); $message->for_user = $user->username; $message->from_user = $this->from_user; $message->message = $this->message; $message->save(); if ($user->username == $this->from_user) { $user->last_activity = time(); //update the last activity; $user->save(); } } }
function refresh($sender, $param) { //refresh the message list $content = ChatBufferRecord::finder()->getUserMessages($this->Application->User->Name); if (strlen($content) > 0) { $client = $this->Page->CallbackClient; $anchor = (string) time(); $content .= "<a href=\"#\" id=\"{$anchor}\"> </a>"; $client->appendContent("messages", $content); $client->focus($anchor); } //refresh the user list $lastUpdate = $this->getViewState('userList', ''); $users = ChatUserRecord::finder()->getUserList(); if ($lastUpdate != $users) { $this->Page->CallbackClient->update('users', $users); $this->setViewstate('userList', $users); } }
/** * @return boolean true if username already exists, false otherwise. */ public function usernameExists($username) { return ChatUserRecord::finder()->findByUsername($username) instanceof ChatUserRecord; }