/** * Get the dialog message * @param int $c_id the user * @return null|\Modules\User\Models\Dialog */ public function getDialogMessage($c_id) { $sql = 'SELECT R.cr_id,R.time,R.reply,U.id,U.name,U.avatar FROM [prefix]_users U, [prefix]_users_dialog_reply R WHERE R.user_id_fk=U.id AND R.c_id_fk=' . $c_id . ' ORDER BY R.cr_id DESC LIMIT 20'; $mailArray = $this->db()->queryArray($sql); if (empty($mailArray)) { return null; } $mails = array(); foreach ($mailArray as $mail) { $mailModel = new DialogModel(); $mailModel->setId($mail['id']); $mailModel->setCrId($mail['cr_id']); $mailModel->setName($mail['name']); $mailModel->setText($mail['reply']); $mailModel->setTime($mail['time']); if (file_exists($mail['avatar'])) { $mailModel->setAvatar($mail['avatar']); } else { $mailModel->setAvatar('static/img/noavatar.jpg'); } $mails[] = $mailModel; } return array_reverse($mails); }
public function dialogviewAction() { $DialogMapper = new DialogMapper(); $ilchdate = new IlchDate(); $c_id = $this->getRequest()->getParam('id'); $user = $DialogMapper->getDialogCheckByCId($c_id); if ($this->getUser()->getId() != $user->getUserTwo()) { $user_two = $user->getUserOne(); } else { $user_two = $user->getUserTwo(); } if ($this->getUser()->getId() == $user_two) { if ($this->getRequest()->isPost()) { $u_id_fk = $this->getUser()->getId(); $text = trim($this->getRequest()->getPost('text')); $model = new DialogModel(); $model->setCId($c_id); $model->setId($u_id_fk); $model->setTime($ilchdate->toDb()); $model->setText($text); $DialogMapper->save($model); $this->redirect(array('action' => 'dialogview', 'id' => $c_id)); } $this->getView()->set('inbox', $DialogMapper->getDialogMessage($c_id)); } else { $this->redirect(array('action' => 'dialog')); } }