public function postAction()
 {
     $user_id = $this->zfcUserAuthentication()->getIdentity()->getId();
     $form = new NewsForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $imagine = $this->getServiceLocator()->get('image_service');
         $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
         $news = new News();
         $form->setInputFilter($news->getInputFilter());
         $form->setData($data);
         if ($form->isValid()) {
             $file_name = rand(999999, 9999999) . '.jpg';
             foreach ($this->image_sizes as $sizes) {
                 $mode = $sizes[2];
                 $folder = $this->image_folder . '/' . $sizes[0] . 'x' . $sizes[1];
                 @mkdir($this->image_folder . '/' . $sizes[0] . 'x' . $sizes[1], 0777, true);
                 $size = new Box($sizes[0], $sizes[1]);
                 $imagine->open($data['photo']['tmp_name'])->thumbnail($size, $mode)->save($folder . '/' . $file_name);
             }
             $news->exchangeArray($form->getData());
             $news->user_id = $user_id;
             $news->photo = $file_name;
             $this->getNewsTable()->saveNews($news);
             return $this->redirect()->toRoute('account');
         }
     }
     return array('form' => $form, 'user_id' => (int) $user_id);
 }
Ejemplo n.º 2
0
 /**
  * Adds a new News to the db or opens up the form for adding, if it isn't opened yet.
  *
  * @return array|\Zend\Http\Response
  * @throws \Exception
  */
 public function addAction()
 {
     $session = $session = new \Zend\Session\Container('user');
     if (!PermissionChecker::check(Role::ELDER)) {
         return $this->redirect()->toRoute('account', ['action' => 'noright']);
     }
     $form = new NewsForm();
     $form->get('category_id')->setValueOptions($this->createCategorySelect());
     $request = $this->getRequest();
     if ($request->isPost()) {
         $news = new News();
         $form->setInputFilter($news->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $news->exchangeArray($form->getData());
             if ($this->checkWordLengths($news->getContent())) {
                 $this->getNewsTable()->saveNews($news);
                 return $this->redirect()->toRoute('news');
             } else {
                 return ['form' => $form, 'accountId' => $session->id, 'error' => 'tooLong'];
             }
         } else {
             return ['form' => $form, 'accountId' => $session->id, 'error' => 'tooLong'];
         }
     }
     return ['form' => $form, 'accountId' => $session->id];
 }
Ejemplo n.º 3
0
 /**
  * Saves the given news object to the db
  *
  * @param \News\Model\News $news
  *
  * @throws \Exception
  */
 public function saveNews(News $news)
 {
     $data = ['account_id' => $news->getAccountId(), 'title' => $news->getTitle(), 'content' => $news->getContent(), 'category_id' => $news->getCategoryId(), 'date_posted' => $news->getDatePosted()];
     $id = (int) $news->getId();
     if ($id == 0) {
         $this->tableGateway->insert($data);
     } else {
         if ($this->getNews($id)) {
             $this->tableGateway->update($data, ['id' => $id]);
         } else {
             throw new \Exception('News id does not exist');
         }
     }
 }
Ejemplo n.º 4
0
 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()));
 }
Ejemplo n.º 5
0
 public function editNewsAction()
 {
     $this->layout('layout/home');
     $catalog = $this->forward()->dispatch('Catalog\\Controller\\Index', array('action' => 'getdata'));
     $this->layout()->catalog = $catalog;
     $allcat = $this->forward()->dispatch('Catalog\\Controller\\Index', array('action' => 'getall'));
     $this->layout()->allcat = $allcat;
     $getuser = $this->forward()->dispatch('Admin\\Controller\\Index', array('action' => 'getuser'));
     if (!$getuser) {
         // not yet login
         $this->redirect()->toRoute('home');
     }
     $this->layout()->getuser = $getuser;
     $news_id = $this->params()->fromRoute('id', 0);
     if ($news_id == 0) {
         return $this->redirect()->toRoute('News', array('controller' => 'news', 'action' => 'list-news'));
     } else {
         $newsTable = $this->getServiceLocator()->get('NewsTable');
         $form = new NewsForm();
         $form->setInputFilter(new NewsFilter());
         $form->get('news_thumbnail')->removeAttributes(array('required'));
         $filter = $form->getInputFilter();
         $filter->get('news_thumbnail')->setRequired(false);
         $newsDetail = $newsTable->getNewsById($news_id);
         $this->_fileName = $newsDetail->news_thumbnail;
         $form->bind($newsDetail);
         if ($this->getRequest()->isPost()) {
             $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
             $form->setData($data);
             if (!$form->isValid()) {
                 return new ViewModel(array('error' => true, 'form' => $form, 'image' => $this->_fileName, 'news_id' => $news_id));
             } else {
                 $exchange_data = array();
                 $exchange_data['news_id'] = $news_id;
                 if ($data['news_thumbnail']['name'] == "") {
                     $exchange_data['news_thumbnail'] = '';
                 } else {
                     $fileName = $this->upload();
                     $exchange_data['news_thumbnail'] = $fileName;
                 }
                 $exchange_data['news_name'] = $data['news_name'];
                 $exchange_data['news_content'] = $data['news_content'];
                 $newsModel = new News();
                 $newsModel->exchangeArray($exchange_data);
                 $newsTable->saveNews($newsModel);
                 return $this->redirect()->toRoute('News', array('controller' => 'news', 'action' => 'list-news'));
             }
         }
         return new ViewModel(array('form' => $form, 'image' => $this->_fileName, 'news_id' => $news_id));
     }
 }