Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
FooterCategoryDAO.inc.php
1 <?php
2 
17 import ('lib.pkp.classes.context.FooterCategory');
18 
19 class FooterCategoryDAO extends DAO {
23  function FooterCategoryDAO() {
24  parent::DAO();
25  }
26 
33  function getById($categoryId, $contextId = null) {
34  $params = array((int) $categoryId);
35  if ($contextId) $params[] = (int) $contextId;
36 
37  $result = $this->retrieve(
38  'SELECT *
39  FROM footer_categories
40  WHERE footer_category_id = ?
41  ' . ($contextId?' AND context_id = ?':''),
42  $params
43  );
44 
45  $returner = null;
46  if ($result->RecordCount() != 0) {
47  $returner = $this->_fromRow($result->GetRowAssoc(false));
48  }
49 
50  $result->Close();
51  return $returner;
52  }
53 
60  function getByPath($path, $contextId) {
61  $returner = null;
62  $result = $this->retrieve(
63  'SELECT * FROM footer_categories WHERE path = ? AND context_id = ?',
64  array((string) $path, (int) $contextId)
65  );
66 
67  if ($result->RecordCount() != 0) {
68  $returner = $this->_fromRow($result->GetRowAssoc(false));
69  }
70 
71  $result->Close();
72  return $returner;
73  }
74 
81  function categoryExistsByPath($path, $contextId = null) {
82  $params = array($path);
83  if ($contextId) $params[] = (int) $contextId;
84 
85  $result = $this->retrieve(
86  'SELECT COUNT(*) FROM footer_categories WHERE path = ?
87  ' . ($contextId?' AND context_id = ?':''),
88  $params
89  );
90  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
91 
92  $result->Close();
93  return $returner;
94  }
95 
100  function newDataObject() {
101  return new FooterCategory();
102  }
103 
109  function _fromRow($row) {
110  $category = $this->newDataObject();
111 
112  $category->setId($row['footer_category_id']);
113  $category->setContextId($row['context_id']);
114  $category->setPath($row['path']);
115 
116  $this->getDataObjectSettings('footer_category_settings', 'footer_category_id', $row['footer_category_id'], $category);
117 
118  HookRegistry::call('FooterCategoryDAO::_fromRow', array(&$category, &$row));
119 
120  return $category;
121  }
122 
127  function getLocaleFieldNames() {
128  return array('title', 'description');
129  }
130 
135  function updateLocaleFields($category) {
137  'footer_category_settings', $category,
138  array(
139  'footer_category_id' => $category->getId()
140  )
141  );
142  }
143 
149  function insertObject($category) {
150  $this->update(
151  'INSERT INTO footer_categories
152  (context_id, path)
153  VALUES
154  (?, ?)',
155  array(
156  (int) $category->getContextId(),
157  $category->getPath()
158  )
159  );
160 
161  $category->setId($this->getInsertId());
162  $this->updateLocaleFields($category);
163  return $category->getId();
164  }
165 
170  function updateObject($category) {
171  $returner = $this->update(
172  'UPDATE footer_categories
173  SET context_id = ?,
174  path = ?
175  WHERE footer_category_id = ?',
176  array(
177  (int) $category->getContextId(),
178  $category->getPath(),
179  (int) $category->getId()
180  )
181  );
182  $this->updateLocaleFields($category);
183  return $returner;
184  }
185 
190  function deleteObject($category) {
191  return $this->deleteById(
192  $category->getId(),
193  $category->getContextId()
194  );
195  }
196 
202  function deleteById($categoryId, $contextId = null) {
203  $params = array((int) $categoryId);
204  if ($contextId) $params[] = (int) $contextId;
205 
206  $this->update(
207  'DELETE FROM footer_categories
208  WHERE footer_category_id = ?
209  ' . ($contextId?' AND context_id = ?':''),
210  $params
211  );
212 
213  // If the category was deleted (this validates context_id,
214  // if specified), delete any associated settings as well.
215  if ($this->getAffectedRows()) {
216  $this->update(
217  'DELETE FROM footer_category_settings WHERE footer_category_id = ?',
218  array((int) $categoryId)
219  );
220 
221  return true;
222  }
223  }
224 
231  function deleteByContextId($contextId) {
232  $categories = $this->getByContextId($contextId);
233  while ($category = $categories->next()) {
234  $this->deleteObject($category, $contextId);
235  }
236  }
237 
244  function getByContextId($contextId, $rangeInfo = null) {
245  $result = $this->retrieveRange(
246  'SELECT *
247  FROM footer_categories
248  WHERE context_id = ?',
249  array((int) $contextId)
250  );
251 
252  return new DAOResultFactory($result, $this, '_fromRow');
253  }
254 
259  function getNotEmptyByContextId($contextId, $rangeInfo = null) {
260  $result = $this->retrieveRange(
261  'SELECT DISTINCT f.footer_category_id, f.*
262  FROM footer_categories f, footerlinks fl
263  WHERE f.footer_category_id = fl.footer_category_id AND f.context_id = ?',
264  array((int) $contextId)
265  );
266 
267  return new DAOResultFactory($result, $this, '_fromRow');
268  }
269 
274  function getCountByContextId($contextId) {
275  $result = $this->retrieve(
276  'SELECT COUNT(*)
277  FROM footer_categories
278  WHERE context_id = ?',
279  (int) $contextId
280  );
281 
282  $returner = $result->fields[0];
283 
284  $result->Close();
285  return $returner;
286  }
287 
292  function getInsertId() {
293  return $this->_getInsertId('footer_categories', 'footer_category_id');
294  }
295 }
296 
297 ?>
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
getByPath($path, $contextId)
getNotEmptyByContextId($contextId, $rangeInfo=null)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:457
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
deleteById($categoryId, $contextId=null)
categoryExistsByPath($path, $contextId=null)
getAffectedRows()
Definition: DAO.inc.php:258
static call($hookName, $args=null)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
getByContextId($contextId, $rangeInfo=null)
Describes basic FooterCategory properties.
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
getById($categoryId, $contextId=null)
Operations for retrieving and modifying FooterCategory objects.