public function viewAction() { $this->accessRights(30); //Check User Roles $this->childModuleAccessRights(30, 'view'); //Accept Child Module ID & it's Actions: add, edit, view, disable $msgs = ''; //Get user id and validate $events_id = (int) $this->params()->fromRoute('id', 0); if (!$events_id) { return $this->redirect()->toRoute('event', array('action' => 'index')); } //Generate Adapter $this->adapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'); // Get the Event with the specified id. An exception is thrown // if it cannot be found, in which case go to the index page. try { $event = $this->getEventTable()->getEvent($events_id); //Get anchor data } catch (\Exception $ex) { return $this->redirect()->toRoute('event', array('action' => 'index')); } $from = (array) $event; $form = new EventForm($this->adapter); $form->setData($event); //Update record after data posting $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); //get previously posted data //Update user credentials $event = new Event(); $form->setInputFilter($event->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $event->exchangeArray($request->getPost()); $guest_lists = $this->getEventTable()->fetchAllMediaProfiles($this->adapter, $events_id); $from_guest_list = array(); $to_guest_list = array(); //Check if we have guests from DB if (count($guest_lists) > 0) { foreach ($guest_lists as $guest_list) { $str = $guest_list['media_profiles_id']; //Check if guest is invited if ($guest_list['invited'] == 'checked') { $str .= "|Invited"; } else { $str .= "|Uninvited"; } //check if user has attended if ($guest_list['attended'] == 'checked') { $str .= "|Attended"; } else { $str .= "|Unattended"; } //check if user has attended if ($guest_list['confirmed'] == 'checked') { $str .= "|Confirmed"; } else { $str .= "|Revoke"; } array_push($from_guest_list, $str); } } //Check if we have new guest lists if (count($request->getPost('guest_lists')) > 1) { foreach ($request->getPost('guest_lists') as $guest_list) { $str = $guest_list; //Check if guest is invited $str .= "|" . $this->checkAttendedInvited('Invited', $request->getPost('invites'), $guest_list); //check if user has attended //Check if guest is invited $str .= "|" . $this->checkAttendedInvited('Attended', $request->getPost('attendees'), $guest_list); //check if user has attended //Check if guest is invited $str .= "|" . $this->checkAttendedInvited('Confirmed', $request->getPost('confirmees'), $guest_list); array_push($to_guest_list, $str); } } //Extract Diff into one string difference $differences_guests = array_diff($to_guest_list, $from_guest_list); $diff_str = ""; foreach ($differences_guests as $difference) { $diff_str .= 'media=full_name:' . $this->getEventTable()->getAllGuestLists($this->adapter, explode('|', $difference)[0])['full_name'] . "|"; $diff_str .= explode('|', $difference)[1] . "|"; $diff_str .= explode('|', $difference)[2] . "|"; $diff_str .= explode('|', $difference)[3] . "|"; } //Save to Audit Trail //prepare audit trail parameters $to = $this->getRequest()->getPost()->toArray(); $diff = array_diff_assoc($to, $from); unset($diff['submit'], $diff['DataTables_Table_0_length'], $diff['guest_lists'], $diff['attendees'], $diff['invites'], $diff['DataTables_Table_1_length'], $diff['guest_list'], $diff['invitee'], $diff['attendee'], $diff['confirmee'], $diff['confirmees']); //Remove IDs $changes = $this->prepare_modified_data($from, $to, $diff); $changes['post'] .= $diff_str; $diff_str_from = ""; //Get the differences and compare from foreach ($differences_guests as $difference) { //Find diff from from_variable $find_me = explode('|', $difference)[0]; foreach ($from_guest_list as $from_guest_list_expand) { if ($find_me == explode('|', $from_guest_list_expand)[0]) { //Get the guest details $diff_str_from .= 'media=full_name:' . $this->getEventTable()->getAllGuestLists($this->adapter, explode('|', $from_guest_list_expand)[0])['full_name'] . "|"; $diff_str_from .= explode('|', $from_guest_list_expand)[1] . "|"; $diff_str_from .= explode('|', $from_guest_list_expand)[2] . "|"; $diff_str_from .= explode('|', $from_guest_list_expand)[3] . "|"; } } } $changes['pre'] .= $diff_str_from; $this->save_to_audit_trail($to['event_name'], $changes['pre'], $changes['post'], 'edit', 30); $this->getEventTable()->saveEvent($request->getPost()); $this->flashMessenger()->addMessage(['content' => $request->getPost('event_name') . ' has been updated.', 'type' => 'success']); return $this->redirect()->toRoute('event'); } } $view = new ViewModel(array('form' => $form, 'msgs' => $msgs, 'channels' => $this->getEventTable()->fetchAll($this->adapter), 'action' => 'preview', 'events_id' => $events_id, 'media_profiles_new' => $this->getEventTable()->fetchAllMediaProfilesNew($this->adapter, $events_id), 'media_profiles' => $this->getEventTable()->fetchAllMediaProfiles($this->adapter, $events_id), 'access_rights' => $this->getSubModuleAccessRights(30))); $view->setTemplate('event/preview'); return $view; }
public function deleteAction() { $request = $this->getRequest(); if ($request->isPost()) { $event = $request->getPost()->toArray(); $events_obj = new Event($this->em, new WebsiteTbEvents()); $json = array('status' => $events_obj->delete($event)); echo Json::encode($json); return false; } }