public function indexAction() { //Accept Parent Module, Return Main Menu Lists with Active Menu Indicator $this->accessRights(12); $this->childModuleAccessRights(28, 'view'); //Accept Child Module ID & it's Actions: add, edit, view, disable $form_email = new RecipientForm(); $form_email->get('mailing_list_id')->setAttribute('options', $this->dropDownMailingList()); $this->adapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'); return new ViewModel(array('mailinglist' => $this->getMailingListTable()->fetchAll(), 'recipient' => $this->getRecipientTable()->fetchAll($this->adapter), 'list_form' => new MailingListForm(), 'email_form' => $form_email, 'access_rights' => $this->getSubModuleAccessRights(28))); }
public function editAction() { $this->accessRights(12); $this->childModuleAccessRights(28, 'edit'); //Accept Child Module ID & it's Actions: add, edit, view, disable $id = (int) $this->params()->fromRoute('id', 0); try { $recipient = $this->getRecipientTable()->getRecipient($id); } catch (\Exception $ex) { return $this->redirect()->toRoute('recipient', array('action' => 'index')); } $form = new RecipientForm(); $form->bind($recipient); $form->get('mailing_list_id')->setAttribute('options', $this->dropDownMailingList()); $form->get('submit')->setAttribute('value', 'Edit'); $request = $this->getRequest(); if ($request->isPost()) { // prepare audit trail parameters $from = (array) $recipient; $to = $this->getRequest()->getPost()->toArray(); // end of audit trail parameters $form->setInputFilter($recipient->getInputFilter()); // arrange data to form $form->setData($request->getPost()); if ($form->isValid()) { $checkIfExists = $this->getRecipientTable()->checkEmailAddressExists($request->getPost('email_address'), $request->getPost('fname'), $request->getPost('mname'), $request->getPost('lname'), $request->getPost('mailing_list_id')); if ($this->noRecordExists('user_emails', 'email_address') || $from['email_address'] == $to['email_address']) { $diff = array_diff_assoc($to, $from); unset($diff['submit'], $diff['email_id']); $changes = $this->prepare_modified_data($from, $to, $diff); $this->getRecipientTable()->saveRecipient($recipient); $this->save_to_audit_trail($to['email_address'], $changes['pre'], $changes['post'], 'edit', 28); // show alert of updated data $this->flashMessenger()->addMessage(['content' => $request->getPost('email_address') . ' email address has been updated.', 'type' => 'success']); } else { $this->flashMessenger()->addMessage(['content' => $request->getPost('email_address') . ' already exists!', 'type' => 'danger']); } } return $this->redirect()->toRoute('mail'); } }