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