コード例 #1
0
ファイル: ContentController.php プロジェクト: jiiarra/site
 /**
  *   editAction
  *
  *   Edit content
  *
  */
 public function editAction()
 {
     // Get authentication
     $auth = Zend_Auth::getInstance();
     // If user has identity
     if ($auth->hasIdentity()) {
         // Get requests
         $params = $this->getRequest()->getParams();
         // Get session data
         $previewSession = new Zend_Session_Namespace('contentpreview');
         // If preview
         $backFromPreview = isset($previewSession->backFromPreview) ? $previewSession->backFromPreview : 0;
         $preview = isset($params['preview']) ? 1 : 0;
         if ($preview) {
             $previewSession->unsetAll();
             $previewSession->previewData = $params;
             $backToUrl = $this->getRequest()->getRequestUri();
             $previewSession->backToUrl = $backToUrl;
             $url = $this->_urlHelper->url(array('controller' => 'content', 'action' => 'preview', 'language' => $this->view->language), 'lang_default', true);
             $this->_redirect($url);
         }
         // Get content type
         $contentId = isset($params['content_id']) ? $params['content_id'] : 0;
         $userId = $auth->getIdentity()->user_id;
         $cntHasUsr = new Default_Model_ContentHasUser();
         $userIsOwner = $cntHasUsr->contentHasOwner($userId, $contentId);
         if ($userIsOwner) {
             if ($contentId != 0) {
                 $content = new Default_Model_Content();
                 $data = $content->getDataAsSimpleArray($contentId);
                 // Creating array for form data
                 $formData = array();
                 // Adding content type to form
                 $formData['content_type'] = $data['id_cty_cnt'];
                 // Adding content id to form
                 $formData['content_id'] = $contentId;
                 $formData['content_header'] = stripslashes($data['title_cnt']);
                 $modelCntHasTag = new Default_Model_ContentHasTag();
                 $keywords = $modelCntHasTag->getContentTags($data['id_cnt']);
                 $tags = "";
                 $tagCount = count($keywords);
                 for ($i = 0; $i < $tagCount; $i++) {
                     $tags .= $keywords[$i]['name_tag'];
                     if ($i != $tagCount - 1) {
                         $tags .= ', ';
                     }
                 }
                 $formData['content_keywords'] = stripslashes($tags);
                 $formData['content_textlead'] = stripslashes($data['lead_cnt']);
                 $formData['content_text'] = stripslashes($data['body_cnt']);
                 $modelCntHasRec = new Default_Model_ContentHasRelatedCompany();
                 $relComps = $modelCntHasRec->getContentRelComps($data['id_cnt']);
                 $recs = "";
                 $recCount = count($relComps);
                 for ($i = 0; $i < $recCount; $i++) {
                     $recs .= $relComps[$i]['name_rec'];
                     if ($i != $recCount - 1) {
                         $recs .= ', ';
                     }
                 }
                 $formData['content_related_companies'] = stripslashes($recs);
                 $formData['content_research'] = $data['research_question_cnt'];
                 $formData['content_opportunity'] = $data['opportunity_cnt'];
                 $formData['content_threat'] = $data['threat_cnt'];
                 $formData['content_solution'] = $data['solution_cnt'];
                 $formData['published_cnt'] = $data['published_cnt'];
                 $formData['content_references'] = $data['references_cnt'];
                 $languages = new Default_Model_Languages();
                 $idLngInd = $languages->getLangIdByLangName($this->view->language);
                 $allLanguages = $languages->getAllNamesAndIds();
                 $formData['languages'] = array();
                 $formData['languages'][0] = $this->view->translate("content-add-select-language");
                 foreach ($allLanguages as $lng) {
                     $formData['languages'][$lng['id_lng']] = $lng['name_lng'];
                 }
                 $finfoClasses = new Default_Model_FutureinfoClasses();
                 $allClasses = $finfoClasses->getAllNamesAndIds();
                 $formData['FutureinfoClasses'] = array();
                 $formData['FutureinfoClasses'][0] = $this->view->translate("content-add-select-finfo-classification");
                 foreach ($allClasses as $class) {
                     $formData['FutureinfoClasses'][$class['id_fic']] = $class['name_fic'];
                 }
                 // Getting innovation types from the database
                 $modelInnovationTypes = new Default_Model_InnovationTypes();
                 $innovationTypes = $modelInnovationTypes->getAllNamesAndIds();
                 // Getting the innovation type of the content
                 $modelCntHasIvt = new Default_Model_ContentHasInnovationTypes();
                 $formData['selected_ivt'] = $modelCntHasIvt->getInnovationTypeIdOfContent($data['id_cnt']);
                 // Adding all innovation types to form
                 $formData['InnovationTypes'] = array();
                 $formData['InnovationTypes'][0] = $this->view->translate("content-add-select-innovation");
                 foreach ($innovationTypes as $ivt) {
                     $formData['InnovationTypes'][$ivt['id_ivt']] = $ivt['name_ivt'];
                 }
                 // end foreach
                 if (empty($formData['InnovationTypes'])) {
                     $formData['InnovationTypes'] = array(0 => '----');
                 }
                 $languages = new Default_Model_Languages();
                 $idLngInd = $languages->getLangIdByLangName($this->view->language);
                 // Getting language of the content
                 $formData['content_language'] = $languages->getLangIdByLangName($data['language_cnt']);
                 // Getting the industry of the content
                 $modelCntHasInd = new Default_Model_ContentHasIndustries();
                 $cntInd = $modelCntHasInd->getIndustryIdOfContent($data['id_cnt']);
                 // Getting industries from the database
                 $modelIndustries = new Default_Model_Industries();
                 $industries = $modelIndustries->getNamesAndIdsById(0, $idLngInd);
                 // Getting all industries of the content
                 $industryIds = $modelIndustries->getAllContentIndustryIds($cntInd);
                 $formData['industryIds'] = $industryIds;
                 // Adding all industries of the content to form
                 $formData['selected_industry'] = $industryIds[0];
                 $formData['selected_division'] = $industryIds[1];
                 $formData['selected_group'] = $industryIds[2];
                 $formData['selected_class'] = $industryIds[3];
                 // Adding all industries to form
                 $formData['Industries'] = array();
                 $formData['Industries'][0] = $this->view->translate("content-add-select-industry");
                 foreach ($industries as $ind) {
                     $formData['Industries'][$ind['id_ind']] = $ind['name_ind'];
                 }
                 // end foreach
                 if (empty($formData['Industries'])) {
                     $formData['Industries'] = array(0 => '----');
                 }
                 // Adding all divisions to form
                 $formData['Divisions'] = array();
                 $formData['Divisions'][0] = $this->view->translate("content-add-select-division-no-industry");
                 if ($industryIds[0] != 0) {
                     $divisions = $modelIndustries->getNamesAndIdsById($industryIds[0], $idLngInd);
                     foreach ($divisions as $div) {
                         $formData['Divisions'][$div['id_ind']] = $div['name_ind'];
                     }
                     // end foreach
                 }
                 // Adding all groups to form
                 $formData['Groups'] = array();
                 $formData['Groups'][0] = $this->view->translate("content-add-select-group-no-division");
                 if ($industryIds[1] != 0) {
                     $groups = $modelIndustries->getNamesAndIdsById($industryIds[1], $idLngInd);
                     foreach ($groups as $grp) {
                         $formData['Groups'][$grp['id_ind']] = $grp['name_ind'];
                     }
                     // end foreach
                 }
                 $formData['Classes'] = array();
                 $formData['Classes'][0] = $this->view->translate("content-add-select-class-no-group");
                 // If there's no group selected
                 if ($industryIds[2] != 0) {
                     $classes = $modelIndustries->getNamesAndIdsById($industryIds[2], $idLngInd);
                     foreach ($classes as $class) {
                         $formData['Classes'][$class['id_ind']] = $class['name_ind'];
                     }
                     // end foreach
                 }
                 $modelContentTypes = new Default_Model_ContentTypes();
                 $contentType = $modelContentTypes->getTypeById($data['id_cty_cnt']);
                 $this->view->short_contenttype = $contentType;
                 $title_cnt = $content->getContentHeaderByContentId($data['id_cnt']);
                 $this->view->contentHeader = $title_cnt;
                 // Get contents filenames from database
                 $filesModel = new Default_Model_Files();
                 $filenames = $filesModel->getFilenamesByCntId($contentId);
                 $formData['filenames'] = $filenames;
                 // Form for content adding
                 $form = new Default_Form_EditContentForm(null, $formData, $contentId, $contentType, $this->view->language);
                 $form->populate($formData);
                 $this->view->form = $form;
                 $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
                 // populate form
                 if ($backFromPreview) {
                     // Get previewdata and populate it to form
                     $previewData = $previewSession->previewData;
                     $form->populate($previewData);
                     // Delete session data
                     $previewSession->unsetAll();
                 }
                 // If posted
                 if ($this->getRequest()->isPost()) {
                     // Get content data
                     $data = $this->getRequest()->getPost();
                     // Content id
                     $data['content_id'] = $contentId;
                     // If form data is valid, handle database insertions
                     $validForm = $form->isValid($data) ? true : isset($data['content_save']) && $data['content_save'] != '';
                     if ($validForm) {
                         // If form data is going to be published
                         if (isset($data['content_publish']) && $data['content_publish'] == 1) {
                             $data['publish'] = 1;
                             $message_error = 'content-publish-not-successful';
                         } elseif (isset($data['content_save']) && $data['content_save'] == 1) {
                             $data['publish'] = 0;
                             $message_error = 'content-save-not-successful';
                         }
                         // Content keywords
                         /* FIXED: split() is deprecated in PHP 5.3.0 -> and removed in
                          * PHP 6.0, so changed to explode(). Also trim(array) doesn't
                          * trim array values, so this is done with foreach now.
                          */
                         $keywords = array();
                         foreach (explode(',', $data['content_keywords']) as $keyword) {
                             if (trim($keyword) != "") {
                                 $keywords[] = strip_tags(trim($keyword));
                             }
                         }
                         $data['content_keywords'] = array_unique($keywords);
                         // Related companies
                         $relatedCompanies = array();
                         foreach (explode(',', $data['content_related_companies']) as $relatedCompany) {
                             if (trim($relatedCompany) != "") {
                                 $relatedCompanies[] = strip_tags(trim($relatedCompany));
                             }
                         }
                         $data['content_related_companies'] = array_unique($relatedCompanies);
                         // Get user id
                         $data['User']['id_usr'] = $auth->getIdentity()->user_id;
                         /*
                         							if($data['content_division'] == 0) {
                         								$data['content_industry_id'] = $data['content_industry'];
                         							} elseif($data['content_group'] == 0) {
                         								$data['content_industry_id'] = $data['content_division'];
                         							} elseif($data['content_class'] == 0) {
                         								$data['content_industry_id'] = $data['content_group'];
                         							} elseif($data['content_class'] != 0) {
                         								$data['content_industry_id'] = $data['content_class'];
                         							}*/
                         if ($data['content_language'] == 0) {
                             $data['content_language'] = $this->view->language;
                         } else {
                             $data['content_language'] = $languages->getLangNameByLangId($data['content_language']);
                         }
                         //echo "<pre>"; print_r($data); echo "</pre>"; die();
                         $data['files'] = $_FILES['content_file_upload'];
                         // Edit content
                         $content = new Default_Model_Content();
                         $oldData = $content->getContentRow($contentId);
                         $edit = $content->editContent($data);
                         $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
                         if ($edit) {
                             //$favourite = new Default_Model_UserHasFavourites();
                             //$favouriteEdited = $favourite->setFavouriteModifiedTrue($edit);
                             if ($oldData['published_cnt'] == 1 || isset($data['content_publish']) && $data['content_publish'] == 1) {
                                 $url = $this->_urlHelper->url(array('content_id' => $edit, 'language' => $this->view->language), 'content_shortview', true);
                                 $this->_redirect($url);
                             } else {
                                 /*$message_ok = $this->view->translate('content-save-successful');
                                 		$message_ok .= ' ('.$content->getContentHeaderByContentId($edit).')';
                                 		
                                 		$message_ok .= '<br /><br />' . $this->view->translate('content-save-successful2');
                                 		$userpage = $this->_urlHelper->url(array('controller' => 'account',
                                                                                                       'action' => 'view', 
                                                                                                       'user' => $auth->getIdentity()->username, 
                                                                                                       'language' =>  $this->view->language), 
                                                                                                 'lang_default', true);
                                 		$message_ok .= ' <a href="'.$userpage.'">'.$this->view->translate('content-save-successful3').'</a>';
                                 		$message_ok .= ' ' . $this->view->translate('content-save-successful4');
                                 		$this->flash($message_ok, $url);*/
                                 $url = $this->_urlHelper->url(array('controller' => 'account', 'action' => 'view', 'language' => $this->view->language, 'user' => $auth->getIdentity()->username), 'lang_default', true);
                                 $this->_redirect($url);
                             }
                         } else {
                             $this->flash($message_error, $url);
                         }
                     } else {
                         // What is this?
                         //Zend_Debug::dump($form); die;
                     }
                     /*
                     						 // Content keywords
                     						 $keywords = split(', ', trim($data['content_keywords']));
                     						 $data['content_keywords'] = array_unique($keywords);
                     
                     						 if($data['content_group'] == 0) {
                     						 $data['content_industry_id'] = $data['content_division'];
                     						 } elseif($data['content_class'] == 0) {
                     						 $data['content_industry_id'] = $data['content_group'];
                     						 } elseif($data['content_class'] != 0) {
                     						 $data['content_industry_id'] = $data['content_class'];
                     						 }
                     
                     						 // Update the edited content to database
                     						 $content = new Default_Model_Content();
                     						 if($content->editContent($data)) {
                     						 $message = 'content-edit-successful';
                     						 } else {
                     						 $message = 'content-edit-not-successful';
                     						 }
                     						 $this->flash($message, $url);*/
                 }
             } else {
                 $message = 'content-edit-no-id';
                 $this->flash($message, $url);
             }
         } else {
             $message = 'content-edit-not-owner';
             $this->flash($message, $url);
         }
     } else {
         // If not logged, redirecting to system message page
         $message = 'content-edit-not-logged';
         $this->flash($message, $url);
     }
     // end else
 }
コード例 #2
0
ファイル: ContentController.php プロジェクト: jaakkop/site
 /**
  * ajaxIndustryAction
  *
  * This function handles the population of industry selection
  * used in addAction and editAction.
  *
  * NOTE: This function is to replace functions:
  * classAction, divisionAction and groupAction,
  * since it's bad to have 3 functions for the same thing.
  */
 public function ajaxindustryAction()
 {
     // Set views layout to empty
     $this->_helper->layout()->setLayout('empty');
     // Get paramesters
     $type = $this->_request->getParam('type');
     $id = $this->_request->getParam('id');
     if (isset($type) && isset($id)) {
         // Get language id
         $languages = new Default_Model_Languages();
         $langId = $languages->getLangIdByLangName($this->view->language);
         $industriesModel = new Default_Model_Industries();
         $industries = $industriesModel->getNamesAndIdsById($id, $langId);
         // Set to view
         $this->view->industries = $industries;
         $this->view->type = $type;
     }
 }