Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
FooterLinkDAO.inc.php
1 <?php
2 
17 import ('lib.pkp.classes.context.FooterLink');
18 
19 class FooterLinkDAO extends DAO {
23  function FooterLinkDAO() {
24  parent::DAO();
25  }
26 
33  function getById($footerLinkId, $contextId = null) {
34  $params = array((int) $footerLinkId);
35  if ($contextId) $params[] = (int) $contextId;
36 
37  $result = $this->retrieve(
38  'SELECT *
39  FROM footerlinks
40  WHERE footerlink_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 
58  function newDataObject() {
59  return new FooterLink();
60  }
61 
67  function _fromRow($row) {
68  $footerLink = $this->newDataObject();
69 
70  $footerLink->setId($row['footerlink_id']);
71  $footerLink->setContextId($row['context_id']);
72  $footerLink->setCategoryId($row['footer_category_id']);
73 
74  $this->getDataObjectSettings('footerlink_settings', 'footerlink_id', $row['footerlink_id'], $footerLink);
75 
76  HookRegistry::call('FooterLinkDAO::_fromRow', array(&$footerLink, &$row));
77 
78  return $footerLink;
79  }
80 
85  function getLocaleFieldNames() {
86  return array('title', 'url');
87  }
88 
93  function updateLocaleFields($footerLink) {
95  'footerlink_settings', $footerLink,
96  array(
97  'footerlink_id' => $footerLink->getId()
98  )
99  );
100  }
101 
107  function insertObject($footerLink) {
108  $this->update(
109  'INSERT INTO footerlinks
110  (context_id, footer_category_id)
111  VALUES
112  (?, ?)',
113  array(
114  (int) $footerLink->getContextId(),
115  (int) $footerLink->getCategoryId(),
116  )
117  );
118 
119  $footerLink->setId($this->getInsertId());
120  $this->updateLocaleFields($footerLink);
121  return $footerLink->getId();
122  }
123 
128  function updateObject($footerLink) {
129  $returner = $this->update(
130  'UPDATE footerlinks
131  SET context_id = ?,
132  footer_category_id = ?
133  WHERE footerlink_id = ?',
134  array(
135  (int) $footerLink->getContextId(),
136  (int) $footerLink->getCategoryId(),
137  (int) $footerLink->getId()
138  )
139  );
140  $this->updateLocaleFields($footerLink);
141  return $returner;
142  }
143 
148  function deleteObject($footerLink) {
149  return $this->deleteById(
150  $footerLink->getId(),
151  $footerLink->getContextId()
152  );
153  }
154 
160  function deleteById($footerLinkId, $contextId = null) {
161  $params = array((int) $footerLinkId);
162  if ($contextId) $params[] = (int) $contextId;
163 
164  $this->update(
165  'DELETE FROM footerlinks
166  WHERE footerlink_id = ?
167  ' . ($contextId?' AND context_id = ?':''),
168  $params
169  );
170 
171  // If the link was deleted (this validates context_id,
172  // if specified), delete any associated settings as well.
173  if ($this->getAffectedRows()) {
174  return $this->update(
175  'DELETE FROM footerlink_settings WHERE footerlink_id = ?',
176  array((int) $footerLinkId)
177  );
178  }
179  }
180 
187  function deleteByContextId($contextId) {
188  $footerlinks = $this->getByContextId($contextId);
189  while ($footerLink = $footerlinks->next()) {
190  $this->deleteObject($footerLink, $contextId);
191  }
192  }
193 
198  function getByCategoryId($categoryId, $contextId = null, $rangeInfo = null) {
199  $params = array((int) $categoryId);
200  if ($contextId) $params[] = (int) $contextId;
201 
202  $result = $this->retrieveRange(
203  'SELECT *
204  FROM footerlinks
205  WHERE footer_category_id = ?
206  ' . ($contextId?' AND context_id = ?':''),
207  $params
208  );
209 
210  $returner = new DAOResultFactory($result, $this, '_fromRow');
211  return $returner;
212  }
213 
218  function getInsertId() {
219  return $this->_getInsertId('footerlinks', 'footerlink_id');
220  }
221 
227  function getLargestCategoryTotalByContextId($contextId) {
228  $result = $this->retrieve(
229  'SELECT count(*) AS total
230  FROM footerlinks
231  WHERE context_id = ? GROUP BY footer_category_id
232  ORDER BY total DESC LIMIT 1', array((int)$contextId));
233 
234  $returner = null;
235  if ($result->RecordCount() != 0) {
236  $row = $result->GetRowAssoc(false);
237  $returner = $row['total'];
238  }
239 
240  $result->Close();
241  return $returner;
242 
243  }
244 }
245 
246 ?>
getByCategoryId($categoryId, $contextId=null, $rangeInfo=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
deleteByContextId($contextId)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:474
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
getAffectedRows()
Definition: DAO.inc.php:258
static call($hookName, $args=null)
updateObject($footerLink)
insertObject($footerLink)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
getById($footerLinkId, $contextId=null)
getDataObjectSettings($tableName, $idFieldName, $idFieldValue, &$dataObject)
Definition: DAO.inc.php:567
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
deleteById($footerLinkId, $contextId=null)
getLargestCategoryTotalByContextId($contextId)
Operations for retrieving and modifying FooterLink objects.
updateLocaleFields($footerLink)
deleteObject($footerLink)