public function indexAction() { $this->accessRights(12); //Accept Parent Module, Return Main Menu Lists with Active Menu Indicator $this->childModuleAccessRights(32, 'view'); //Accept Child Module ID & it's Actions: add, edit, view, disable $source_form = new SourceForm(); $source_form->get('media_outfit_name')->setAttribute('options', $this->dropDownSourceKindId()); $source_form->get('media_outfit_name')->setLabel('Source Kind'); $this->adapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'); return array('source' => $this->getSourceTable()->fetchSource($this->adapter), 'source_form' => $source_form, 'access_rights' => $this->getSubModuleAccessRights(32), 'tab_menus' => $this->getTabMenu('Source')); }
public function editAction() { $this->accessRights(12); //Accept Parent Module, Return Main Menu Lists with Active Menu Indicator $this->childModuleAccessRights(32, 'edit'); //Accept Child Module ID & it's Actions: add, edit, view, disable $id = (int) $this->params()->fromRoute('id', 0); if (!$id) { return $this->redirect()->toRoute('source', array('action' => 'add')); } try { $source = $this->getSourceTable()->getSource($id); } catch (\Exception $ex) { return $this->redirect()->toRoute('source', array('action' => 'index')); } $form = new SourceForm(); $form->bind($source); // $form->get('source_kind_id')->setAttribute('options', $this->dropDownSourceKindId()); $form->get('submit')->setAttribute('value', 'Edit'); $request = $this->getRequest(); if ($request->isPost()) { // prepare audit trail parameters $from = (array) $source; $to = $this->getRequest()->getPost()->toArray(); $diff = array_diff_assoc($to, $from); unset($diff['submit'], $diff['sources_id']); $changes = $this->prepare_modified_data($from, $to, $diff); // end of audit trail parameters $form->setInputFilter($source->getInputFilter()); $form->setData($request->getPost()); $form->getInputFilter()->remove('media_outfit_name'); if ($form->isValid()) { $this->getSourceTable()->saveSource($this->getRequest()->getPost()); $this->save_to_audit_trail($to['source_name'], $changes['pre'], $changes['post'], 'edit', 32); // show alert of updated data $this->flashMessenger()->addMessage(['content' => $request->getPost('source_name') . ' source has been updated.', 'type' => 'success']); } return $this->redirect()->toRoute('sources'); } }
public function editAction() { $this->accessRights(15); //Accept Parent Module, Return Main Menu Lists with Active Menu Indicator $this->childModuleAccessRights(15, 'edit'); //Accept Child Module ID & it's Actions: add, edit, view, disable $id = (int) $this->params()->fromRoute('id', 0); // get the specific article type's id //Get session variable $session = new Container('base'); $user = $session->offsetGet('user'); if (!$id) { //if id from route is null, then redirect to add form return $this->redirect()->toRoute('news_management', array('action' => 'ne', 'access_rights' => $this->getSubModuleAccessRights(15))); } // Get the article type with the specified id. An exception is thrown // if it cannot be found, in which case go to the index page. try { $news = $this->getNewsTable()->getNews($id); $news_detail = $this->getNewsTable()->getNewsDetail($id, $this->serviceLocator()); } catch (\Exception $ex) { return $this->redirect()->toRoute('news_management', array('action' => 'nyoknyok', 'access_rights' => $this->getSubModuleAccessRights(15))); } $form = new NewsForm($this->serviceLocator()); //instantiate the Article Type's Form $form->setData($news); // populate news header data $form->setData($news_detail); // populate news detail data $form_storyAngle = new StoryAngleForm(); //instantiate Story Angle's Form $form_source = new SourceForm(); //instantiate Source's Form $form_source->get('media_outfit_name')->setAttribute('options', $this->optionMediaOutfits()); $form_initiated_by = new InitiatedByForm(); //instantiate initiated by's form $form_radio_station = new RadioStationForm(); // instantiate radio station's form $form_tv_channel = new TVChannelForm(); // instantiate radio station's form $form_tv_program = new TVProgramForm($this->serviceLocatorInterface()); // instantiate radio station's form $form_section = new SectionForm(); // instantiate section's form $form_radio_program = new RadioProgramForm($this->serviceLocator()); // instantiate section's form $form_media_profile = new MediaProfileForm($this->serviceLocator()); // instantiate media profile's form //get all id for approval $story_angle_id = $news['story_angle_id'] == '' ? 0 : $news['story_angle_id']; $section_id = $news_detail['section_id'] == '' ? 0 : $news_detail['section_id']; $source_id = $news_detail['source_id'] == '' ? 0 : $news_detail['source_id']; $initiated_by = $news_detail['initiated_by'] == '' ? 0 : $news_detail['initiated_by']; $media_profile_id = $news_detail['media_profile_id'] == '' ? 0 : $news_detail['media_profile_id']; $radio_program_id = $news_detail['radio_program_id'] == '' ? 0 : $news_detail['radio_program_id']; $radio_station_id = $news_detail['radio_station_id'] == '' ? 0 : $news_detail['radio_station_id']; $tv_channel_id = $news_detail['tv_channel_id'] == '' ? 0 : $news_detail['tv_channel_id']; $program_title = $news_detail['program_title'] == '' ? 0 : $news_detail['program_title']; //count all approvals, if yes, submit button will hide //format : CheckHasApproval(Adapter, table_name, column_name_id, $id) $story_angle_for_approvals = $this->getNewsTable()->CheckHasApproval($this->serviceLocator(), 'story_angles', 'story_angles_id', $story_angle_id); $section_for_approvals = $this->getNewsTable()->CheckHasApproval($this->serviceLocator(), 'sections', 'sections_id', $section_id); $source_for_approvals = $this->getNewsTable()->CheckHasApproval($this->serviceLocator(), 'sources', 'sources_id', $source_id); $initiated_for_approvals = $this->getNewsTable()->CheckHasApproval($this->serviceLocator(), 'initiated_by', 'initiated_id', $initiated_by); $media_profile_for_approvals = $this->getNewsTable()->CheckHasApproval($this->serviceLocator(), 'media_profiles', 'media_profiles_id', $media_profile_id); $radio_program_for_approvals = $this->getNewsTable()->CheckHasApproval($this->serviceLocator(), 'radio_programs', 'radio_programs_id', $radio_program_id); $radio_station_for_approvals = $this->getNewsTable()->CheckHasApproval($this->serviceLocator(), 'radio_stations', 'radio_stations_id', $radio_station_id); $tv_channel_for_approvals = $this->getNewsTable()->CheckHasApproval($this->serviceLocator(), 'tv_channels', 'tv_channels_id', $tv_channel_id); $tv_program_for_approvals = $this->getNewsTable()->CheckHasApproval($this->serviceLocator(), 'tv_programs', 'tv_programs_id', $program_title); $count_all_for_approvals = $story_angle_for_approvals + $section_for_approvals + $source_for_approvals + $initiated_for_approvals + $media_profile_for_approvals + $radio_program_for_approvals + $radio_station_for_approvals + $tv_channel_for_approvals + $tv_program_for_approvals; if ($news['status'] == 2) { $form->get('story_angle_id')->setAttribute('options', $this->optionStoryAnglesForApproval($story_angle_id)); $form->get('section_id')->setAttribute('options', $this->optionSectionsForApproval($section_id)); $form->get('source_id')->setAttribute('options', $this->optionSourcesForApproval($source_id)); $form->get('initiated_by')->setAttribute('options', $this->optionInitiatedBysForApproval($initiated_by)); $form->get('media_profile_id')->setAttribute('options', $this->optionMediaProfilesForApproval($media_profile_id)); $form->get('radio_program_id')->setAttribute('options', $this->optionRadioProgramsForApproval($radio_program_id)); $form->get('radio_station_id')->setAttribute('options', $this->optionRadioStationsForApproval($radio_station_id)); $form->get('tv_channel_id')->setAttribute('options', $this->optionTvChannelsForApproval($tv_channel_id)); $form->get('program_title')->setAttribute('options', $this->optionTvProgramsForApproval($program_title)); } else { $form->get('story_angle_id')->setAttribute('options', $this->optionStoryAngles()); $form->get('section_id')->setAttribute('options', $this->optionSections()); $form->get('source_id')->setAttribute('options', $this->optionSources()); $form->get('initiated_by')->setAttribute('options', $this->optionInitiatedBys()); $form->get('media_profile_id')->setAttribute('options', $this->optionMediaProfiles()); $form->get('radio_program_id')->setAttribute('options', $this->optionRadioPrograms()); $form->get('radio_station_id')->setAttribute('options', $this->optionRadioStations()); $form->get('tv_channel_id')->setAttribute('options', $this->optionTvChannels()); $form->get('program_title')->setAttribute('options', $this->optionTvPrograms()); } $form->get('radio_station_id')->setAttribute('options', $this->optionRadioStations()); // //populate the data in dropdown menu for ONLINE NEWS and PRINT NEWS(local and national) $form->get('company_id')->setAttribute('options', $this->optionCompanies()); $form->get('industry_id')->setAttribute('options', $this->optionIndustries()); $form->get('article_type_id')->setAttribute('options', $this->optionArticleTypes()); $form->get('section_editor_id')->setAttribute('options', $this->optionMediaProfiles()); //check if request is post and if it's valid, if so, the data will save $request = $this->getRequest(); if ($request->isPost()) { $news_model = new News(); $from = (array) $news; $to = $this->getRequest()->getPost()->toArray(); //get post data $post = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray()); //get 3 fields for validating news article $title = $_POST['title']; $article_date = $_POST['article_date']; $media_outfit = $_POST['media_outfit_id']; //switch source depending on media outfit switch ($media_outfit) { case 1: $source = $_POST['source_id']; break; case 4: $source = $_POST['source_id']; break; case 5: $source = $_POST['source_id']; break; case 6: $source = $_POST['radio_station_id']; break; case 7: $source = $_POST['tv_channel_id']; } $news_source_exists = $this->getNewsTable()->news3FieldExists($this->serviceLocator(), $title, $article_date, $source); if (count($news_source_exists) == 0 || $from['title'] == $to['title']) { $news_model->exchangeArray($post); //save news details $last_id = $this->getNewsTable()->saveNewsDetail($this->serviceLocator(), $news_model); //save news header $this->getNewsTable()->saveNewsHeader($news_model, $last_id); //save link picture if ($_POST['link']) { $this->saveLinkImage($_POST['link']); } //flash message $this->flashMessenger()->addMessage(['content' => $request->getPost('title') . ' article updated!', 'type' => 'success']); } else { $this->flashMessenger()->addMessage(['content' => 'Article already exist in the system.', 'type' => 'danger']); } //Redirect to list of article type return $this->redirect()->toRoute('news_list'); } //return the form before saving changes in news article. return new ViewModel(array('news_header_id' => $id, 'media_outfit_id' => $news_detail['media_outfit_id'], 'sub_kind' => $news_detail['sub_kind'], 'score' => $news_detail['score'], 'article_date' => $news['article_date'], 'video_status' => $news['video_status'], 'link' => $news_detail['link'], 'attachment' => $news_detail['attachment'], 'form' => $form, 'count_all_for_approvals' => $count_all_for_approvals, 'access_rights' => $this->getSubModuleAccessRights(15), 'form_storyAngle' => $form_storyAngle, 'story_angle_last_id' => $this->getStoryAngleLastId(), 'form_source' => $form_source, 'source_last_id' => $this->getSourceLastId(), 'form_initiated_by' => $form_initiated_by, 'initiated_by_last_id' => $this->getInitiatedByLastId(), 'form_radio_station' => $form_radio_station, 'radio_station_last_id' => $this->getRadioStationLastId(), 'form_tv_channel' => $form_tv_channel, 'tv_channel_last_id' => $this->getTVChannelLastId(), 'form_tv_program' => $form_tv_program, 'tv_program_last_id' => $this->getTVProgramLastId(), 'form_section' => $form_section, 'section_last_id' => $this->getSectionLastId(), 'form_radio_program' => $form_radio_program, 'radio_program_last_id' => $this->getRadioProgramLastId(), 'form_media_profile' => $form_media_profile, 'media_profile_last_id' => $this->getMediaProfileLastId())); }