17 import(
'lib.pkp.classes.controlledVocab.ControlledVocab');
36 'SELECT * FROM controlled_vocabs WHERE controlled_vocab_id = ?', array((
int) $controlledVocabId)
40 if ($result->RecordCount() != 0) {
41 $returner = $this->
_fromRow($result->GetRowAssoc(
false));
54 function _build($symbolic, $assocType = 0, $assocId = 0) {
56 $controlledVocab = $this->
getBySymbolic($symbolic, $assocType, $assocId);
57 if ($controlledVocab)
return $controlledVocab;
61 $controlledVocab->setSymbolic($symbolic);
62 $controlledVocab->setAssocType($assocType);
63 $controlledVocab->setAssocId($assocId);
65 if ($id !==
null)
return $controlledVocab;
88 $controlledVocab->setId($row[
'controlled_vocab_id']);
89 $controlledVocab->setAssocType($row[
'assoc_type']);
90 $controlledVocab->setAssocId($row[
'assoc_id']);
91 $controlledVocab->setSymbolic($row[
'symbolic']);
93 return $controlledVocab;
103 sprintf(
'INSERT INTO controlled_vocabs
104 (symbolic, assoc_type, assoc_id)
108 $controlledVocab->getSymbolic(),
109 (
int) $controlledVocab->getAssocType(),
110 (
int) $controlledVocab->getAssocId()
117 return $controlledVocab->getId();
128 $returner = $this->
update(
129 sprintf(
'UPDATE controlled_vocabs
133 WHERE controlled_vocab_id = ?'),
135 $controlledVocab->getSymbolic(),
136 (
int) $controlledVocab->getAssocType(),
137 (
int) $controlledVocab->getAssocId(),
138 (
int) $controlledVocab->getId()
159 $params = array((
int) $controlledVocabId);
161 $controlledVocabEntries = $this->
enumerate($controlledVocabId);
162 foreach ($controlledVocabEntries as $controlledVocabEntryId => $controlledVocabEntryName) {
163 $controlledVocabEntryDao->deleteObjectById($controlledVocabEntryId);
165 return $this->
update(
'DELETE FROM controlled_vocabs WHERE controlled_vocab_id = ?', $params);
177 'SELECT * FROM controlled_vocabs WHERE symbolic = ? AND assoc_type = ? AND assoc_id = ?',
178 array($symbolic, (
int) $assocType, (
int) $assocId)
182 if ($result->RecordCount() != 0) {
183 $returner = $this->
_fromRow($result->GetRowAssoc(
false));
198 $controlledVocab = $this->
getBySymbolic($symbolic, $assocType, $assocId);
199 if (!$controlledVocab) {
203 return $controlledVocab->enumerate($settingName);
212 function enumerate($controlledVocabId, $settingName =
'name') {
214 'SELECT e.controlled_vocab_entry_id,
215 COALESCE(l.setting_value, p.setting_value, n.setting_value) AS setting_value,
216 COALESCE(l.setting_type, p.setting_type, n.setting_type) AS setting_type
217 FROM controlled_vocab_entries e
218 LEFT JOIN controlled_vocab_entry_settings l ON (l.controlled_vocab_entry_id = e.controlled_vocab_entry_id AND l.setting_name = ? AND l.locale = ?)
219 LEFT JOIN controlled_vocab_entry_settings p ON (p.controlled_vocab_entry_id = e.controlled_vocab_entry_id AND p.setting_name = ? AND p.locale = ?)
220 LEFT JOIN controlled_vocab_entry_settings n ON (n.controlled_vocab_entry_id = e.controlled_vocab_entry_id AND n.setting_name = ? AND n.locale = ?)
221 WHERE e.controlled_vocab_id = ?
227 (
int) $controlledVocabId
232 while (!$result->EOF) {
233 $row = $result->GetRowAssoc(
false);
234 $returner[$row[
'controlled_vocab_entry_id']] = $this->
convertFromDB(
235 $row[
'setting_value'],
249 return parent::_getInsertId(
'controlled_vocabs',
'controlled_vocab_id');
258 $controlledVocabs = array();
260 $controlledVocabEntrySettingsDao = $controlledVocabEntryDao->getSettingsDAO();
262 $tree = $parser->parse($filename);
263 foreach ($tree->getChildren() as $controlledVocabNode) {
264 assert($controlledVocabNode->getName() ==
'controlled_vocab');
268 $symbolic = $controlledVocabNode->getAttribute(
'symbolic'),
269 $assocType = (
int) $controlledVocabNode->getAttribute(
'assoc-type'),
270 $assocId = (
int) $controlledVocabNode->getAttribute(
'assoc-id')
272 if ($controlledVocab) {
273 $controlledVocabs[] = $controlledVocab;
278 $controlledVocabs[] = $controlledVocab = $this->
_build($symbolic, $assocType, $assocId);
279 foreach ($controlledVocabNode->getChildren() as $entryNode) {
280 $seq = $entryNode->getAttribute(
'seq');
281 if ($seq !==
null) $seq = (float) $seq;
283 $controlledVocabEntry = $controlledVocabEntryDao->newDataObject();
284 $controlledVocabEntry->setControlledVocabId($controlledVocab->getId());
285 $controlledVocabEntry->setSequence($seq);
286 $controlledVocabEntryDao->insertObject($controlledVocabEntry);
288 foreach ($entryNode->getChildren() as $settingNode) {
289 $controlledVocabEntrySettingsDao->updateSetting(
290 $controlledVocabEntry->getId(),
291 $settingNode->getAttribute(
'name'),
292 $settingNode->getValue(),
293 $settingNode->getAttribute(
'type'),
299 return $controlledVocabs;