/** * 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 }
/** * unlinkAction * * Shows user contents which are linket to campaign. User can select and remove link. * * @author Mikko Korpinen */ public function unlinkAction() { // Get authentication $auth = Zend_Auth::getInstance(); // If user has identity if ($auth->hasIdentity()) { // Get requests $params = $this->getRequest()->getParams(); $relatestoid = $params['relatestoid']; if (!isset($relatestoid)) { $redirectUrl = $this->_urlHelper->url(array('controller' => 'campaign', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true); $this->_redirector->gotoUrl($redirectUrl); } $contenttype = ''; $campaigns = array(); $model_content = new Default_Model_Content(); $contentexists = $model_content->checkIfContentExists($relatestoid); if ($contentexists) { $relatesToContent = $model_content->getDataAsSimpleArray($relatestoid); $this->view->relatesToContentTitle = $relatesToContent['title_cnt']; $model_content_types = new Default_Model_ContentTypes(); $model_cmp_has_cnt = new Default_Model_CampaignHasContent(); $contenttype = $model_content_types->getTypeById($relatesToContent['id_cty_cnt']); $contentCampaigns = $model_cmp_has_cnt->getContentCampaigns($relatestoid); } $this->view->contentexists = $contentexists; $this->view->relatesToId = $relatestoid; $this->view->linkingContentType = $contenttype; $this->view->campaigns = $contentCampaigns; } else { // If not logged, redirecting to system message page $message = 'content-link-not-logged'; $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true); $this->flash($message, $url); } }
/** * 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; }
/** * 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; }
/** * index page: Contains the content viewing functionality. * * @todo Implement group ownership user images and content links * @todo Include translation and content info for page title * @todo More from box should show ratings * @todo If not ajax "more from", at least separate to proper MVC * @todo Look over comment loading for data being fetched and not shown * @todo Comment rating, userpic (maybe not) * * @param id integer id of content to view * @param page integer (optional) Page number for paginator * @param count integer (optional) Count of content for paginator * @param rate integer (optional) Rating given by user */ function indexAction() { // get requests $request = $this->getRequest(); $params = $request->getParams(); $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl(); $absoluteBaseUrl = strtolower(trim(array_shift(explode('/', $_SERVER['SERVER_PROTOCOL'])))) . '://' . $_SERVER['HTTP_HOST'] . Zend_Controller_Front::getInstance()->getBaseUrl(); // get content id from params, if not set or invalid, send a message $id = (int) $params['content_id']; if ($id == 0) { $this->flash('content-not-found', $baseUrl . '/' . $this->view->language . '/msg/'); } // Get specific content data -- this could fail? Needs check? $contentModel = new Default_Model_Content(); $contentData = $contentModel->getDataAsSimpleArray($id); // Translate content data $this->gtranslate->setLangFrom($contentData['language_cnt']); $contentData = $this->gtranslate->translateContent($contentData); $filesModel = new Default_Model_Files(); $files = $filesModel->getFilenamesByCntId($id); // Get content owner id (groups to be implemented later) $contentHasUserModel = new Default_Model_ContentHasUser(); $owner = $contentHasUserModel->getContentOwners($id); $ownerId = $owner['id_usr']; // Get authentication $auth = Zend_Auth::getInstance(); if ($contentData['published_cnt'] == 0 && $auth->getIdentity()->user_id != $ownerId && !in_array("admin", $this->view->logged_user_roles)) { $this->flash('content-not-found', $baseUrl . '/' . $this->view->language . '/msg/'); } // get rating from params (if set) $rate = isset($params['rate']) ? $params['rate'] : "NONE"; // get favourite method, "add" or "remove" //$favouriteMethod = isset($params['favourite']) ? $params['favourite'] : "NONE"; // get page number and comments per page (if set) $page = isset($params['page']) ? $params['page'] : 1; $count = isset($params['count']) ? $params['count'] : 10; // turn commenting off by default $user_can_comment = false; // turn rating off by default $user_can_rate = false; // Comment model $comment = new Default_Model_Comments(); $parentId = isset($params['replyto']) ? $params['replyto'] : 0; // If user has identity if ($auth->hasIdentity() && $contentData['published_cnt'] == 1) { // enable comment form $user_can_comment = true; // enable rating if the content was not published by the user // (also used for flagging) if ($ownerId != $auth->getIdentity()->user_id) { $user_can_rate = true; } // generate comment form $comment_form = new Default_Form_CommentForm($parentId); // if there is something in POST if ($request->isPost()) { // Get comment form data $formData = $this->_request->getPost(); // Validate and save comment data if ($comment_form->isValid($formData)) { $user_id = $auth->getIdentity()->user_id; $comment->addComment($id, $user_id, $formData); $comment_form = new Default_Form_CommentForm($parentId); if ($user_id != $ownerId) { $user = new Default_Model_User(); $comment_sender = $user->getUserNameById($user_id); $Default_Model_privmsg = new Default_Model_PrivateMessages(); $data = array(); $data['privmsg_sender_id'] = 0; $data['privmsg_receiver_id'] = $ownerId; $data['privmsg_header'] = 'You have new comment!'; $data['privmsg_message'] = '<a href="' . $baseUrl . "/" . $this->view->language . '/account/view/user/' . $comment_sender . '">' . $comment_sender . '</a> commented your content <a href="' . $baseUrl . "/" . $this->view->language . '/view/' . $id . '">' . $contentData['title_cnt'] . '</a>'; $data['privmsg_email'] = ''; // Send email to contentowner about new comment // if its allowed $notificationsModel = new Default_Model_Notifications(); $notifications = $notificationsModel->getNotificationsById($ownerId); if (in_array('comment', $notifications)) { $emailNotification = new Oibs_Controller_Plugin_Email(); $emailNotification->setNotificationType('comment')->setSenderId($user_id)->setReceiverId($ownerId)->setParameter('URL', $absoluteBaseUrl . "/en")->setParameter('SENDER-NAME', $comment_sender)->setParameter('CONTENT-ID', $id)->setParameter('CONTENT-TITLE', $contentData['title_cnt'])->setParameter('COMMENT', $formData['comment_message']); if ($emailNotification->isValid()) { $emailNotification->send(); } else { //echo $emailNotification->getErrorMessage(); die; } } $Default_Model_privmsg->addMessage($data); } } // end if } // end if $this->view->comment_form = $comment_form; } // end if // get content type of the specific content viewed $contentTypesModel = new Default_Model_ContentTypes(); $contentType = $contentTypesModel->getTypeById($contentData['id_cty_cnt']); // Get content innovation type / industry / division / group / class // and send to view... somehow. // TO BE IMPLEMENTED // Get content owner data $userModel = new Default_Model_User(); $userData = $userModel->getSimpleUserDataById($ownerId); // get content owner picture ... to be implemented later $userImage = $userModel->getUserImageData($ownerId); // get other content from user.. function needs a looking-over! // Also it needs to be separated from this action so the MVC-is correct! $moreFromUser = $userModel->getUserContent($ownerId, 0, $id); // get related contents $relatedContents = $contentModel->getRelatedContents($id); // get (VIEWED) content views (returns a string directly) $contentViewsModel = new Default_Model_ContentViews(); if (!$this->alreadyViewed($id)) { $contentViewsModel->increaseViewCount($id); } $views = $contentViewsModel->getViewsByContentId($id); // get content rating (returns a string directly) $contentRatingsModel = new Default_Model_ContentRatings(); //$rating = $contentRatingsModel->getById($id); $rating = $contentRatingsModel->getPercentagesById($id); // $rate is gotten from params[], 1 and -1 are the only allowed if ($rate != "NONE" && ($rate == 1 || $rate == -1) && $auth->hasIdentity()) { if ($contentRatingsModel->addRating($id, $auth->getIdentity()->user_id, $rate)) { $this->view->savedRating = $rate; //$rating = $contentRatingsModel->getById($id); $rating = $contentRatingsModel->getPercentagesById($id); } else { $this->flash('rating-failed-msg', $baseUrl . '/en/msg/'); } } // get contents total favourites $userFavouritesModel = new Default_Model_UserHasFavourites(); $totalFavourites = $userFavouritesModel->getUsersCountByFavouriteContent($id); $totalFavourites = $totalFavourites[0]['users_count_fvr']; $isFavourite = $userFavouritesModel->checkIfContentIsUsersFavourite($id, $auth->getIdentity()->user_id); /* * favouritemethod comes from parameters sent by * ajax function (ajaxLoad_favourite(method)) in index.phtml in /view/. * this function gets parameter "method" (add/remove) from onClick event that is in index.ajax.phtml. * if this onClick event is activated by clicking "heart" (icon_fav_on/off) icon in content view page, * it runs the ajaxLoad_favourite(method) function which sends parameter "favourite" (add/remove) to * this viewController which then handles the adding or removing the content from favourites. */ if ($favouriteMethod != "NONE" && $auth->hasIdentity()) { $favouriteUserId = $auth->getIdentity()->user_id; //If favourite method was "add", then add content to user favourites if ($favouriteMethod == "add" && !$isFavourite) { if ($userFavouritesModel->addContentToFavourites($id, $favouriteUserId)) { $this->view->favouriteMethod = $favouriteMethod; } else { $this->flash('favourite-adding-failed', $baseUrl . '/en/msg'); } } elseif ($favouriteMethod == "remove" && $isFavourite) { if ($userFavouritesModel->removeUserFavouriteContent($id, $favouriteUserId)) { $this->view->favouriteMethod = $favouriteMethod; } else { $this->flash('favourite-removing-failed', $baseUrl . '/en/msg'); } } else { unset($favouriteMethod); } } $favourite = array('total_favourites' => $totalFavourites, 'is_favourite' => $isFavourite); $languagesModel = new Default_Model_Languages(); $languageName = $languagesModel->getLanguageByLangCode($contentData['language_cnt']); $gtranslateLangPair = $this->gtranslate->getLangPair(); // get content tags - functions returns names as well // needs updating to proper MVC? $contentHasTagModel = new Default_Model_ContentHasTag(); $tags = $contentHasTagModel->getContentTags($id); //echo "<pre>"; print_r($tags); echo "</pre>"; die; // get content links, to be implemented $links = array(); // Get all content campaigns $campaignHasContentModel = new Default_Model_CampaignHasContent(); $campaigns = $campaignHasContentModel->getContentCampaigns($id); // This functionality needs looking over (code and general idea) // get content family (array of children, parents and siblings) $contentHasContentModel = new Default_Model_ContentHasContent(); $family = $contentHasContentModel->getContentFamilyTree($id); // split family array to child, parent and sibling arrays (full content) $children = array(); $children_siblings = array(); if (isset($family['children'])) { foreach ($family['children'] as $child) { $contenttypeid = $contentModel->getContentTypeIdByContentId((int) $child); $contenttype = $contentTypesModel->getTypeById($contenttypeid); if ($contenttype == "idea") { $children[] = $contentModel->getDataAsSimpleArray((int) $child); } else { $children_siblings[] = $contentModel->getDataAsSimpleArray((int) $child); } // $i++; } } $parents = array(); $parent_siblings = array(); if (isset($family['parents'])) { foreach ($family['parents'] as $parent) { $contenttypeid = $contentModel->getContentTypeIdByContentId((int) $parent); $contenttype = $contentTypesModel->getTypeById($contenttypeid); if ($contenttype == "idea") { $parents[] = $contentModel->getDataAsSimpleArray((int) $parent); } else { $parent_siblings[] = $contentModel->getDataAsSimpleArray((int) $parent); } } } // Here we get the rival solutions for a solution $rivals = array(); if ($contentType == "idea" && isset($family['parents'])) { $i = 0; // First here is checked the parents of this solution (=the problem // or the future info) foreach ($family['parents'] as $parent) { // Get the family of the problem or future info $parents_family = $contentHasContentModel->getContentFamilyTree((int) $parent); // Get the children of the problem or future info if (isset($parents_family['children'])) { // Going through the children foreach ($parents_family['children'] as $parent_child) { // Those children are rivals which are not this solution // which is currently viewed if ((int) $parent_child != $id) { $rivals[$i] = $contentModel->getDataAsSimpleArray((int) $parent_child); } } } $i++; } } // get comments data // $commentList = $comment->getAllByContentId($id, $page, $count); $commentList = $comment->getCommentsByContent($id); $commentsSorted = array(); $this->getCommentChilds($commentList, $commentsSorted, 0, 0, 3); // Get total comment count $commentCount = $comment->getCommentCountByContentId($id); // Calculate total page count $pageCount = ceil($commentCount / $count); // Custom pagination to fix memory error on large amount of data $paginator = new Zend_View(); $paginator->setScriptPath('../application/views/scripts'); $paginator->pageCount = $pageCount; $paginator->currentPage = $page; $paginator->pagesInRange = 10; // get content industries -- will be updated later. $cntHasIndModel = new Default_Model_ContentHasIndustries(); $hasIndustry = $cntHasIndModel->getIndustryIdOfContent($id); $industriesModel = new Default_Model_Industries(); $industriesArray = $industriesModel->getAllContentIndustryIds($hasIndustry); // roll values to an array /*$industries = array(); foreach ($industriesArray as $industry) { $value = $industriesModel->getNameById($industry); // $industriesModel->getNameById($industry); if (!empty($value)) { $industries[] = $value; } }*/ // Check if and when the content is modified and if its more than 10minutes ago add for the view $dateCreated = strtotime($contentData['created_cnt']); $dateModified = strtotime($contentData['modified_cnt']); $modified = 0; if (($dateModified - $dateCreated) / 60 > 10) { $modified = $contentData['modified_cnt']; } // Inject data to view $this->view->files = $files; $this->view->id = $id; $this->view->userImage = $userImage; $this->view->commentPaginator = $paginator; $this->view->commentData = $commentsSorted; $this->view->user_can_comment = $user_can_comment; $this->view->user_can_rate = $user_can_rate; $this->view->contentData = $contentData; $this->view->modified = $modified; $this->view->userData = $userData; $this->view->moreFromUser = $moreFromUser; $this->view->relatedContents = $relatedContents; $this->view->views = $views; $this->view->rating = $rating; $this->view->languageName = $languageName; $this->view->gtranslateLangPair = $gtranslateLangPair; $this->view->tags = $tags; $this->view->links = $links; $this->view->parents = $parents; $this->view->parent_siblings = $parent_siblings; $this->view->children = $children; $this->view->children_siblings = $children_siblings; $this->view->rivals = $rivals; $this->view->comments = $commentCount; $this->view->contentType = $contentType; $this->view->count = $count; $this->view->campaigns = $campaigns; //$this->view->favourite = $favourite; // Inject title to view $this->view->title = $this->view->translate('index-home') . " - " . $contentData['title_cnt']; }
/** * index page: Contains the content viewing functionality. * * @todo Implement group ownership user images and content links * @todo Include translation and content info for page title * @todo More from box should show ratings * @todo If not ajax "more from", at least separate to proper MVC * @todo Look over comment loading for data being fetched and not shown * @todo Comment rating, userpic (maybe not) * * @param id integer id of content to view * @param page integer (optional) Page number for paginator * @param count integer (optional) Count of content for paginator * @param rate integer (optional) Rating given by user */ function indexAction() { // get requests $request = $this->getRequest(); $params = $request->getParams(); $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl(); $absoluteBaseUrl = strtolower(trim(array_shift(explode('/', $_SERVER['SERVER_PROTOCOL'])))) . '://' . $_SERVER['HTTP_HOST'] . Zend_Controller_Front::getInstance()->getBaseUrl(); // get content id from params, if not set or invalid, send a message $id = (int) $params['content_id']; if ($id == 0) { $this->flash('content-not-found', $baseUrl . '/' . $this->view->language . '/msg/'); } // Get specific content data -- this could fail? Needs check? $contentModel = new Default_Model_Content(); $contentData = $contentModel->getDataAsSimpleArray($id); $isTranslated = isset($params['notranslate']) ? false : true; if ($isTranslated) { // Translate content data $this->gtranslate->setLangFrom($contentData['language_cnt']); $contentData = $this->gtranslate->translateContent($contentData); } $filesModel = new Default_Model_Files(); $files = $filesModel->getFilenames($id, "content"); // Get content owner id (groups to be implemented later) $contentHasUserModel = new Default_Model_ContentHasUser(); $owner = $contentHasUserModel->getContentOwners($id); $ownerId = $owner['id_usr']; // Get authentication $auth = Zend_Auth::getInstance(); // Get user_id $usrId = 0; if ($auth->hasIdentity()) { $usrId = $auth->getIdentity()->user_id; } if ($contentData['published_cnt'] == 0 && $usrId != $ownerId && !in_array("admin", $this->view->logged_user_roles)) { $this->flash('content-not-found', $baseUrl . '/' . $this->view->language . '/msg/'); } // get rating from params (if set) $rate = isset($params['rate']) ? $params['rate'] : "NONE"; // get page number and comments per page (if set) $page = isset($params['page']) ? $params['page'] : 1; // turn commenting off by default $user_can_comment = false; // turn rating off by default $user_can_rate = false; // user is not owner by default $user_is_owner = false; // Comment model $comment = new Default_Model_Comments(); $favouriteModel = new Default_Model_UserHasFavourites(); $cntHasUsrModel = new Default_Model_ContentHasUser(); //$parentId = isset($params['replyto']) ? $params['replyto'] : 0; // If user has identity if ($auth->hasIdentity() && $contentData['published_cnt'] == 1) { // enable rating if the content was not published by the user // (also used for flagging) if ($ownerId != $auth->getIdentity()->user_id) { $user_can_rate = true; } // Check if user is owner of content if ($ownerId == $auth->getIdentity()->user_id) { $user_is_owner = true; } if ($favouriteModel->checkIfContentIsUsersFavourite($id, $usrId)) { $favouriteModel->updateLastChecked($usrId, $id); $profileModel = new Default_Model_UserProfiles(); $profileModel->deleteNotificationCache($id, $usrId); } if ($user_is_owner) { $cntHasUsrModel->updateLastChecked($ownerId, $id); $profileModel = new Default_Model_UserProfiles(); $profileModel->deleteNotificationCache($id, $usrId); } // generate comment form //$comment_form = new Default_Form_CommentForm($parentId); // if there is something in POST /*if ($request->isPost()) { if($user_id != $ownerId) { $user = new Default_Model_User(); $comment_sender = $user->getUserNameById($user_id); $Default_Model_privmsg = new Default_Model_PrivateMessages(); $data = array(); $data['privmsg_sender_id'] = 0; $data['privmsg_receiver_id'] = $ownerId; $data['privmsg_header'] = 'You have new comment!'; $data['privmsg_message'] = '<a href="'.$baseUrl."/".$this->view->language.'/account/view/user/'.$comment_sender.'">' .$comment_sender.'</a> commented your content <a href="'.$baseUrl."/".$this->view->language.'/view/'.$id.'">'.$contentData['title_cnt'].'</a>'; $data['privmsg_email'] = ''; // Send email to contentowner about new comment // if its allowed $notificationsModel = new Default_Model_Notifications(); $notifications = $notificationsModel->getNotificationsById($ownerId); if (in_array('comment', $notifications)) { $emailNotification = new Oibs_Controller_Plugin_Email(); $emailNotification->setNotificationType('comment') ->setSenderId($user_id) ->setReceiverId($ownerId) ->setParameter('URL', $absoluteBaseUrl."/en") ->setParameter('SENDER-NAME', $comment_sender) ->setParameter('CONTENT-ID', $id) ->setParameter('CONTENT-TITLE', $contentData['title_cnt']) ->setParameter('COMMENT', $formData['comment_message']); if ($emailNotification->isValid()) { $emailNotification->send(); } else { //echo $emailNotification->getErrorMessage(); die; } } $Default_Model_privmsg->addMessage($data); } // end if }*/ // end if } // end if // get content type of the specific content viewed $contentTypesModel = new Default_Model_ContentTypes(); $contentType = $contentTypesModel->getTypeById($contentData['id_cty_cnt']); // Get content innovation type / industry / division / group / class // and send to view... somehow. // TO BE IMPLEMENTED // Get content owner data $userModel = new Default_Model_User(); $userData = $userModel->getSimpleUserDataById($ownerId); // get content owner picture ... to be implemented later $userImage = $userModel->getUserImageData($ownerId); // get (VIEWED) content views (returns a string directly) $contentViewsModel = new Default_Model_ContentViews(); if (!$this->alreadyViewed($id, $auth->hasIdentity() ? $auth->getIdentity()->username : "******")) { $contentViewsModel->increaseViewCount($id); } $views = $contentViewsModel->getViewsByContentId($id); $languagesModel = new Default_Model_Languages(); $languageName = $languagesModel->getLanguageByLangCode($contentData['language_cnt']); $gtranslateLangPair = $this->gtranslate->getLangPair(); // get content tags - functions returns names as well // needs updating to proper MVC? $contentHasTagModel = new Default_Model_ContentHasTag(); $tags = $contentHasTagModel->getContentTags($id); if ($isTranslated) { $tags = $this->gtranslate->translateTags($tags); } // get content links, to be implemented $links = array(); // Get all content campaigns // $campaignHasContentModel = new Default_Model_CampaignHasContent(); // $campaigns = $campaignHasContentModel->getContentCampaigns($id); // This functionality needs looking over (code and general idea) // get content family (array of children, parents and siblings) $contentHasContentModel = new Default_Model_ContentHasContent(); $family = $contentHasContentModel->getContentFamilyTree($id); // split family array to child, parent and sibling arrays (full content) $children = array(); $children_siblings = array(); //TODO: It would be best effiency to send just an array of childs to ContentModel // and get all data in 1 query rather than querying many times. New function // to models is needed for this or then edit the one we have now and allow it // to have a possibility to receive ids as array. if (isset($family['children'])) { foreach ($family['children'] as $child) { $contenttypeid = $contentModel->getContentTypeIdByContentId((int) $child); $contenttype = $contentTypesModel->getTypeById($contenttypeid); if ($contenttype == "idea") { $children[] = $contentModel->getDataAsSimpleArray((int) $child); } else { $children_siblings[] = $contentModel->getDataAsSimpleArray((int) $child); } // $i++; } } $parents = array(); $parent_siblings = array(); if (isset($family['parents'])) { foreach ($family['parents'] as $parent) { $contenttypeid = $contentModel->getContentTypeIdByContentId((int) $parent); $contenttype = $contentTypesModel->getTypeById($contenttypeid); if ($contenttype == "idea") { $parents[] = $contentModel->getDataAsSimpleArray((int) $parent); } else { $parent_siblings[] = $contentModel->getDataAsSimpleArray((int) $parent); } } } // Here we get the rival solutions for a solution $rivals = array(); if ($contentType == "idea" && isset($family['parents'])) { $i = 0; // First here is checked the parents of this solution (=the problem // or the future info) foreach ($family['parents'] as $parent) { // Get the family of the problem or future info $parents_family = $contentHasContentModel->getContentFamilyTree((int) $parent); // Get the children of the problem or future info if (isset($parents_family['children'])) { // Going through the children foreach ($parents_family['children'] as $parent_child) { // Those children are rivals which are not this solution // which is currently viewed if ((int) $parent_child != $id) { $rivals[$i] = $contentModel->getDataAsSimpleArray((int) $parent_child); } } } $i++; } } // get comments data // $commentList = $comment->getAllByContentId($id, $page, $count); /*$commentList = $comment->getCommentsByContent($id); $commentsSorted = array(); $this->getCommentChilds($commentList, $commentsSorted, 0, 0, 3); // Get total comment count $commentCount = $comment->getCommentCountByContentId($id); // Calculate total page count $pageCount = ceil($commentCount / $count); // Custom pagination to fix memory error on large amount of data $paginator = new Zend_View(); $paginator->setScriptPath('../application/views/scripts'); $paginator->pageCount = $pageCount; $paginator->currentPage = $page; $paginator->pagesInRange = 10;*/ // get content industries -- will be updated later. /*$cntHasIndModel = new Default_Model_ContentHasIndustries(); $hasIndustry = $cntHasIndModel->getIndustryIdOfContent($id); $industriesModel = new Default_Model_Industries(); $industriesArray = $industriesModel->getAllContentIndustryIds($hasIndustry);*/ // roll values to an array /*$industries = array(); foreach ($industriesArray as $industry) { $value = $industriesModel->getNameById($industry); // $industriesModel->getNameById($industry); if (!empty($value)) { $industries[] = $value; } }*/ // Check if and when the content is modified and if its more than 10minutes ago add for the view $dateCreated = strtotime($contentData['created_cnt']); $dateModified = strtotime($contentData['modified_cnt']); $modified = 0; if (($dateModified - $dateCreated) / 60 > 10) { $modified = $contentData['modified_cnt']; } // Comment module $comments = new Oibs_Controller_Plugin_Comments("content", $id); $this->view->jsmetabox->append('commentUrls', $comments->getUrls()); // enable comment form if ($auth->hasIdentity() && $contentData['published_cnt'] == 1) { $comments->allowComments(true); } $comments->loadComments(); //$contentData['references_cnt']; $contentData['references_cnt'] = Oibs_Controller_Plugin_Utils::clickable($contentData['references_cnt'], true); $contentData['body_cnt'] = Oibs_Controller_Plugin_Utils::clickable($contentData['body_cnt']); // Inject data to view $this->view->files = $files; $this->view->id = $id; $this->view->userImage = $userImage; $this->view->comments = $comments; $this->view->user_can_rate = $user_can_rate; $this->view->user_is_owner = $user_is_owner; $this->view->usrId = $usrId; $this->view->contentData = $contentData; $this->view->modified = $modified; $this->view->userData = $userData; $this->view->views = $views; $this->view->isTranslated = $isTranslated; $this->view->languageName = $languageName; $this->view->gtranslateLangPair = $gtranslateLangPair; $this->view->tags = $tags; $this->view->links = $links; $this->view->parents = $parents; $this->view->parent_siblings = $parent_siblings; $this->view->children = $children; $this->view->children_siblings = $children_siblings; $this->view->rivals = $rivals; $this->view->contentType = $contentType; //$this->view->campaigns = $campaigns; $this->view->viewers = $this->getViewers($id); $this->view->boxStates = $this->getBoxStates(); // Inject title to view $this->view->title = $this->view->translate('index-home') . " - " . $contentData['title_cnt']; }