Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
ControlledVocabEntryDAO.inc.php
1 <?php
2 
17 import('lib.pkp.classes.controlledVocab.ControlledVocabEntry');
18 
24  parent::DAO();
25  }
26 
33  function getById($controlledVocabEntryId, $controlledVocabId = null) {
34  $params = array((int) $controlledVocabEntryId);
35  if (!empty($controlledVocabId)) $params[] = (int) $controlledVocabId;
36 
37  $result = $this->retrieve(
38  'SELECT * FROM controlled_vocab_entries WHERE controlled_vocab_entry_id = ?' .
39  (!empty($controlledVocabId)?' AND controlled_vocab_id = ?':''),
40  $params
41  );
42 
43  $returner = null;
44  if ($result->RecordCount() != 0) {
45  $returner = $this->_fromRow($result->GetRowAssoc(false));
46  }
47  $result->Close();
48  return $returner;
49  }
50 
62  function getBySetting($settingValue, $symbolic, $assocType = 0, $assocId = 0, $settingName = 'name', $locale = '') {
63  $result = $this->retrieve(
64  'SELECT cve.*
65  FROM controlled_vocabs cv
66  INNER JOIN controlled_vocab_entries cve ON cv.controlled_vocab_id = cve.controlled_vocab_id
67  INNER JOIN controlled_vocab_entry_settings cves ON cve.controlled_vocab_entry_id = cves.controlled_vocab_entry_id
68  WHERE cves.setting_name = ? AND
69  cves.locale = ? AND
70  cves.setting_value = ? AND
71  cv.symbolic = ? AND
72  cv.assoc_type = ? AND
73  cv.assoc_id = ?',
74  array($settingName, $locale, $settingValue, $symbolic, $assocType, $assocId)
75  );
76 
77  $returner = null;
78  if ($result->RecordCount() != 0) {
79  $returner = $this->_fromRow($result->GetRowAssoc(false));
80  }
81  $result->Close();
82  return $returner;
83  }
84 
89  function newDataObject() {
90  return new ControlledVocabEntry();
91  }
92 
99  function _fromRow($row) {
100  $controlledVocabEntry = $this->newDataObject();
101  $controlledVocabEntry->setControlledVocabId($row['controlled_vocab_id']);
102  $controlledVocabEntry->setId($row['controlled_vocab_entry_id']);
103  $controlledVocabEntry->setSequence($row['seq']);
104 
105  $this->getDataObjectSettings('controlled_vocab_entry_settings', 'controlled_vocab_entry_id', $row['controlled_vocab_entry_id'], $controlledVocabEntry);
106 
107  return $controlledVocabEntry;
108  }
109 
114  function getLocaleFieldNames() {
115  return array('name');
116  }
117 
122  function updateLocaleFields(&$controlledVocabEntry) {
123  $this->updateDataObjectSettings('controlled_vocab_entry_settings', $controlledVocabEntry, array(
124  'controlled_vocab_entry_id' => $controlledVocabEntry->getId()
125  ));
126  }
127 
133  function insertObject(&$controlledVocabEntry) {
134  $this->update(
135  sprintf('INSERT INTO controlled_vocab_entries
136  (controlled_vocab_id, seq)
137  VALUES
138  (?, ?)'),
139  array(
140  (int) $controlledVocabEntry->getControlledVocabId(),
141  (float) $controlledVocabEntry->getSequence()
142  )
143  );
144  $controlledVocabEntry->setId($this->getInsertId());
145  $this->updateLocaleFields($controlledVocabEntry);
146  return (int)$controlledVocabEntry->getId();
147  }
148 
154  function deleteObject($controlledVocabEntry) {
155  return $this->deleteObjectById($controlledVocabEntry->getId());
156  }
157 
163  function deleteObjectById($controlledVocabEntryId) {
164  $params = array((int) $controlledVocabEntryId);
165  $this->update('DELETE FROM controlled_vocab_entry_settings WHERE controlled_vocab_entry_id = ?', $params);
166  return $this->update('DELETE FROM controlled_vocab_entries WHERE controlled_vocab_entry_id = ?', $params);
167  }
168 
175  function getByControlledVocabId($controlledVocabId, $rangeInfo = null, $filter = null) {
176  $params = array((int) $controlledVocabId);
177  if (!empty($filter)) $params[] = "%$filter%";
178 
179  $result = $this->retrieveRange(
180  'SELECT *
181  FROM controlled_vocab_entries cve '.
182  (!empty($filter) ? 'INNER JOIN controlled_vocab_entry_settings cves ON cve.controlled_vocab_entry_id = cves.controlled_vocab_entry_id ' : '') .
183  'WHERE controlled_vocab_id = ? ' .
184  (!empty($filter) ? 'AND cves.setting_value LIKE ? ' : '') .
185  'ORDER BY seq',
186  $params,
187  $rangeInfo
188  );
189 
190  $returner = new DAOResultFactory($result, $this, '_fromRow');
191  return $returner;
192  }
193 
198  function updateObject(&$controlledVocabEntry) {
199  $this->update(
200  'UPDATE controlled_vocab_entries
201  SET controlled_vocab_id = ?,
202  seq = ?
203  WHERE controlled_vocab_entry_id = ?',
204  array(
205  (int) $controlledVocabEntry->getControlledVocabId(),
206  (float) $controlledVocabEntry->getSequence(),
207  (int) $controlledVocabEntry->getId()
208  )
209  );
210  $this->updateLocaleFields($controlledVocabEntry);
211  }
212 
216  function resequence($controlledVocabId) {
217  $result = $this->retrieve(
218  'SELECT controlled_vocab_entry_id FROM controlled_vocab_entries WHERE controlled_vocab_id = ? ORDER BY seq',
219  array((int) $controlledVocabId)
220  );
221 
222  for ($i=1; !$result->EOF; $i++) {
223  list($controlledVocabEntryId) = $result->fields;
224  $this->update(
225  'UPDATE controlled_vocab_entries SET seq = ? WHERE controlled_vocab_entry_id = ?',
226  array(
227  (int) $i,
228  (int) $controlledVocabEntryId
229  )
230  );
231 
232  $result->MoveNext();
233  }
234 
235  $result->Close();
236  }
237 
242  function getInsertId() {
243  return parent::_getInsertId('controlled_vocab_entries', 'controlled_vocab_entry_id');
244  }
245 }
246 
247 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
updateObject(&$controlledVocabEntry)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
insertObject(&$controlledVocabEntry)
deleteObjectById($controlledVocabEntryId)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:474
updateLocaleFields(&$controlledVocabEntry)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
Operations for retrieving and modifying ControlledVocabEntry objects.
getByControlledVocabId($controlledVocabId, $rangeInfo=null, $filter=null)
getDataObjectSettings($tableName, $idFieldName, $idFieldValue, &$dataObject)
Definition: DAO.inc.php:567
getById($controlledVocabEntryId, $controlledVocabId=null)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
getBySetting($settingValue, $symbolic, $assocType=0, $assocId=0, $settingName= 'name', $locale= '')
Basic class describing a controlled vocab.