Open Journal Systems  3.3.0
AnnouncementDAO.inc.php
1 <?php
2 
17 import('lib.pkp.classes.announcement.Announcement');
18 import('lib.pkp.classes.db.SchemaDAO');
19 
20 class AnnouncementDAO extends SchemaDAO {
22  var $schemaName = SCHEMA_ANNOUNCEMENT;
23 
25  var $tableName = 'announcements';
26 
28  var $settingsTableName = 'announcement_settings';
29 
31  var $primaryKeyColumn = 'announcement_id';
32 
34  var $primaryTableColumns = [
35  'id' => 'announcement_id',
36  'assocId' => 'assoc_id',
37  'assocType' => 'assoc_type',
38  'typeId' => 'type_id',
39  'dateExpire' => 'date_expire',
40  'datePosted' => 'date_posted',
41  ];
42 
50  function getById($announcementId, $assocType = null, $assocId = null) {
51  $params = array((int) $announcementId);
52  if ($assocType !== null) $params[] = (int) $assocType;
53  if ($assocId !== null) $params[] = (int) $assocId;
54  $result = $this->retrieve(
55  'SELECT * FROM announcements WHERE announcement_id = ?' .
56  ($assocType !== null?' AND assoc_type = ?':'') .
57  ($assocId !== null?' AND assoc_id = ?':''),
58  $params
59  );
60 
61  $returner = null;
62  if ($result->RecordCount() != 0) {
63  $returner = $this->_fromRow($result->GetRowAssoc(false));
64  }
65  $result->Close();
66  return $returner;
67  }
68 
74  function getAnnouncementAssocId($announcementId) {
75  $result = $this->retrieve(
76  'SELECT assoc_id FROM announcements WHERE announcement_id = ?',
77  (int) $announcementId
78  );
79 
80  return isset($result->fields[0]) ? $result->fields[0] : 0;
81  }
82 
88  function getAnnouncementAssocType($announcementId) {
89  $result = $this->retrieve(
90  'SELECT assoc_type FROM announcements WHERE announcement_id = ?',
91  (int) $announcementId
92  );
93 
94  return isset($result->fields[0]) ? $result->fields[0] : 0;
95  }
96 
101  function newDataObject() {
102  return new Announcement();
103  }
104 
110  function deleteByTypeId($typeId) {
111  $announcements = $this->getByTypeId($typeId);
112  while ($announcement = $announcements->next()) {
113  $this->deleteObject($announcement);
114  }
115  }
116 
122  function deleteByAssoc($assocType, $assocId) {
123  $announcements = $this->getByAssocId($assocType, $assocId);
124  while ($announcement = $announcements->next()) {
125  $this->deleteById($announcement->getId());
126  }
127  return true;
128  }
129 
137  function getByAssocId($assocType, $assocId, $rangeInfo = null) {
138  $result = $this->retrieveRange(
139  'SELECT *
140  FROM announcements
141  WHERE assoc_type = ? AND assoc_id = ?
142  ORDER BY date_posted DESC',
143  array((int) $assocType, (int) $assocId),
144  $rangeInfo
145  );
146 
147  return new DAOResultFactory($result, $this, '_fromRow');
148  }
149 
156  function getByTypeId($typeId, $rangeInfo = null) {
157  $result = $this->retrieveRange(
158  'SELECT * FROM announcements WHERE type_id = ? ORDER BY date_posted DESC',
159  (int) $typeId,
160  $rangeInfo
161  );
162 
163  return new DAOResultFactory($result, $this, '_fromRow');
164  }
165 
174  function getNumAnnouncementsByAssocId($assocType, $assocId, $numAnnouncements, $rangeInfo = null) {
175  $result = $this->retrieveRange(
176  'SELECT *
177  FROM announcements
178  WHERE assoc_type = ?
179  AND assoc_id = ?
180  ORDER BY date_posted DESC LIMIT ?',
181  array((int) $assocType, (int) $assocId, (int) $numAnnouncements),
182  $rangeInfo
183  );
184 
185  return new DAOResultFactory($result, $this, '_fromRow');
186  }
187 
195  function getAnnouncementsNotExpiredByAssocId($assocType, $assocId, $rangeInfo = null) {
196  $result = $this->retrieveRange(
197  'SELECT *
198  FROM announcements
199  WHERE assoc_type = ?
200  AND assoc_id = ?
201  AND (date_expire IS NULL OR DATE(date_expire) > DATE(NOW()))
202  AND (DATE(date_posted) <= DATE(NOW()))
203  ORDER BY date_posted DESC',
204  array((int) $assocType, (int) $assocId),
205  $rangeInfo
206  );
207 
208  return new DAOResultFactory($result, $this, '_fromRow');
209  }
210 
219  function getNumAnnouncementsNotExpiredByAssocId($assocType, $assocId, $numAnnouncements, $rangeInfo = null) {
220  $result = $this->retrieveRange(
221  'SELECT *
222  FROM announcements
223  WHERE assoc_type = ?
224  AND assoc_id = ?
225  AND (date_expire IS NULL OR DATE(date_expire) > DATE(NOW()))
226  AND (DATE(date_posted) <= DATE(NOW()))
227  ORDER BY date_posted DESC LIMIT ?',
228  array((int) $assocType, (int) $assocId, (int) $numAnnouncements),
229  $rangeInfo
230  );
231 
232  return new DAOResultFactory($result, $this, '_fromRow');
233  }
234 
241  function getMostRecentAnnouncementByAssocId($assocType, $assocId) {
242  $result = $this->retrieve(
243  'SELECT *
244  FROM announcements
245  WHERE assoc_type = ?
246  AND assoc_id = ?
247  ORDER BY date_posted DESC LIMIT 1',
248  array((int) $assocType, (int) $assocId)
249  );
250 
251  $returner = null;
252  if ($result->RecordCount() != 0) {
253  $returner = $this->_fromRow($result->GetRowAssoc(false));
254  }
255  $result->Close();
256  return $returner;
257  }
258 
263  function getInsertId() {
264  return $this->_getInsertId('announcements', 'announcement_id');
265  }
266 }
267 
268 
AnnouncementDAO\deleteByTypeId
deleteByTypeId($typeId)
Definition: AnnouncementDAO.inc.php:125
AnnouncementDAO\getNumAnnouncementsByAssocId
getNumAnnouncementsByAssocId($assocType, $assocId, $numAnnouncements, $rangeInfo=null)
Definition: AnnouncementDAO.inc.php:189
DAOResultFactory
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
Definition: DAOResultFactory.inc.php:21
DAO\retrieveRange
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
AnnouncementDAO\$primaryKeyColumn
$primaryKeyColumn
Definition: AnnouncementDAO.inc.php:43
AnnouncementDAO\deleteByAssoc
deleteByAssoc($assocType, $assocId)
Definition: AnnouncementDAO.inc.php:137
AnnouncementDAO\$settingsTableName
$settingsTableName
Definition: AnnouncementDAO.inc.php:37
DAO\retrieve
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:85
AnnouncementDAO\getAnnouncementAssocId
getAnnouncementAssocId($announcementId)
Definition: AnnouncementDAO.inc.php:89
AnnouncementDAO\getAnnouncementsNotExpiredByAssocId
getAnnouncementsNotExpiredByAssocId($assocType, $assocId, $rangeInfo=null)
Definition: AnnouncementDAO.inc.php:210
AnnouncementDAO\getById
getById($announcementId, $assocType=null, $assocId=null)
Definition: AnnouncementDAO.inc.php:65
AnnouncementDAO
Operations for retrieving and modifying Announcement objects.
Definition: AnnouncementDAO.inc.php:20
SchemaDAO\deleteById
deleteById($objectId)
Definition: SchemaDAO.inc.php:223
AnnouncementDAO\getByAssocId
getByAssocId($assocType, $assocId, $rangeInfo=null)
Definition: AnnouncementDAO.inc.php:152
SchemaDAO\_fromRow
_fromRow($primaryRow)
Definition: SchemaDAO.inc.php:240
AnnouncementDAO\getInsertId
getInsertId()
Definition: AnnouncementDAO.inc.php:278
DAO\_getInsertId
_getInsertId($table='', $id='')
Definition: DAO.inc.php:255
Announcement
Basic class describing a announcement.
Definition: Announcement.inc.php:22
AnnouncementDAO\$schemaName
$schemaName
Definition: AnnouncementDAO.inc.php:25
AnnouncementDAO\getMostRecentAnnouncementByAssocId
getMostRecentAnnouncementByAssocId($assocType, $assocId)
Definition: AnnouncementDAO.inc.php:256
SchemaDAO\deleteObject
deleteObject($object)
Definition: SchemaDAO.inc.php:214
AnnouncementDAO\getNumAnnouncementsNotExpiredByAssocId
getNumAnnouncementsNotExpiredByAssocId($assocType, $assocId, $numAnnouncements, $rangeInfo=null)
Definition: AnnouncementDAO.inc.php:234
AnnouncementDAO\newDataObject
newDataObject()
Definition: AnnouncementDAO.inc.php:116
AnnouncementDAO\$tableName
$tableName
Definition: AnnouncementDAO.inc.php:31
AnnouncementDAO\getAnnouncementAssocType
getAnnouncementAssocType($announcementId)
Definition: AnnouncementDAO.inc.php:103
AnnouncementDAO\getByTypeId
getByTypeId($typeId, $rangeInfo=null)
Definition: AnnouncementDAO.inc.php:171
SchemaDAO
A base class for DAOs which rely on a json-schema file to define the data object.
Definition: SchemaDAO.inc.php:18
AnnouncementDAO\$primaryTableColumns
$primaryTableColumns
Definition: AnnouncementDAO.inc.php:49