Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
PKPAnnouncementTypeDAO.inc.php
1 <?php
2 
18 import('lib.pkp.classes.announcement.PKPAnnouncementType');
19 
20 class PKPAnnouncementTypeDAO extends DAO {
25  parent::DAO();
26  }
27 
32  function newDataObject() {
33  assert(false); // To be implemented by subclasses
34  }
35 
41  function getById($typeId) {
42  $result = $this->retrieve(
43  'SELECT * FROM announcement_types WHERE type_id = ?',
44  (int) $typeId
45  );
46 
47  $returner = null;
48  if ($result->RecordCount() != 0) {
49  $returner = $this->_fromRow($result->GetRowAssoc(false));
50  }
51  $result->Close();
52  return $returner;
53  }
54 
60  function getAnnouncementTypeAssocId($typeId) {
61  $result = $this->retrieve(
62  'SELECT assoc_id FROM announcement_types WHERE type_id = ?',
63  (int) $typeId
64  );
65 
66  return isset($result->fields[0]) ? $result->fields[0] : 0;
67  }
68 
74  function getAnnouncementTypeName($typeId) {
75  $result = $this->retrieve(
76  '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 = ?',
77  array(
78  (int) $typeId, 'name', AppLocale::getLocale(),
79  (int) $typeId, 'name', AppLocale::getPrimaryLocale()
80  )
81  );
82 
83  $returner = isset($result->fields[0]) ? $result->fields[0] : false;
84 
85  $result->Close();
86  return $returner;
87  }
88 
89 
97  function announcementTypeExistsByTypeId($typeId, $assocType, $assocId) {
98  $result = $this->retrieve(
99  'SELECT COUNT(*)
100  FROM announcement_types
101  WHERE type_id = ? AND
102  assoc_type = ? AND
103  assoc_id = ?',
104  array(
105  (int) $typeId,
106  (int) $assocType,
107  (int) $assocId
108  )
109  );
110  $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
111 
112  $result->Close();
113  return $returner;
114  }
115 
120  function getLocaleFieldNames() {
121  return array('name');
122  }
123 
131  function getByTypeName($typeName, $assocType, $assocId) {
132  $result = $this->retrieve(
133  'SELECT ats.type_id
134  FROM announcement_type_settings AS ats
135  LEFT JOIN announcement_types at ON ats.type_id = at.type_id
136  WHERE ats.setting_name = "name"
137  AND ats.setting_value = ?
138  AND at.assoc_type = ?
139  AND at.assoc_id = ?',
140  array(
141  $typeName,
142  (int) $assocType,
143  (int) $assocId
144  )
145  );
146  $returner = isset($result->fields[0]) ? $result->fields[0] : 0;
147 
148  $result->Close();
149  return $returner;
150  }
151 
157  function _fromRow($row) {
158  $announcementType = $this->newDataObject();
159  $announcementType->setId($row['type_id']);
160  $announcementType->setAssocType($row['assoc_type']);
161  $announcementType->setAssocId($row['assoc_id']);
162  $this->getDataObjectSettings('announcement_type_settings', 'type_id', $row['type_id'], $announcementType);
163 
164  return $announcementType;
165  }
166 
171  function updateLocaleFields($announcementType) {
172  $this->updateDataObjectSettings('announcement_type_settings', $announcementType, array(
173  'type_id' => (int) $announcementType->getId()
174  ));
175  }
176 
182  function insertObject($announcementType) {
183  $this->update(
184  sprintf('INSERT INTO announcement_types
185  (assoc_type, assoc_id)
186  VALUES
187  (?, ?)'),
188  array(
189  (int) $announcementType->getAssocType(),
190  (int) $announcementType->getAssocId()
191  )
192  );
193  $announcementType->setId($this->getInsertId());
194  $this->updateLocaleFields($announcementType);
195  return $announcementType->getId();
196  }
197 
203  function updateObject($announcementType) {
204  $returner = $this->update(
205  'UPDATE announcement_types
206  SET assoc_type = ?,
207  assoc_id = ?
208  WHERE type_id = ?',
209  array(
210  (int) $announcementType->getAssocType(),
211  (int) $announcementType->getAssocId(),
212  (int) $announcementType->getId()
213  )
214  );
215 
216  $this->updateLocaleFields($announcementType);
217  return $returner;
218  }
219 
226  function deleteObject($announcementType) {
227  return $this->deleteById($announcementType->getId());
228  }
229 
235  function deleteById($typeId) {
236  $this->update('DELETE FROM announcement_type_settings WHERE type_id = ?', (int) $typeId);
237  $this->update('DELETE FROM announcement_types WHERE type_id = ?', (int) $typeId);
238 
239  $announcementDao = DAORegistry::getDAO('AnnouncementDAO');
240  $announcementDao->deleteByTypeId($typeId);
241  }
242 
248  function deleteByAssoc($assocType, $assocId) {
249  $types = $this->getByAssoc($assocType, $assocId);
250  while ($type = $types->next()) {
251  $this->deleteObject($type);
252  }
253  }
254 
262  function getByAssoc($assocType, $assocId, $rangeInfo = null) {
263  $result = $this->retrieveRange(
264  'SELECT * FROM announcement_types WHERE assoc_type = ? AND assoc_id = ? ORDER BY type_id',
265  array((int) $assocType, (int) $assocId),
266  $rangeInfo
267  );
268 
269  return new DAOResultFactory($result, $this, '_fromRow');
270  }
271 
276  function getInsertId() {
277  return $this->_getInsertId('announcement_types', 'type_id');
278  }
279 }
280 
281 ?>
static & getDAO($name, $dbconn=null)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
announcementTypeExistsByTypeId($typeId, $assocType, $assocId)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
static getPrimaryLocale()
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:457
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
static getLocale()
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
Operations for retrieving and modifying AnnouncementType objects.
getByAssoc($assocType, $assocId, $rangeInfo=null)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
getByTypeName($typeName, $assocType, $assocId)
deleteByAssoc($assocType, $assocId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208