Open Journal Systems  3.0.0
 All Data Structures Namespaces Functions Variables Groups Pages
ControlledVocabEntryDAO.inc.php
1 <?php
2 
17 import('lib.pkp.classes.controlledVocab.ControlledVocabEntry');
18 
24  parent::DAO();
25  }
26 
31  function getSettingsDAO() {
32  return DAORegistry::getDAO('ControlledVocabEntrySettingsDAO');
33  }
34 
41  function getById($controlledVocabEntryId, $controlledVocabId = null) {
42  $params = array((int) $controlledVocabEntryId);
43  if (!empty($controlledVocabId)) $params[] = (int) $controlledVocabId;
44 
45  $result = $this->retrieve(
46  'SELECT * FROM controlled_vocab_entries WHERE controlled_vocab_entry_id = ?' .
47  (!empty($controlledVocabId)?' AND controlled_vocab_id = ?':''),
48  $params
49  );
50 
51  $returner = null;
52  if ($result->RecordCount() != 0) {
53  $returner = $this->_fromRow($result->GetRowAssoc(false));
54  }
55  $result->Close();
56  return $returner;
57  }
58 
70  function getBySetting($settingValue, $symbolic, $assocType = 0, $assocId = 0, $settingName = 'name', $locale = '') {
71  $result = $this->retrieve(
72  'SELECT cve.*
73  FROM controlled_vocabs cv
74  INNER JOIN controlled_vocab_entries cve ON cv.controlled_vocab_id = cve.controlled_vocab_id
75  INNER JOIN controlled_vocab_entry_settings cves ON cve.controlled_vocab_entry_id = cves.controlled_vocab_entry_id
76  WHERE cves.setting_name = ? AND
77  cves.locale = ? AND
78  cves.setting_value = ? AND
79  cv.symbolic = ? AND
80  cv.assoc_type = ? AND
81  cv.assoc_id = ?',
82  array($settingName, $locale, $settingValue, $symbolic, $assocType, $assocId)
83  );
84 
85  $returner = null;
86  if ($result->RecordCount() != 0) {
87  $returner = $this->_fromRow($result->GetRowAssoc(false));
88  }
89  $result->Close();
90  return $returner;
91  }
92 
97  function newDataObject() {
98  return new ControlledVocabEntry();
99  }
100 
107  function _fromRow($row) {
108  $controlledVocabEntry = $this->newDataObject();
109  $controlledVocabEntry->setControlledVocabId($row['controlled_vocab_id']);
110  $controlledVocabEntry->setId($row['controlled_vocab_entry_id']);
111  $controlledVocabEntry->setSequence($row['seq']);
112 
113  $this->getDataObjectSettings('controlled_vocab_entry_settings', 'controlled_vocab_entry_id', $row['controlled_vocab_entry_id'], $controlledVocabEntry);
114 
115  return $controlledVocabEntry;
116  }
117 
122  function getLocaleFieldNames() {
123  return array('name');
124  }
125 
130  function updateLocaleFields($controlledVocabEntry) {
131  $this->updateDataObjectSettings('controlled_vocab_entry_settings', $controlledVocabEntry, array(
132  'controlled_vocab_entry_id' => $controlledVocabEntry->getId()
133  ));
134  }
135 
141  function insertObject($controlledVocabEntry) {
142  $this->update(
143  'INSERT INTO controlled_vocab_entries (controlled_vocab_id, seq)
144  VALUES (?, ?)',
145  array(
146  (int) $controlledVocabEntry->getControlledVocabId(),
147  (float) $controlledVocabEntry->getSequence()
148  )
149  );
150  $controlledVocabEntry->setId($this->getInsertId());
151  $this->updateLocaleFields($controlledVocabEntry);
152  return (int)$controlledVocabEntry->getId();
153  }
154 
159  function deleteObject($controlledVocabEntry) {
160  $this->deleteObjectById($controlledVocabEntry->getId());
161  }
162 
167  function deleteObjectById($controlledVocabEntryId) {
168  $params = array((int) $controlledVocabEntryId);
169  $this->update('DELETE FROM controlled_vocab_entry_settings WHERE controlled_vocab_entry_id = ?', $params);
170  $this->update('DELETE FROM controlled_vocab_entries WHERE controlled_vocab_entry_id = ?', $params);
171  }
172 
179  function getByControlledVocabId($controlledVocabId, $rangeInfo = null, $filter = null) {
180  $params = array((int) $controlledVocabId);
181  if (!empty($filter)) $params[] = "%$filter%";
182 
183  $result = $this->retrieveRange(
184  'SELECT *
185  FROM controlled_vocab_entries cve '.
186  (!empty($filter) ? 'INNER JOIN controlled_vocab_entry_settings cves ON cve.controlled_vocab_entry_id = cves.controlled_vocab_entry_id ' : '') .
187  'WHERE controlled_vocab_id = ? ' .
188  (!empty($filter) ? 'AND cves.setting_value LIKE ? ' : '') .
189  'ORDER BY seq',
190  $params,
191  $rangeInfo
192  );
193 
194  return new DAOResultFactory($result, $this, '_fromRow');
195  }
196 
201  function updateObject($controlledVocabEntry) {
202  $this->update(
203  'UPDATE controlled_vocab_entries
204  SET controlled_vocab_id = ?,
205  seq = ?
206  WHERE controlled_vocab_entry_id = ?',
207  array(
208  (int) $controlledVocabEntry->getControlledVocabId(),
209  (float) $controlledVocabEntry->getSequence(),
210  (int) $controlledVocabEntry->getId()
211  )
212  );
213  $this->updateLocaleFields($controlledVocabEntry);
214  }
215 
220  function resequence($controlledVocabId) {
221  $result = $this->retrieve(
222  'SELECT controlled_vocab_entry_id FROM controlled_vocab_entries WHERE controlled_vocab_id = ? ORDER BY seq',
223  array((int) $controlledVocabId)
224  );
225 
226  for ($i=1; !$result->EOF; $i++) {
227  list($controlledVocabEntryId) = $result->fields;
228  $this->update(
229  'UPDATE controlled_vocab_entries SET seq = ? WHERE controlled_vocab_entry_id = ?',
230  array(
231  (int) $i,
232  (int) $controlledVocabEntryId
233  )
234  );
235 
236  $result->MoveNext();
237  }
238 
239  $result->Close();
240  }
241 
246  function getInsertId() {
247  return parent::_getInsertId('controlled_vocab_entries', 'controlled_vocab_entry_id');
248  }
249 }
250 
251 ?>
static & getDAO($name, $dbconn=null)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
deleteObjectById($controlledVocabEntryId)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
updateDataObjectSettings($tableName, $dataObject, $idArray)
Definition: DAO.inc.php:474
updateLocaleFields($controlledVocabEntry)
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)
getById($controlledVocabEntryId, $controlledVocabId=null)
getDataObjectSettings($tableName, $idFieldName, $idFieldValue, $dataObject)
Definition: DAO.inc.php:568
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.