/** * editContent * * Edit content. * * @param array $data */ public function editContent($data) { // Get the original content $content = $this->getContentRow($data['content_id']); // Get content type $contentTypes = new Default_Model_ContentTypes(); $contentType = $contentTypes->getTypeById($content['id_cty_cnt']); // Unset fields that are not going to be updated unset($content['id_cnt']); unset($content['id_cty_cnt']); unset($content['views_cnt']); unset($content['created_cnt']); $content['title_cnt'] = htmlspecialchars($data['content_header']); $content['lead_cnt'] = htmlspecialchars($data['content_textlead']); $content['language_cnt'] = $data['content_language']; $content['body_cnt'] = htmlspecialchars($data['content_text']); if (!isset($data['content_research'])) { $data['content_research'] = ""; } if (!isset($data['content_opportunity'])) { $data['content_opportunity'] = ""; } if (!isset($data['content_threat'])) { $data['content_threat'] = ""; } if (!isset($data['content_solution'])) { $data['content_solution'] = ""; } $content['research_question_cnt'] = htmlspecialchars($data['content_research']); $content['opportunity_cnt'] = htmlspecialchars($data['content_opportunity']); $content['threat_cnt'] = htmlspecialchars($data['content_threat']); $content['solution_cnt'] = htmlspecialchars($data['content_solution']); $content['references_cnt'] = htmlspecialchars($data['content_references']); //$content['published_cnt'] = $data['publish']; //it defaults to 0 so let it be 1 if data is already published� $content['modified_cnt'] = new Zend_Db_Expr('NOW()'); $where = $this->getAdapter()->quoteInto('`id_cnt` = ?', $data['content_id']); // MIKÄ VITTU TÄSSÄ KUSEE? if (!$this->update($content, $where)) { $return = false; } else { $return = $data['content_id']; } // Check if user has given keywords if (!empty($data['content_keywords'])) { // Get existing keywords of the content $cntHasTag = new Default_Model_ContentHasTag(); $existingTags = $cntHasTag->checkExistingTags($data['content_id'], $data['content_keywords']); //$existingTags = $cntHasTag->getContentTags($data['content_id']); $modelTags = new Default_Model_Tags(); $modelTags->addTagsToContent($data['content_id'], $data['content_keywords'], $existingTags); } // end if // Check if user has related companies if (!empty($data['content_related_companies'])) { // Get existing related companies of the content $cntHasRec = new Default_Model_ContentHasRelatedCompany(); $existingCompanies = $cntHasRec->checkExistingCompanies($data['content_id'], $data['content_related_companies']); //$existingRecs = $cntHasRec->getContentRelComps($data['content_id']); $modelRecs = new Default_Model_RelatedCompanies(); $modelRecs->addRelatedCompaniesToContent($data['content_id'], $data['content_related_companies'], $existingCompanies); } // end if /* if($_FILES['content_file_upload']['size'] != 0) { $files = new Default_Model_Files(); $files->newFile($content->id_cnt, $auth->getIdentity()->user_id); */ /*// Update industry to content $contentHasIndustry = new Default_Model_ContentHasIndustries(); $current_industry = $contentHasIndustry->getIndustryIdOfContent($data['content_id']); if($current_industry != $data['content_industry_id']) { if(!$contentHasIndustry->updateIndustryToContent($data['content_industry_id'], $data['content_id'])) { $return = false; } }*/ if ($return) { $filesModel = new Default_Model_Files(); for ($i = 1; $i < count($data['files']['name']); $i++) { $files = $data['files']; $file['name'] = $files['name'][$i]; $file['type'] = $files['type'][$i]; $file['tmp_name'] = $files['tmp_name'][$i]; $file['error'] = $files['error'][$i]; $file['size'] = $files['size'][$i]; $filesModel->newFile($data['content_id'], $data['User']['id_usr'], $file); } $filesModel->deleteFiles($data['uploadedFiles']); //die; } if ($contentType == "idea") { // Update innovation type to content $contentHasInnovationType = new Default_Model_ContentHasInnovationTypes(); $current_innovation_type = $contentHasInnovationType->getInnovationTypeIdOfContent($data['content_id']); if ($current_innovation_type != $data['innovation_type']) { if (!$contentHasInnovationType->updateInnovationTypeToContent($data['innovation_type'], $data['content_id'])) { $return = false; } } } return $return; }
/** * editContent * * Edit content. * * @param array $data */ public function editContent($data) { // Get the original content $content = $this->getContentRow($data['content_id']); // Get content type $contentTypes = new Default_Model_ContentTypes(); $contentType = $contentTypes->getTypeById($content['id_cty_cnt']); // Unset fields that are not going to be updated unset($content['id_cnt']); unset($content['id_cty_cnt']); unset($content['views_cnt']); unset($content['created_cnt']); $content['title_cnt'] = htmlspecialchars($data['content_header']); $content['lead_cnt'] = htmlspecialchars($data['content_textlead']); $content['language_cnt'] = $data['content_language']; $content['body_cnt'] = htmlspecialchars($data['content_text']); if (!isset($data['content_research'])) { $data['content_research'] = ""; } if (!isset($data['content_opportunity'])) { $data['content_opportunity'] = ""; } if (!isset($data['content_threat'])) { $data['content_threat'] = ""; } if (!isset($data['content_solution'])) { $data['content_solution'] = ""; } $content['research_question_cnt'] = htmlspecialchars($data['content_research']); $content['opportunity_cnt'] = htmlspecialchars($data['content_opportunity']); $content['threat_cnt'] = htmlspecialchars($data['content_threat']); $content['solution_cnt'] = htmlspecialchars($data['content_solution']); $content['references_cnt'] = htmlspecialchars($data['content_references']); $content['modified_cnt'] = new Zend_Db_Expr('NOW()'); if (isset($data['publish']) && $data['publish'] == 1) { $content['published_cnt'] = 1; } $where = $this->getAdapter()->quoteInto('`id_cnt` = ?', $data['content_id']); // MIK� VITTU T�SS� KUSEE? if (!$this->update($content, $where)) { $return = false; } else { $return = $data['content_id']; } // Check if user has given keywords if (!empty($data['content_keywords'])) { // Get existing keywords of the content $cntHasTag = new Default_Model_ContentHasTag(); $existingTags = $cntHasTag->checkExistingTags($data['content_id'], $data['content_keywords']); //$existingTags = $cntHasTag->getContentTags($data['content_id']); $modelTags = new Default_Model_Tags(); $modelTags->addTagsToContent($data['content_id'], $data['content_keywords'], $existingTags); /* $i = 0; // Go through all existing keywords // This belongs to contentHasTags model foreach($existingTags as $existingTag) { // If some of the existing keywords aren't found in sent keywords, // that keyword is deleted the from content and maybe even from the // database if(!in_array($existingTag['name_tag'], $data['content_keywords'])) { // Removing tag from content $cntHasTag->deleteTagFromContent($existingTag['id_tag'], $data['content_id']); // If other content(s) doesn't have this tag, the whole // tag is going to be removed from the database if(!$cntHasTag->checkIfOtherContentHasTag($existingTag['id_tag'], $data['content_id'])) { $modelTags->removeTag($existingTag['id_tag']); } // Remove tag from existingTags array unset($existingTags[$i]); } $i++; } */ /* // Go through all sent keywords // This belongs to Tags model foreach($data['content_keywords'] as $tag) { $tag = strip_tags($tag); $foundTag = false; foreach($existingTags as $existingTag) { if($tag == $existingTag['name_tag']) { $foundTag = true; } } // If tag is not found in existing tags if(!$foundTag) { // Check if given keyword does not exists in database if($modelTags->tagExists($tag)) { // Create new keyword $tag = $modelTags->createTag($tag); } else { // Get keyword $tag = $modelTags->getTag($tag); } // end else // Add keywords to content $cntHasTag->addTagToContent($tag->id_tag, $data['content_id']); } } // end foreach */ } // end if // Check if user has related companies if (!empty($data['content_related_companies'])) { // Get existing related companies of the content $cntHasRec = new Default_Model_ContentHasRelatedCompany(); $existingCompanies = $cntHasRec->checkExistingCompanies($data['content_id'], $data['content_related_companies']); //$existingRecs = $cntHasRec->getContentRelComps($data['content_id']); $modelRecs = new Default_Model_RelatedCompanies(); $modelRecs->addRelatedCompaniesToContent($data['content_id'], $data['content_related_companies'], $existingCompanies); /* $i = 0; // Go through all existing related companies // FIX: This belongs to ContentHasRelatedCompany model foreach($existingRecs as $existingRec) { // If some of the existing related companies aren't found in sent // related companies, that related company is deleted from the // content and maybe even from thedatabase // FIXED: Could have caused mismatches when adding, // since when related company is added strip_tags is used // but not when doing comparisons here. // This goes for campaigns as well. if(!in_array($existingRec['name_rec'], $data['content_related_companies'])) { // Removing rec from content $cntHasRec->deleteRelCompFromContent($existingRec['id_rec'], $data['content_id']); // If other content(s) doesn't have this related company, the whole // related company is going to be removed from the database if(!$cntHasRec->checkIfOtherContentHasRelComp($existingRec['id_rec'], $data['content_id'])) { $modelRecs->removeRelComp($existingRec['id_rec']); } // Remove related company from existingRecs array unset($existingRecs[$i]); } $i++; } */ /* // Go through all sent related companies // FIX: This belongs to RelatedCompany model foreach($data['content_related_companies'] as $rec) { //$rec = strip_tags($rec); $foundRec = false; foreach($existingRecs as $existingRec) { if($rec == $existingRec['name_rec']) { $foundRec = true; } } // If related company is not found in existing related companies if(!$foundRec) { // Check if given related company does not exists in database if($modelRecs ->relCompExists($rec)) { // Create new related company $rec = $modelRecs ->createRelComp($rec); } else { // Get related company $rec = $modelRecs ->getRelComp($rec); } // end else // Add related company to content $cntHasRec->addRelCompToContent($rec->id_rec, $data['content_id']); } } // end foreach */ } // end if /* if($_FILES['content_file_upload']['size'] != 0) { $files = new Default_Model_Files(); $files->newFile($content->id_cnt, $auth->getIdentity()->user_id); } */ // Check if user has given campaigns if (!empty($data['content_campaigns'])) { // Get existing campaigns of the content $cntHasCmp = new Default_Model_ContentHasCampaign(); $existingCampaigns = $cntHasCmp->checkExistingCampaigns($data['content_id'], $data['content_campaigns']); //$existingCmps = $cntHasCmp->getContentCampaigns($data['content_id']); $modelCmps = new Default_Model_Campaigns(); $modelCmps->addCampaignsToContent($data['content_id'], $data['content_campaigns'], $existingCampaigns); /* $i = 0; // Go through all existing campaigns // FIX: This belongs to ContentHasCampaign moodel foreach($existingCmps as $existingCmp) { // If some of the existing campaigns aren't found in sent campaigns, // that campaign is deleted the from content and maybe even from the // database if(!in_array($existingCmp['name_cmp'], $data['content_campaigns'])) { // Removing campaign from content $cntHasCmp->deleteCampaignFromContent($existingCmp['id_cmp'], $data['content_id']); // If other content(s) doesn't have this campaign, the whole // campaign is going to be removed from the database if(!$cntHasCmp->checkIfOtherContentHasCampaign($existingCmp['id_cmp'], $data['content_id'])) { $modelCmps->removeCampaign($existingCmp['id_cmp']); } // Remove campaign from existingCmps array unset($existingCmps[$i]); } $i++; } */ /* // Go through all sent campaigns // FIX: This belongs to Campaigns model foreach($data['content_campaigns'] as $cmp) { //$cmp = strip_tags($cmp); $foundCmp = false; foreach($existingCmps as $existingCmp) { if($cmp == $existingCmp['name_cmp']) { $foundCmp = true; } } // If campaign is not found in existing tags if(!$foundCmp) { // Check if given campaign does not exists in database if($modelCmps->campaignExists($cmp)) { // Create new campaign $cmp = $modelCmps->createCampaign($cmp); } else { // Get campaign $cmp = $modelCmps->getCampaign($cmp); } // end else // Add campaigns to content $cntHasCmp->addCampaignToContent($cmp->id_cmp, $data['content_id']); } } // end foreach */ } // end if /*// Update industry to content $contentHasIndustry = new Default_Model_ContentHasIndustries(); $current_industry = $contentHasIndustry->getIndustryIdOfContent($data['content_id']); if($current_industry != $data['content_industry_id']) { if(!$contentHasIndustry->updateIndustryToContent($data['content_industry_id'], $data['content_id'])) { $return = false; } }*/ if ($return) { $filesModel = new Default_Model_Files(); for ($i = 1; $i < count($data['files']['name']); $i++) { $files = $data['files']; $file['name'] = $files['name'][$i]; $file['type'] = $files['type'][$i]; $file['tmp_name'] = $files['tmp_name'][$i]; $file['error'] = $files['error'][$i]; $file['size'] = $files['size'][$i]; $filesModel->newFile($data['content_id'], $data['User']['id_usr'], $file); } if (isset($data['uploadedFiles'])) { $filesModel->deleteFiles($data['uploadedFiles']); } //die; } if ($contentType == "idea") { // Update innovation type to content $contentHasInnovationType = new Default_Model_ContentHasInnovationTypes(); $current_innovation_type = $contentHasInnovationType->getInnovationTypeIdOfContent($data['content_id']); if ($current_innovation_type != $data['innovation_type']) { if (!$contentHasInnovationType->updateInnovationTypeToContent($data['innovation_type'], $data['content_id'])) { $return = false; } } } return $return; }