/**
  * Internal function to return an articleDrugInfo object from a row.
  * @param $row array
  * @return articleDrugInfo ArticleDrugInfo
  */
 function &_returnArticleDrugInfoFromRow(&$row)
 {
     $articleDrugInfo = new ArticleDrugInfo();
     $articleDrugInfo->setId($row['drug_id']);
     $articleDrugInfo->setArticleId($row['article_id']);
     $articleDrugInfo->setType($row['type']);
     $articleDrugInfo->setName($row['name']);
     $articleDrugInfo->setBrandName($row['brand_name']);
     $articleDrugInfo->setAdministration($row['administration']);
     $articleDrugInfo->setOtherAdministration($row['other_administration']);
     $articleDrugInfo->setForm($row['form']);
     $articleDrugInfo->setOtherForm($row['other_form']);
     $articleDrugInfo->setStrength($row['strength']);
     $articleDrugInfo->setStorage($row['storage']);
     $articleDrugInfo->setPharmaClass($row['pharma_class']);
     $articleDrugInfo->setClasses($row['study_class']);
     $articleDrugInfo->setCountries($row['countries']);
     $articleDrugInfo->setDifferentConditionsOfUse($row['different_conditions_of_use']);
     $articleDrugInfo->setCPR($row['cpr']);
     $articleDrugInfo->setDrugRegistrationNumber($row['drug_registration_number']);
     $articleDrugInfo->setImportedQuantity($row['imported_quantity']);
     $articleDrugInfo->setManufacturers($this->drugManufacturerDao->getArticleDrugManufacturersByDrugId($row['drug_id']));
     HookRegistry::call('ArticleDrugInfoDAO::_returnArticleDrugInfoFromRow', array(&$articleDrugInfo, &$row));
     return $articleDrugInfo;
 }
 /**
  * Save changes to article.
  * @param $request Request
  * @return int the article ID
  */
 function execute(&$request)
 {
     $articleDao =& DAORegistry::getDAO('ArticleDAO');
     $article =& $this->article;
     $articleDrugsData = $this->getData('articleDrugs');
     $articleDrugs = $article->getArticleDrugs();
     // Remove deleted article drugs
     foreach ($articleDrugs as $articleDrug) {
         $isPresent = false;
         foreach ($articleDrugsData as $articleDrugData) {
             if (!empty($articleDrugData['id'])) {
                 if ($articleDrug->getId() == $articleDrugData['id']) {
                     $isPresent = true;
                 }
             }
         }
         if (!$isPresent) {
             $article->removeArticleDrug($articleDrug->getId());
         }
         unset($isPresent);
         unset($articleDrug);
     }
     // Update article drugs
     foreach ($articleDrugsData as $articleDrugData) {
         if (isset($articleDrugData['id'])) {
             $articleDrug = $article->getArticleDrug($articleDrugData['id']);
             $isExistingDrug = true;
         } else {
             $articleDrug = new ArticleDrugInfo();
             $isExistingDrug = false;
         }
         $articleDrug->setArticleId($article->getId());
         $articleDrug->setType($articleDrugData['type']);
         $articleDrug->setName($articleDrugData['name']);
         $articleDrug->setBrandName($articleDrugData['brandName']);
         $articleDrug->setAdministration($articleDrugData['administration']);
         $articleDrug->setOtherAdministration($articleDrugData['otherAdministration']);
         $articleDrug->setForm($articleDrugData['form']);
         $articleDrug->setOtherForm($articleDrugData['otherForm']);
         $articleDrug->setStrength($articleDrugData['strength']);
         $articleDrug->setStorage($articleDrugData['storage']);
         $articleDrug->setPharmaClass($articleDrugData['pharmaClass']);
         $articleDrug->setClassesFromArray($articleDrugData['studyClasses']);
         $articleDrug->setCountriesFromArray($articleDrugData['countries']);
         $articleDrug->setDifferentConditionsOfUse($articleDrugData['conditionsOfUse']);
         $articleDrug->setCPR($articleDrugData['cpr']);
         $articleDrug->setDrugRegistrationNumber($articleDrugData['drugRegistrationNumber']);
         $articleDrug->setImportedQuantity($articleDrugData['importedQuantity']);
         $manufacturersData = $articleDrugData['manufacturers'];
         $manufacturers = $articleDrug->getManufacturers();
         // Remove deleted manufacturers
         foreach ($manufacturers as $manufacturer) {
             $isPresent = false;
             foreach ($manufacturersData as $manufacturerData) {
                 if (!empty($manufacturerData['id'])) {
                     if ($manufacturer->getId() == $manufacturerData['id']) {
                         $isPresent = true;
                     }
                 }
             }
             if (!$isPresent) {
                 $articleDrug->removeManufacturer($manufacturer->getId());
             }
             unset($isPresent);
             unset($manufacturer);
         }
         // Update manufacturers
         foreach ($manufacturersData as $manufacturerData) {
             if (isset($manufacturerData['id'])) {
                 $manufacturer = $articleDrug->getManufacturer($manufacturerData['id']);
             } else {
                 $manufacturer = new ArticleDrugManufacturer();
             }
             if ($isExistingDrug) {
                 $manufacturer->setDrugId($articleDrug->getId());
             }
             $manufacturer->setName($manufacturerData['name']);
             $manufacturer->setAddress($manufacturerData['address']);
             $articleDrug->addManufacturer($manufacturer);
         }
         $article->addArticleDrug($articleDrug);
     }
     //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;
 }