public function restPostMessage() { $postData = $this->params()->fromPost(); $form = new Form\MessageForm(); $form->useSubFormGroup()->bind($postData); $callback = $this->params()->fromPost('callback', '/message/messages/'); if ($form->isValid()) { $messageData = $form->getData(); $userModel = Api::_()->getModel('User\\Model\\User'); $recipient = $userModel->getUser($messageData['Conversation']['recipient_id']); $sender = \Core\Auth::getLoginUser(); if (!isset($recipient['id']) || !isset($sender['id']) || $recipient['id'] == $sender['id']) { exit; } if (!is_numeric($messageData['Conversation']['recipient_id'])) { $messageData['Conversation']['recipient_id'] = $recipient['id']; } $itemModel = Api::_()->getModel('Message\\Model\\Message'); $messageId = $itemModel->setItem($messageData)->createMessage(); $this->flashMessenger()->addMessage('message-create-succeed'); $this->redirect()->toUrl($callback); } else { } return array('form' => $form, 'message' => $messageData); }
public function editAction() { $form = new MessageForm(); $this->translator = $this->getServiceLocator()->get('translator'); $form->get('submitbutton')->setAttribute('value', $this->translator->translate('Modifier')); $this->messageDao = new MessageDao(); $id = (int) $this->params()->fromRoute('id', 0); /* if ($id == 0) { return $this->redirect()->toRoute('Message', array( 'action' => 'add' )); } */ $message = $this->messageDao->getMessage($id); $messageId = $message->getId(); if (!empty($id)) { if (empty($messageId)) { //return $this->getResponse()->setStatusCode(404); return $this->notFoundAction(); } } $form->get('id')->setAttribute('value', $message->getId()); $form->get('row1')->setAttribute('value', $message->getRow1()); $form->get('row2')->setAttribute('value', $message->getRow2()); $form->get('row3')->setAttribute('value', $message->getRow3()); $form->get('row4')->setAttribute('value', $message->getRow4()); $form->get('type')->setAttribute('value', $message->getType()); $form->get('msg')->setAttribute('value', $message->getMessage()); //$form->get('position')->setAttribute('value', $message->getRang()); $form->get('timestamp')->setAttribute('value', $message->getDate()); $form->get('submitbutton')->setAttribute('value', 'Modifier'); $request = $this->getRequest(); if ($request->isPost()) { //trigger data controls $message = new Message(); $form->setInputFilter(new MessageInputFilter()); $form->setData($request->getPost()); //$form->setUseInputFilterDefaults(false); //print_r('nonOK'); // exit; if ($form->isValid()) { $filterData = new Utils(); $message->setId($filterData->stripTags_replaceHtmlChar_trim($request->getPost('id'), true, false, true)); $message->setRow1($filterData->stripTags_replaceHtmlChar_trim($request->getPost('row1'), false, false, true)); $message->setRow2($filterData->stripTags_replaceHtmlChar_trim($request->getPost('row2'), false, false, true)); $message->setRow3($filterData->stripTags_replaceHtmlChar_trim($request->getPost('row3'), false, false, true)); $message->setRow4($filterData->stripTags_replaceHtmlChar_trim($request->getPost('row4'), false, false, true)); $message->setType($filterData->stripTags_replaceHtmlChar_trim($request->getPost('type'), true, true, true)); $message->setDate($filterData->stripTags_replaceHtmlChar_trim($request->getPost('timestamp'), true, false, true)); //$message['position'] = $filterData->stripTags_replaceHtmlChar_trim($request->getPost('position'), true, true, true); $message->setMessage($filterData->stripTags_replaceHtmlChar_trim($request->getPost('msg'), true, true, true)); $this->messageDao->saveMessage($message); //flush cache $this->getServiceLocator()->get('CacheDataListener')->getCacheService()->flush(); return $this->redirect()->toRoute('Message'); } else { return array('id' => $id, 'form' => $form, 'error' => $form->getMessages()); } } return array('id' => $id, 'form' => $form, 'error' => "no error"); }