Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
PKPAnnouncementDAO.inc.php
1 <?php
2 
17 import('lib.pkp.classes.announcement.PKPAnnouncement');
18 
19 class PKPAnnouncementDAO extends DAO {
23  function PKPAnnouncementDAO() {
24  parent::DAO();
25  }
26 
32  function getById($announcementId) {
33  $result = $this->retrieve(
34  'SELECT * FROM announcements WHERE announcement_id = ?',
35  (int) $announcementId
36  );
37 
38  $returner = null;
39  if ($result->RecordCount() != 0) {
40  $returner = $this->_fromRow($result->GetRowAssoc(false));
41  }
42  $result->Close();
43  return $returner;
44  }
45 
51  function getAnnouncementAssocId($announcementId) {
52  $result = $this->retrieve(
53  'SELECT assoc_id FROM announcements WHERE announcement_id = ?',
54  (int) $announcementId
55  );
56 
57  return isset($result->fields[0]) ? $result->fields[0] : 0;
58  }
59 
65  function getAnnouncementAssocType($announcementId) {
66  $result = $this->retrieve(
67  'SELECT assoc_type FROM announcements WHERE announcement_id = ?',
68  (int) $announcementId
69  );
70 
71  return isset($result->fields[0]) ? $result->fields[0] : 0;
72  }
73 
78  function getLocaleFieldNames() {
79  return array('title', 'descriptionShort', 'description');
80  }
81 
86  function newDataObject() {
87  assert(false); // Should be implemented by subclasses
88  }
89 
95  function _fromRow($row) {
96  $announcement = $this->newDataObject();
97  $announcement->setId($row['announcement_id']);
98  $announcement->setAssocType($row['assoc_type']);
99  $announcement->setAssocId($row['assoc_id']);
100  $announcement->setTypeId($row['type_id']);
101  $announcement->setDateExpire($this->datetimeFromDB($row['date_expire']));
102  $announcement->setDatePosted($this->datetimeFromDB($row['date_posted']));
103 
104  $this->getDataObjectSettings('announcement_settings', 'announcement_id', $row['announcement_id'], $announcement);
105 
106  return $announcement;
107  }
108 
113  function updateLocaleFields($announcement) {
114  $this->updateDataObjectSettings('announcement_settings', $announcement, array(
115  'announcement_id' => $announcement->getId()
116  ));
117  }
118 
124  function insertObject($announcement) {
125  $this->update(
126  sprintf('INSERT INTO announcements
127  (assoc_type, assoc_id, type_id, date_expire, date_posted)
128  VALUES
129  (?, ?, ?, %s, %s)',
130  $this->datetimeToDB($announcement->getDateExpire()), $this->datetimeToDB($announcement->getDatetimePosted())),
131  array(
132  (int) $announcement->getAssocType(),
133  (int) $announcement->getAssocId(),
134  (int) $announcement->getTypeId()
135  )
136  );
137  $announcement->setId($this->getInsertId());
138  $this->updateLocaleFields($announcement);
139  return $announcement->getId();
140  }
141 
147  function updateObject($announcement) {
148  $returner = $this->update(
149  sprintf('UPDATE announcements
150  SET
151  assoc_type = ?,
152  assoc_id = ?,
153  type_id = ?,
154  date_expire = %s
155  WHERE announcement_id = ?',
156  $this->datetimeToDB($announcement->getDateExpire())),
157  array(
158  (int) $announcement->getAssocType(),
159  (int) $announcement->getAssocId(),
160  (int) $announcement->getTypeId(),
161  (int) $announcement->getId()
162  )
163  );
164  $this->updateLocaleFields($announcement);
165  return $returner;
166  }
167 
173  function deleteObject($announcement) {
174  return $this->deleteById($announcement->getId());
175  }
176 
182  function deleteById($announcementId) {
183  $this->update('DELETE FROM announcement_settings WHERE announcement_id = ?', (int) $announcementId);
184  return $this->update('DELETE FROM announcements WHERE announcement_id = ?', (int) $announcementId);
185  }
186 
192  function deleteByTypeId($typeId) {
193  $announcements = $this->getByTypeId($typeId);
194  while ($announcement = $announcements->next()) {
195  $this->deleteObject($announcement);
196  }
197  }
198 
204  function deleteByAssoc($assocType, $assocId) {
205  $announcements = $this->getByAssocId($assocType, $assocId);
206  while ($announcement = $announcements->next()) {
207  $this->deleteById($announcement->getId());
208  }
209  return true;
210  }
211 
219  function getByAssocId($assocType, $assocId, $rangeInfo = null) {
220  $result = $this->retrieveRange(
221  'SELECT *
222  FROM announcements
223  WHERE assoc_type = ? AND assoc_id = ?
224  ORDER BY announcement_id DESC',
225  array((int) $assocType, (int) $assocId),
226  $rangeInfo
227  );
228 
229  return new DAOResultFactory($result, $this, '_fromRow');
230  }
231 
238  function getByTypeId($typeId, $rangeInfo = null) {
239  $result = $this->retrieveRange(
240  'SELECT * FROM announcements WHERE type_id = ? ORDER BY announcement_id DESC',
241  (int) $typeId,
242  $rangeInfo
243  );
244 
245  return new DAOResultFactory($result, $this, '_fromRow');
246  }
247 
256  function getNumAnnouncementsByAssocId($assocType, $assocId, $numAnnouncements, $rangeInfo = null) {
257  $result = $this->retrieveRange(
258  'SELECT *
259  FROM announcements
260  WHERE assoc_type = ?
261  AND assoc_id = ?
262  ORDER BY announcement_id DESC LIMIT ?',
263  array((int) $assocType, (int) $assocId, (int) $numAnnouncements),
264  $rangeInfo
265  );
266 
267  return new DAOResultFactory($result, $this, '_fromRow');
268  }
269 
277  function getAnnouncementsNotExpiredByAssocId($assocType, $assocId, $rangeInfo = null) {
278  $result = $this->retrieveRange(
279  'SELECT *
280  FROM announcements
281  WHERE assoc_type = ?
282  AND assoc_id = ?
283  AND (date_expire IS NULL OR date_expire > CURRENT_DATE)
284  ORDER BY announcement_id DESC',
285  array((int) $assocType, (int) $assocId),
286  $rangeInfo
287  );
288 
289  return new DAOResultFactory($result, $this, '_fromRow');
290  }
291 
300  function getNumAnnouncementsNotExpiredByAssocId($assocType, $assocId, $numAnnouncements, $rangeInfo = null) {
301  $result = $this->retrieveRange(
302  'SELECT *
303  FROM announcements
304  WHERE assoc_type = ?
305  AND assoc_id = ?
306  AND (date_expire IS NULL OR date_expire > CURRENT_DATE)
307  ORDER BY announcement_id DESC LIMIT ?',
308  array((int) $assocType, (int) $assocId, (int) $numAnnouncements),
309  $rangeInfo
310  );
311 
312  return new DAOResultFactory($result, $this, '_fromRow');
313  }
314 
321  function getMostRecentAnnouncementByAssocId($assocType, $assocId) {
322  $result = $this->retrieve(
323  'SELECT *
324  FROM announcements
325  WHERE assoc_type = ?
326  AND assoc_id = ?
327  ORDER BY announcement_id DESC LIMIT 1',
328  array((int) $assocType, (int) $assocId)
329  );
330 
331  $returner = null;
332  if ($result->RecordCount() != 0) {
333  $returner = $this->_fromRow($result->GetRowAssoc(false));
334  }
335  $result->Close();
336  return $returner;
337  }
338 
343  function getInsertId() {
344  return $this->_getInsertId('announcements', 'announcement_id');
345  }
346 }
347 
348 ?>
getAnnouncementAssocType($announcementId)
updateLocaleFields($announcement)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
getNumAnnouncementsByAssocId($assocType, $assocId, $numAnnouncements, $rangeInfo=null)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
getMostRecentAnnouncementByAssocId($assocType, $assocId)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:457
deleteByAssoc($assocType, $assocId)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
getAnnouncementAssocId($announcementId)
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
datetimeFromDB($dt)
Definition: DAO.inc.php:313
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
getNumAnnouncementsNotExpiredByAssocId($assocType, $assocId, $numAnnouncements, $rangeInfo=null)
getByAssocId($assocType, $assocId, $rangeInfo=null)
getByTypeId($typeId, $rangeInfo=null)
datetimeToDB($dt)
Definition: DAO.inc.php:293
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
getAnnouncementsNotExpiredByAssocId($assocType, $assocId, $rangeInfo=null)
Operations for retrieving and modifying Announcement objects.