Open Journal Systems  2.4.4
 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->_returnAnnouncementFromRow($result->GetRowAssoc(false));
41  }
42  $result->Close();
43  return $returner;
44  }
45 
49  function &getAnnouncement($announcementId) {
50  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
51  return $this->getById($announcementId);
52  }
53 
59  function getAnnouncementAssocId($announcementId) {
60  $result =& $this->retrieve(
61  'SELECT assoc_id FROM announcements WHERE announcement_id = ?',
62  (int) $announcementId
63  );
64 
65  return isset($result->fields[0]) ? $result->fields[0] : 0;
66  }
67 
73  function getAnnouncementAssocType($announcementId) {
74  $result =& $this->retrieve(
75  'SELECT assoc_type FROM announcements WHERE announcement_id = ?',
76  (int) $announcementId
77  );
78 
79  return isset($result->fields[0]) ? $result->fields[0] : 0;
80  }
81 
86  function getLocaleFieldNames() {
87  return array('title', 'descriptionShort', 'description');
88  }
89 
94  function newDataObject() {
95  assert(false); // Should be implemented by subclasses
96  }
97 
103  function &_returnAnnouncementFromRow(&$row) {
104  $announcement = $this->newDataObject();
105  $announcement->setId($row['announcement_id']);
106  $announcement->setAssocType($row['assoc_type']);
107  $announcement->setAssocId($row['assoc_id']);
108  $announcement->setTypeId($row['type_id']);
109  $announcement->setDateExpire($this->datetimeFromDB($row['date_expire']));
110  $announcement->setDatePosted($this->datetimeFromDB($row['date_posted']));
111 
112  $this->getDataObjectSettings('announcement_settings', 'announcement_id', $row['announcement_id'], $announcement);
113 
114  return $announcement;
115  }
116 
121  function updateLocaleFields(&$announcement) {
122  $this->updateDataObjectSettings('announcement_settings', $announcement, array(
123  'announcement_id' => $announcement->getId()
124  ));
125  }
126 
132  function insertAnnouncement(&$announcement) {
133  $this->update(
134  sprintf('INSERT INTO announcements
135  (assoc_type, assoc_id, type_id, date_expire, date_posted)
136  VALUES
137  (?, ?, ?, %s, %s)',
138  $this->datetimeToDB($announcement->getDateExpire()),
139  $this->datetimeToDB($announcement->getDatetimePosted())
140  ), array(
141  (int) $announcement->getAssocType(),
142  (int) $announcement->getAssocId(),
143  (int) $announcement->getTypeId()
144  )
145  );
146  $announcement->setId($this->getInsertAnnouncementId());
147  $this->updateLocaleFields($announcement);
148  return $announcement->getId();
149  }
150 
156  function updateObject(&$announcement) {
157  $returner = $this->update(
158  sprintf('UPDATE announcements
159  SET
160  assoc_type = ?,
161  assoc_id = ?,
162  type_id = ?,
163  date_expire = %s,
164  date_posted = %s
165  WHERE announcement_id = ?',
166  $this->datetimeToDB($announcement->getDateExpire()),
167  $this->datetimeToDB($announcement->getDatetimePosted())),
168  array(
169  (int) $announcement->getAssocType(),
170  (int) $announcement->getAssocId(),
171  (int) $announcement->getTypeId(),
172  (int) $announcement->getId()
173  )
174  );
175  $this->updateLocaleFields($announcement);
176  return $returner;
177  }
178 
182  function updateAnnouncement(&$announcement) {
183  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
184  return $this->updateObject($announcement);
185  }
186 
192  function deleteObject($announcement) {
193  return $this->deleteById($announcement->getId());
194  }
195 
199  function deleteAnnouncement($announcement) {
200  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
201  return $this->deleteObject($announcement);
202  }
203 
209  function deleteById($announcementId) {
210  $this->update('DELETE FROM announcement_settings WHERE announcement_id = ?', (int) $announcementId);
211  return $this->update('DELETE FROM announcements WHERE announcement_id = ?', (int) $announcementId);
212  }
213 
217  function deleteAnnouncementById($announcementId) {
218  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
219  return $this->deleteById($announcementId);
220  }
221 
227  function deleteByTypeId($typeId) {
228  $announcements =& $this->getByTypeId($typeId);
229  while (($announcement =& $announcements->next())) {
230  $this->deleteObject($announcement);
231  unset($announcement);
232  }
233  }
234 
240  function deleteByAssoc($assocType, $assocId) {
241  $announcements =& $this->getByAssocId($assocType, $assocId);
242  while (($announcement =& $announcements->next())) {
243  $this->deleteById($announcement->getId());
244  unset($announcement);
245  }
246  return true;
247  }
248 
252  function deleteAnnouncementsByAssocId($assocType, $assocId) {
253  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
254  return $this->deleteByAssocId($assocType, $assocId);
255  }
256 
262  function &getByAssocId($assocType, $assocId, $rangeInfo = null) {
263  $result =& $this->retrieveRange(
264  'SELECT *
265  FROM announcements
266  WHERE assoc_type = ? AND assoc_id = ?
267  ORDER BY announcement_id DESC',
268  array((int) $assocType, (int) $assocId),
269  $rangeInfo
270  );
271 
272  $returner = new DAOResultFactory($result, $this, '_returnAnnouncementFromRow');
273  return $returner;
274  }
275 
279  function &getAnnouncementsByAssocId($assocType, $assocId, $rangeInfo = null) {
280  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
281  return $this->getByAssocId($assocType, $assocId, $rangeInfo);
282  }
283 
289  function &getByTypeId($typeId, $rangeInfo = null) {
290  $result =& $this->retrieveRange(
291  'SELECT * FROM announcements WHERE type_id = ? ORDER BY announcement_id DESC',
292  (int) $typeId,
293  $rangeInfo
294  );
295 
296  $returner = new DAOResultFactory($result, $this, '_returnAnnouncementFromRow');
297  return $returner;
298  }
299 
303  function &getAnnouncementsByTypeId($typeId, $rangeInfo = null) {
304  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
305  return $this->getByTypeId($typeId, $rangeInfo);
306  }
307 
313  function &getNumAnnouncementsByAssocId($assocType, $assocId, $numAnnouncements, $rangeInfo = null) {
314  $result =& $this->retrieveRange(
315  'SELECT *
316  FROM announcements
317  WHERE assoc_type = ?
318  AND assoc_id = ?
319  ORDER BY announcement_id DESC LIMIT ?',
320  array((int) $assocType, (int) $assocId, (int) $numAnnouncements),
321  $rangeInfo
322  );
323 
324  $returner = new DAOResultFactory($result, $this, '_returnAnnouncementFromRow');
325  return $returner;
326  }
327 
335  function &getAnnouncementsNotExpiredByAssocId($assocType, $assocId, $rangeInfo = null) {
336  $result =& $this->retrieveRange(
337  'SELECT *
338  FROM announcements
339  WHERE assoc_type = ?
340  AND assoc_id = ?
341  AND (date_expire IS NULL OR date_expire > CURRENT_DATE)
342  ORDER BY announcement_id DESC',
343  array((int) $assocType, (int) $assocId),
344  $rangeInfo
345  );
346 
347  $returner = new DAOResultFactory($result, $this, '_returnAnnouncementFromRow');
348  return $returner;
349  }
350 
356  function &getNumAnnouncementsNotExpiredByAssocId($assocType, $assocId, $numAnnouncements, $rangeInfo = null) {
357  $result =& $this->retrieveRange(
358  'SELECT *
359  FROM announcements
360  WHERE assoc_type = ?
361  AND assoc_id = ?
362  AND (date_expire IS NULL OR date_expire > CURRENT_DATE)
363  ORDER BY announcement_id DESC LIMIT ?',
364  array((int) $assocType, (int) $assocId, (int) $numAnnouncements),
365  $rangeInfo
366  );
367 
368  $returner = new DAOResultFactory($result, $this, '_returnAnnouncementFromRow');
369  return $returner;
370  }
371 
377  function &getMostRecentAnnouncementByAssocId($assocType, $assocId) {
378  $result =& $this->retrieve(
379  'SELECT *
380  FROM announcements
381  WHERE assoc_type = ?
382  AND assoc_id = ?
383  ORDER BY announcement_id DESC LIMIT 1',
384  array((int) $assocType, (int) $assocId)
385  );
386 
387  $returner = null;
388  if ($result->RecordCount() != 0) {
389  $returner =& $this->_returnAnnouncementFromRow($result->GetRowAssoc(false));
390  }
391  $result->Close();
392  return $returner;
393  }
394 
400  return $this->getInsertId('announcements', 'announcement_id');
401  }
402 }
403 
404 ?>
getAnnouncementAssocType($announcementId)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:460
deleteByAssoc($assocType, $assocId)
& getByTypeId($typeId, $rangeInfo=null)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
getAnnouncementAssocId($announcementId)
& getAnnouncementsByAssocId($assocType, $assocId, $rangeInfo=null)
datetimeFromDB($dt)
Definition: DAO.inc.php:316
updateAnnouncement(&$announcement)
& getByAssocId($assocType, $assocId, $rangeInfo=null)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
getVar($section, $key, $default=null)
Definition: Config.inc.php:34
insertAnnouncement(&$announcement)
deleteAnnouncementsByAssocId($assocType, $assocId)
updateLocaleFields(&$announcement)
& getById($announcementId)
& getAnnouncementsByTypeId($typeId, $rangeInfo=null)
& getAnnouncement($announcementId)
& getAnnouncementsNotExpiredByAssocId($assocType, $assocId, $rangeInfo=null)
deleteAnnouncement($announcement)
& getNumAnnouncementsNotExpiredByAssocId($assocType, $assocId, $numAnnouncements, $rangeInfo=null)
& getNumAnnouncementsByAssocId($assocType, $assocId, $numAnnouncements, $rangeInfo=null)
datetimeToDB($dt)
Definition: DAO.inc.php:296
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
& getMostRecentAnnouncementByAssocId($assocType, $assocId)
deleteAnnouncementById($announcementId)
Operations for retrieving and modifying Announcement objects.