Пример #1
0
 /**
  *   addContent
  *
  *   Add content.
  *
  *    @param array $data
  */
 public function addContent($data)
 {
     $auth = Zend_Auth::getInstance();
     // Create a new row
     $content = $this->createRow();
     //Zend_Debug::dump($content, $label=null, $echo=true);
     // Set data to row
     $content->id_cty_cnt = $data['content_type'];
     $content->title_cnt = htmlspecialchars($data['content_header']);
     $content->lead_cnt = htmlspecialchars($data['content_textlead']);
     $content->body_cnt = htmlspecialchars($data['content_text']);
     if (isset($data['content_research'])) {
         $content->research_question_cnt = htmlspecialchars($data['content_research']);
     }
     if (isset($data['content_opportunity'])) {
         $content->opportunity_cnt = htmlspecialchars($data['content_opportunity']);
     }
     if (isset($data['content_threat'])) {
         $content->threat_cnt = htmlspecialchars($data['content_threat']);
     }
     if (isset($data['content_solution'])) {
         $content->solution_cnt = htmlspecialchars($data['content_solution']);
     }
     $content->references_cnt = $data['content_references'];
     $content->published_cnt = $data['publish'];
     $content->created_cnt = new Zend_Db_Expr('NOW()');
     $content->modified_cnt = new Zend_Db_Expr('NOW()');
     $content->language_cnt = $data['content_language'];
     if (!$content->save()) {
         $return = false;
     } else {
         // If save was successful, content id is returned, because it is needed
         // when redirecting
         $return = $content->id_cnt;
         /*if($_FILES['content_file_upload']['size'] != 0) {
         	 $files = new Default_Model_Files();
         	 $files->newFile($content->id_cnt, $auth->getIdentity()->user_id);
         	 }*/
         $filesModel = new Default_Model_Files();
         $filesModel->newFiles($content->id_cnt, "content", $data['files']);
     }
     // What is this used for
     //$contentTypes = new Default_Model_ContentTypes();
     //$content_type = $contentTypes->getTypeById($data['content_type']);
     if ($data['content_relatesto_id'] != 0) {
         $contentHasContent = new Default_Model_ContentHasContent();
         $contentHasContent->addContentToContent($data['content_relatesto_id'], $content->id_cnt);
     }
     // Add user to content
     $contentHasUser = new Default_Model_ContentHasUser();
     $contentHasUser->addUserToContent($content->id_cnt, $data['User']['id_usr'], 1);
     // Check if user has given keywords
     if (!empty($data['content_keywords'])) {
         $tagModel = new Default_Model_Tags();
         $tagModel->addTagsToContent($content->id_cnt, $data['content_keywords']);
         // Go through all given keywords
         // This should be in Tags model
         /*
         foreach($data['content_keywords'] as $tag) {
             $tagRow = new Default_Model_Tags();
             $tag = strip_tags($tag);
             
             // Check if given keyword does not exists in database
             if($tagRow->tagExists($tag)) {
                 // Create new keyword
                 $tag = $tagRow->createTag($tag);
             } else {
                 // Get keyword
                 $tag = $tagRow->getTag($tag);
             } // end else
             
             // echo '<pre>';echo $tag->id_tag.'    '.$content->id_cnt;echo '</pre>';
             //die();
             
             // Add keywords to content
             $contentHasTag = new Default_Model_ContentHasTag();
             $contentHasTag->addTagToContent($tag->id_tag, $content->id_cnt);
         } // end foreach 
         */
     }
     // end if
     // Check if user has given related companies
     if (!empty($data['content_related_companies'])) {
         $recModel = new Default_Model_RelatedCompanies();
         $recModel->addRelatedCompaniesToContent($content->id_cnt, $data['content_related_companies']);
         // Go through all given related companies
         // FIX: This should be in RelatedCompanies model
         /*foreach($data['content_related_companies'] as $relComp) {
               $relCompRow = new Default_Model_RelatedCompanies();
               $relComp = strip_tags($relComp);
               
               // Check if given related company does not exists in database
               if($relCompRow->relCompExists($relComp)) {
                   // Create new related company
                   $relComp = $relCompRow->createRelComp($relComp);
               } else {
                   // Get related company
                   $relComp = $relCompRow->getRelComp($relComp);
               } // end else
               
               // echo '<pre>';echo $tag->id_tag.'    '.$content->id_cnt;echo '</pre>';
               //die();
               
               // Add related companies to content
               $contentHasRelatedCompany = new Default_Model_ContentHasRelatedCompany();
               $contentHasRelatedCompany->addRelCompToContent($relComp->id_rec, $content->id_cnt);
           } // end foreach */
     }
     // end if
     // Check if user has given campaigns
     if (!empty($data['content_campaigns'])) {
         $cmpModel = new Default_Model_Campaigns();
         $cmpModel->addCampaignsToContent($content->id_cnt, $data['content_campaigns']);
         // Go through all given campaigns
         // FIX: This should be in Campaigns model
         /*foreach($data['content_campaigns'] as $campaign) {
               $campaignRow = new Default_Model_Campaigns();
               $campaign = strip_tags($campaign);
               
               // Check if given campaign does not exists in database
               if($campaignRow->campaignExists($campaign)) {
                   // Create new campaign
                   $campaign = $campaignRow->createCampaign($campaign);
               } else {
                   // Get campaign
                   $campaign = $campaignRow->getCampaign($campaign);
               } // end else
               
               // echo '<pre>';echo $tag->id_tag.'    '.$content->id_cnt;echo '</pre>';
               //die();
               
               // Add related companies to content
               $contentHasCampaign = new Default_Model_ContentHasCampaign();
               $contentHasCampaign->addCampaignToContent($campaign->id_cmp, $content->id_cnt);
           } // end foreach */
     }
     // end if
     // Add industry to content
     /*$contentHasIndustry = new Default_Model_ContentHasIndustries();
       
       if(isset($data['content_industry'])) {
           $id_ind = 0;
           
           if($data['content_class'] != 0) {
               $id_ind = $data['content_class'];
           } elseif($data['content_group'] != 0) {
               $id_ind = $data['content_group'];
           } elseif($data['content_division'] != 0) {
               $id_ind = $data['content_division'];
           } elseif($data['content_industry'] != 0) {
               $id_ind = $data['content_industry'];
           }
       }
       
       if($id_ind != 0) {
           $contentHasIndustry->addIndustryToContent($content->id_cnt, $id_ind);
       }
       */
     // Add future info classification to content
     if (isset($data['content_finfo_class'])) {
         if ($data['content_finfo_class'] != 0) {
             $contentHasFutureinfoClass = new Default_Model_ContentHasFutureinfoClasses();
             $contentHasFutureinfoClass->addFutureinfoClassToContent($content->id_cnt, $data['content_finfo_class']);
         }
     }
     // Add innovation type to content
     if (isset($data['innovation_type'])) {
         if ($data['innovation_type'] != 0) {
             $contentHasInnovationType = new Default_Model_ContentHasInnovationTypes();
             $contentHasInnovationType->addInnovationTypeToContent($content->id_cnt, $data['innovation_type']);
         }
     }
     return $return;
 }
Пример #2
0
 /**
  *   makelinksAction
  *
  *   Make content link to content.
  *
  */
 public function makelinksAction()
 {
     // Get authentication
     $auth = Zend_Auth::getInstance();
     $absoluteBaseUrl = strtolower(trim(array_shift(explode('/', $_SERVER['SERVER_PROTOCOL'])))) . '://' . $_SERVER['HTTP_HOST'] . Zend_Controller_Front::getInstance()->getBaseUrl();
     // If user has identity
     if ($auth->hasIdentity()) {
         // Get requests
         $params = $this->getRequest()->getParams();
         // Get content type
         $contenttype = isset($params['contenttype']) ? $params['contenttype'] : '';
         $relatestoid = isset($params['parentid']) ? $params['parentid'] : '';
         $linkedcontentid = isset($params['childid']) ? $params['childid'] : '';
         if ($this->validateLinking($contenttype, $relatestoid, $linkedcontentid)) {
             $model_cnt_has_cnt = new Default_Model_ContentHasContent();
             $model_cnt_has_cnt->addContentToContent($relatestoid, $linkedcontentid);
             // Send email to owner of content about a new link
             // if user allows linking notifications
             $userModel = new Default_Model_User();
             $owner = $userModel->getContentOwner($relatestoid);
             $notificationsModel = new Default_Model_Notifications();
             $notifications = $notificationsModel->getNotificationsById($owner['id_usr']);
             if (in_array('link', $notifications)) {
                 $cntModel = new Default_Model_Content();
                 $originalHeader = $cntModel->getContentHeaderByContentId($relatestoid);
                 $linkedHeader = $cntModel->getContentHeaderByContentId($linkedcontentid);
                 $senderId = $auth->getIdentity()->user_id;
                 $senderName = $auth->getIdentity()->username;
                 $emailNotification = new Oibs_Controller_Plugin_Email();
                 $emailNotification->setNotificationType('link')->setSenderId($auth->getIdentity()->user_id)->setReceiverId($owner['id_usr'])->setParameter('URL', $absoluteBaseUrl . "/en")->setParameter('SENDER-NAME', $senderName)->setParameter('LINKED-ID', $linkedcontentid)->setParameter('LINKED-TITLE', $linkedHeader)->setParameter('ORIGINAL-ID', $relatestoid)->setParameter('ORIGINAL-TITLE', $originalHeader);
                 if ($emailNotification->isValid()) {
                     $emailNotification->send();
                 } else {
                     //echo $emailNotification->getErrorMessage(); die;
                 }
             }
             $url = $this->_urlHelper->url(array('controller' => 'view', 'action' => $relatestoid, 'language' => $this->view->language), 'lang_default', true);
             $message = "content-linked-successfully";
             $this->flash($message, $url);
         }
     } 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);
     }
 }
Пример #3
0
 /**
  *   addContent
  *
  *   Add content.
  *
  *    @param array $data
  */
 public function addContent($data)
 {
     $auth = Zend_Auth::getInstance();
     // Create a new row
     $content = $this->createRow();
     //Zend_Debug::dump($content, $label=null, $echo=true);
     // Set data to row
     $content->id_cty_cnt = $data['content_type'];
     $content->title_cnt = htmlspecialchars($data['content_header']);
     $content->lead_cnt = htmlspecialchars($data['content_textlead']);
     $content->body_cnt = htmlspecialchars($data['content_text']);
     if (isset($data['content_research'])) {
         $content->research_question_cnt = htmlspecialchars($data['content_research']);
     }
     if (isset($data['content_opportunity'])) {
         $content->opportunity_cnt = htmlspecialchars($data['content_opportunity']);
     }
     if (isset($data['content_threat'])) {
         $content->threat_cnt = htmlspecialchars($data['content_threat']);
     }
     if (isset($data['content_solution'])) {
         $content->solution_cnt = htmlspecialchars($data['content_solution']);
     }
     $content->references_cnt = $data['content_references'];
     $content->published_cnt = $data['publish'];
     $content->created_cnt = new Zend_Db_Expr('NOW()');
     $content->modified_cnt = new Zend_Db_Expr('NOW()');
     $content->language_cnt = $data['content_language'];
     //Zend_Debug::dump($content, $label=null, $echo=true); die();
     /*$query = "INSERT INTO contents_cnt (id_cty_cnt, id_ind_cnt, title_cnt, lead_cnt, body_cnt, views_cnt, published_cnt, created_cnt, modified_cnt) ";
     	 $query .= "VALUES (".$data['content_type'].", ".$data['content_industry_id'].", '".strip_tags($data['content_header'])."', '".strip_tags($data['content_textlead'])."', '";
     	 $query .= strip_tags($data['content_text'])."', 0, 0, ".new Zend_Db_Expr('NOW()').", ".new Zend_Db_Expr('NOW()').")";*/
     //Zend_Debug::dump($query, $label=null, $echo=true); die();
     /*mysql_connect("localhost", "root", "lollero");
     	 mysql_query($query);
     	 echo mysql_error();
     	 mysql_close();
     	 die();*/
     if (!$content->save()) {
         $return = false;
     } else {
         // If save was successful, content id is returned, because it is needed
         // when redirecting
         $return = $content->id_cnt;
         /*if($_FILES['content_file_upload']['size'] != 0) {
         	 $files = new Default_Model_Files();
         	 $files->newFile($content->id_cnt, $auth->getIdentity()->user_id);
         	 }*/
         $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($content->id_cnt, $data['User']['id_usr'], $file);
         }
     }
     // What is this used for
     //$contentTypes = new Default_Model_ContentTypes();
     //$content_type = $contentTypes->getTypeById($data['content_type']);
     if ($data['content_relatesto_id'] != 0) {
         $contentHasContent = new Default_Model_ContentHasContent();
         $contentHasContent->addContentToContent($data['content_relatesto_id'], $content->id_cnt);
     }
     // Add user to content
     $contentHasUser = new Default_Model_ContentHasUser();
     $contentHasUser->addUserToContent($content->id_cnt, $data['User']['id_usr'], 1);
     // Check if user has given keywords
     if (!empty($data['content_keywords'])) {
         $tagModel = new Default_Model_Tags();
         $tagModel->addTagsToContent($content->id_cnt, $data['content_keywords']);
     }
     // end if
     // Check if user has given related companies
     if (!empty($data['content_related_companies'])) {
         $recModel = new Default_Model_RelatedCompanies();
         $recModel->addRelatedCompaniesToContent($content->id_cnt, $data['content_related_companies']);
     }
     // end if
     // Add industry to content
     $contentHasIndustry = new Default_Model_ContentHasIndustries();
     if (isset($data['content_industry'])) {
         $id_ind = 0;
         if ($data['content_class'] != 0) {
             $id_ind = $data['content_class'];
         } elseif ($data['content_group'] != 0) {
             $id_ind = $data['content_group'];
         } elseif ($data['content_division'] != 0) {
             $id_ind = $data['content_division'];
         } elseif ($data['content_industry'] != 0) {
             $id_ind = $data['content_industry'];
         }
     }
     if ($id_ind != 0) {
         $contentHasIndustry->addIndustryToContent($content->id_cnt, $id_ind);
     }
     // Add future info classification to content
     if (isset($data['content_finfo_class'])) {
         if ($data['content_finfo_class'] != 0) {
             $contentHasFutureinfoClass = new Default_Model_ContentHasFutureinfoClasses();
             $contentHasFutureinfoClass->addFutureinfoClassToContent($content->id_cnt, $data['content_finfo_class']);
         }
     }
     // Add innovation type to content
     if (isset($data['innovation_type'])) {
         if ($data['innovation_type'] != 0) {
             $contentHasInnovationType = new Default_Model_ContentHasInnovationTypes();
             $contentHasInnovationType->addInnovationTypeToContent($content->id_cnt, $data['innovation_type']);
         }
     }
     // Reset and save latest post time hash in cache
     $cache = Zend_Registry::get('cache');
     $cache->remove('LatestPostHash');
     $cache->save('LatestPostHash', md5(time()));
     return $return;
 }