Open Journal Systems  2.4.4
 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->_returnAnnouncementTypeFromRow($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  unset($result);
87 
88  return $returner;
89  }
90 
91 
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  unset($result);
115 
116  return $returner;
117  }
118 
119  function getLocaleFieldNames() {
120  return array('name');
121  }
122 
130  function getByTypeName($typeName, $assocType, $assocId) {
131  $result =& $this->retrieve(
132  'SELECT ats.type_id
133  FROM announcement_type_settings AS ats
134  LEFT JOIN announcement_types at ON ats.type_id = at.type_id
135  WHERE ats.setting_name = "name"
136  AND ats.setting_value = ?
137  AND at.assoc_type = ?
138  AND at.assoc_id = ?',
139  array(
140  $typeName,
141  (int) $assocType,
142  (int) $assocId
143  )
144  );
145  $returner = isset($result->fields[0]) ? $result->fields[0] : 0;
146 
147  $result->Close();
148  unset($result);
149 
150  return $returner;
151  }
152 
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 insertAnnouncementType(&$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->getInsertTypeId());
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 
221  function updateAnnouncementType(&$announcementType) {
222  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
223  return $this->updateObject($announcementType);
224  }
225 
232  function deleteObject($announcementType) {
233  return $this->deleteById($announcementType->getId());
234  }
235 
236  function deleteAnnouncementType($announcementType) {
237  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
238  return $this->deleteObject($announcementType);
239  }
240 
246  function deleteById($typeId) {
247  $this->update('DELETE FROM announcement_type_settings WHERE type_id = ?', (int) $typeId);
248  $this->update('DELETE FROM announcement_types WHERE type_id = ?', (int) $typeId);
249 
250  $announcementDao =& DAORegistry::getDAO('AnnouncementDAO');
251  $announcementDao->deleteByTypeId($typeId);
252  }
253 
258  function deleteByAssoc($assocType, $assocId) {
259  $types =& $this->getByAssoc($assocType, $assocId);
260  while (($type =& $types->next())) {
261  $this->deleteObject($type);
262  unset($type);
263  }
264  }
265 
271  function &getByAssoc($assocType, $assocId, $rangeInfo = null) {
272  $result =& $this->retrieveRange(
273  'SELECT * FROM announcement_types WHERE assoc_type = ? AND assoc_id = ? ORDER BY type_id',
274  array((int) $assocType, (int) $assocId),
275  $rangeInfo
276  );
277 
278  $returner = new DAOResultFactory($result, $this, '_returnAnnouncementTypeFromRow');
279  return $returner;
280  }
281 
286  function getInsertTypeId() {
287  return $this->getInsertId('announcement_types', 'type_id');
288  }
289 }
290 
291 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
announcementTypeExistsByTypeId($typeId, $assocType, $assocId)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:460
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
updateLocaleFields(&$announcementType)
Operations for retrieving and modifying AnnouncementType objects.
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
getVar($section, $key, $default=null)
Definition: Config.inc.php:34
& getDAO($name, $dbconn=null)
getByTypeName($typeName, $assocType, $assocId)
deleteByAssoc($assocType, $assocId)
insertAnnouncementType(&$announcementType)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
& getByAssoc($assocType, $assocId, $rangeInfo=null)