ocs  2.3.6
About: OCS (Open Conference System) is a Web publishing tool that will create a complete Web presence for your scholarly conference.
  Fossies Dox: ocs-2.3.6.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

ControlledVocabDAO.inc.php
Go to the documentation of this file.
1 <?php
2 
16 //$Id$
17 
18 
19 import('controlledVocab.ControlledVocab');
20 
21 class ControlledVocabDAO extends DAO {
27  function getById($controlledVocabId) {
28  $result =& $this->retrieve(
29  'SELECT * FROM controlled_vocabs WHERE controlled_vocab_id = ?', array((int) $controlledVocabId)
30  );
31 
32  $returner = null;
33  if ($result->RecordCount() != 0) {
34  $returner =& $this->_fromRow($result->GetRowAssoc(false));
35  }
36  $result->Close();
37  return $returner;
38  }
39 
47  function build($symbolic, $assocType, $assocId) {
48  // If one exists, fetch and return.
49  $controlledVocab = $this->getBySymbolic($symbolic, $assocType, $assocId);
50  if ($controlledVocab) return $controlledVocab;
51 
52  // Otherwise, build one.
53  unset($controlledVocab);
54  $controlledVocab = $this->newDataObject();
55  $controlledVocab->setSymbolic($symbolic);
56  $controlledVocab->setAssocType($assocType);
57  $controlledVocab->setAssocId($assocId);
58  $this->insertObject($controlledVocab);
59  return $controlledVocab;
60  }
61 
66  function newDataObject() {
67  return new ControlledVocab();
68  }
69 
75  function _fromRow(&$row) {
76  $controlledVocab = $this->newDataObject();
77  $controlledVocab->setId($row['controlled_vocab_id']);
78  $controlledVocab->setAssocType($row['assoc_type']);
79  $controlledVocab->setAssocId($row['assoc_id']);
80  $controlledVocab->setSymbolic($row['symbolic']);
81 
82  return $controlledVocab;
83  }
84 
90  function insertObject(&$controlledVocab) {
91  $this->update(
92  sprintf('INSERT INTO controlled_vocabs
93  (symbolic, assoc_type, assoc_id)
94  VALUES
95  (?, ?, ?)'),
96  array(
97  $controlledVocab->getSymbolic(),
98  (int) $controlledVocab->getAssocType(),
99  (int) $controlledVocab->getAssocId()
100  )
101  );
102  $controlledVocab->setId($this->getInsertId());
103  return $controlledVocab->getId();
104  }
105 
111  function updateObject(&$controlledVocab) {
112  $returner = $this->update(
113  sprintf('UPDATE controlled_vocabs
114  SET symbolic = ?,
115  assoc_type = ?,
116  assoc_id = ?
117  WHERE controlled_vocab_id = ?'),
118  array(
119  $controlledVocab->getSymbolic(),
120  (int) $controlledVocab->getAssocType(),
121  (int) $controlledVocab->getAssocId(),
122  (int) $controlledVocab->getId()
123  )
124  );
125  return $returner;
126  }
127 
133  function deleteObject($controlledVocab) {
134  return $this->deleteObjectById($controlledVocab->getId());
135  }
136 
142  function deleteObjectById($controlledVocabId) {
143  $params = array((int) $controlledVocabId);
144  $controlledVocabEntryDao =& DAORegistry::getDAO('ControlledVocabEntryDAO');
145  $controlledVocabEntries =& $controlledVocabEntryDao->getControlledVocabEntries($controlledVocabId);
146  while ($controlledVocabEntry =& $controlledVocabEntries->next()) {
147  $controlledVocabEntryDao->deleteObject($controlledVocabEntry);
148  unset($controlledVocabEntry);
149  }
150  return $this->update('DELETE FROM controlled_vocabs WHERE controlled_vocab_id = ?', $params);
151  }
152 
160  function getBySymbolic($symbolic, $assocType, $assocId) {
161  $result =& $this->retrieve(
162  'SELECT * FROM controlled_vocabs WHERE symbolic = ? AND assoc_type = ? AND assoc_id = ?',
163  array($symbolic, (int) $assocType, (int) $assocId)
164  );
165 
166  $returner = null;
167  if ($result->RecordCount() != 0) {
168  $returner = $this->_fromRow($result->GetRowAssoc(false));
169  }
170  $result->Close();
171  return $returner;
172  }
173 
182  function enumerateBySymbolic($symbolic, $assocType, $assocId, $settingName = 'name') {
183  $controlledVocab = $this->getBySymbolic($symbolic, $assocType, $assocId);
184  if (!$controlledVocab) {
185  $returner = array();
186  return $returner;
187  }
188  return $controlledVocab->enumerate($settingName);
189  }
190 
197  function enumerate($controlledVocabId, $settingName = 'name') {
198  $result =& $this->retrieve(
199  'SELECT e.controlled_vocab_entry_id,
200  COALESCE(l.setting_value, p.setting_value, n.setting_value) AS setting_value,
201  COALESCE(l.setting_type, p.setting_type, n.setting_type) AS setting_type
202  FROM controlled_vocab_entries e
203  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 = ?)
204  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 = ?)
205  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 = ?)
206  WHERE e.controlled_vocab_id = ?
207  ORDER BY e.seq',
208  array(
209  $settingName, AppLocale::getLocale(), // Current locale
210  $settingName, AppLocale::getPrimaryLocale(), // Primary locale
211  $settingName, '', // No locale
212  (int) $controlledVocabId
213  )
214  );
215 
216  $returner = array();
217  while (!$result->EOF) {
218  $row = $result->GetRowAssoc(false);
219  $returner[$row['controlled_vocab_entry_id']] = $this->convertFromDB(
220  $row['setting_value'],
221  $row['setting_type']
222  );
223  $result->MoveNext();
224  }
225  $result->Close();
226 
227  return $returner;
228  }
229 
234  function getInsertId() {
235  return parent::getInsertId('controlled_vocabs', 'controlled_vocab_id');
236  }
237 }
238 
239 ?>
config TEMPLATE inc php
Definition: config.inc.php:4
getById($controlledVocabId)
Basic class describing an controlled vocab.
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:62
enumerate($controlledVocabId, $settingName='name')
enumerateBySymbolic($symbolic, $assocType, $assocId, $settingName='name')
updateObject(&$controlledVocab)
insertObject(&$controlledVocab)
Operations for retrieving and modifying ControlledVocab objects.
convertFromDB($value, $type)
Definition: DAO.inc.php:296
& getDAO($name, $dbconn=null)
deleteObject($controlledVocab)
deleteObjectById($controlledVocabId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:186
build($symbolic, $assocType, $assocId)
getBySymbolic($symbolic, $assocType, $assocId)