/** * Inserts or updates dialog entry. * * @param DialogModel $model */ public function save(DialogModel $model) { $fields = array('user_id_fk' => $model->getId(), 'reply' => $model->getText(), 'time' => $model->getTime(), 'c_id_fk' => $model->getCId(), 'user_one' => $model->getUserOne(), 'user_two' => $model->getUserTwo()); if (!empty($fields['user_one']) or !empty($fields['user_two'])) { $this->db()->insert('users_dialog')->values($fields)->execute(); return; } else { $this->db()->insert('users_dialog_reply')->values($fields)->execute(); } return; }
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())); } }