Example #1
0
 /**
  * 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);
 }
Example #2
0
 public function dialognewAction()
 {
     $DialogMapper = new DialogMapper();
     $ilchdate = new IlchDate();
     $user_one = $this->getUser()->getId();
     $user_two = $this->getRequest()->getParam('id');
     if ($user_one != $user_two) {
         $c_exist = $DialogMapper->getDialogCheck($user_one, $user_two);
         if ($c_exist == 0) {
             $model = new DialogModel();
             $model->setUserOne($user_one);
             $model->setUserTwo($user_two);
             $model->setTime($ilchdate->toDb());
             $DialogMapper->save($model);
             $c_id = $DialogMapper->getDialogId($user_one);
             $this->redirect(array('action' => 'dialogview', 'id' => $c_id->getCId()));
         }
         $c_id = $DialogMapper->getDialogId($user_one);
         $this->redirect(array('action' => 'dialogview', 'id' => $c_id->getCId()));
     }
 }