Open Monograph Press  3.3.0
ControlledVocabEntryDAO.inc.php
1 <?php
2 
17 import('lib.pkp.classes.controlledVocab.ControlledVocabEntry');
18 
20 
25  function getSettingsDAO() {
26  return DAORegistry::getDAO('ControlledVocabEntrySettingsDAO');
27  }
28 
35  function getById($controlledVocabEntryId, $controlledVocabId = null) {
36  $params = array((int) $controlledVocabEntryId);
37  if (!empty($controlledVocabId)) $params[] = (int) $controlledVocabId;
38 
39  $result = $this->retrieve(
40  'SELECT * FROM controlled_vocab_entries WHERE controlled_vocab_entry_id = ?' .
41  (!empty($controlledVocabId)?' AND controlled_vocab_id = ?':''),
42  $params
43  );
44 
45  $returner = null;
46  if ($result->RecordCount() != 0) {
47  $returner = $this->_fromRow($result->GetRowAssoc(false));
48  }
49  $result->Close();
50  return $returner;
51  }
52 
64  function getBySetting($settingValue, $symbolic, $assocType = 0, $assocId = 0, $settingName = 'name', $locale = '') {
65  $result = $this->retrieve(
66  'SELECT cve.*
67  FROM controlled_vocabs cv
68  INNER JOIN controlled_vocab_entries cve ON cv.controlled_vocab_id = cve.controlled_vocab_id
69  INNER JOIN controlled_vocab_entry_settings cves ON cve.controlled_vocab_entry_id = cves.controlled_vocab_entry_id
70  WHERE cves.setting_name = ? AND
71  cves.locale = ? AND
72  cves.setting_value = ? AND
73  cv.symbolic = ? AND
74  cv.assoc_type = ? AND
75  cv.assoc_id = ?',
76  array($settingName, $locale, $settingValue, $symbolic, $assocType, $assocId)
77  );
78 
79  $returner = null;
80  if ($result->RecordCount() != 0) {
81  $returner = $this->_fromRow($result->GetRowAssoc(false));
82  }
83  $result->Close();
84  return $returner;
85  }
86 
91  function newDataObject() {
92  return new ControlledVocabEntry();
93  }
94 
101  function _fromRow($row) {
102  $controlledVocabEntry = $this->newDataObject();
103  $controlledVocabEntry->setControlledVocabId($row['controlled_vocab_id']);
104  $controlledVocabEntry->setId($row['controlled_vocab_entry_id']);
105  $controlledVocabEntry->setSequence($row['seq']);
106 
107  $this->getDataObjectSettings('controlled_vocab_entry_settings', 'controlled_vocab_entry_id', $row['controlled_vocab_entry_id'], $controlledVocabEntry);
108 
109  return $controlledVocabEntry;
110  }
111 
116  function getLocaleFieldNames() {
117  return array('name');
118  }
119 
124  function updateLocaleFields($controlledVocabEntry) {
125  $this->updateDataObjectSettings('controlled_vocab_entry_settings', $controlledVocabEntry, array(
126  'controlled_vocab_entry_id' => $controlledVocabEntry->getId()
127  ));
128  }
129 
135  function insertObject($controlledVocabEntry) {
136  $this->update(
137  'INSERT INTO controlled_vocab_entries (controlled_vocab_id, seq)
138  VALUES (?, ?)',
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 
153  function deleteObject($controlledVocabEntry) {
154  $this->deleteObjectById($controlledVocabEntry->getId());
155  }
156 
161  function deleteObjectById($controlledVocabEntryId) {
162  $params = array((int) $controlledVocabEntryId);
163  $this->update('DELETE FROM controlled_vocab_entry_settings WHERE controlled_vocab_entry_id = ?', $params);
164  $this->update('DELETE FROM controlled_vocab_entries WHERE controlled_vocab_entry_id = ?', $params);
165  }
166 
173  function getByControlledVocabId($controlledVocabId, $rangeInfo = null, $filter = null) {
174  $params = array((int) $controlledVocabId);
175  if (!empty($filter)) $params[] = "%$filter%";
176 
177  $result = $this->retrieveRange(
178  'SELECT *
179  FROM controlled_vocab_entries cve '.
180  (!empty($filter) ? 'INNER JOIN controlled_vocab_entry_settings cves ON cve.controlled_vocab_entry_id = cves.controlled_vocab_entry_id ' : '') .
181  'WHERE controlled_vocab_id = ? ' .
182  (!empty($filter) ? 'AND cves.setting_value LIKE ? ' : '') .
183  'ORDER BY seq',
184  $params,
185  $rangeInfo
186  );
187 
188  return new DAOResultFactory($result, $this, '_fromRow');
189  }
190 
201  public function getByContextId($symbolic, $contextId, $locale) {
202  $result = $this->retrieve(
203  'SELECT cve.*
204  FROM controlled_vocab_entries AS cve
205  LEFT JOIN controlled_vocabs AS cv ON (cv.controlled_vocab_id = cve.controlled_vocab_id)
206  LEFT JOIN controlled_vocab_entry_settings AS cves ON (cves.controlled_vocab_entry_id = cve.controlled_vocab_entry_id)
207  LEFT JOIN publications as p ON (p.publication_id = cv.assoc_id)
208  LEFT JOIN submissions AS s ON (s.submission_id = p.submission_id)
209  WHERE cv.symbolic = ?
210  AND cv.assoc_type = ?
211  AND s.context_id = ?
212  AND cves.locale = ?
213  ORDER BY cve.seq DESC',
214  [
215  $symbolic,
216  ASSOC_TYPE_PUBLICATION,
217  $contextId,
218  $locale
219  ]
220  );
221 
222  return new DAOResultFactory($result, $this, '_fromRow');
223  }
224 
229  function updateObject($controlledVocabEntry) {
230  $this->update(
231  'UPDATE controlled_vocab_entries
232  SET controlled_vocab_id = ?,
233  seq = ?
234  WHERE controlled_vocab_entry_id = ?',
235  array(
236  (int) $controlledVocabEntry->getControlledVocabId(),
237  (float) $controlledVocabEntry->getSequence(),
238  (int) $controlledVocabEntry->getId()
239  )
240  );
241  $this->updateLocaleFields($controlledVocabEntry);
242  }
243 
248  function resequence($controlledVocabId) {
249  $result = $this->retrieve(
250  'SELECT controlled_vocab_entry_id FROM controlled_vocab_entries WHERE controlled_vocab_id = ? ORDER BY seq',
251  array((int) $controlledVocabId)
252  );
253 
254  for ($i=1; !$result->EOF; $i++) {
255  list($controlledVocabEntryId) = $result->fields;
256  $this->update(
257  'UPDATE controlled_vocab_entries SET seq = ? WHERE controlled_vocab_entry_id = ?',
258  array(
259  (int) $i,
260  (int) $controlledVocabEntryId
261  )
262  );
263 
264  $result->MoveNext();
265  }
266 
267  $result->Close();
268  }
269 
274  function getInsertId() {
275  return parent::_getInsertId('controlled_vocab_entries', 'controlled_vocab_entry_id');
276  }
277 }
278 
279 
ControlledVocabEntryDAO\getSettingsDAO
getSettingsDAO()
Definition: ControlledVocabEntryDAO.inc.php:25
ControlledVocabEntryDAO\newDataObject
newDataObject()
Definition: ControlledVocabEntryDAO.inc.php:91
DAOResultFactory
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
Definition: DAOResultFactory.inc.php:21
ControlledVocabEntryDAO\deleteObjectById
deleteObjectById($controlledVocabEntryId)
Definition: ControlledVocabEntryDAO.inc.php:161
DAO\retrieveRange
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
ControlledVocabEntryDAO\resequence
resequence($controlledVocabId)
Definition: ControlledVocabEntryDAO.inc.php:248
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
ControlledVocabEntryDAO\updateObject
updateObject($controlledVocabEntry)
Definition: ControlledVocabEntryDAO.inc.php:229
ControlledVocabEntryDAO\_fromRow
_fromRow($row)
Definition: ControlledVocabEntryDAO.inc.php:101
ControlledVocabEntryDAO\getLocaleFieldNames
getLocaleFieldNames()
Definition: ControlledVocabEntryDAO.inc.php:116
DAO\retrieve
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:85
ControlledVocabEntryDAO\updateLocaleFields
updateLocaleFields($controlledVocabEntry)
Definition: ControlledVocabEntryDAO.inc.php:124
ControlledVocabEntryDAO\getByContextId
getByContextId($symbolic, $contextId, $locale)
Definition: ControlledVocabEntryDAO.inc.php:201
ControlledVocabEntryDAO\deleteObject
deleteObject($controlledVocabEntry)
Definition: ControlledVocabEntryDAO.inc.php:153
ControlledVocabEntry
Basic class describing a controlled vocab.
Definition: ControlledVocabEntry.inc.php:18
ControlledVocabEntryDAO\getInsertId
getInsertId()
Definition: ControlledVocabEntryDAO.inc.php:274
ControlledVocabEntryDAO\getByControlledVocabId
getByControlledVocabId($controlledVocabId, $rangeInfo=null, $filter=null)
Definition: ControlledVocabEntryDAO.inc.php:173
DAO\update
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:214
ControlledVocabEntryDAO\getById
getById($controlledVocabEntryId, $controlledVocabId=null)
Definition: ControlledVocabEntryDAO.inc.php:35
DAO\getDataObjectSettings
getDataObjectSettings($tableName, $idFieldName, $idFieldValue, $dataObject)
Definition: DAO.inc.php:582
ControlledVocabEntryDAO\getBySetting
getBySetting($settingValue, $symbolic, $assocType=0, $assocId=0, $settingName='name', $locale='')
Definition: ControlledVocabEntryDAO.inc.php:64
ControlledVocabEntryDAO\insertObject
insertObject($controlledVocabEntry)
Definition: ControlledVocabEntryDAO.inc.php:135
DAO\updateDataObjectSettings
updateDataObjectSettings($tableName, $dataObject, $idArray)
Definition: DAO.inc.php:488
DAO
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:31
ControlledVocabEntryDAO
Operations for retrieving and modifying ControlledVocabEntry objects.
Definition: ControlledVocabEntryDAO.inc.php:19