00001 <?php
00002
00017 import ('reviewForm.ReviewForm');
00018
00019 class ReviewFormDAO extends DAO {
00020
00024 function ReviewFormDAO() {
00025 parent::DAO();
00026 }
00027
00034 function &getReviewForm($reviewFormId, $journalId = null) {
00035 $params = array((int) $reviewFormId);
00036 if ($journalId !== null) $params[] = (int) $journalId;
00037
00038 $result =& $this->retrieve (
00039 'SELECT rf.review_form_id,
00040 rf.journal_id,
00041 rf.seq,
00042 rf.is_active,
00043 COUNT(rac.review_id) AS complete_count,
00044 COUNT(rai.review_id) AS incomplete_count
00045 FROM review_forms rf
00046 LEFT JOIN review_assignments rac ON (
00047 rac.review_form_id = rf.review_form_id AND
00048 rac.date_confirmed IS NOT NULL
00049 )
00050 LEFT JOIN review_assignments rai ON (
00051 rai.review_form_id = rf.review_form_id AND
00052 rai.date_notified IS NOT NULL AND
00053 rai.date_confirmed IS NULL
00054 )
00055 WHERE rf.review_form_id = ?
00056 ' . ($journalId!==null?' AND rf.journal_id = ?':'') . '
00057 GROUP BY rf.journal_id, rf.review_form_id, rf.seq, rf.is_active',
00058 $params
00059 );
00060
00061 $returner = null;
00062 if ($result->RecordCount() != 0) {
00063 $returner =& $this->_returnReviewFormFromRow($result->GetRowAssoc(false));
00064 }
00065
00066 $result->Close();
00067 unset($result);
00068
00069 return $returner;
00070 }
00071
00077 function &_returnReviewFormFromRow(&$row) {
00078 $reviewForm =& new ReviewForm();
00079 $reviewForm->setReviewFormId($row['review_form_id']);
00080 $reviewForm->setJournalId($row['journal_id']);
00081 $reviewForm->setSequence($row['seq']);
00082 $reviewForm->setActive($row['is_active']);
00083 $reviewForm->setCompleteCount($row['complete_count']);
00084 $reviewForm->setIncompleteCount($row['incomplete_count']);
00085
00086 $this->getDataObjectSettings('review_form_settings', 'review_form_id', $row['review_form_id'], $reviewForm);
00087
00088 HookRegistry::call('ReviewFormDAO::_returnReviewFormFromRow', array(&$reviewForm, &$row));
00089
00090 return $reviewForm;
00091 }
00092
00099 function reviewFormExists($reviewFormId, $journalId) {
00100 $result = &$this->retrieve(
00101 'SELECT COUNT(*) FROM review_forms WHERE review_form_id = ? AND journal_id = ?',
00102 array($reviewFormId, $journalId)
00103 );
00104 $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
00105
00106 $result->Close();
00107 unset($result);
00108
00109 return $returner;
00110 }
00111
00116 function getLocaleFieldNames() {
00117 return array('title', 'description');
00118 }
00119
00124 function updateLocaleFields(&$reviewForm) {
00125 $this->updateDataObjectSettings('review_form_settings', $reviewForm, array(
00126 'review_form_id' => $reviewForm->getReviewFormId()
00127 ));
00128 }
00129
00134 function insertReviewForm(&$reviewForm) {
00135 $this->update(
00136 'INSERT INTO review_forms
00137 (journal_id, seq, is_active)
00138 VALUES
00139 (?, ?, ?)',
00140 array(
00141 $reviewForm->getJournalId(),
00142 $reviewForm->getSequence() == null ? 0 : $reviewForm->getSequence(),
00143 $reviewForm->getActive() ? 1 : 0
00144 )
00145 );
00146
00147 $reviewForm->setReviewFormId($this->getInsertReviewFormId());
00148 $this->updateLocaleFields($reviewForm);
00149
00150 return $reviewForm->getReviewFormId();
00151 }
00152
00157 function updateReviewForm(&$reviewForm) {
00158 $returner = $this->update(
00159 'UPDATE review_forms
00160 SET
00161 journal_id = ?,
00162 seq = ?,
00163 is_active = ?
00164 WHERE review_form_id = ?',
00165 array(
00166 $reviewForm->getJournalId(),
00167 $reviewForm->getSequence(),
00168 $reviewForm->getActive(),
00169 $reviewForm->getReviewFormId()
00170 )
00171 );
00172
00173 $this->updateLocaleFields($reviewForm);
00174
00175 return $returner;
00176 }
00177
00182 function deleteReviewForm(&$reviewForm) {
00183 return $this->deleteReviewFormById($reviewForm->getReviewFormId(), $reviewForm->getJournalId());
00184 }
00185
00191 function deleteReviewFormById($reviewFormId, $journalId = null) {
00192 if (isset($journalId)) {
00193 $reviewForm =& $this->getReviewForm($reviewFormId, $journalId);
00194 if (!$reviewForm) return null;
00195 unset($reviewForm);
00196 }
00197
00198 $reviewFormElementDao =& DAORegistry::getDAO('ReviewFormElementDAO');
00199 $reviewFormElementDao->deleteReviewFormElementsByReviewForm($reviewFormId);
00200
00201 $this->update('DELETE FROM review_form_settings WHERE review_form_id = ?', array($reviewFormId));
00202 return $this->update('DELETE FROM review_forms WHERE review_form_id = ?', array($reviewFormId));
00203 }
00204
00209 function deleteReviewFormsByJournalId($journalId) {
00210 $reviewForms = $this->getJournalReviewForms($journalId);
00211
00212 while (!$reviewForms->eof()) {
00213 $reviewForm =& $reviewForms->next();
00214 $this->deleteReviewFormById($reviewForm->getReviewFormId());
00215 }
00216 }
00217
00223 function &getJournalReviewForms($journalId) {
00224 $result =& $this->retrieveRange(
00225 'SELECT rf.review_form_id,
00226 rf.journal_id,
00227 rf.seq,
00228 rf.is_active,
00229 COUNT(rac.review_id) AS complete_count,
00230 COUNT(rai.review_id) AS incomplete_count
00231 FROM review_forms rf
00232 LEFT JOIN review_assignments rac ON (
00233 rac.review_form_id = rf.review_form_id AND
00234 rac.date_confirmed IS NOT NULL
00235 )
00236 LEFT JOIN review_assignments rai ON (
00237 rai.review_form_id = rf.review_form_id AND
00238 rai.date_notified IS NOT NULL AND
00239 rai.date_confirmed IS NULL
00240 )
00241 WHERE rf.journal_id = ?
00242 GROUP BY rf.journal_id, rf.review_form_id, rf.seq, rf.is_active
00243 ORDER BY rf.seq',
00244 $journalId
00245 );
00246
00247 $returner =& new DAOResultFactory($result, $this, '_returnReviewFormFromRow');
00248 return $returner;
00249 }
00250
00257 function &getJournalActiveReviewForms($journalId, $rangeInfo = null) {
00258 $result =& $this->retrieveRange(
00259 'SELECT rf.review_form_id,
00260 rf.journal_id,
00261 rf.seq,
00262 rf.is_active,
00263 COUNT(rac.review_id) AS complete_count,
00264 COUNT(rai.review_id) AS incomplete_count
00265 FROM review_forms rf
00266 LEFT JOIN review_assignments rac ON (
00267 rac.review_form_id = rf.review_form_id AND
00268 rac.date_confirmed IS NOT NULL
00269 )
00270 LEFT JOIN review_assignments rai ON (
00271 rai.review_form_id = rf.review_form_id AND
00272 rai.date_notified IS NOT NULL AND
00273 rai.date_confirmed IS NULL
00274 )
00275 WHERE rf.journal_id = ? AND
00276 rf.is_active = 1
00277 GROUP BY rf.journal_id, rf.review_form_id, rf.seq, rf.is_active
00278 ORDER BY rf.seq',
00279 $journalId, $rangeInfo
00280 );
00281
00282 $returner =& new DAOResultFactory($result, $this, '_returnReviewFormFromRow');
00283 return $returner;
00284 }
00285
00292 function &getJournalUsedReviewForms($journalId, $rangeInfo = null) {
00293 $result =& $this->retrieveRange(
00294 'SELECT rf.review_form_id,
00295 rf.journal_id,
00296 rf.seq,
00297 rf.is_active,
00298 COUNT(rac.review_id) AS complete_count,
00299 COUNT(rai.review_id) AS incomplete_count
00300 FROM review_forms rf
00301 LEFT JOIN review_assignments rac ON (
00302 rac.review_form_id = rf.review_form_id AND
00303 rac.date_confirmed IS NOT NULL
00304 )
00305 LEFT JOIN review_assignments rai ON (
00306 rai.review_form_id = rf.review_form_id AND
00307 rai.date_notified IS NOT NULL AND
00308 rai.date_confirmed IS NULL
00309 )
00310 WHERE rf.journal_id = ? AND
00311 rf.is_active = 1
00312 GROUP BY rf.journal_id, rf.review_form_id, rf.seq, rf.is_active
00313 HAVING COUNT(rac.review_id) > 0 OR COUNT(rai.review_id) > 0
00314 ORDER BY rf.seq',
00315 $journalId, $rangeInfo
00316 );
00317
00318 $returner =& new DAOResultFactory($result, $this, '_returnReviewFormFromRow');
00319 return $returner;
00320 }
00321
00328 function &getJournalUnusedReviewForms($journalId, $rangeInfo = null) {
00329 $result =& $this->retrieveRange(
00330 'SELECT rf.review_form_id,
00331 rf.journal_id,
00332 rf.seq,
00333 rf.is_active,
00334 COUNT(rac.review_id) AS complete_count,
00335 COUNT(rai.review_id) AS incomplete_count
00336 FROM review_forms rf
00337 LEFT JOIN review_assignments rac ON (
00338 rac.review_form_id = rf.review_form_id AND
00339 rac.date_confirmed IS NOT NULL
00340 )
00341 LEFT JOIN review_assignments rai ON (
00342 rai.review_form_id = rf.review_form_id AND
00343 rai.date_notified IS NOT NULL AND
00344 rai.date_confirmed IS NULL
00345 )
00346 WHERE rf.journal_id = ?
00347 GROUP BY rf.journal_id, rf.review_form_id, rf.seq, rf.is_active
00348 HAVING COUNT(rac.review_id) = 0 AND COUNT(rai.review_id) = 0
00349 ORDER BY rf.seq',
00350 $journalId, $rangeInfo
00351 );
00352
00353 $returner =& new DAOResultFactory($result, $this, '_returnReviewFormFromRow');
00354 return $returner;
00355 }
00356
00363 function &getJournalReviewFormTitles($journalId, $used) {
00364 $reviewFormTitles = array();
00365
00366 if ($used) {
00367 $reviewForms =& $this->getJournalUsedReviewForms($journalId);
00368 } else {
00369 $reviewForms =& $this->getJournalUnusedReviewForms($journalId);
00370 }
00371 while (($reviewForm =& $reviewForms->next())) {
00372 $reviewFormTitles[$reviewForm->getReviewFormId()] = $reviewForm->getReviewFormTitle();
00373 unset($reviewForm);
00374 }
00375
00376 return $reviewFormTitles;
00377 }
00378
00385 function unusedReviewFormExists($reviewFormId, $journalId = null) {
00386 $params = array((int) $reviewFormId);
00387 if ($journalId !== null) $params[] = (int) $journalId;
00388
00389 $result =& $this->retrieve (
00390 'SELECT rf.review_form_id,
00391 COUNT(rac.review_id) AS complete_count,
00392 COUNT(rai.review_id) AS incomplete_count
00393 FROM review_forms rf
00394 LEFT JOIN review_assignments rac ON (
00395 rac.review_form_id = rf.review_form_id AND
00396 rac.date_confirmed IS NOT NULL
00397 )
00398 LEFT JOIN review_assignments rai ON (
00399 rai.review_form_id = rf.review_form_id AND
00400 rai.date_notified IS NOT NULL AND
00401 rai.date_confirmed IS NULL
00402 )
00403 WHERE rf.review_form_id = ?
00404 ' . ($journalId!==null?' AND rf.journal_id = ?':'') . '
00405 GROUP BY rf.review_form_id
00406 HAVING COUNT(rac.review_id) = 0 AND COUNT(rai.review_id) = 0',
00407 $params
00408 );
00409
00410 $returner = $result->RecordCount() != 0;
00411
00412 $result->Close();
00413 unset($result);
00414
00415 return $returner;
00416 }
00417
00422 function resequenceReviewForms($journalId) {
00423 $result =& $this->retrieve(
00424 'SELECT review_form_id FROM review_forms WHERE journal_id = ? ORDER BY seq',
00425 (int) $journalId
00426 );
00427
00428 for ($i=1; !$result->EOF; $i++) {
00429 list($reviewFormId) = $result->fields;
00430 $this->update(
00431 'UPDATE review_forms SET seq = ? WHERE review_form_id = ?',
00432 array(
00433 $i,
00434 $reviewFormId
00435 )
00436 );
00437
00438 $result->moveNext();
00439 }
00440
00441 $result->close();
00442 unset($result);
00443 }
00444
00449 function getInsertReviewFormId() {
00450 return $this->getInsertId('review_forms', 'review_form_id');
00451 }
00452 }
00453
00454 ?>