Open Journal Systems  3.3.0
AnnouncementTypeDAO.inc.php
1 <?php
2 
18 import('lib.pkp.classes.announcement.AnnouncementType');
19 
20 class AnnouncementTypeDAO extends DAO {
21 
26  function newDataObject() {
27  return new AnnouncementType();
28  }
29 
37  function getById($typeId, $assocType = null, $assocId = null) {
38  $params = array((int) $typeId);
39  if ($assocType !== null) $params[] = (int) $assocType;
40  if ($assocId !== null) $params[] = (int) $assocId;
41  $result = $this->retrieve(
42  'SELECT * FROM announcement_types WHERE type_id = ?' .
43  ($assocType !== null?' AND assoc_type = ?':'') .
44  ($assocId !== null?' AND assoc_id = ?':''),
45  $params
46  );
47 
48  $returner = null;
49  if ($result->RecordCount() != 0) {
50  $returner = $this->_fromRow($result->GetRowAssoc(false));
51  }
52  $result->Close();
53  return $returner;
54  }
55 
61  function getAnnouncementTypeAssocId($typeId) {
62  $result = $this->retrieve(
63  'SELECT assoc_id FROM announcement_types WHERE type_id = ?',
64  (int) $typeId
65  );
66 
67  return isset($result->fields[0]) ? $result->fields[0] : 0;
68  }
69 
75  function getAnnouncementTypeName($typeId) {
76  $result = $this->retrieve(
77  'SELECT COALESCE(l.setting_value, p.setting_value) FROM announcement_type_settings p LEFT JOIN announcement_type_settings l ON (l.type_id = ? AND l.setting_name = ? AND l.locale = ?) WHERE p.type_id = ? AND p.setting_name = ? AND p.locale = ?',
78  array(
79  (int) $typeId, 'name', AppLocale::getLocale(),
80  (int) $typeId, 'name', AppLocale::getPrimaryLocale()
81  )
82  );
83 
84  $returner = isset($result->fields[0]) ? $result->fields[0] : false;
85 
86  $result->Close();
87  return $returner;
88  }
89 
90 
98  function announcementTypeExistsByTypeId($typeId, $assocType, $assocId) {
99  $result = $this->retrieve(
100  'SELECT COUNT(*)
101  FROM announcement_types
102  WHERE type_id = ? AND
103  assoc_type = ? AND
104  assoc_id = ?',
105  array(
106  (int) $typeId,
107  (int) $assocType,
108  (int) $assocId
109  )
110  );
111  $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
112 
113  $result->Close();
114  return $returner;
115  }
116 
121  function getLocaleFieldNames() {
122  return array('name');
123  }
124 
132  function getByTypeName($typeName, $assocType, $assocId) {
133  $result = $this->retrieve(
134  'SELECT ats.type_id
135  FROM announcement_type_settings AS ats
136  LEFT JOIN announcement_types at ON ats.type_id = at.type_id
137  WHERE ats.setting_name = \'name\'
138  AND ats.setting_value = ?
139  AND at.assoc_type = ?
140  AND at.assoc_id = ?',
141  array(
142  $typeName,
143  (int) $assocType,
144  (int) $assocId
145  )
146  );
147  $returner = isset($result->fields[0]) ? $result->fields[0] : 0;
148 
149  $result->Close();
150  return $returner;
151  }
152 
158  function _fromRow($row) {
159  $announcementType = $this->newDataObject();
160  $announcementType->setId($row['type_id']);
161  $announcementType->setAssocType($row['assoc_type']);
162  $announcementType->setAssocId($row['assoc_id']);
163  $this->getDataObjectSettings('announcement_type_settings', 'type_id', $row['type_id'], $announcementType);
164 
165  return $announcementType;
166  }
167 
172  function updateLocaleFields($announcementType) {
173  $this->updateDataObjectSettings('announcement_type_settings', $announcementType, array(
174  'type_id' => (int) $announcementType->getId()
175  ));
176  }
177 
183  function insertObject($announcementType) {
184  $this->update(
185  sprintf('INSERT INTO announcement_types
186  (assoc_type, assoc_id)
187  VALUES
188  (?, ?)'),
189  array(
190  (int) $announcementType->getAssocType(),
191  (int) $announcementType->getAssocId()
192  )
193  );
194  $announcementType->setId($this->getInsertId());
195  $this->updateLocaleFields($announcementType);
196  return $announcementType->getId();
197  }
198 
204  function updateObject($announcementType) {
205  $returner = $this->update(
206  'UPDATE announcement_types
207  SET assoc_type = ?,
208  assoc_id = ?
209  WHERE type_id = ?',
210  array(
211  (int) $announcementType->getAssocType(),
212  (int) $announcementType->getAssocId(),
213  (int) $announcementType->getId()
214  )
215  );
216 
217  $this->updateLocaleFields($announcementType);
218  return $returner;
219  }
220 
227  function deleteObject($announcementType) {
228  return $this->deleteById($announcementType->getId());
229  }
230 
236  function deleteById($typeId) {
237  $this->update('DELETE FROM announcement_type_settings WHERE type_id = ?', (int) $typeId);
238  $this->update('DELETE FROM announcement_types WHERE type_id = ?', (int) $typeId);
239 
240  $announcementDao = DAORegistry::getDAO('AnnouncementDAO'); /* @var $announcementDao AnnouncementDAO */
241  $announcementDao->deleteByTypeId($typeId);
242  }
243 
249  function deleteByAssoc($assocType, $assocId) {
250  $types = $this->getByAssoc($assocType, $assocId);
251  while ($type = $types->next()) {
252  $this->deleteObject($type);
253  }
254  }
255 
263  function getByAssoc($assocType, $assocId, $rangeInfo = null) {
264  $result = $this->retrieveRange(
265  'SELECT * FROM announcement_types WHERE assoc_type = ? AND assoc_id = ? ORDER BY type_id',
266  array((int) $assocType, (int) $assocId),
267  $rangeInfo
268  );
269 
270  return new DAOResultFactory($result, $this, '_fromRow');
271  }
272 
277  function getInsertId() {
278  return $this->_getInsertId('announcement_types', 'type_id');
279  }
280 }
281 
282 
AnnouncementType
Basic class describing an announcement type.
Definition: AnnouncementType.inc.php:17
AnnouncementTypeDAO\deleteObject
deleteObject($announcementType)
Definition: AnnouncementTypeDAO.inc.php:227
DAOResultFactory
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
Definition: DAOResultFactory.inc.php:21
AnnouncementTypeDAO\getByAssoc
getByAssoc($assocType, $assocId, $rangeInfo=null)
Definition: AnnouncementTypeDAO.inc.php:263
DAO\retrieveRange
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
AnnouncementTypeDAO\deleteByAssoc
deleteByAssoc($assocType, $assocId)
Definition: AnnouncementTypeDAO.inc.php:249
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
DAO\retrieve
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:85
AnnouncementTypeDAO\getAnnouncementTypeAssocId
getAnnouncementTypeAssocId($typeId)
Definition: AnnouncementTypeDAO.inc.php:61
AppLocale\getPrimaryLocale
static getPrimaryLocale()
Definition: env1/MockAppLocale.inc.php:95
AnnouncementTypeDAO\announcementTypeExistsByTypeId
announcementTypeExistsByTypeId($typeId, $assocType, $assocId)
Definition: AnnouncementTypeDAO.inc.php:98
AnnouncementTypeDAO\getAnnouncementTypeName
getAnnouncementTypeName($typeId)
Definition: AnnouncementTypeDAO.inc.php:75
AnnouncementTypeDAO\newDataObject
newDataObject()
Definition: AnnouncementTypeDAO.inc.php:26
DAO\update
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:214
DAO\_getInsertId
_getInsertId($table='', $id='')
Definition: DAO.inc.php:255
DAO\getDataObjectSettings
getDataObjectSettings($tableName, $idFieldName, $idFieldValue, $dataObject)
Definition: DAO.inc.php:582
AnnouncementTypeDAO\getLocaleFieldNames
getLocaleFieldNames()
Definition: AnnouncementTypeDAO.inc.php:121
AnnouncementTypeDAO\getById
getById($typeId, $assocType=null, $assocId=null)
Definition: AnnouncementTypeDAO.inc.php:37
AnnouncementTypeDAO
Operations for retrieving and modifying AnnouncementType objects.
Definition: AnnouncementTypeDAO.inc.php:20
AnnouncementTypeDAO\deleteById
deleteById($typeId)
Definition: AnnouncementTypeDAO.inc.php:236
AnnouncementTypeDAO\getInsertId
getInsertId()
Definition: AnnouncementTypeDAO.inc.php:277
AnnouncementTypeDAO\updateObject
updateObject($announcementType)
Definition: AnnouncementTypeDAO.inc.php:204
DAO\updateDataObjectSettings
updateDataObjectSettings($tableName, $dataObject, $idArray)
Definition: DAO.inc.php:488
AnnouncementTypeDAO\_fromRow
_fromRow($row)
Definition: AnnouncementTypeDAO.inc.php:158
AppLocale\getLocale
static getLocale()
Definition: env1/MockAppLocale.inc.php:40
DAO
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:31
AnnouncementTypeDAO\updateLocaleFields
updateLocaleFields($announcementType)
Definition: AnnouncementTypeDAO.inc.php:172
AnnouncementTypeDAO\insertObject
insertObject($announcementType)
Definition: AnnouncementTypeDAO.inc.php:183
AnnouncementTypeDAO\getByTypeName
getByTypeName($typeName, $assocType, $assocId)
Definition: AnnouncementTypeDAO.inc.php:132