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