4 * @file PKPAnnouncementTypeDAO.inc.php
6 * Copyright (c) 2000-2009 John Willinsky
7 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
9 * @class PKPAnnouncementTypeDAO
10 * @ingroup announcement
11 * @see AnnouncementType, PKPAnnouncementType
13 * @brief Operations for retrieving and modifying AnnouncementType objects.
16 //$Id: PKPAnnouncementTypeDAO.inc.php,v 1.6 2009/08/18 23:44:08 asmecher Exp $
18 import('announcement.PKPAnnouncementType');
20 class PKPAnnouncementTypeDAO
extends DAO
{
22 * Retrieve an announcement type by announcement type ID.
24 * @return AnnouncementType
26 function &getAnnouncementType($typeId) {
27 $result =& $this->retrieve(
28 'SELECT * FROM announcement_types WHERE type_id = ?', $typeId
32 if ($result->RecordCount() != 0) {
33 $returner =& $this->_returnAnnouncementTypeFromRow($result->GetRowAssoc(false));
40 * Retrieve announcement type Assoc ID by announcement type ID.
44 function getAnnouncementTypeAssocId($typeId) {
45 $result =& $this->retrieve(
46 'SELECT assoc_id FROM announcement_types WHERE type_id = ?', $typeId
49 return isset($result->fields
[0]) ?
$result->fields
[0] : 0;
53 * Retrieve announcement type name by ID.
57 function getAnnouncementTypeName($typeId) {
58 $result =& $this->retrieve(
59 '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 = ?',
61 $typeId, 'name', Locale
::getLocale(),
62 $typeId, 'name', Locale
::getPrimaryLocale()
66 $returner = isset($result->fields
[0]) ?
$result->fields
[0] : false;
76 * Check if a announcement type exists with the given type id for a assoc type/id pair.
78 * @param $assocType int
81 function announcementTypeExistsByTypeId($typeId, $assocType, $assocId) {
82 $result =& $this->retrieve(
84 FROM announcement_types
94 $returner = isset($result->fields
[0]) && $result->fields
[0] != 0 ?
true : false;
102 function getLocaleFieldNames() {
103 return array('name');
107 * Return announcement type ID based on a type name for an assoc type/id pair.
108 * @param $typeName string
109 * @param $assocType int
112 function getAnnouncementTypeByTypeName($typeName, $assocType) {
113 $result =& $this->retrieve(
115 FROM announcement_types
124 $returner = isset($result->fields
[0]) ?
$result->fields
[0] : 0;
133 * Internal function to return an AnnouncementType object from a row.
135 * @return AnnouncementType
137 function &_returnAnnouncementTypeFromRow(&$row) {
138 $announcementType = new AnnouncementType();
139 $announcementType->setId($row['type_id']);
140 $announcementType->setAssocType($row['assoc_type']);
141 $announcementType->setAssocId($row['assoc_id']);
142 $this->getDataObjectSettings('announcement_type_settings', 'type_id', $row['type_id'], $announcementType);
144 return $announcementType;
148 * Update the localized settings for this object
149 * @param $announcementType object
151 function updateLocaleFields(&$announcementType) {
152 $this->updateDataObjectSettings('announcement_type_settings', $announcementType, array(
153 'type_id' => $announcementType->getId()
158 * Insert a new AnnouncementType.
159 * @param $announcementType AnnouncementType
162 function insertAnnouncementType(&$announcementType) {
164 sprintf('INSERT INTO announcement_types
165 (assoc_type, assoc_id)
169 $announcementType->getAssocType(),
170 $announcementType->getAssocId()
173 $announcementType->setId($this->getInsertTypeId());
174 $this->updateLocaleFields($announcementType);
175 return $announcementType->getId();
179 * Update an existing announcement type.
180 * @param $announcement AnnouncementType
183 function updateObject(&$announcementType) {
184 $returner = $this->update(
185 'UPDATE announcement_types
190 $announcementType->getAssocType(),
191 $announcementType->getAssocId(),
192 $announcementType->getId()
196 $this->updateLocaleFields($announcementType);
200 function updateAnnouncementType(&$announcementType) {
201 trigger_error('Deprecated function.');
202 return $this->updateObject($announcementType);
206 * Delete an announcement type. Note that all announcements with this type are also
208 * @param $announcementType AnnouncementType
211 function deleteObject($announcementType) {
212 return $this->deleteAnnouncementTypeById($announcementType->getId());
215 function deleteAnnouncementType($announcementType) {
216 trigger_error('Deprecated function.');
217 return $this->deleteObject($announcementType);
221 * Delete an announcement type by announcement type ID. Note that all announcements with
222 * this type ID are also deleted.
226 function deleteAnnouncementTypeById($typeId) {
227 $this->update('DELETE FROM announcement_type_settings WHERE type_id = ?', $typeId);
228 $ret = $this->update('DELETE FROM announcement_types WHERE type_id = ?', $typeId);
230 // Delete all announcements with this announcement type
232 $announcementDao =& DAORegistry
::getDAO('AnnouncementDAO');
233 return $announcementDao->deleteAnnouncementByTypeId($typeId);
240 * Delete announcement types by Assoc ID.
241 * @param $assocType int
243 function deleteAnnouncementTypesByAssocId($assocType, $assocId) {
244 $types =& $this->getAnnouncementTypesByAssocId($assocType, $assocId);
245 while (($type =& $types->next())) {
246 $this->deleteObject($type);
252 * Retrieve an array of announcement types matching a particular Assoc ID.
253 * @param $assocType int
254 * @return object DAOResultFactory containing matching AnnouncementTypes
256 function &getAnnouncementTypesByAssocId($assocType, $assocId, $rangeInfo = null) {
257 $result =& $this->retrieveRange(
258 'SELECT * FROM announcement_types WHERE assoc_type = ? AND assoc_id = ? ORDER BY type_id', array($assocType, $assocId), $rangeInfo
261 $returner = new DAOResultFactory($result, $this, '_returnAnnouncementTypeFromRow');
266 * Get the ID of the last inserted announcement type.
269 function getInsertTypeId() {
270 return $this->getInsertId('announcement_types', 'type_id');