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->setUrl($row['url']);
73  $footerLink->setCategoryId($row['footer_category_id']);
74 
75  $this->getDataObjectSettings('footerlink_settings', 'footerlink_id', $row['footerlink_id'], $footerLink);
76 
77  HookRegistry::call('FooterLinkDAO::_fromRow', array(&$footerLink, &$row));
78 
79  return $footerLink;
80  }
81 
86  function getLocaleFieldNames() {
87  return array('title');
88  }
89 
94  function updateLocaleFields($footerLink) {
96  'footerlink_settings', $footerLink,
97  array(
98  'footerlink_id' => $footerLink->getId()
99  )
100  );
101  }
102 
108  function insertObject($footerLink) {
109  $this->update(
110  'INSERT INTO footerlinks
111  (context_id, footer_category_id, url)
112  VALUES
113  (?, ?, ?)',
114  array(
115  (int) $footerLink->getContextId(),
116  (int) $footerLink->getCategoryId(),
117  $footerLink->getUrl()
118  )
119  );
120 
121  $footerLink->setId($this->getInsertId());
122  $this->updateLocaleFields($footerLink);
123  return $footerLink->getId();
124  }
125 
130  function updateObject($footerLink) {
131  $returner = $this->update(
132  'UPDATE footerlinks
133  SET context_id = ?,
134  footer_category_id = ?,
135  url = ?
136  WHERE footerlink_id = ?',
137  array(
138  (int) $footerLink->getContextId(),
139  (int) $footerLink->getCategoryId(),
140  $footerLink->getUrl(),
141  (int) $footerLink->getId()
142  )
143  );
144  $this->updateLocaleFields($footerLink);
145  return $returner;
146  }
147 
152  function deleteObject($footerLink) {
153  return $this->deleteById(
154  $footerLink->getId(),
155  $footerLink->getContextId()
156  );
157  }
158 
164  function deleteById($footerLinkId, $contextId = null) {
165  $params = array((int) $footerLinkId);
166  if ($contextId) $params[] = (int) $contextId;
167 
168  $this->update(
169  'DELETE FROM footerlinks
170  WHERE footerlink_id = ?
171  ' . ($contextId?' AND context_id = ?':''),
172  $params
173  );
174 
175  // If the link was deleted (this validates context_id,
176  // if specified), delete any associated settings as well.
177  if ($this->getAffectedRows()) {
178  return $this->update(
179  'DELETE FROM footerlink_settings WHERE footerlink_id = ?',
180  array((int) $footerLinkId)
181  );
182  }
183  }
184 
191  function deleteByContextId($contextId) {
192  $footerlinks = $this->getByContextId($contextId);
193  while ($footerLink = $footerlinks->next()) {
194  $this->deleteObject($footerLink, $contextId);
195  }
196  }
197 
202  function getByCategoryId($categoryId, $contextId = null, $rangeInfo = null) {
203  $params = array((int) $categoryId);
204  if ($contextId) $params[] = (int) $contextId;
205 
206  $result = $this->retrieveRange(
207  'SELECT *
208  FROM footerlinks
209  WHERE footer_category_id = ?
210  ' . ($contextId?' AND context_id = ?':''),
211  $params
212  );
213 
214  $returner = new DAOResultFactory($result, $this, '_fromRow');
215  return $returner;
216  }
217 
222  function getInsertId() {
223  return $this->_getInsertId('footerlinks', 'footerlink_id');
224  }
225 
231  function getLargestCategoryTotalByContextId($contextId) {
232  $result = $this->retrieve(
233  'SELECT count(*) AS total
234  FROM footerlinks
235  WHERE context_id = ? GROUP BY footer_category_id
236  ORDER BY total DESC LIMIT 1', array((int)$contextId));
237 
238  $returner = null;
239  if ($result->RecordCount() != 0) {
240  $row = $result->GetRowAssoc(false);
241  $returner = $row['total'];
242  }
243 
244  $result->Close();
245  return $returner;
246 
247  }
248 }
249 
250 ?>
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:457
& 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)
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)