Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
SubmissionLanguageDAO.inc.php
1 <?php
2 
17 import('lib.pkp.classes.controlledVocab.ControlledVocabDAO');
18 
19 define('CONTROLLED_VOCAB_SUBMISSION_LANGUAGE', 'submissionLanguage');
20 
25  function submissionLanguageDAO() {
26  parent::ControlledVocabDAO();
27  }
28 
34  function build($submissionId) {
35  // may return an array of ControlledVocabs
36  return parent::build(CONTROLLED_VOCAB_SUBMISSION_LANGUAGE, ASSOC_TYPE_SUBMISSION, $submissionId);
37  }
38 
43  function getLocaleFieldNames() {
44  return array('submissionLanguage');
45  }
46 
53  function getLanguages($submissionId, $locales) {
54 
55  $returner = array();
56  foreach ($locales as $locale) {
57  $returner[$locale] = array();
58  $languages = $this->build($submissionId);
59  $submissionLanguageEntryDao = DAORegistry::getDAO('SubmissionLanguageEntryDAO');
60  $submissionLanguages = $submissionLanguageEntryDao->getByControlledVocabId($languages->getId());
61 
62  while ($language = $submissionLanguages->next()) {
63  $language = $language->getLanguage();
64  if (array_key_exists($locale, $language)) { // quiets PHP when there are no Languages for a given locale
65  $returner[$locale][] = $language[$locale];
66  }
67  }
68  }
69  return $returner;
70  }
71 
76  function getAllUniqueLanguages() {
77  $languages = array();
78 
79  $result = $this->retrieve(
80  'SELECT DISTINCT setting_value FROM controlled_vocab_entry_settings WHERE setting_name = ?', CONTROLLED_VOCAB_SUBMISSION_LANGUAGE
81  );
82 
83  while (!$result->EOF) {
84  $languages[] = $result->fields[0];
85  $result->MoveNext();
86  }
87 
88  $result->Close();
89  return $languages;
90  }
91 
97  function getSubmissionIdsByLanguage($language) {
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_LANGUAGE, $language)
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 insertLanguages($languages, $submissionId, $deleteFirst = true) {
125  $languageDao = DAORegistry::getDAO('SubmissionLanguageDAO');
126  $submissionLanguageEntryDao = DAORegistry::getDAO('SubmissionLanguageEntryDAO');
127  $currentLanguages = $this->build($submissionId);
128 
129  if ($deleteFirst) {
130  $existingEntries = $languageDao->enumerate($currentLanguages->getId(), CONTROLLED_VOCAB_SUBMISSION_LANGUAGE);
131 
132  foreach ($existingEntries as $id => $entry) {
133  $entry = trim($entry);
134  $submissionLanguageEntryDao->deleteObjectById($id);
135  }
136  }
137  if (is_array($languages)) { // localized, array of arrays
138 
139  foreach ($languages as $locale => $list) {
140  if (is_array($list)) {
141  $list = array_unique($list); // Remove any duplicate Languages
142  $i = 1;
143  foreach ($list as $language) {
144  $languageEntry = $submissionLanguageEntryDao->newDataObject();
145  $languageEntry->setControlledVocabId($currentLanguages->getID());
146  $languageEntry->setLanguage(urldecode($language), $locale);
147  $languageEntry->setSequence($i);
148  $i++;
149  $submissionLanguageEntryDao->insertObject($languageEntry);
150  }
151  }
152  }
153  }
154  }
155 }
156 
157 ?>
static & getDAO($name, $dbconn=null)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
Operations for retrieving and modifying ControlledVocab objects.
getLanguages($submissionId, $locales)
insertLanguages($languages, $submissionId, $deleteFirst=true)
Operations for retrieving and modifying a submission&#39;s assigned languages.