build($submissionId); $submissionKeywordEntryDao = DAORegistry::getDAO('SubmissionKeywordEntryDAO'); $submissionKeywords = $submissionKeywordEntryDao->getByControlledVocabId($keywords->getId()); while ($keyword = $submissionKeywords->next()) { $keyword = $keyword->getKeyword(); if (array_key_exists($locale, $keyword)) { // quiets PHP when there are no keywords for a given locale $returner[$locale][] = $keyword[$locale]; } } } return $returner; } /** * Get an array of all of the submission's keywords * @return array */ function getAllUniqueKeywords() { $keywords = array(); $result = $this->retrieve( 'SELECT DISTINCT setting_value FROM controlled_vocab_entry_settings WHERE setting_name = ?', CONTROLLED_VOCAB_SUBMISSION_KEYWORD ); while (!$result->EOF) { $keywords[] = $result->fields[0]; $result->MoveNext(); } $result->Close(); return $keywords; } /** * Get an array of submissionIds that have a given keyword * @param $content string * @return array */ function getSubmissionIdsByKeyword($keyword) { $result = $this->retrieve( 'SELECT assoc_id FROM controlled_vocabs cv LEFT JOIN controlled_vocab_entries cve ON cv.controlled_vocab_id = cve.controlled_vocab_id INNER JOIN controlled_vocab_entry_settings cves ON cve.controlled_vocab_entry_id = cves.controlled_vocab_entry_id WHERE cves.setting_name = ? AND cves.setting_value = ?', array(CONTROLLED_VOCAB_SUBMISSION_KEYWORD, $keyword) ); $returner = array(); while (!$result->EOF) { $row = $result->GetRowAssoc(false); $returner[] = $row['assoc_id']; $result->MoveNext(); } $result->Close(); return $returner; } /** * Add an array of keywords * @param $keywords array * @param $submissionId int * @param $deleteFirst boolean * @return int */ function insertKeywords($keywords, $submissionId, $deleteFirst = true) { $keywordDao = DAORegistry::getDAO('SubmissionKeywordDAO'); $submissionKeywordEntryDao = DAORegistry::getDAO('SubmissionKeywordEntryDAO'); $currentKeywords = $this->build($submissionId); if ($deleteFirst) { $existingEntries = $keywordDao->enumerate($currentKeywords->getId(), CONTROLLED_VOCAB_SUBMISSION_KEYWORD); foreach ($existingEntries as $id => $entry) { $entry = trim($entry); $submissionKeywordEntryDao->deleteObjectById($id); } } if (is_array($keywords)) { // localized, array of arrays foreach ($keywords as $locale => $list) { if (is_array($list)) { $list = array_unique($list); // Remove any duplicate keywords $i = 1; foreach ($list as $keyword) { $keywordEntry = $submissionKeywordEntryDao->newDataObject(); $keywordEntry->setControlledVocabId($currentKeywords->getID()); $keywordEntry->setKeyword(urldecode($keyword), $locale); $keywordEntry->setSequence($i); $i++; $submissionKeywordEntryDao->insertObject($keywordEntry); } } } } } } ?>