Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
ContextDAO.inc.php
1 <?php
2 
17 class ContextDAO extends DAO {
21  function ContextDAO() {
22  parent::DAO();
23  }
24 
30  function getById($contextId) {
31  $result = $this->retrieve(
32  'SELECT * FROM ' . $this->_getTableName() . ' WHERE ' . $this->_getPrimaryKeyColumn() . ' = ?',
33  (int) $contextId
34  );
35 
36  $returner = null;
37  if ($result->RecordCount() != 0) {
38  $returner = $this->_fromRow($result->GetRowAssoc(false));
39  }
40  $result->Close();
41  return $returner;
42  }
43 
49  function getNames($enabledOnly = false) {
50  $contexts = array();
51  $iterator = $this->getAll($enabledOnly);
52  while ($context = $iterator->next()) {
53  $contexts[$context->getId()] = $context->getLocalizedName();
54  }
55  return $contexts;
56  }
57 
62  function getLocaleFieldNames() {
63  return array('name', 'description');
64  }
65 
71  function _fromRow($row) {
72  $context = $this->newDataObject();
73  $context->setId($row[$this->_getPrimaryKeyColumn()]);
74  $context->setPath($row['path']);
75  $context->setSequence($row['seq']);
76  $this->getDataObjectSettings($this->_getSettingsTableName(), $this->_getPrimaryKeyColumn(), $row[$this->_getPrimaryKeyColumn()], $context);
77  return $context;
78  }
79 
85  function existsByPath($path) {
86  $result = $this->retrieve(
87  'SELECT COUNT(*) FROM ' . $this->_getTableName() . ' WHERE path = ?',
88  (string) $path
89  );
90  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
91  $result->Close();
92  return $returner;
93  }
94 
100  function getByPath($path) {
101  $result = $this->retrieve(
102  'SELECT * FROM ' . $this->_getTableName() . ' WHERE path = ?',
103  (string) $path
104  );
105  if ($result->RecordCount() == 0) return null;
106 
107  $returner = $this->_fromRow($result->GetRowAssoc(false));
108  $result->Close();
109  return $returner;
110  }
111 
118  function getAll($enabledOnly = false, $rangeInfo = null) {
119  $result = $this->retrieveRange(
120  'SELECT * FROM ' . $this->_getTableName() .
121  ($enabledOnly?' WHERE enabled = 1':'') .
122  ' ORDER BY seq',
123  false,
124  $rangeInfo
125  );
126 
127  return new DAOResultFactory($result, $this, '_fromRow');
128  }
129 
137  function getBySetting($settingName, $settingValue, $contextId = null) {
138  $params = array($settingName, $settingValue);
139  if ($contextId) $params[] = $contextId;
140 
141  $result = $this->retrieve(
142  'SELECT * FROM ' . $this->_getTableName() . 'AS c
143  LEFT JOIN ' . $this->_getSettingsTableName() . 'AS cs
144  ON c.' . $this->_getPrimaryKeyColumn() . ' = cs.' . $this->_getPrimaryKeyColumn() .
145  'WHERE cs.setting_name = ? AND cs.setting_value = ?' .
146  ($contextId?' AND c.' . $this->_getPrimaryKeyColumn() . ' = ?':''),
147  $params
148  );
149 
150  return new DAOResultFactory($result, $this, '_fromRow');
151  }
152 
153 
158  function getInsertId() {
159  return $this->_getInsertId($this->_getTableName(), $this->_getPrimaryKeyColumn());
160  }
161 
166  function deleteObject($context) {
167  $this->deleteById($context->getId());
168  }
169 
174  function deleteById($contextId) {
175  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
176  $userGroupDao->deleteAssignmentsByContextId($contextId);
177  $userGroupDao->deleteByContextId($contextId);
178 
179  $genreDao = DAORegistry::getDAO('GenreDAO');
180  $genreDao->deleteByContextId($contextId);
181 
182  $this->update(
183  'DELETE FROM ' . $this->_getTableName() . ' WHERE ' . $this->_getPrimaryKeyColumn() . ' = ?',
184  (int) $contextId
185  );
186  }
187 
191  function resequence() {
192  $result = $this->retrieve(
193  'SELECT ' . $this->_getPrimaryKeyColumn() . ' FROM ' . $this->_getTableName() . ' ORDER BY seq'
194  );
195 
196  for ($i=1; !$result->EOF; $i+=2) {
197  list($contextId) = $result->fields;
198  $this->update(
199  'UPDATE ' . $this->_getTableName() . ' SET seq = ? WHERE ' . $this->_getPrimaryKeyColumn() . ' = ?',
200  array(
201  $i,
202  $contextId
203  )
204  );
205 
206  $result->MoveNext();
207  }
208  $result->Close();
209  }
210 
211  //
212  // Protected methods
213  //
218  protected function _getTableName() {
219  assert(false); // Must be overridden by subclasses.
220  }
221 
226  protected function _getSettingsTableName() {
227  assert(false); // Must be overridden by subclasses.
228  }
229 
234  protected function _getPrimaryKeyColumn() {
235  assert(false); // Must be overridden by subclasses
236  }
237 }
238 
239 ?>
static & getDAO($name, $dbconn=null)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
deleteObject($context)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
getById($contextId)
Operations for retrieving and modifying context objects.
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
getBySetting($settingName, $settingValue, $contextId=null)
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
getNames($enabledOnly=false)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
getAll($enabledOnly=false, $rangeInfo=null)
existsByPath($path)
deleteById($contextId)
getDataObjectSettings($tableName, $idFieldName, $idFieldValue, &$dataObject)
Definition: DAO.inc.php:567
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
getByPath($path)