Beispiel #1
0
 /**
  *   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();
         $filesModel->newFiles($data['content_id'], "content", $data['files']);
         if (isset($data['uploadedFiles'])) {
             $filesModel->deleteCertainFiles($data['content_id'], "content", $data['uploadedFiles']);
         }
     }
     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;
 }
Beispiel #2
0
 function editAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $cmpId = $this->_request->getParam('id');
         if (!$cmpId) {
             $target = $this->_urlHelper->url(array('controller' => 'index', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
             $this->_redirector->gotoUrl($target);
         }
         // Get group id from campaign info.
         $cmpModel = new Default_Model_Campaigns();
         $cmp = $cmpModel->getCampaignById($cmpId)->toArray();
         $grpId = $cmp['id_grp_cmp'];
         // Only group admins get to edit campaign info.
         $grpAdminsModel = new Default_Model_GroupAdmins();
         $grpAdmins = $grpAdminsModel->getGroupAdmins($grpId);
         $userIsGroupAdmin = $this->checkIfArrayHasKeyWithValue($grpAdmins, 'id_usr', $auth->getIdentity()->user_id);
         if (!$userIsGroupAdmin) {
             $redirectUrl = $this->_urlHelper->url(array('controller' => 'campaign', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
             $this->_redirector->gotoUrl($redirectUrl);
         }
         // Get contents filenames from database
         $filesModel = new Default_Model_Files();
         $filenames = $filesModel->getFilenames($cmpId, "campaign");
         $formData['filenames'] = $filenames;
         // Create & populate the form.
         $form = new Default_Form_AddCampaignForm($this, array('mode' => 'edit', 'startdate' => $cmp['start_time_cmp'], 'fileNames' => $filenames));
         $formData = array();
         $formData['campaign_name'] = $cmp['name_cmp'];
         $formData['campaign_ingress'] = $cmp['ingress_cmp'];
         $formData['campaign_desc'] = $cmp['description_cmp'];
         $formData['campaign_start'] = $cmp['start_time_cmp'];
         if ($cmp['end_time_cmp'] != '0000-00-00') {
             $formData['campaign_end'] = $cmp['end_time_cmp'];
         }
         // Get campaign weblinks
         $campaignWeblinksModel = new Default_Model_CampaignWeblinks();
         $campaignWeblinks = $campaignWeblinksModel->getCampaignWeblinks($cmpId);
         foreach ($campaignWeblinks as $campaignWeblink) {
             $formData['weblinks_name_site' . $campaignWeblink['count_cwl']] = $campaignWeblink['name_cwl'];
             $formData['weblinks_url_site' . $campaignWeblink['count_cwl']] = $campaignWeblink['url_cwl'];
         }
         $form->populate($formData);
         $this->view->form = $form;
         $this->view->cmpName = $cmp['name_cmp'];
         // If the form is posted and valid, save the changes to db.
         $request = $this->getRequest();
         if ($request->isPost()) {
             $post = $request->getPost();
             if ($form->isValid($post)) {
                 // Change existing group info.
                 if (isset($post['campaign_start'])) {
                     $cmpModel->editCampaign($cmpId, $post['campaign_name'], $post['campaign_ingress'], $post['campaign_desc'], $post['campaign_start'], $post['campaign_end']);
                 } else {
                     $cmpModel->editCampaign($cmpId, $post['campaign_name'], $post['campaign_ingress'], $post['campaign_desc'], 'keepExisting', $post['campaign_end']);
                 }
                 // Set weblinks
                 if (isset($post['weblinks_name_site1']) && isset($post['weblinks_url_site1'])) {
                     $campaignWeblinksModel->setWeblink($cmpId, $post['weblinks_name_site1'], $post['weblinks_url_site1'], 1);
                 }
                 if (isset($post['weblinks_name_site2']) && isset($post['weblinks_url_site2'])) {
                     $campaignWeblinksModel->setWeblink($cmpId, $post['weblinks_name_site2'], $post['weblinks_url_site2'], 2);
                 }
                 if (isset($post['weblinks_name_site3']) && isset($post['weblinks_url_site3'])) {
                     $campaignWeblinksModel->setWeblink($cmpId, $post['weblinks_name_site3'], $post['weblinks_url_site3'], 3);
                 }
                 if (isset($post['weblinks_name_site4']) && isset($post['weblinks_url_site4'])) {
                     $campaignWeblinksModel->setWeblink($cmpId, $post['weblinks_name_site4'], $post['weblinks_url_site4'], 4);
                 }
                 if (isset($post['weblinks_name_site5']) && isset($post['weblinks_url_site5'])) {
                     $campaignWeblinksModel->setWeblink($cmpId, $post['weblinks_name_site5'], $post['weblinks_url_site5'], 5);
                 }
                 $filesModel = new Default_Model_Files();
                 $files = $_FILES['content_file_upload'];
                 $filesModel->newFiles($cmpId, "campaign", $files);
                 if (isset($post['uploadedFiles'])) {
                     $filesModel->deleteCertainFiles($cmpId, "campaign", $post['uploadedFiles']);
                 }
                 // Redirect back to the campaign page.
                 $target = $this->_urlHelper->url(array('cmpid' => $cmpId, 'language' => $this->view->language), 'campaign_view', true);
                 $this->_redirector->gotoUrl($target);
             }
         }
     } else {
         // Not logged in.
         $target = $this->_urlHelper->url(array('controller' => 'groupsandcampaigns', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
         $this->_redirector->gotoUrl($target);
     }
 }
Beispiel #3
0
 function createAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         // Add the "add new group"-form to the view.
         $form = new Default_Form_AddGroupForm();
         $this->view->form = $form;
         // If the form is posted and valid, add the new group to db.
         $request = $this->getRequest();
         if ($request->isPost()) {
             $post = $request->getPost();
             if ($form->isValid($post)) {
                 // Add new group to db.
                 $groupModel = new Default_Model_Groups();
                 $newGroupId = $groupModel->createGroup($this->replaceWhitespace($post['groupname']), $post['grouptype'], $post['groupdesc'], $post['groupbody']);
                 // Set weblinks
                 $groupWeblinksModel = new Default_Model_GroupWeblinks();
                 if (isset($post['weblinks_name_site1']) && isset($post['weblinks_url_site1'])) {
                     $groupWeblinksModel->setWeblink($newGroupId, $post['weblinks_name_site1'], $post['weblinks_url_site1'], 1);
                 }
                 if (isset($post['weblinks_name_site2']) && isset($post['weblinks_url_site2'])) {
                     $groupWeblinksModel->setWeblink($newGroupId, $post['weblinks_name_site2'], $post['weblinks_url_site2'], 2);
                 }
                 if (isset($post['weblinks_name_site3']) && isset($post['weblinks_url_site3'])) {
                     $groupWeblinksModel->setWeblink($newGroupId, $post['weblinks_name_site3'], $post['weblinks_url_site3'], 3);
                 }
                 if (isset($post['weblinks_name_site4']) && isset($post['weblinks_url_site4'])) {
                     $groupWeblinksModel->setWeblink($newGroupId, $post['weblinks_name_site4'], $post['weblinks_url_site4'], 4);
                 }
                 if (isset($post['weblinks_name_site5']) && isset($post['weblinks_url_site5'])) {
                     $groupWeblinksModel->setWeblink($newGroupId, $post['weblinks_name_site5'], $post['weblinks_url_site5'], 5);
                 }
                 // Add the files to the group
                 $files = $_FILES['content_file_upload'];
                 $filesModel = new Default_Model_Files();
                 $filesModel->newFiles($newGroupId, "group", $files);
                 // Add the current user to the new group.
                 $userHasGroupModel = new Default_Model_UserHasGroup();
                 $userHasGroupModel->addUserToGroup($newGroupId, $this->view->userid);
                 // Make the current user an admin for the new group.
                 $groupAdminModel = new Default_Model_GroupAdmins();
                 $groupAdminModel->addAdminToGroup($newGroupId, $this->view->userid);
                 $target = $this->_urlHelper->url(array('groupid' => $newGroupId, 'language' => $this->view->language), 'group_shortview', true);
                 $this->_redirector->gotoUrl($target);
             }
         }
     } else {
         // Not logged in.
         $target = $this->_urlHelper->url(array('controller' => 'groupsandcampaigns', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
         $this->_redirector->gotoUrl($target);
     }
 }