/** * Counter report as CSV */ function report() { $this->validate(); $plugin =& $this->plugin; $this->setupTemplate(true); $journal =& Request::getJournal(); $year = Request::getUserVar('year'); $begin = "{$year}-01-01"; $end = "{$year}-12-01"; $counterReportDao =& DAORegistry::getDAO('CounterReportDAO'); header('content-type: text/comma-separated-values'); header('content-disposition: attachment; filename=counter-' . date('Ymd') . '.csv'); $fp = fopen('php://output', 'wt'); String::fputcsv($fp, array(__('plugins.generic.counter.1a.title1'))); String::fputcsv($fp, array(__('plugins.generic.counter.1a.title2', array('year' => $year)))); String::fputcsv($fp, array()); // FIXME: Criteria should be here? String::fputcsv($fp, array(__('plugins.generic.counter.1a.dateRun'))); String::fputcsv($fp, array(strftime("%Y-%m-%d"))); $cols = array('', __('plugins.generic.counter.1a.publisher'), __('plugins.generic.counter.1a.platform'), __('plugins.generic.counter.1a.printIssn'), __('plugins.generic.counter.1a.onlineIssn')); for ($i = 1; $i <= 12; $i++) { $time = strtotime($year . '-' . $i . '-01'); strftime('%b', $time); $cols[] = strftime('%b-%Y', $time); } $cols[] = __('plugins.generic.counter.1a.ytdTotal'); $cols[] = __('plugins.generic.counter.1a.ytdHtml'); $cols[] = __('plugins.generic.counter.1a.ytdPdf'); fputcsv($fp, $cols); // Display the totals first $totals = $counterReportDao->getMonthlyTotalRange($begin, $end); $cols = array(__('plugins.generic.counter.1a.totalForAllJournals'), '-', '', '-', '-'); CounterHandler::_formColumns($cols, $totals); fputcsv($fp, $cols); // Get statistics from the log. $journalDao =& DAORegistry::getDAO('JournalDAO'); $journalIds = $counterReportDao->getJournalIds(); foreach ($journalIds as $journalId) { $journal =& $journalDao->getById($journalId); if (!$journal) { continue; } $entries = $counterReportDao->getMonthlyLogRange($journalId, $begin, $end); $cols = array($journal->getLocalizedTitle(), $journal->getSetting('publisherInstitution'), 'Open Journal Systems', $journal->getSetting('printIssn'), $journal->getSetting('onlineIssn')); CounterHandler::_formColumns($cols, $entries); fputcsv($fp, $cols); unset($journal, $entry); } fclose($fp); }
function clearLog() { list($plugin) = CounterHandler::validate(false); $logEntryDao =& DAORegistry::getDAO('LogEntryDAO'); $logEntryDao->clearLog(); Request::redirect(null, 'counter'); }