/**
  * Save changes to article.
  * @param $request Request
  * @return int the article ID
  */
 function execute(&$request)
 {
     $articleDao =& DAORegistry::getDAO('ArticleDAO');
     $articleDetailsDao =& DAORegistry::getDAO('ArticleDetailsDAO');
     $institutionDao =& DAORegistry::getDAO('InstitutionDAO');
     import('classes.journal.Institution');
     $article =& $this->article;
     $fundingSourcesData = $this->getData('fundingSources');
     $fundingSources = $article->getArticleFundingSources();
     $primarySponsorData = $this->getData('primarySponsor');
     $secondarySponsorsData = $this->getData('secondarySponsors');
     $secondarySponsors = $article->getArticleSecondarySponsors();
     $details = $article->getArticleDetails();
     $CROsData = $this->getData('CROs');
     $CROs = $article->getArticleCROs();
     $newInstitutions = array();
     // Remove deleted funding sources
     foreach ($fundingSources as $fundingSource) {
         $isPresent = false;
         foreach ($fundingSourcesData as $fundingSourceData) {
             if (!empty($fundingSourceData['id'])) {
                 if ($fundingSource->getId() == $fundingSourceData['id']) {
                     $isPresent = true;
                 }
             }
         }
         if (!$isPresent) {
             $article->removeArticleFundingSource($fundingSource->getId());
         }
         unset($isPresent);
         unset($fundingSource);
     }
     // Update / Insert funding sources
     foreach ($fundingSourcesData as $fundingSourceData) {
         if (isset($fundingSourceData['id'])) {
             $articleSource = $article->getArticleFundingSource($fundingSourceData['id']);
         } else {
             $articleSource = new ArticleSponsor();
         }
         $articleSource->setArticleId($article->getId());
         $articleSource->setType(ARTICLE_SPONSOR_TYPE_FUNDING);
         if ($fundingSourceData['institutionId'] == 'OTHER') {
             $institution = new Institution();
             $institution->setInstitutionName($fundingSourceData['name']);
             $institution->setInstitutionAcronym($fundingSourceData['acronym']);
             $institution->setInstitutionType($fundingSourceData['type']);
             $institution->setInstitutionInternational($fundingSourceData['location']);
             if ($fundingSourceData['location'] == INSTITUTION_NATIONAL) {
                 $institution->setInstitutionLocation($fundingSourceData['locationCountry']);
             } elseif ($fundingSourceData['location'] == INSTITUTION_INTERNATIONAL) {
                 $institution->setInstitutionLocation($fundingSourceData['locationInternational']);
             }
             $institutionId = $institutionDao->insertInstitution($institution);
             $articleSource->setInstitutionId($institutionId);
             $fundingSourceData['institutionId'] = $institutionId;
             array_push($newInstitutions, $fundingSourceData);
             unset($institution);
         } else {
             $articleSource->setInstitutionId($fundingSourceData['institutionId']);
         }
         $article->addArticleFundingSource($articleSource);
         unset($articleSource);
     }
     if (isset($primarySponsorData['id'])) {
         $primarySponsor = $article->getArticlePrimarySponsor();
     } else {
         $primarySponsor = new ArticleSponsor();
     }
     $primarySponsor->setArticleId($article->getId());
     $primarySponsor->setType(ARTICLE_SPONSOR_TYPE_PRIMARY);
     if ($primarySponsorData['institutionId'] == 'OTHER') {
         $found = false;
         foreach ($newInstitutions as $newInstitution) {
             if ($newInstitution['name'] == $primarySponsorData['name'] || $newInstitution['acronym'] == $primarySponsorData['acronym']) {
                 $found = $newInstitution['institutionId'];
             }
         }
         if (!$found) {
             $institution = new Institution();
             $institution->setInstitutionName($primarySponsorData['name']);
             $institution->setInstitutionAcronym($primarySponsorData['acronym']);
             $institution->setInstitutionType($primarySponsorData['type']);
             $institution->setInstitutionInternational($primarySponsorData['location']);
             if ($primarySponsorData['location'] == INSTITUTION_NATIONAL) {
                 $institution->setInstitutionLocation($primarySponsorData['locationCountry']);
             } elseif ($primarySponsorData['location'] == INSTITUTION_INTERNATIONAL) {
                 $institution->setInstitutionLocation($primarySponsorData['locationInternational']);
             }
             $institutionId = $institutionDao->insertInstitution($institution);
             $primarySponsor->setInstitutionId($institutionId);
             $primarySponsorData['institutionId'] = $institutionId;
             array_push($newInstitutions, $primarySponsorData);
             unset($institution);
         } else {
             $primarySponsor->setInstitutionId($found);
         }
     } else {
         $primarySponsor->setInstitutionId($primarySponsorData['institutionId']);
     }
     $article->setArticlePrimarySponsor($primarySponsor);
     // Remove deleted secondary sponsors
     foreach ($secondarySponsors as $secondarySponsor) {
         $isPresent = false;
         foreach ($secondarySponsorsData as $secondarySponsorData) {
             if (!empty($secondarySponsorData['id'])) {
                 if ($secondarySponsor->getId() == $secondarySponsorData['id']) {
                     $isPresent = true;
                 }
             }
         }
         if (!$isPresent) {
             $article->removeArticleSecondarySponsor($secondarySponsor->getId());
         }
         unset($isPresent);
         unset($secondarySponsor);
     }
     // Update / Insert secondary sponsors
     foreach ($secondarySponsorsData as $secondarySponsorData) {
         if (isset($secondarySponsorData['id'])) {
             $secondarySponsor = $article->getArticleSecondarySponsor($secondarySponsorData['id']);
         } else {
             $secondarySponsor = new ArticleSponsor();
         }
         $secondarySponsor->setArticleId($article->getId());
         $secondarySponsor->setType(ARTICLE_SPONSOR_TYPE_SECONDARY);
         if ($secondarySponsorData['ssInstitutionId'] == 'OTHER') {
             $found = false;
             foreach ($newInstitutions as $newInstitution) {
                 if ($newInstitution['name'] == $secondarySponsorData['ssName'] || $newInstitution['acronym'] == $secondarySponsorData['ssAcronym']) {
                     $found = $newInstitution['institutionId'];
                 }
             }
             if (!$found) {
                 $institution = new Institution();
                 $institution->setInstitutionName($secondarySponsorData['ssName']);
                 $institution->setInstitutionAcronym($secondarySponsorData['ssAcronym']);
                 $institution->setInstitutionType($secondarySponsorData['ssType']);
                 $institution->setInstitutionInternational($secondarySponsorData['ssLocation']);
                 if ($secondarySponsorData['ssLocation'] == INSTITUTION_NATIONAL) {
                     $institution->setInstitutionLocation($secondarySponsorData['ssLocationCountry']);
                 } elseif ($secondarySponsorData['ssLocation'] == INSTITUTION_INTERNATIONAL) {
                     $institution->setInstitutionLocation($secondarySponsorData['ssLocationInternational']);
                 }
                 $institutionId = $institutionDao->insertInstitution($institution);
                 $secondarySponsor->setInstitutionId($institutionId);
                 $primarySponsorData['institutionId'] = $institutionId;
                 array_push($newInstitutions, array('institutionId' => $institutionId, 'name' => $secondarySponsorData['ssName'], 'acronym' => $secondarySponsorData['ssAcronym']));
                 unset($institution);
             } else {
                 $secondarySponsor->setInstitutionId($found);
             }
         } else {
             $secondarySponsor->setInstitutionId($secondarySponsorData['ssInstitutionId']);
         }
         $article->addArticleSecondarySponsor($secondarySponsor);
         unset($secondarySponsor);
     }
     $details->setCROInvolved($this->getData('croInvolved'));
     $articleDetailsDao->updateArticleDetails($details);
     // Remove deleted CROs
     foreach ($CROs as $CRO) {
         $isPresent = false;
         foreach ($CROsData as $CROData) {
             if (!empty($CROData['id'])) {
                 if ($CRO->getId() == $CROData['id']) {
                     $isPresent = true;
                 }
             }
         }
         if (!$isPresent) {
             $article->removeArticleCRO($CRO->getId());
         }
         unset($isPresent);
         unset($CRO);
     }
     // Update / Insert CROs
     if ($details->getCROInvolved() == ARTICLE_DETAIL_YES) {
         foreach ($CROsData as $CROData) {
             if (isset($CROData['id'])) {
                 $CRO = $article->getArticleCRO($CROData['id']);
             } else {
                 $CRO = new ArticleCRO();
             }
             $CRO->setArticleId($article->getId());
             $CRO->setName($CROData['croName']);
             $CRO->setInternational($CROData['croLocation']);
             if ($CROData['croLocation'] == CRO_NATIONAL) {
                 $CRO->setLocation($CROData['croLocationCountry']);
             } elseif ($CROData['croLocation'] == CRO_INTERNATIONAL) {
                 $CRO->setLocation($CROData['croLocationInternational']);
             }
             $CRO->setCity($CROData['city']);
             $CRO->setAddress($CROData['address']);
             $CRO->setPrimaryPhone($CROData['primaryPhone']);
             $CRO->setSecondaryPhone($CROData['secondaryPhone']);
             $CRO->setFax($CROData['fax']);
             $CRO->setEmail($CROData['email']);
             $article->addArticleCRO($CRO);
             unset($CRO);
         }
     }
     //update step
     if ($article->getSubmissionProgress() <= $this->step) {
         $article->stampStatusModified();
         $article->setSubmissionProgress($this->step + 1);
     } elseif ($article->getSubmissionProgress() == 9) {
         $article->setSubmissionProgress(8);
     }
     parent::execute();
     // Save the article
     $articleDao->updateArticle($article);
     return $this->articleId;
 }
Beispiel #2
0
 /**
  * Internal function to return an articleCRO object from a row.
  * @param $row array
  * @return articleCRO ArticleCRO
  */
 function &_returnArticleCROFromRow(&$row)
 {
     $articleCRO = new ArticleCRO();
     $articleCRO->setId($row['article_cro_id']);
     $articleCRO->setArticleId($row['article_id']);
     $articleCRO->setName($row['name']);
     $articleCRO->setInternational($row['international']);
     $articleCRO->setLocation($row['region_country']);
     $articleCRO->setCity($row['city']);
     $articleCRO->setAddress($row['address']);
     $articleCRO->setPrimaryPhone($row['primary_phone']);
     $articleCRO->setSecondaryPhone($row['secondary_phone']);
     $articleCRO->setFax($row['fax']);
     $articleCRO->setEmail($row['email']);
     HookRegistry::call('ArticleCRODAO::_returnArticleCROFromRow', array(&$articleCRO, &$row));
     return $articleCRO;
 }