Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
SubmissionAgencyDAO.inc.php
1 <?php
2 
17 import('lib.pkp.classes.controlledVocab.ControlledVocabDAO');
18 
19 define('CONTROLLED_VOCAB_SUBMISSION_AGENCY', 'submissionAgency');
20 
25  function submissionAgencyDAO() {
26  parent::ControlledVocabDAO();
27  }
28 
34  function build($submissionId) {
35  return parent::build(CONTROLLED_VOCAB_SUBMISSION_AGENCY, ASSOC_TYPE_SUBMISSION, $submissionId);
36  }
37 
42  function getLocaleFieldNames() {
43  return array('submissionAgency');
44  }
45 
52  function getAgencies($submissionId, $locales) {
53 
54  $returner = array();
55  foreach ($locales as $locale) {
56  $returner[$locale] = array();
57  $agencies = $this->build($submissionId);
58  $submissionAgencyEntryDao = DAORegistry::getDAO('SubmissionAgencyEntryDAO');
59  $submissionAgencies = $submissionAgencyEntryDao->getByControlledVocabId($agencies->getId());
60 
61  while ($agency = $submissionAgencies->next()) {
62  $agency = $agency->getAgency();
63  if (array_key_exists($locale, $agency)) { // quiets PHP when there are no agencies for a given locale
64  $returner[$locale][] = $agency[$locale];
65  }
66  }
67  }
68  return $returner;
69  }
70 
75  function getAllUniqueAgencies() {
76  $agencies = array();
77 
78  $result = $this->retrieve(
79  'SELECT DISTINCT setting_value FROM controlled_vocab_entry_settings WHERE setting_name = ?', CONTROLLED_VOCAB_SUBMISSION_AGENCY
80  );
81 
82  while (!$result->EOF) {
83  $agencies[] = $result->fields[0];
84  $result->MoveNext();
85  }
86 
87  $result->Close();
88  return $agencies;
89  }
90 
96  function getSubmissionIdsByAgency($agency) {
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_AGENCY, $agency)
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 insertAgencies($agencies, $submissionId, $deleteFirst = true) {
124  $agencyDao = DAORegistry::getDAO('SubmissionAgencyDAO');
125  $submissionAgencyEntryDao = DAORegistry::getDAO('SubmissionAgencyEntryDAO');
126  $currentAgencies = $this->build($submissionId);
127 
128  if ($deleteFirst) {
129  $existingEntries = $agencyDao->enumerate($currentAgencies->getId(), CONTROLLED_VOCAB_SUBMISSION_AGENCY);
130 
131  foreach ($existingEntries as $id => $entry) {
132  $entry = trim($entry);
133  $submissionAgencyEntryDao->deleteObjectById($id);
134  }
135  }
136  if (is_array($agencies)) { // localized, array of arrays
137 
138  foreach ($agencies as $locale => $list) {
139  if (is_array($list)) {
140  $list = array_unique($list); // Remove any duplicate keywords
141  $i = 1;
142  foreach ($list as $agency) {
143  $agencyEntry = $submissionAgencyEntryDao->newDataObject();
144  $agencyEntry->setControlledVocabId($currentAgencies->getID());
145  $agencyEntry->setAgency(urldecode($agency), $locale);
146  $agencyEntry->setSequence($i);
147  $i++;
148  $submissionAgencyEntryDao->insertObject($agencyEntry);
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.
insertAgencies($agencies, $submissionId, $deleteFirst=true)
getAgencies($submissionId, $locales)
Operations for retrieving and modifying a submission&#39;s assigned agencies.