00001 <?php
00002
00016
00017
00018
00019 import('db.DBRowIterator');
00020
00021 class JournalReportIterator extends DBRowIterator {
00023 var $locale;
00024
00026 var $sectionDao;
00027
00029 var $articleDao;
00030
00032 var $journalStatisticsDao;
00033
00035 var $authorDao;
00036
00038 var $userDao;
00039
00041 var $countryDao;
00042
00044 var $authorSubmissionDao;
00045
00047 var $editAssignmentDao;
00048
00050 var $maxAuthorCount;
00051
00053 var $maxReviewerCount;
00054
00056 var $maxEditorCount;
00057
00059 var $type;
00060
00062 var $sectionCache;
00063
00073 function JournalReportIterator($journalId, &$records, $dateStart, $dateEnd, $reportType) {
00074 $this->sectionDao =& DAORegistry::getDAO('SectionDAO');
00075 $this->articleDao =& DAORegistry::getDAO('ArticleDAO');
00076 $this->authorDao =& DAORegistry::getDAO('AuthorDAO');
00077 $this->authorSubmissionDao =& DAORegistry::getDAO('AuthorSubmissionDAO');
00078 $this->userDao =& DAORegistry::getDAO('UserDAO');
00079 $this->journalStatisticsDao =& DAORegistry::getDAO('JournalStatisticsDAO');
00080 $this->countryDao =& DAORegistry::getDAO('CountryDAO');
00081 $this->reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
00082 $this->editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
00083
00084 parent::DBRowIterator($records);
00085
00086 $this->type = $reportType;
00087
00088 $this->maxAuthorCount = $this->journalStatisticsDao->getMaxAuthorCount($journalId, $dateStart, $dateEnd);
00089 $this->maxReviewerCount = $this->journalStatisticsDao->getMaxReviewerCount($journalId, $dateStart, $dateEnd);
00090 if ($this->type !== REPORT_TYPE_EDITOR) {
00091 $this->maxEditorCount = $this->journalStatisticsDao->getMaxEditorCount($journalId, $dateStart, $dateEnd);
00092 }
00093 }
00094
00100 function &getSection($sectionId) {
00101 if (!isset($this->sectionCache[$sectionId])) {
00102 $this->sectionCache[$sectionId] =& $this->sectionDao->getSection($sectionId);
00103 }
00104 return $this->sectionCache[$sectionId];
00105 }
00106
00111 function &next() {
00112 $row =& parent::next();
00113 if ($row == null) return $row;
00114
00115 $ret = array(
00116 'articleId' => $row['article_id']
00117 );
00118
00119 $ret['dateSubmitted'] = $this->journalStatisticsDao->dateFromDB($row['date_submitted']);
00120
00121 $article =& $this->articleDao->getArticle($row['article_id']);
00122 $ret['title'] = $article->getArticleTitle();
00123
00124 $section =& $this->getSection($row['section_id']);
00125 $ret['section'] = $section->getSectionTitle();
00126
00127
00128 $maxAuthors = $this->getMaxAuthors();
00129 $ret['authors'] = $maxAuthors==0?array():array_fill(0, $maxAuthors, '');
00130 $ret['affiliations'] = $maxAuthors==0?array():array_fill(0, $maxAuthors, '');
00131 $ret['countries'] = $maxAuthors==0?array():array_fill(0, $maxAuthors, '');
00132 $authors =& $this->authorDao->getAuthorsByArticle($row['article_id']);
00133 $authorIndex = 0;
00134 foreach ($authors as $author) {
00135 $ret['authors'][$authorIndex] = $author->getFullName();
00136 $ret['affiliations'][$authorIndex] = $author->getAffiliation();
00137
00138 $country = $author->getCountry();
00139 if (!empty($country)) {
00140 $ret['countries'][$authorIndex] = $this->countryDao->getCountry($country);
00141 }
00142 $authorIndex++;
00143 }
00144
00145 if ($this->type === REPORT_TYPE_EDITOR) {
00146 $user = null;
00147 if ($row['editor_id']) $user =& $this->userDao->getUser($row['editor_id']);
00148 $ret['editor'] = $user?$user->getFullName():'';
00149 } else {
00150 $editAssignments =& $this->editAssignmentDao->getEditAssignmentsByArticleId($row['article_id']);
00151 $maxEditors = $this->getMaxEditors();
00152 $ret['editors'] = $maxEditors==0?array():array_fill(0, $maxEditors, '');
00153
00154 $editorIndex = 0;
00155 while ($editAssignment =& $editAssignments->next()) {
00156 $ret['editors'][$editorIndex++] = $editAssignment->getEditorFullName();
00157 }
00158 }
00159
00160
00161 $ratingOptions =& ReviewAssignment::getReviewerRatingOptions();
00162 if ($this->type === REPORT_TYPE_REVIEWER) {
00163 $user = null;
00164 if ($row['reviewer_id']) $user =& $this->userDao->getUser($row['reviewer_id']);
00165 $ret['reviewer'] = $user?$user->getFullName():'';
00166
00167 if ($row['quality']) {
00168 $ret['score'] = Locale::translate($ratingOptions[$row['quality']]);
00169 } else {
00170 $ret['score'] = '';
00171 }
00172 $ret['affiliation'] = $user?$user->getAffiliation():'';
00173 } else {
00174 $maxReviewers = $this->getMaxReviewers();
00175 $ret['reviewers'] = $maxReviewers==0?array():array_fill(0, $maxReviewers, '');
00176 $ret['scores'] = $maxReviewers==0?array():array_fill(0, $maxReviewers, '');
00177 $ret['recommendations'] = $maxReviewers==0?array():array_fill(0, $maxReviewers, '');
00178 $reviewAssignments =& $this->reviewAssignmentDao->getReviewAssignmentsByArticleId($row['article_id']);
00179 $reviewerIndex = 0;
00180 foreach ($reviewAssignments as $reviewAssignment) {
00181 $reviewerId = $reviewAssignment->getReviewerId();
00182 $ret['reviewers'][$reviewerIndex] = $reviewAssignment->getReviewerFullName();
00183 $rating = $reviewAssignment->getQuality();
00184 if ($rating != '') {
00185 $ret['scores'][$reviewerIndex] = Locale::translate($ratingOptions[$rating]);
00186 }
00187 $recommendation = $reviewAssignment->getRecommendation();
00188 if ($recommendation !== '' && $recommendation !== null) {
00189 $recommendationOptions =& $reviewAssignment->getReviewerRecommendationOptions();
00190 $ret['recommendations'][$reviewerIndex] = Locale::translate($recommendationOptions[$recommendation]);
00191 }
00192 $reviewerIndex++;
00193 }
00194 }
00195
00196
00197 $editorDecisions = $this->authorSubmissionDao->getEditorDecisions($row['article_id']);
00198 $lastDecision = array_pop($editorDecisions);
00199
00200 if ($lastDecision) {
00201 import('submission.sectionEditor.SectionEditorSubmission');
00202 $decisionOptions =& SectionEditorSubmission::getEditorDecisionOptions();
00203 $ret['decision'] = Locale::translate($decisionOptions[$lastDecision['decision']]);
00204 $ret['dateDecided'] = $lastDecision['dateDecided'];
00205
00206 $decisionTime = strtotime($lastDecision['dateDecided']);
00207 $submitTime = strtotime($ret['dateSubmitted']);
00208 if ($decisionTime === false || $decisionTime === -1 || $submitTime === false || $submitTime === -1) {
00209 $ret['daysToDecision'] = '';
00210 } else {
00211 $ret['daysToDecision'] = round(($decisionTime - $submitTime) / 3600 / 24);
00212 }
00213 } else {
00214 $ret['decision'] = '';
00215 $ret['daysToDecision'] = '';
00216 $ret['dateDecided'] = '';
00217 }
00218
00219 $ret['daysToPublication'] = '';
00220 if ($row['pub_id']) {
00221 $submitTime = strtotime($ret['dateSubmitted']);
00222 $publishTime = strtotime($this->journalStatisticsDao->dateFromDB($row['date_published']));
00223 if ($publishTime > $submitTime) {
00224
00225
00226
00227
00228 $ret['daysToPublication'] = round(($publishTime - $submitTime) / 3600 / 24);
00229 }
00230 }
00231
00232 $ret['status'] = $row['status'];
00233
00234 return $ret;
00235 }
00236
00241 function &nextWithKey() {
00242
00243
00244 return array(null, $this->next());
00245 }
00246
00247 function _cleanup() {
00248 parent::_cleanup();
00249 }
00250
00255 function getMaxAuthors() {
00256 return $this->maxAuthorCount;
00257 }
00258
00263 function getMaxReviewers() {
00264 return $this->maxReviewerCount;
00265 }
00266
00272 function getMaxEditors() {
00273 return $this->maxEditorCount;
00274 }
00275 }
00276
00277 ?>