plugins/reports/papers/PaperReportPlugin.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 //$Id$
00017 
00018 import('classes.plugins.ReportPlugin');
00019 
00020 class PaperReportPlugin extends ReportPlugin {
00027    function register($category, $path) {
00028       $success = parent::register($category, $path);
00029       if ($success) {
00030          $this->import('PaperReportDAO');
00031          $paperReportDAO = new PaperReportDAO();
00032          DAORegistry::registerDAO('PaperReportDAO', $paperReportDAO);
00033       }
00034       $this->addLocaleData();
00035       return $success;
00036    }
00037 
00043    function getName() {
00044       return 'PaperReportPlugin';
00045    }
00046 
00047    function getDisplayName() {
00048       return __('plugins.reports.papers.displayName');
00049    }
00050 
00051    function getDescription() {
00052       return __('plugins.reports.papers.description');
00053    }
00054 
00055    function display(&$args) {
00056       $conference =& Request::getConference();
00057       $schedConf =& Request::getSchedConf();
00058       AppLocale::requireComponents(array(LOCALE_COMPONENT_APPLICATION_COMMON, LOCALE_COMPONENT_PKP_SUBMISSION, LOCALE_COMPONENT_PKP_USER, LOCALE_COMPONENT_OCS_MANAGER));
00059 
00060       header('content-type: text/comma-separated-values; charset=utf-8');
00061       header('content-disposition: attachment; filename=report.csv');
00062 
00063       $paperReportDao =& DAORegistry::getDAO('PaperReportDAO');
00064       list($papersIterator, $authorsIterator, $decisionsIteratorsArray) = $paperReportDao->getPaperReport(
00065          $conference->getId(),
00066          $schedConf->getId()
00067       );
00068       $maxAuthors = $this->getMaxAuthorCount($authorsIterator);
00069       
00070       $decisions = array();
00071       foreach ($decisionsIteratorsArray as $decisionsIterator) {
00072          while ($row =& $decisionsIterator->next()) {
00073             $decisions[$row['paper_id']] = $row['decision'];
00074          }
00075       }
00076 
00077       AppLocale::requireComponents(array(LOCALE_COMPONENT_OCS_DIRECTOR));
00078       import('classes.paper.Paper');
00079       $decisionMessages = array(
00080          SUBMISSION_DIRECTOR_DECISION_INVITE => __('director.paper.decision.invitePresentation'),
00081          SUBMISSION_DIRECTOR_DECISION_ACCEPT => __('director.paper.decision.accept'),
00082          SUBMISSION_DIRECTOR_DECISION_PENDING_REVISIONS => __('director.paper.decision.pendingRevisions'),
00083          SUBMISSION_DIRECTOR_DECISION_DECLINE => __('director.paper.decision.decline'),
00084          null => __('plugins.reports.papers.nodecision')
00085       );
00086 
00087       $columns = array(
00088          'paper_id' => __('paper.submissionId'),
00089          'title' => __('paper.title'),
00090          'abstract' => __('paper.abstract'),
00091       );
00092       
00093       for ($a = 1; $a <= $maxAuthors; $a++) {
00094          $columns = array_merge($columns, array(
00095             'fname' . $a => __('user.firstName') . " (" . __('user.role.author') . " $a)",
00096             'mname' . $a => __('user.middleName') . " (" . __('user.role.author') . " $a)",
00097             'lname' . $a => __('user.lastName') . " (" . __('user.role.author') . " $a)",
00098             'country' . $a => __('common.country') . " (" . __('user.role.author') . " $a)",
00099             'affiliation' . $a => __('user.affiliation') . " (" . __('user.role.author') . " $a)",
00100             'email' . $a => __('user.email') . " (" . __('user.role.author') . " $a)",
00101             'url' . $a => __('user.url') . " (" . __('user.role.author') . " $a)",
00102             'biography' . $a => __('user.biography') . " (" . __('user.role.author') . " $a)"
00103          ));
00104       }
00105       
00106       $columns = array_merge($columns, array(
00107          'track_title' => __('track.title'),
00108          'language' => __('common.language'),
00109          'director_decision' => __('submission.directorDecision'),
00110          'start_time' => __('manager.scheduler.startTime'),
00111          'end_time' => __('manager.scheduler.endTime'),
00112          'building' => __('manager.scheduler.building'),
00113          'room' => __('manager.scheduler.room'),
00114          'status' => __('common.status')
00115       ));
00116 
00117       $fp = fopen('php://output', 'wt');
00118       String::fputcsv($fp, array_values($columns));
00119 
00120       import('paper.Paper'); // Bring in getStatusMap function
00121       $statusMap =& Paper::getStatusMap();
00122 
00123       $controlledVocabDao =& DAORegistry::getDAO('ControlledVocabDAO');
00124       $sessionTypes = $controlledVocabDao->enumerateBySymbolic('paperType', ASSOC_TYPE_SCHED_CONF, $schedConf->getId());
00125 
00126       // Load building and room data
00127       $buildingDao =& DAORegistry::getDAO('BuildingDAO');
00128       $roomDao =& DAORegistry::getDAO('RoomDAO');
00129 
00130       $buildings = $rooms = array();
00131       $buildingsIterator =& $buildingDao->getBuildingsBySchedConfId($schedConf->getId());
00132       while ($building =& $buildingsIterator->next()) {
00133          $buildingId = $building->getId();
00134          $buildings[$buildingId] =& $building;
00135          $roomsIterator =& $roomDao->getRoomsByBuildingId($buildingId);
00136          while ($room =& $roomsIterator->next()) {
00137             $roomId = $room->getId();
00138             $rooms[$roomId] =& $room;
00139             unset($room);
00140          }
00141          unset($building);
00142          unset($roomsIterator);
00143       }
00144       unset($buildingsIterator);
00145 
00146       $authorIndex = 0;
00147       while ($row =& $papersIterator->next()) {
00148          if (isset($authorsIterator[$row['paper_id']])) {
00149             $authorIterator =& $authorsIterator[$row['paper_id']];
00150             $authors = $this->mergeAuthors($authorIterator->toArray());
00151          } else {
00152             // No authors for a submission.
00153             $authors = array();
00154          }
00155          unset($authorIterator);
00156          foreach ($columns as $index => $junk) {
00157             if ($index == 'director_decision') {
00158                if (isset($decisions[$row['paper_id']])) {
00159                   $columns[$index] = $decisionMessages[$decisions[$row['paper_id']]];
00160                } else {
00161                   $columns[$index] = $decisionMessages[null];
00162                }
00163             } elseif ($index == 'status') {
00164                $columns[$index] = __($statusMap[$row[$index]]);
00165             } elseif ($index == 'abstract' || $index == 'title' || $index == 'affiliation') {
00166                $columns[$index] = html_entity_decode(strip_tags($row[$index]), ENT_QUOTES, 'UTF-8');
00167             } elseif ($index == 'start_time' || $index == 'end_time') {
00168                $columns[$index] = $row[$index];
00169             } elseif ($index == 'building') {
00170                $columns['building'] = '';
00171                $room =& $rooms[$row['room_id']];
00172                if ($room) {
00173                   $building =& $buildings[$room->getBuildingId()];
00174                   if ($building) $columns[$index] = $building->getBuildingName();
00175                }
00176                unset($room, $building);
00177             } elseif ($index == 'room') {
00178                $columns['room'] = '';
00179                $room =& $rooms[$row['room_id']];
00180                if ($room) $columns[$index] = $room->getRoomName();
00181                unset($room);
00182             } elseif (strstr($index, 'biography') !== false) {
00183                // "Convert" HTML to text for export
00184                $columns[$index] = isset($authors[$index])?html_entity_decode(strip_tags($authors[$index]), ENT_QUOTES, 'UTF-8'):'';
00185             } else {
00186                if (isset($row[$index])) {
00187                   $columns[$index] = $row[$index];
00188                } else if (isset($authors[$index])) {
00189                   $columns[$index] = $authors[$index];
00190                } else $columns[$index] = '';
00191             }
00192          }
00193          String::fputcsv($fp, $columns);
00194          $authorIndex++;
00195          unset($row);
00196       }
00197       
00198       fclose($fp);
00199    }
00200    
00206    function getMaxAuthorCount(&$authorsIterator) {
00207       $maxAuthors = 0;
00208       foreach ($authorsIterator as $authorIterator) {
00209          $maxAuthors = $authorIterator->getCount() > $maxAuthors ? $authorIterator->getCount() : $maxAuthors;
00210       }
00211       return $maxAuthors;
00212    }
00213    
00219    function mergeAuthors($authors) {
00220       $returner = array();
00221       $seq = 0;
00222       foreach($authors as $author) {
00223          $seq++;
00224          
00225          $returner['fname' . $seq] = isset($author['fname']) ? $author['fname'] : '';
00226          $returner['mname' . $seq] = isset($author['mname']) ? $author['mname'] : '';
00227          $returner['lname' . $seq] = isset($author['lname']) ? $author['lname'] : '';
00228          $returner['email' . $seq] = isset($author['email']) ? $author['email'] : '';
00229          $returner['affiliation' . $seq] = isset($author['affiliation']) ? $author['affiliation'] : '';
00230          $returner['country' . $seq] = isset($author['country']) ? $author['country'] : '';
00231          $returner['url' . $seq] = isset($author['url']) ? $author['url'] : '';
00232          $returner['biography' . $seq] = isset($author['biography']) ? $author['biography'] : '';
00233       }
00234       return $returner;
00235    }
00236 }
00237 
00238 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7