Ejemplo n.º 1
0
 /**
  *
  */
 private function load()
 {
     $table = new Db\Table\Conversations();
     $userTable = new Users();
     $view = new \Cunity\Messages\View\Conversation();
     $conversation = $table->loadConversationDetails($_GET['action']);
     $users = explode(",", $conversation['users']);
     if (!in_array($_SESSION['user']->userid, $users)) {
         $view = new PageNotFound();
     } else {
         unset($users[array_search($_SESSION['user']->userid, $users)]);
     }
     $table->markAsRead($_GET['action']);
     if (!empty($users)) {
         $conversation['users'] = $userTable->getSet($users, "u.userid", ["u.userid", "u.username", "u.name"])->toArray();
         $usernames = "";
         foreach ($conversation['users'] as $user) {
             $usernames .= $user['name'] . ',';
         }
         $view->setMetaData(["title" => substr($usernames, 0, -1)]);
     } else {
         $view->setMetaData(["title" => "Conversation"]);
     }
     $view->assign("conversation", $conversation);
     $view->show();
 }
Ejemplo n.º 2
0
 /** @noinspection PhpUnusedPrivateMethodInspection */
 private function send()
 {
     $table = new Db\Table\Messages();
     $res = $table->insert(["sender" => $_SESSION['user']->userid, "conversation" => $_POST['conversation_id'], "message" => $_POST['message'], "source" => $_POST['source']]);
     $conversation = new Conversations();
     if ($_POST['source'] == "chat") {
         $conversation->markAsRead($_POST['conversation_id']);
     }
     $c = $conversation->loadConversationDetails($_GET['action']);
     $users = explode(",", $c['users']);
     unset($users[array_search($_SESSION['user']->userid, $users)]);
     $view = new View($res !== false);
     $view->addData(["data" => ["conversation_id" => $_POST['conversation_id'], "message" => $_POST['message'], "time" => date("Y-m-d H:i:s", time()), "sender" => $_SESSION['user']->userid, "id" => $res]]);
     $view->sendResponse();
 }
Ejemplo n.º 3
0
 /**
  * @param array $data
  * @return mixed
  */
 public function insert(array $data)
 {
     $conversation = new Conversations();
     $conversation->markAsUnRead($data['conversation']);
     return parent::insert($data);
 }
Ejemplo n.º 4
0
 /**
  *
  */
 private function markAsRead()
 {
     $conversation = new Db\Table\Conversations();
     $view = new View($conversation->markAsRead($_POST['conversation_id']));
     $view->sendResponse();
 }