Commit 5ce88219 authored by jalperin's avatar jalperin
Browse files

#4205# Overhaul of Handler Validation and Announcement Abstraction

parent 1b7bf7d8
......@@ -15,215 +15,15 @@
* @see AnnouncementDAO
*
* @brief Basic class describing a announcement.
*
*/
// $Id$
import('announcement.PKPAnnouncement');
class Announcement extends PKPAnnouncement {
define('ANNOUNCEMENT_EXPIRE_YEAR_OFFSET_FUTURE', '+10');
class Announcement extends DataObject {
//
// Get/set methods
//
/**
* Get the ID of the announcement.
* @return int
*/
function getAnnouncementId() {
return $this->getData('announcementId');
}
/**
* Set the ID of the announcement.
* @param $announcementId int
*/
function setAnnouncementId($announcementId) {
return $this->setData('announcementId', $announcementId);
}
/**
* Get the journal ID of the announcement.
* @return int
*/
function getJournalId() {
return $this->getData('journalId');
}
/**
* Set the journal ID of the announcement.
* @param $journalId int
*/
function setJournalId($journalId) {
return $this->setData('journalId', $journalId);
}
/**
* Get the announcement type of the announcement.
* @return int
*/
function getTypeId() {
return $this->getData('typeId');
}
/**
* Set the announcement type of the announcement.
* @param $typeId int
*/
function setTypeId($typeId) {
return $this->setData('typeId', $typeId);
}
/**
* Get the announcement type name of the announcement.
* @return string
*/
function getAnnouncementTypeName() {
$announcementTypeDao = &DAORegistry::getDAO('AnnouncementTypeDAO');
return $announcementTypeDao->getAnnouncementTypeName($this->getData('typeId'));
}
/**
* Get localized announcement title
* @return string
*/
function getAnnouncementTitle() {
return $this->getLocalizedData('title');
}
/**
* Get full localized announcement title including type name
* @return string
*/
function getAnnouncementTitleFull() {
$typeName = $this->getAnnouncementTypeName();
$title = $this->getAnnouncementTitle();
if (!empty($typeName)) {
return $typeName . ': ' . $title;
} else {
return $title;
}
}
/**
* Get announcement title.
* @param $locale
* @return string
*/
function getTitle($locale) {
return $this->getData('title', $locale);
}
/**
* Set announcement title.
* @param $title string
* @param $locale string
*/
function setTitle($title, $locale) {
return $this->setData('title', $title, $locale);
}
/**
* Get localized short description
* @return string
*/
function getAnnouncementDescriptionShort() {
return $this->getLocalizedData('descriptionShort');
}
/**
* Get announcement brief description.
* @param $locale string
* @return string
*/
function getDescriptionShort($locale) {
return $this->getData('descriptionShort', $locale);
}
/**
* Set announcement brief description.
* @param $descriptionShort string
* @param $locale string
*/
function setDescriptionShort($descriptionShort, $locale) {
return $this->setData('descriptionShort', $descriptionShort, $locale);
}
/**
* Get localized full description
* @return string
*/
function getAnnouncementDescription() {
return $this->getLocalizedData('description');
}
/**
* Get announcement description.
* @param $locale string
* @return string
*/
function getDescription($locale) {
return $this->getData('description', $locale);
}
/**
* Set announcement description.
* @param $description string
* @param $locale string
*/
function setDescription($description, $locale) {
return $this->setData('description', $description, $locale);
}
/**
* Get announcement expiration date.
* @return date (YYYY-MM-DD)
*/
function getDateExpire() {
return $this->getData('dateExpire');
}
/**
* Set announcement expiration date.
* @param $dateExpire date (YYYY-MM-DD)
*/
function setDateExpire($dateExpire) {
return $this->setData('dateExpire', $dateExpire);
}
/**
* Get announcement posted date.
* @return date (YYYY-MM-DD)
*/
function getDatePosted() {
return date('Y-m-d', strtotime($this->getData('datePosted')));
}
/**
* Get announcement posted datetime.
* @return datetime (YYYY-MM-DD HH:MM:SS)
*/
function getDatetimePosted() {
return $this->getData('datePosted');
}
/**
* Set announcement posted date.
* @param $datePosted date (YYYY-MM-DD)
*/
function setDatePosted($datePosted) {
return $this->setData('datePosted', $datePosted);
}
/**
* Set announcement posted datetime.
* @param $datetimePosted date (YYYY-MM-DD HH:MM:SS)
*/
function setDatetimePosted($datetimePosted) {
return $this->setData('datePosted', $datetimePosted);
}
}
?>
......@@ -15,262 +15,11 @@
// $Id$
import('announcement.Announcement');
import('announcement.PKPAnnouncementDAO');
class AnnouncementDAO extends DAO {
/**
* Retrieve an announcement by announcement ID.
* @param $announcementId int
* @return Announcement
*/
function &getAnnouncement($announcementId) {
$result = &$this->retrieve(
'SELECT * FROM announcements WHERE announcement_id = ?', $announcementId
);
$returner = null;
if ($result->RecordCount() != 0) {
$returner = &$this->_returnAnnouncementFromRow($result->GetRowAssoc(false));
}
$result->Close();
return $returner;
}
/**
* Retrieve announcement journal ID by announcement ID.
* @param $announcementId int
* @return int
*/
function getAnnouncementJournalId($announcementId) {
$result = &$this->retrieve(
'SELECT journal_id FROM announcements WHERE announcement_id = ?', $announcementId
);
return isset($result->fields[0]) ? $result->fields[0] : 0;
}
/**
* Get the list of localized field names for this table
* @return array
*/
function getLocaleFieldNames() {
return array('title', 'descriptionShort', 'description');
}
/**
* Internal function to return an Announcement object from a row.
* @param $row array
* @return Announcement
*/
function &_returnAnnouncementFromRow(&$row) {
$announcement = new Announcement();
$announcement->setAnnouncementId($row['announcement_id']);
$announcement->setJournalId($row['journal_id']);
$announcement->setTypeId($row['type_id']);
$announcement->setDateExpire($this->dateFromDB($row['date_expire']));
$announcement->setDatePosted($this->datetimeFromDB($row['date_posted']));
$this->getDataObjectSettings('announcement_settings', 'announcement_id', $row['announcement_id'], $announcement);
return $announcement;
}
/**
* Update the settings for this object
* @param $announcement object
*/
function updateLocaleFields(&$announcement) {
$this->updateDataObjectSettings('announcement_settings', $announcement, array(
'announcement_id' => $announcement->getAnnouncementId()
));
}
/**
* Insert a new Announcement.
* @param $announcement Announcement
* @return int
*/
function insertAnnouncement(&$announcement) {
$this->update(
sprintf('INSERT INTO announcements
(journal_id, type_id, date_expire, date_posted)
VALUES
(?, ?, %s, %s)',
$this->dateToDB($announcement->getDateExpire()), $this->dateToDB($announcement->getDatetimePosted())),
array(
$announcement->getJournalId(),
$announcement->getTypeId()
)
);
$announcement->setAnnouncementId($this->getInsertAnnouncementId());
$this->updateLocaleFields($announcement);
return $announcement->getAnnouncementId();
}
/**
* Update an existing announcement.
* @param $announcement Announcement
* @return boolean
*/
function updateAnnouncement(&$announcement) {
$returner = $this->update(
sprintf('UPDATE announcements
SET
journal_id = ?,
type_id = ?,
date_expire = %s
WHERE announcement_id = ?',
$this->dateToDB($announcement->getDateExpire())),
array(
$announcement->getJournalId(),
$announcement->getTypeId(),
$announcement->getAnnouncementId()
)
);
$this->updateLocaleFields($announcement);
return $returner;
}
/**
* Delete an announcement.
* @param $announcement Announcement
* @return boolean
*/
function deleteAnnouncement($announcement) {
return $this->deleteAnnouncementById($announcement->getAnnouncementId());
}
/**
* Delete an announcement by announcement ID.
* @param $announcementId int
* @return boolean
*/
function deleteAnnouncementById($announcementId) {
$this->update('DELETE FROM announcement_settings WHERE announcement_id = ?', $announcementId);
return $this->update('DELETE FROM announcements WHERE announcement_id = ?', $announcementId);
}
/**
* Delete announcements by announcement type ID.
* @param $typeId int
* @return boolean
*/
function deleteAnnouncementByTypeId($typeId) {
$announcements =& $this->getAnnouncementsByTypeId($typeId);
while (($announcement =& $announcements->next())) {
$this->deleteAnnouncement($announcement->getAnnouncementId());
unset($announcement);
}
}
/**
* Delete announcements by journal ID.
* @param $journalId int
*/
function deleteAnnouncementsByJournal($journalId) {
$announcements =& $this->getAnnouncementsByJournalId($journalId);
while (($announcement =& $announcements->next())) {
$this->deleteAnnouncementById($announcement->getAnnouncementId());
unset($announcement);
}
}
/**
* Retrieve an array of announcements matching a particular journal ID.
* @param $journalId int
* @return object DAOResultFactory containing matching Announcements
*/
function &getAnnouncementsByJournalId($journalId, $rangeInfo = null) {
$result = &$this->retrieveRange(
'SELECT * FROM announcements WHERE journal_id = ? ORDER BY announcement_id DESC', $journalId, $rangeInfo
);
$returner = new DAOResultFactory($result, $this, '_returnAnnouncementFromRow');
return $returner;
}
/**
* Retrieve an array of announcements matching a particular type ID.
* @param $typeId int
* @return object DAOResultFactory containing matching Announcements
*/
function &getAnnouncementsByTypeId($typeId, $rangeInfo = null) {
$result = &$this->retrieveRange(
'SELECT * FROM announcements WHERE type_id = ? ORDER BY announcement_id DESC', $typeId, $rangeInfo
);
$returner = new DAOResultFactory($result, $this, '_returnAnnouncementFromRow');
return $returner;
}
/**
* Retrieve an array of numAnnouncements announcements matching a particular journal ID.
* @param $journalId int
* @return object DAOResultFactory containing matching Announcements
*/
function &getNumAnnouncementsByJournalId($journalId, $numAnnouncements, $rangeInfo = null) {
$result = &$this->retrieveRange(
'SELECT * FROM announcements WHERE journal_id = ? ORDER BY announcement_id DESC LIMIT ?', array($journalId, $numAnnouncements), $rangeInfo
);
$returner = new DAOResultFactory($result, $this, '_returnAnnouncementFromRow');
return $returner;
}
/**
* Retrieve an array of announcements with no/valid expiry date matching a particular journal ID.
* @param $journalId int
* @return object DAOResultFactory containing matching Announcements
*/
function &getAnnouncementsNotExpiredByJournalId($journalId, $rangeInfo = null) {
$result = &$this->retrieveRange(
'SELECT * FROM announcements WHERE journal_id = ? AND (date_expire IS NULL OR date_expire > CURRENT_DATE) ORDER BY announcement_id DESC', $journalId, $rangeInfo
);
$returner = new DAOResultFactory($result, $this, '_returnAnnouncementFromRow');
return $returner;
}
/**
* Retrieve an array of numAnnouncements announcements with no/valid expiry date matching a particular journal ID.
* @param $journalId int
* @return object DAOResultFactory containing matching Announcements
*/
function &getNumAnnouncementsNotExpiredByJournalId($journalId, $numAnnouncements, $rangeInfo = null) {
$result = &$this->retrieveRange(
'SELECT * FROM announcements WHERE journal_id = ? AND (date_expire IS NULL OR date_expire > CURRENT_DATE) ORDER BY announcement_id DESC LIMIT ?', array($journalId, $numAnnouncements), $rangeInfo
);
$returner = new DAOResultFactory($result, $this, '_returnAnnouncementFromRow');
return $returner;
}
/**
* Retrieve most recent announcement by journal ID.
* @param $journalId int
* @return Announcement
*/
function &getMostRecentAnnouncementByJournalId($journalId) {
$result = &$this->retrieve(
'SELECT * FROM announcements WHERE journal_id = ? ORDER BY announcement_id DESC LIMIT 1', $journalId
);
$returner = null;
if ($result->RecordCount() != 0) {
$returner = &$this->_returnAnnouncementFromRow($result->GetRowAssoc(false));
}
$result->Close();
return $returner;
}
class AnnouncementDAO extends PKPAnnouncementDAO {
/**
* Get the ID of the last inserted announcement.
* @return int
*/
function getInsertAnnouncementId() {
return $this->getInsertId('announcements', 'announcement_id');
}
}
?>
......@@ -8,76 +8,16 @@
*
* @class AnnouncementType
* @ingroup announcement
* @see AnnouncementTypeDAO
* @see AnnouncementTypeDAO, AnnouncementTypeForm
*
* @brief Basic class describing an announcement type.
*/
// $Id$
import('announcement.PKPAnnouncementType');
class AnnouncementType extends DataObject {
//
// Get/set methods
//
/**
* Get the ID of the announcement type.
* @return int
*/
function getTypeId() {
return $this->getData('typeId');
}
/**
* Set the ID of the announcement type.
* @param $typeId int
*/
function setTypeId($typeId) {
return $this->setData('typeId', $typeId);
}
/**
* Get the journal ID of the announcement type.
* @return int
*/
function getJournalId() {
return $this->getData('journalId');
}
/**
* Set the journal ID of the announcement type.
* @param $journalId int
*/
function setJournalId($journalId) {
return $this->setData('journalId', $journalId);
}
/**
* Get the type of the announcement type.
* @return string
*/
function getAnnouncementTypeName() {
return $this->getLocalizedData('name');
}
/**
* Get the type of the announcement type.
* @param $locale string
* @return string
*/
function getName($locale) {
return $this->getData('name', $locale);
}
/**
* Set the type of the announcement type.
* @param $name string
* @param $locale string
*/
function setName($name, $locale) {
return $this->setData('name', $name, $locale);
}
class AnnouncementType extends PKPAnnouncementType {
}
......
......@@ -15,219 +15,11 @@
// $Id$
import('announcement.AnnouncementType');
import('announcement.PKPAnnouncementTypeDAO');
class AnnouncementTypeDAO extends DAO {
/**
* Retrieve an announcement type by announcement type ID.
* @param $typeId int
* @return AnnouncementType
*/
function &getAnnouncementType($typeId) {
$result = &$this->retrieve(
'SELECT * FROM announcement_types WHERE type_id = ?', $typeId
);
$returner = null;
if ($result->RecordCount() != 0) {
$returner = &$this->_returnAnnouncementTypeFromRow($result->GetRowAssoc(false));
}
$result->Close();
return $returner;
}
/**
* Retrieve announcement type journal ID by announcement type ID.
* @param $typeId int
* @return int
*/
function getAnnouncementTypeJournalId($typeId) {
$result = &$this->retrieve(
'SELECT journal_id FROM announcement_types WHERE type_id = ?', $typeId
);
return isset($result->fields[0]) ? $result->fields[0] : 0;
}
/**
* Retrieve announcement type name by ID.
* @param $typeId int
* @return string
*/
function getAnnouncementTypeName($typeId) {
$result = &$this->retrieve(
'SELECT COALESCE(l.setting_value, p.setting_value) FROM announcement_type_settings l LEFT JOIN announcement_type_settings p ON (p.type_id = ? AND p.setting_name = ? AND p.locale = ?) WHERE l.type_id = ? AND l.setting_name = ? AND l.locale = ?',
array(
$typeId, 'name', Locale