Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
SubmissionKeywordDAO.inc.php
1 <?php
2 
17 import('lib.pkp.classes.controlledVocab.ControlledVocabDAO');
18 
19 define('CONTROLLED_VOCAB_SUBMISSION_KEYWORD', 'submissionKeyword');
20 
25  function submissionKeywordDAO() {
26  parent::ControlledVocabDAO();
27  }
28 
34  function build($submissionId) {
35  // may return an array of ControlledVocabs
36  return parent::build(CONTROLLED_VOCAB_SUBMISSION_KEYWORD, ASSOC_TYPE_SUBMISSION, $submissionId);
37  }
38 
43  function getLocaleFieldNames() {
44  return array('submissionKeyword');
45  }
46 
53  function getKeywords($submissionId, $locales) {
54 
55  $returner = array();
56  foreach ($locales as $locale) {
57  $returner[$locale] = array();
58  $keywords = $this->build($submissionId);
59  $submissionKeywordEntryDao = DAORegistry::getDAO('SubmissionKeywordEntryDAO');
60  $submissionKeywords = $submissionKeywordEntryDao->getByControlledVocabId($keywords->getId());
61 
62  while ($keyword = $submissionKeywords->next()) {
63  $keyword = $keyword->getKeyword();
64  if (array_key_exists($locale, $keyword)) { // quiets PHP when there are no keywords for a given locale
65  $returner[$locale][] = $keyword[$locale];
66  }
67  }
68  }
69  return $returner;
70  }
71 
76  function getAllUniqueKeywords() {
77  $keywords = array();
78 
79  $result = $this->retrieve(
80  'SELECT DISTINCT setting_value FROM controlled_vocab_entry_settings WHERE setting_name = ?', CONTROLLED_VOCAB_SUBMISSION_KEYWORD
81  );
82 
83  while (!$result->EOF) {
84  $keywords[] = $result->fields[0];
85  $result->MoveNext();
86  }
87 
88  $result->Close();
89  return $keywords;
90  }
91 
97  function getSubmissionIdsByKeyword($keyword) {
98  $result = $this->retrieve(
99  'SELECT assoc_id
100  FROM controlled_vocabs cv
101  LEFT JOIN controlled_vocab_entries cve ON cv.controlled_vocab_id = cve.controlled_vocab_id
102  INNER JOIN controlled_vocab_entry_settings cves ON cve.controlled_vocab_entry_id = cves.controlled_vocab_entry_id
103  WHERE cves.setting_name = ? AND cves.setting_value = ?',
104  array(CONTROLLED_VOCAB_SUBMISSION_KEYWORD, $keyword)
105  );
106 
107  $returner = array();
108  while (!$result->EOF) {
109  $row = $result->GetRowAssoc(false);
110  $returner[] = $row['assoc_id'];
111  $result->MoveNext();
112  }
113  $result->Close();
114  return $returner;
115  }
116 
124  function insertKeywords($keywords, $submissionId, $deleteFirst = true) {
125  $keywordDao = DAORegistry::getDAO('SubmissionKeywordDAO');
126  $submissionKeywordEntryDao = DAORegistry::getDAO('SubmissionKeywordEntryDAO');
127  $currentKeywords = $this->build($submissionId);
128 
129  if ($deleteFirst) {
130  $existingEntries = $keywordDao->enumerate($currentKeywords->getId(), CONTROLLED_VOCAB_SUBMISSION_KEYWORD);
131 
132  foreach ($existingEntries as $id => $entry) {
133  $entry = trim($entry);
134  $submissionKeywordEntryDao->deleteObjectById($id);
135  }
136  }
137  if (is_array($keywords)) { // localized, array of arrays
138 
139  foreach ($keywords as $locale => $list) {
140  if (is_array($list)) {
141  $list = array_unique($list); // Remove any duplicate keywords
142  $i = 1;
143  foreach ($list as $keyword) {
144  $keywordEntry = $submissionKeywordEntryDao->newDataObject();
145  $keywordEntry->setControlledVocabId($currentKeywords->getID());
146  $keywordEntry->setKeyword(urldecode($keyword), $locale);
147  $keywordEntry->setSequence($i);
148  $i++;
149  $submissionKeywordEntryDao->insertObject($keywordEntry);
150  }
151  }
152  }
153  }
154  }
155 }
156 
157 ?>
static & getDAO($name, $dbconn=null)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
getKeywords($submissionId, $locales)
Operations for retrieving and modifying ControlledVocab objects.
insertKeywords($keywords, $submissionId, $deleteFirst=true)
Operations for retrieving and modifying a submission&#39;s assigned keywords.