diff --git a/code/web/interface/themes/responsive/MaterialsRequest/dashboard.tpl b/code/web/interface/themes/responsive/MaterialsRequest/dashboard.tpl index 1dc87976c2..a1b0d76f73 100644 --- a/code/web/interface/themes/responsive/MaterialsRequest/dashboard.tpl +++ b/code/web/interface/themes/responsive/MaterialsRequest/dashboard.tpl @@ -7,7 +7,7 @@
-

{$statusStats.label}

{* No translation needed *} +

{$statusStats.label}

{* No translation needed *}
diff --git a/code/web/interface/themes/responsive/SideLoads/usage-graph.tpl b/code/web/interface/themes/responsive/SideLoads/usage-graph.tpl deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/code/web/services/API/UsageGraphs.php b/code/web/services/API/UsageGraphs.php index bd0b93307d..50f66b8b5d 100644 --- a/code/web/services/API/UsageGraphs.php +++ b/code/web/services/API/UsageGraphs.php @@ -1,34 +1,15 @@ assign('section', 'API'); - $interface->assign('showCSVExportButton', true); - $interface->assign('graphTitle', $title); - $this->assignGraphSpecificTitle($stat); - $this->getAndSetInterfaceDataSeries($stat, $instanceName); - $interface->assign('stat', $stat); - $interface->assign('propName', 'exportToCSV'); - $title = $interface->getVariable('graphTitle'); - $this->display('../Admin/usage-graph.tpl', $title); +class API_UsageGraphs extends Admin_AbstractUsageGraphs { + function launch(): void { + $this->launchGraph('API'); } - function getBreadcrumbs(): array - { + + function getBreadcrumbs(): array { $breadcrumbs = []; $breadcrumbs[] = new Breadcrumb('/Admin/Home', 'Administration Home'); $breadcrumbs[] = new Breadcrumb('/Admin/Home#system_reports', 'System Reports'); @@ -37,63 +18,11 @@ function getBreadcrumbs(): array return $breadcrumbs; } - function getActiveAdminSection(): string - { + function getActiveAdminSection(): string { return 'system_reports'; } - function canView(): bool - { - return UserAccount::userHasPermission([ - 'View Dashboards', - 'View System Reports', - ]); - } - - // note that this will only handle tables with one stat (as is needed for Summon usage data) - // to see a version that handle multpile stats, see the Admin/UsageGraphs.php implementation - public function buildCSV() { - global $interface; - $stat = $_REQUEST['stat']; - if (!empty($_REQUEST['instance'])) { - $instanceName = $_REQUEST['instance']; - } else { - $instanceName = ''; - } - $this->getAndSetInterfaceDataSeries($stat, $instanceName); - $dataSeries = $interface->getVariable('dataSeries'); - - $filename = "AspenAPIUsageData_{$stat}.csv"; - header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); - header("Cache-Control: no-store, no-cache, must-revalidate"); - header("Cache-Control: post-check=0, pre-check=0", false); - header("Pragma: no-cache"); - header('Content-Type: text/csv; charset=utf-8'); - header("Content-Disposition: attachment;filename={$filename}"); - $fp = fopen('php://output', 'w'); - - // builds the first row of the table in the CSV - column headers: Dates, and the title of the graph - fputcsv($fp, ['Dates', $stat]); - - // builds each subsequent data row - aka the column value - foreach ($dataSeries as $dataSerie) { - $data = $dataSerie['data']; - $numRows = count($data); - $dates = array_keys($data); - - if( empty($numRows)) { - fputcsv($fp, ['no data found!']); - } - for($i = 0; $i < $numRows; $i++) { - $date = $dates[$i]; - $value = $data[$date]; - $row = [$date, $value]; - fputcsv($fp, $row); - } - } - exit(); - } - private function getAndSetInterfaceDataSeries($stat, $instanceName) { + protected function getAndSetInterfaceDataSeries($stat, $instanceName): void { global $interface; $dataSeries = []; @@ -108,11 +37,7 @@ private function getAndSetInterfaceDataSeries($stat, $instanceName) { $usage->selectAdd('year'); $usage->selectAdd('month'); $usage->orderBy('year, month'); - $dataSeries[$stat] = [ - 'borderColor' => 'rgba(255, 99, 132, 1)', - 'backgroundColor' => 'rgba(255, 99, 132, 0.2)', - 'data' => [], - ]; + $dataSeries[$stat] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $usage->selectAdd('SUM(numCalls) as numCalls'); //Collect results @@ -130,8 +55,7 @@ private function getAndSetInterfaceDataSeries($stat, $instanceName) { $interface->assign('translateColumnLabels', false); } - private function assignGraphSpecificTitle($stat) - { + protected function assignGraphSpecificTitle($stat): void { global $interface; $title = 'Aspen Discovery API Usage Graph'; $title .= " - $stat"; diff --git a/code/web/services/Admin/AJAX.php b/code/web/services/Admin/AJAX.php index 57071fd580..59b4c11394 100644 --- a/code/web/services/Admin/AJAX.php +++ b/code/web/services/Admin/AJAX.php @@ -1679,5 +1679,6 @@ public function exportUsageData() { require_once ROOT_DIR . '/services/Admin/UsageGraphs.php'; $aspenUsageGraph = new Admin_UsageGraphs(); $aspenUsageGraph->buildCSV(); + } } \ No newline at end of file diff --git a/code/web/services/Admin/AbstractUsageGraphs.php b/code/web/services/Admin/AbstractUsageGraphs.php new file mode 100644 index 0000000000..3726e746c7 --- /dev/null +++ b/code/web/services/Admin/AbstractUsageGraphs.php @@ -0,0 +1,105 @@ +assign('stat', $stat); + $interface->assign('section', $sectionName); + $interface->assign('subSection', $subSectionName); + $interface->assign('graphTitle', $sectionTitle); + $interface->assign('showCSVExportButton', true); + $interface->assign('propName', 'exportToCSV'); + + $this->assignGraphSpecificTitle($stat); + $this->getAndSetInterfaceDataSeries($stat, $instanceName); + + $graphTitle = $interface->getVariable('graphTitle'); + $this->display('../Admin/usage-graph.tpl', $graphTitle); + } + + public function canView(): bool { + return UserAccount::userHasPermission([ + 'View Dashboards', + 'View System Reports', + ]); + } + + public function buildCSV(string $section): void { + global $interface; + + $stat = $_REQUEST['stat']; + if (!empty($_REQUEST['instance'])) { + $instanceName = $_REQUEST['instance']; + } else { + $instanceName = ''; + } + $this->getAndSetInterfaceDataSeries($stat, $instanceName); + $dataSeries = $interface->getVariable('dataSeries'); + + // ensures csv filename contains dashboard subsection name if relevant + $subSectionName = str_replace(' ', '_', $_REQUEST['subSection']); + $filename = $section . '_'; + if (!empty($subSectionName)) { + $filename .= $subSectionName . '_'; + } + $filename .= 'UsageData_' . $stat . '.csv'; + + // sets up the csv file + header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); + header("Cache-Control: no-store, no-cache, must-revalidate"); + header("Cache-Control: post-check=0, pre-check=0", false); + header("Pragma: no-cache"); + header('Content-Type: text/csv; charset=utf-8'); + header("Content-Disposition: attachment;filename={$filename}"); + $fp = fopen('php://output', 'w'); + + // builds the file content + $graphTitles = array_keys($dataSeries); + $numGraphTitles = count($dataSeries); + + for($i = 0; $i < $numGraphTitles; $i++) { + // builds the header for each section of the table in the CSV - column headers: Dates, and the title of the graph + $dataSerie = $dataSeries[$graphTitles[$i]]; + $numRows = count($dataSerie['data']); + $dates = array_keys($dataSerie['data']); + $header = ['Dates', $graphTitles[$i]]; + fputcsv($fp, $header); + + // builds each subsequent data row - aka the column value + if (empty($numRows)) { + fputcsv($fp, ['no data found']); + } + for($j = 0; $j < $numRows; $j++) { + $date = $dates[$j]; + $value = $dataSerie['data'][$date]; + $row = [$date, $value]; + fputcsv($fp, $row); + } + } + exit(); + } +} \ No newline at end of file diff --git a/code/web/services/Admin/UsageGraphs.php b/code/web/services/Admin/UsageGraphs.php index 89eaf25eb9..6fdb7723f9 100644 --- a/code/web/services/Admin/UsageGraphs.php +++ b/code/web/services/Admin/UsageGraphs.php @@ -1,30 +1,14 @@ assign('section', 'Admin'); - $interface->assign('showCSVExportButton', true); - $interface->assign('graphTitle', $title); - $this->assignGraphSpecificTitle($stat); - $this->getAndSetInterfaceDataSeries($stat, $instanceName); - $interface->assign('stat', $stat); - $interface->assign('propName', 'exportToCSV'); - $title = $interface->getVariable('graphTitle'); - $this->display('usage-graph.tpl', $title); +class Admin_UsageGraphs extends Admin_AbstractUsageGraphs { + function launch(): void { + $this->launchGraph('Admin'); // could refactor to extract the section name ('Admin') from the URL within UsageGraphs_UsageGraphs::launch() itself } + function getBreadcrumbs(): array { $breadcrumbs = []; $breadcrumbs[] = new Breadcrumb('/Admin/Home', 'Administration Home'); @@ -38,58 +22,7 @@ function getActiveAdminSection(): string { return 'system_reports'; } - function canView(): bool { - return UserAccount::userHasPermission([ - 'View Dashboards', - 'View System Reports', - ]); - } - - public function buildCSV() { - global $interface; - - $stat = $_REQUEST['stat']; - if (!empty($_REQUEST['instance'])) { - $instanceName = $_REQUEST['instance']; - } else { - $instanceName = ''; - } - $this->getAndSetInterfaceDataSeries($stat, $instanceName); - $dataSeries = $interface->getVariable('dataSeries'); - - $filename = "AspenUsageData_{$stat}.csv"; - header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); - header("Cache-Control: no-store, no-cache, must-revalidate"); - header("Cache-Control: post-check=0, pre-check=0", false); - header("Pragma: no-cache"); - header('Content-Type: text/csv; charset=utf-8'); - header("Content-Disposition: attachment;filename={$filename}"); - $fp = fopen('php://output', 'w'); - $graphTitles = array_keys($dataSeries); - $numGraphTitles = count($dataSeries); - - // builds the header for each section of the table in the CSV - column headers: Dates, and the title of the graph - for($i = 0; $i < $numGraphTitles; $i++) { - $dataSerie = $dataSeries[$graphTitles[$i]]; - $numRows = count($dataSerie['data']); - $dates = array_keys($dataSerie['data']); - $header = ['Dates', $graphTitles[$i]]; - fputcsv($fp, $header); - - if( empty($numRows)) { - fputcsv($fp, ['no data found!']); - } - // builds each subsequent data row - aka the column value - for($j = 0; $j < $numRows; $j++) { - $date = $dates[$j]; - $value = $dataSerie['data'][$date]; - $row = [$date, $value]; - fputcsv($fp, $row); - } - } - exit(); - } - private function getAndSetInterfaceDataSeries($stat, $instanceName) { + protected function getAndSetInterfaceDataSeries($stat, $instanceName): void { global $interface; global $enabledModules; global $library; @@ -108,183 +41,95 @@ private function getAndSetInterfaceDataSeries($stat, $instanceName) { //General Usage Stats if ($stat == 'pageViews' || $stat == 'generalUsage') { - $dataSeries['Page Views'] = [ - 'borderColor' => 'rgba(255, 99, 132, 1)', - 'backgroundColor' => 'rgba(255, 99, 132, 0.2)', - 'data' => [], - ]; + $dataSeries['Page Views'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(pageViews) as sumPageViews'); } if ($stat == 'authenticatedPageViews' || $stat == 'generalUsage') { - $dataSeries['Authenticated Page Views'] = [ - 'borderColor' => 'rgba(255, 159, 64, 1)', - 'backgroundColor' => 'rgba(255, 159, 64, 0.2)', - 'data' => [], - ]; + $dataSeries['Authenticated Page Views'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(pageViewsByAuthenticatedUsers) as sumPageViewsByAuthenticatedUsers'); } if ($stat == 'sessionsStarted' || $stat == 'generalUsage') { - $dataSeries['Sessions Started'] = [ - 'borderColor' => 'rgba(0, 255, 55, 1)', - 'backgroundColor' => 'rgba(0, 255, 55, 0.2)', - 'data' => [], - ]; + $dataSeries['Sessions Started'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(sessionsStarted) as sumSessionsStarted'); } if ($stat == 'pageViewsByBots' || $stat == 'generalUsage') { - $dataSeries['Page Views By Bots'] = [ - 'borderColor' => 'rgba(154, 75, 244, 1)', - 'backgroundColor' => 'rgba(154, 75, 244, 0.2)', - 'data' => [], - ]; + $dataSeries['Page Views By Bots'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(pageViewsByBots) as sumPageViewsByBots'); } if ($stat == 'asyncRequests' || $stat == 'generalUsage') { - $dataSeries['Asynchronous Requests'] = [ - 'borderColor' => 'rgba(54, 162, 235, 1)', - 'backgroundColor' => 'rgba(54, 162, 235, 0.2)', - 'data' => [], - ]; + $dataSeries['Asynchronous Requests'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(ajaxRequests) as sumAjaxRequests'); } if ($stat == 'coversRequested' || $stat == 'generalUsage') { - $dataSeries['Covers Requested'] = [ - 'borderColor' => 'rgba(255, 206, 86, 1)', - 'backgroundColor' => 'rgba(255, 206, 86, 0.2)', - 'data' => [], - ]; + $dataSeries['Covers Requested'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(coverViews) as sumCoverViews'); } //Search Stats if ($stat == 'groupedWorksSearches' || $stat == 'searches') { - $dataSeries['Grouped Work Searches'] = [ - 'borderColor' => 'rgba(255, 99, 132, 1)', - 'backgroundColor' => 'rgba(255, 99, 132, 0.2)', - 'data' => [], - ]; + $dataSeries['Grouped Work Searches'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(groupedWorkSearches) as sumGroupedWorkSearches'); } if ($stat == 'listSearches' || $stat == 'searches') { - $dataSeries['List Searches'] = [ - 'borderColor' => 'rgba(54, 162, 235, 1)', - 'backgroundColor' => 'rgba(54, 162, 235, 0.2)', - 'data' => [], - ]; + $dataSeries['List Searches'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(userListSearches) as sumUserListSearches'); } if (array_key_exists('EBSCO EDS', $enabledModules) && ($stat == 'edsSearches' || $stat == 'searches')) { - $dataSeries['EDS Searches'] = [ - 'borderColor' => 'rgba(255, 206, 86, 1)', - 'backgroundColor' => 'rgba(255, 206, 86, 0.2)', - 'data' => [], - ]; + $dataSeries['EDS Searches'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(ebscoEdsSearches) as sumEbscoEdsSearches'); } if (array_key_exists('EBSCOhost', $enabledModules) && ($stat == 'ebscohostSearches' || $stat == 'searches')) { - $dataSeries['EBSCOhost Searches'] = [ - 'borderColor' => 'rgba(255, 206, 86, 1)', - 'backgroundColor' => 'rgba(255, 206, 86, 0.2)', - 'data' => [], - ]; + $dataSeries['EBSCOhost Searches'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(ebscohostSearches) as sumEbscohostSearches'); } if (array_key_exists('Events', $enabledModules) && ($stat == 'eventSearches' || $stat == 'searches')) { - $dataSeries['Events Searches'] = [ - 'borderColor' => 'rgba(75, 192, 192, 1)', - 'backgroundColor' => 'rgba(75, 192, 192, 0.2)', - 'data' => [], - ]; + $dataSeries['Events Searches'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(eventsSearches) as sumEventsSearches'); } if ((array_key_exists('Web Indexer', $enabledModules) || array_key_exists('Web Builder', $enabledModules)) && ($stat == 'websiteSearches' || $stat == 'searches')) { - $dataSeries['Website Searches'] = [ - 'borderColor' => 'rgba(153, 102, 255, 1)', - 'backgroundColor' => 'rgba(153, 102, 255, 0.2)', - 'data' => [], - ]; + $dataSeries['Website Searches'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(websiteSearches) as sumWebsiteSearches'); } if (array_key_exists('Open Archives', $enabledModules) && ($stat == 'openArchivesSearches' || $stat == 'searches')) { - $dataSeries['Open Archives Searches'] = [ - 'borderColor' => 'rgba(255, 159, 64, 1)', - 'backgroundColor' => 'rgba(255, 159, 64, 0.2)', - 'data' => [], - ]; + $dataSeries['Open Archives Searches'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(openArchivesSearches) as sumOpenArchivesSearches'); } if ($library->enableGenealogy && ($stat == 'genealogySearches' || $stat == 'searches')) { - $dataSeries['Genealogy Searches'] = [ - 'borderColor' => 'rgba(154, 75, 244, 1)', - 'backgroundColor' => 'rgba(2154, 75, 244, 0.2)', - 'data' => [], - ]; + $dataSeries['Genealogy Searches'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(genealogySearches) as sumGenealogySearches'); } //Exceptions if ($stat == 'blockedPages' || $stat == 'exceptionsReport') { - $dataSeries['Blocked Pages'] = [ - 'borderColor' => 'rgba(255, 99, 132, 1)', - 'backgroundColor' => 'rgba(255, 99, 132, 0.2)', - 'data' => [], - ]; + $dataSeries['Blocked Pages'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(blockedRequests) as sumBlockedRequests'); } if ($stat == 'blockedApiRequests' || $stat == 'exceptionsReport') { - $dataSeries['Blocked API Requests'] = [ - 'borderColor' => 'rgba(255, 159, 64, 1)', - 'backgroundColor' => 'rgba(255, 159, 64, 0.2)', - 'data' => [], - ]; + $dataSeries['Blocked API Requests'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(blockedApiRequests) as sumBlockedApiRequests'); } if ($stat == 'errors' || $stat == 'exceptionsReport') { - $dataSeries['Errors'] = [ - 'borderColor' => 'rgba(154, 75, 244, 1)', - 'backgroundColor' => 'rgba(154, 75, 244, 0.2)', - 'data' => [], - ]; + $dataSeries['Errors'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(pagesWithErrors) as sumPagesWithErrors'); } if ($stat == 'searchesWithErrors' || $stat == 'exceptionsReport') { - $dataSeries['Searches with Errors'] = [ - 'borderColor' => 'rgba(154, 10, 120, 1)', - 'backgroundColor' => 'rgba(154, 10, 120, 0.2)', - 'data' => [], - ]; + $dataSeries['Searches with Errors'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(searchesWithErrors) as sumSearchesWithErrors'); } if ($stat == 'timedOutSearches' || $stat == 'exceptionsReport') { - $dataSeries['Timed Out Searches'] = [ - 'borderColor' => 'rgba(120, 10 244, 1)', - 'backgroundColor' => 'rgba(120, 10, 244, 0.2)', - 'data' => [], - ]; + $dataSeries['Timed Out Searches'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(timedOutSearches) as sumTimedOutSearches'); } if ($stat == 'timedOutSearchesWithHighLoad' || $stat == 'exceptionsReport') { - $dataSeries['Timed Out Searches Under High Load'] = [ - 'borderColor' => 'rgba(10, 120, 244, 1)', - 'backgroundColor' => 'rgba(10, 120, 244, 0.2)', - 'data' => [], - ]; + $dataSeries['Timed Out Searches Under High Load'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(timedOutSearchesWithHighLoad) as sumTimedOutSearchesWithHighLoad'); } if ($stat == 'emailsSent' || $stat == 'emailSending') { - $dataSeries['Emails Sent'] = [ - 'borderColor' => 'rgba(120, 10 244, 1)', - 'backgroundColor' => 'rgba(120, 10, 244, 0.2)', - 'data' => [], - ]; + $dataSeries['Emails Sent'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(emailsSent) as sumEmailsSent'); } if ($stat == 'failedEmails' || $stat == 'emailSending') { - $dataSeries['Failed Emails'] = [ - 'borderColor' => 'rgba(154, 10, 120, 1)', - 'backgroundColor' => 'rgba(154, 10, 120, 0.2)', - 'data' => [], - ]; + $dataSeries['Failed Emails'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userUsage->selectAdd('SUM(emailsFailed) as sumFailedEmails'); } @@ -390,7 +235,7 @@ private function getAndSetInterfaceDataSeries($stat, $instanceName) { $interface->assign('translateColumnLabels', false); } - private function assignGraphSpecificTitle($stat) { + protected function assignGraphSpecificTitle(string $stat): void { global $interface; $title = $interface->getVariable('graphTitle'); switch ($stat) { diff --git a/code/web/services/Axis360/AJAX.php b/code/web/services/Axis360/AJAX.php index a049409115..7dab8490a8 100644 --- a/code/web/services/Axis360/AJAX.php +++ b/code/web/services/Axis360/AJAX.php @@ -489,9 +489,9 @@ function getLargeCover() { ]; } - public function exportUsageData() { + public function exportUsageData(): void { require_once ROOT_DIR . '/services/Axis360/UsageGraphs.php'; $axis360UsageGraph = new Axis360_UsageGraphs(); - $axis360UsageGraph->buildCSV(); + $axis360UsageGraph->buildCSV('Boundless'); } } \ No newline at end of file diff --git a/code/web/services/Axis360/UsageGraphs.php b/code/web/services/Axis360/UsageGraphs.php index 2636a6141f..a27efa397f 100644 --- a/code/web/services/Axis360/UsageGraphs.php +++ b/code/web/services/Axis360/UsageGraphs.php @@ -1,31 +1,14 @@ assign('graphTitle', $title); - $this->assignGraphSpecificTitle($stat); - $this->getAndSetInterfaceDataSeries($stat, $instanceName); - $interface->assign('stat', $stat); - $interface->assign('propName', 'exportToCSV'); - $interface->assign('showCSVExportButton', true); - $interface->assign('section', 'Axis360'); - - $this->display('../Admin/usage-graph.tpl', $title); +class Axis360_UsageGraphs extends Admin_AbstractUsageGraphs { + function launch(): void { + $this->launchGraph('Boundless'); } function getBreadcrumbs(): array { @@ -48,52 +31,7 @@ function canView(): bool { ]); } - public function buildCSV() { - global $interface; - - $stat = $_REQUEST['stat']; - if (!empty($_REQUEST['instance'])) { - $instanceName = $_REQUEST['instance']; - } else { - $instanceName = ''; - } - $this->getAndSetInterfaceDataSeries($stat, $instanceName); - $dataSeries = $interface->getVariable('dataSeries'); - - $filename = "BoundlessUsageData_{$stat}.csv"; - header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); - header("Cache-Control: no-store, no-cache, must-revalidate"); - header("Cache-Control: post-check=0, pre-check=0", false); - header("Pragma: no-cache"); - header('Content-Type: text/csv; charset=utf-8'); - header("Content-Disposition: attachment;filename={$filename}"); - $fp = fopen('php://output', 'w'); - $graphTitles = array_keys($dataSeries); - $numGraphTitles = count($dataSeries); - - // builds the header for each section of the table in the CSV - column headers: Dates, and the title of the graph - for($i = 0; $i < $numGraphTitles; $i++) { - $dataSerie = $dataSeries[$graphTitles[$i]]; - $numRows = count($dataSerie['data']); - $dates = array_keys($dataSerie['data']); - $header = ['Dates', $graphTitles[$i]]; - fputcsv($fp, $header); - - if( empty($numRows)) { - fputcsv($fp, ['no data found!']); - } - // builds each subsequent data row - aka the column value - for($j = 0; $j < $numRows; $j++) { - $date = $dates[$j]; - $value = $dataSerie['data'][$date]; - $row = [$date, $value]; - fputcsv($fp, $row); - } - } - exit(); - } - - private function getAndSetInterfaceDataSeries($stat, $instanceName) { + protected function getAndSetInterfaceDataSeries($stat, $instanceName): void { global $interface; $dataSeries = []; $columnLabels = []; @@ -270,7 +208,7 @@ private function getAndSetInterfaceDataSeries($stat, $instanceName) { $interface->assign('translateColumnLabels', false); } - private function assignGraphSpecificTitle($stat) { + protected function assignGraphSpecificTitle($stat): void { global $interface; $title = $interface->getVariable('graphTitle'); switch ($stat) { diff --git a/code/web/services/ILS/AJAX.php b/code/web/services/ILS/AJAX.php index a0c67d2695..594f670335 100644 --- a/code/web/services/ILS/AJAX.php +++ b/code/web/services/ILS/AJAX.php @@ -1,9 +1,9 @@ buildCSV(); + $ILSUsageGraph->buildCSV('ILS'); } } \ No newline at end of file diff --git a/code/web/services/ILS/UsageGraphs.php b/code/web/services/ILS/UsageGraphs.php index 05c1b78fc2..4105551650 100644 --- a/code/web/services/ILS/UsageGraphs.php +++ b/code/web/services/ILS/UsageGraphs.php @@ -1,28 +1,14 @@ assign('graphTitle', $title); - $interface->assign('section', 'ILS'); - $interface->assign('showCSVExportButton', true); - $this->assignGraphSpecificTitle($stat); - $this->getAndSetInterfaceDataSeries($stat, $instanceName); - $interface->assign('stat', $stat); - $this->display('../Admin/usage-graph.tpl', $title); +class ILS_UsageGraphs extends Admin_AbstractUsageGraphs { + function launch(): void { + $this->launchGraph('ILS'); } function getBreadcrumbs(): array { @@ -45,51 +31,7 @@ function canView(): bool { ]); } - // note that this will only handle tables with one stat (as is needed for Summon usage data) - // to see a version that handle multpile stats, see the Admin/UsageGraphs.php implementation - public function buildCSV() { - global $interface; - $stat = $_REQUEST['stat']; - if (!empty($_REQUEST['instance'])) { - $instanceName = $_REQUEST['instance']; - } else { - $instanceName = ''; - } - $this->getAndSetInterfaceDataSeries($stat, $instanceName); - $dataSeries = $interface->getVariable('dataSeries'); - - $filename = "ILSUsageData_{$stat}.csv"; - header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); - header("Cache-Control: no-store, no-cache, must-revalidate"); - header("Cache-Control: post-check=0, pre-check=0", false); - header("Pragma: no-cache"); - header('Content-Type: text/csv; charset=utf-8'); - header("Content-Disposition: attachment;filename={$filename}"); - $fp = fopen('php://output', 'w'); - - // builds the first row of the table in the CSV - column headers: Dates, and the title of the graph - fputcsv($fp, ['Dates', $stat]); - - // builds each subsequent data row - aka the column value - foreach ($dataSeries as $dataSerie) { - $data = $dataSerie['data']; - $numRows = count($data); - $dates = array_keys($data); - - if( empty($numRows)) { - fputcsv($fp, ['no data found!']); - } - for($i = 0; $i < $numRows; $i++) { - $date = $dates[$i]; - $value = $data[$date]; - $row = [$date, $value]; - fputcsv($fp, $row); - } - } - exit(); - } - - private function getAndSetInterfaceDataSeries($stat, $instanceName) { + protected function getAndSetInterfaceDataSeries($stat, $instanceName): void { global $interface; $dataSeries = []; $columnLabels = []; @@ -114,51 +56,27 @@ private function getAndSetInterfaceDataSeries($stat, $instanceName) { $userILSUsage->orderBy('year, month'); if ($stat == 'userLogins') { - $dataSeries['User Logins'] = [ - 'borderColor' => 'rgba(255, 99, 132, 1)', - 'backgroundColor' => 'rgba(255, 99, 132, 0.2)', - 'data' => [], - ]; + $dataSeries['User Logins'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userILSUsage->selectAdd('SUM(usageCount) as sumUserLogins'); } if ($stat == 'selfRegistrations') { - $dataSeries['Self Registrations'] = [ - 'borderColor' => 'rgba(255, 159, 64, 1)', - 'backgroundColor' => 'rgba(255, 159, 64, 0.2)', - 'data' => [], - ]; + $dataSeries['Self Registrations'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userILSUsage->selectAdd('SUM(selfRegistrationCount) as sumSelfRegistrations'); } if ($stat == 'usersWithPdfDownloads') { - $dataSeries['Users Who Downloaded At Least One PDF'] = [ - 'borderColor' => 'rgba(255, 206, 86, 1)', - 'backgroundColor' => 'rgba(255, 206, 86, 0.2)', - 'data' => [], - ]; + $dataSeries['Users Who Downloaded At Least One PDF'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userILSUsage->selectAdd('SUM(IF(pdfDownloadCount>0,1,0)) as usersWithPdfDownloads'); } if ($stat == 'usersWithPdfViews') { - $dataSeries['Users Who Viewed At Least One PDF'] = [ - 'borderColor' => 'rgba(255, 206, 86, 1)', - 'backgroundColor' => 'rgba(255, 206, 86, 0.2)', - 'data' => [], - ]; + $dataSeries['Users Who Viewed At Least One PDF'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userILSUsage->selectAdd('SUM(IF(pdfViewCount>0,1,0)) as usersWithPdfViews'); } if ($stat == 'usersWithSupplementalFileDownloads') { - $dataSeries['Users Who Downloaded At Least One Supplemental File'] = [ - 'borderColor' => 'rgba(255, 206, 86, 1)', - 'backgroundColor' => 'rgba(255, 206, 86, 0.2)', - 'data' => [], - ]; + $dataSeries['Users Who Downloaded At Least One Supplemental File'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userILSUsage->selectAdd('SUM(IF(supplementalFileDownloadCount>0,1,0)) as usersWithSupplementalFileDownloads'); } if ($stat == 'usersWithHolds') { - $dataSeries['Users Who Placed At Least One Hold'] = [ - 'borderColor' => 'rgba(0, 255, 55, 1)', - 'backgroundColor' => 'rgba(0, 255, 55, 0.2)', - 'data' => [], - ]; + $dataSeries['Users Who Placed At Least One Hold'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userILSUsage->selectAdd('SUM(IF(usageCount>0,1,0)) as usersWithHolds'); } @@ -214,43 +132,23 @@ private function getAndSetInterfaceDataSeries($stat, $instanceName) { $recordILSUsage->orderBy('year, month'); if ($stat == 'pdfsDownloaded') { - $dataSeries['PDFs Downloaded'] = [ - 'borderColor' => 'rgba(255, 206, 86, 1)', - 'backgroundColor' => 'rgba(255, 206, 86, 0.2)', - 'data' => [], - ]; + $dataSeries['PDFs Downloaded'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $recordILSUsage->selectAdd('SUM(pdfDownloadCount) as sumPdfsDownloaded'); } if ($stat == 'pdfsViewed') { - $dataSeries['PDFs Viewed'] = [ - 'borderColor' => 'rgba(255, 206, 86, 1)', - 'backgroundColor' => 'rgba(255, 206, 86, 0.2)', - 'data' => [], - ]; + $dataSeries['PDFs Viewed'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $recordILSUsage->selectAdd('SUM(pdfViewCount) as sumPdfsViewed'); } if ($stat == 'supplementalFilesDownloaded') { - $dataSeries['Supplemental Files Downloaded'] = [ - 'borderColor' => 'rgba(255, 206, 86, 1)', - 'backgroundColor' => 'rgba(255, 206, 86, 0.2)', - 'data' => [], - ]; + $dataSeries['Supplemental Files Downloaded'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $recordILSUsage->selectAdd('SUM(supplementalFileDownloadCount) as sumSupplementalFilesDownloaded'); } if ($stat == 'recordsHeld') { - $dataSeries['Records Held'] = [ - 'borderColor' => 'rgba(154, 75, 244, 1)', - 'backgroundColor' => 'rgba(154, 75, 244, 0.2)', - 'data' => [], - ]; + $dataSeries['Records Held'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $recordILSUsage->selectAdd('SUM(IF(timesUsed>0,1,0)) as numRecordsUsed'); } if ($stat == 'totalHolds') { - $dataSeries['Total Holds'] = [ - 'borderColor' => 'rgba(54, 162, 235, 1)', - 'backgroundColor' => 'rgba(54, 162, 235, 0.2)', - 'data' => [], - ]; + $dataSeries['Total Holds'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $recordILSUsage->selectAdd('SUM(timesUsed) as totalHolds'); } @@ -288,7 +186,7 @@ private function getAndSetInterfaceDataSeries($stat, $instanceName) { $interface->assign('translateColumnLabels', false); } - private function assignGraphSpecificTitle($stat) { + protected function assignGraphSpecificTitle($stat): void { global $interface; $title = $interface->getVariable('graphTitle'); switch ($stat) { diff --git a/code/web/services/MaterialsRequest/AJAX.php b/code/web/services/MaterialsRequest/AJAX.php index 3dfddfe241..ee5f48cc9d 100644 --- a/code/web/services/MaterialsRequest/AJAX.php +++ b/code/web/services/MaterialsRequest/AJAX.php @@ -497,4 +497,10 @@ function selectHoldCandidate() : array { function getBreadcrumbs(): array { return []; } + + public function exportUsageData(): void { + require_once ROOT_DIR . '/services/MaterialsRequest/UsageGraphs.php'; + $MaterialsRequestUsageGraph = new MaterialsRequest_UsageGraphs(); + $MaterialsRequestUsageGraph->buildCSV('MaterialsRequest'); + } } \ No newline at end of file diff --git a/code/web/services/MaterialsRequest/Graph.php b/code/web/services/MaterialsRequest/Graph.php deleted file mode 100644 index 8580123c04..0000000000 --- a/code/web/services/MaterialsRequest/Graph.php +++ /dev/null @@ -1,160 +0,0 @@ -assign('curStatus', $status); - - $dataSeries = []; - $columnLabels = []; - - $userHomeLibrary = Library::getPatronHomeLibrary(); - if (is_null($userHomeLibrary)) { - //User does not have a home library, this is likely an admin account. Use the active library - global $library; - $userHomeLibrary = $library; - } - $libraryId = $userHomeLibrary->libraryId; - - $thisStatus = new MaterialsRequestStatus(); - $thisStatus->id = $status; - $thisStatus->libraryId = $libraryId; - $thisStatus->find(); - while ($thisStatus->fetch()) { - $title = 'Materials Request Usage Graph - ' . $thisStatus->description; - $materialsRequestUsage = new MaterialsRequestUsage(); - $materialsRequestUsage->groupBy('year, month'); - $materialsRequestUsage->selectAdd(); - $materialsRequestUsage->statusId = $status; - $materialsRequestUsage->selectAdd('year'); - $materialsRequestUsage->selectAdd('month'); - $materialsRequestUsage->selectAdd('SUM(numUsed) as numUsed'); - $materialsRequestUsage->orderBy('year, month'); - - $dataSeries[$thisStatus->description] = [ - 'borderColor' => 'rgba(255, 99, 132, 1)', - 'backgroundColor' => 'rgba(255, 99, 132, 0.2)', - 'data' => [], - ]; - - //Collect results - $materialsRequestUsage->find(); - - while ($materialsRequestUsage->fetch()) { - $curPeriod = "{$materialsRequestUsage->month}-{$materialsRequestUsage->year}"; - $columnLabels[] = $curPeriod; - $dataSeries[$thisStatus->description]['data'][$curPeriod] = $materialsRequestUsage->numUsed; - } - } - $interface->assign('columnLabels', $columnLabels); - $interface->assign('dataSeries', $dataSeries); - $interface->assign('graphTitle', $title); - $interface->assign('translateDataSeries', true); - $interface->assign('translateColumnLabels', false); - - //Check to see if we are exporting to Excel - if (isset($_REQUEST['exportToExcel'])) { - $this->exportToExcel(); - } - - $this->display('graph.tpl', $title); - } - - public function getAllPeriods() { - $usage = new MaterialsRequestUsage(); - $usage->selectAdd(null); - $usage->selectAdd('DISTINCT year, month'); - $usage->find(); - - $stats = []; - while ($usage->fetch()) { - $stats[$usage->month . '-' . $usage->year]['year'] = $usage->year; - $stats[$usage->month . '-' . $usage->year]['month'] = $usage->month; - } - return $stats; - } - - function exportToExcel() { - $status = $_REQUEST['status']; - - $periods = $this->getAllPeriods(); - - header('Content-Type: text/csv; charset=utf-8'); - header('Content-Disposition: attachment;filename="MaterialsRequestGraphReport.csv"'); - header('Cache-Control: max-age=0'); - $fp = fopen('php://output', 'w'); - - $header= ['Date', 'Requests Pending']; - fputcsv($fp, $header); - - $userHomeLibrary = Library::getPatronHomeLibrary(); - if (is_null($userHomeLibrary)) { - //User does not have a home library, this is likely an admin account. Use the active library - global $library; - $userHomeLibrary = $library; - } - $libraryId = $userHomeLibrary->libraryId; - - $thisStatus = new MaterialsRequestStatus(); - $thisStatus->libraryId = $libraryId; - $thisStatus->find(); - - foreach ($periods as $period) { - $materialsRequestUsage = new MaterialsRequestUsage(); - $materialsRequestUsage->year = $period['year']; - $materialsRequestUsage->month = $period['month']; - $materialsRequestUsage->statusId = $status; - $materialsRequestUsage->find(); - - $row = []; - $date = "{$materialsRequestUsage->month}-{$materialsRequestUsage->year}"; - $row[] = $date; - - $thisStatus = new MaterialsRequestStatus(); - $thisStatus->libraryId = $libraryId; - $thisStatus->find(); - - $materialsRequestUsage = new MaterialsRequestUsage(); - $materialsRequestUsage->year = $period['year']; - $materialsRequestUsage->month = $period['month']; - $materialsRequestUsage->statusId = $thisStatus->id; - - if ($materialsRequestUsage->find(true)){ //if we find a match on year, month, and id/statusId - $row[] = $materialsRequestUsage->numUsed ?? 0; - }else{ - $row[] = 0; - } - fputcsv($fp, $row); - } - exit; - } - - function getBreadcrumbs(): array { - $breadcrumbs = []; - $breadcrumbs[] = new Breadcrumb('/Admin/Home', 'Administration Home'); - $breadcrumbs[] = new Breadcrumb('/Admin/Home#materialsrequest', 'Materials Request'); - $breadcrumbs[] = new Breadcrumb('/MaterialsRequest/Dashboard', 'Usage Dashboard'); - $breadcrumbs[] = new Breadcrumb('', 'Usage Graph'); - return $breadcrumbs; - } - - function getActiveAdminSection(): string { - return 'materials_request'; - } - - function canView(): bool { - return UserAccount::userHasPermission([ - 'View Dashboards', - 'View System Reports', - ]); - } -} \ No newline at end of file diff --git a/code/web/services/MaterialsRequest/UsageGraphs.php b/code/web/services/MaterialsRequest/UsageGraphs.php new file mode 100644 index 0000000000..d51c9448ed --- /dev/null +++ b/code/web/services/MaterialsRequest/UsageGraphs.php @@ -0,0 +1,100 @@ +launchGraph('MaterialsRequest'); + } + + public function getAllPeriods() { + $usage = new MaterialsRequestUsage(); + $usage->selectAdd(null); + $usage->selectAdd('DISTINCT year, month'); + $usage->find(); + + $stats = []; + while ($usage->fetch()) { + $stats[$usage->month . '-' . $usage->year]['year'] = $usage->year; + $stats[$usage->month . '-' . $usage->year]['month'] = $usage->month; + } + return $stats; + } + + function getBreadcrumbs(): array { + $breadcrumbs = []; + $breadcrumbs[] = new Breadcrumb('/Admin/Home', 'Administration Home'); + $breadcrumbs[] = new Breadcrumb('/Admin/Home#materialsrequest', 'Materials Request'); + $breadcrumbs[] = new Breadcrumb('/MaterialsRequest/Dashboard', 'Usage Dashboard'); + $breadcrumbs[] = new Breadcrumb('', 'Usage Graph'); + return $breadcrumbs; + } + + function getActiveAdminSection(): string { + return 'materials_request'; + } + + function canView(): bool { + return UserAccount::userHasPermission([ + 'View Dashboards', + 'View System Reports', + ]); + } + + protected function assignGraphSpecificTitle($stat): void {} //unnecessary as achieved programmatically in getAndSetInterfaceDataSeries + + private function getMaterialsRequestStatusDescription($status, $libraryId) { + $thisStatus = new MaterialsRequestStatus(); + $thisStatus->id = $status; + $thisStatus->libraryId = $libraryId; + $thisStatus->find(); + return $thisStatus->fetch()->description; + } + + protected function getAndSetInterfaceDataSeries($stat, $instanceName): void { + global $interface; + + $status = $_REQUEST['stat']; + $interface->assign('curStatus', $status); + $dataSeries = []; + + $userHomeLibrary = Library::getPatronHomeLibrary(); + if (is_null($userHomeLibrary)) { + //User does not have a home library, this is likely an admin account. Use the active library + global $library; + $userHomeLibrary = $library; + } + $libraryId = $userHomeLibrary->libraryId; + $statusDescription = $this->getMaterialsRequestStatusDescription($status, $libraryId); + + $title = 'Materials Request Usage Graph - ' . $statusDescription; + $materialsRequestUsage = new MaterialsRequestUsage(); + $materialsRequestUsage->groupBy('year, month'); + $materialsRequestUsage->selectAdd(); + $materialsRequestUsage->statusId = $status; + $materialsRequestUsage->selectAdd('year'); + $materialsRequestUsage->selectAdd('month'); + $materialsRequestUsage->selectAdd('SUM(numUsed) as numUsed'); + $materialsRequestUsage->orderBy('year, month'); + + $dataSeries[$statusDescription] = GraphingUtils::getDataSeriesArray(count($dataSeries)); + + //Collect results + $materialsRequestUsage->find(); + + while ($materialsRequestUsage->fetch()) { + $curPeriod = "{$materialsRequestUsage->month}-{$materialsRequestUsage->year}"; + $columnLabels[] = $curPeriod; + $dataSeries[$statusDescription]['data'][$curPeriod] = $materialsRequestUsage->numUsed; + } + + $interface->assign('columnLabels', $columnLabels); + $interface->assign('dataSeries', $dataSeries); + $interface->assign('graphTitle', $title); + $interface->assign('translateDataSeries', true); + $interface->assign('translateColumnLabels', false); + } +} \ No newline at end of file diff --git a/code/web/services/SideLoads/AJAX.php b/code/web/services/SideLoads/AJAX.php index 5f638f58d6..b04f9ae905 100644 --- a/code/web/services/SideLoads/AJAX.php +++ b/code/web/services/SideLoads/AJAX.php @@ -49,6 +49,6 @@ public function deleteMarc() { public function exportUsageData() { require_once ROOT_DIR . '/services/SideLoads/UsageGraphs.php'; $aspenUsageGraph = new SideLoads_UsageGraphs(); - $aspenUsageGraph->buildCSV(); + $aspenUsageGraph->buildCSV('SideLoads'); } } \ No newline at end of file diff --git a/code/web/services/SideLoads/UsageGraphs.php b/code/web/services/SideLoads/UsageGraphs.php index 4d64f41707..7d0701e5bb 100644 --- a/code/web/services/SideLoads/UsageGraphs.php +++ b/code/web/services/SideLoads/UsageGraphs.php @@ -1,35 +1,14 @@ assign('graphTitle', $title); - $this->assignGraphSpecificTitle($stat); - - $profileName= $_REQUEST['profileName']; - $sideloadId = $this->getSideloadIdBySideLoadName($profileName); - $this->getAndSetInterfaceDataSeries($stat, $instanceName, $sideloadId); - $interface->assign('profileName', $profileName); - $interface->assign('stat', $stat); - $interface->assign('propName', 'exportToCSV'); - $interface->assign('showCSVExportButton', true); - $interface->assign('section', 'SideLoads'); - - $title = $interface->getVariable('graphTitle'); - $this->display('../Admin/usage-graph.tpl', $title); +class SideLoads_UsageGraphs extends Admin_AbstractUsageGraphs { + function launch(): void { + $this->launchGraph('SideLoads'); } function getBreadcrumbs(): array { @@ -52,60 +31,13 @@ function canView(): bool { ]); } - // note that this will only handle tables with one stat (as is needed for Summon usage data) - // to see a version that handle multpile stats, see the Admin/UsageGraphs.php implementation - public function buildCSV() { - global $interface; - $stat = $_REQUEST['stat']; - if (!empty($_REQUEST['instance'])) { - $instanceName = $_REQUEST['instance']; - } else { - $instanceName = ''; - } - - $profileName= $_REQUEST['profileName']; - $sideloadId = $this->getSideloadIdBySideLoadName($profileName); - $this->getAndSetInterfaceDataSeries($stat, $instanceName, $sideloadId); - $dataSeries = $interface->getVariable('dataSeries'); - - $filename = "SideLoadsUsageData_{$stat}.csv"; - header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); - header("Cache-Control: no-store, no-cache, must-revalidate"); - header("Cache-Control: post-check=0, pre-check=0", false); - header("Pragma: no-cache"); - header('Content-Type: text/csv; charset=utf-8'); - header("Content-Disposition: attachment;filename={$filename}"); - $fp = fopen('php://output', 'w'); - - // builds the first row of the table in the CSV - column headers: Dates, and the title of the graph - fputcsv($fp, ['Dates', $stat]); - - // builds each subsequent data row - aka the column value - foreach ($dataSeries as $dataSerie) { - $data = $dataSerie['data']; - $numRows = count($data); - $dates = array_keys($data); - - if( empty($numRows)) { - fputcsv($fp, ['no data found!']); - } - for($i = 0; $i < $numRows; $i++) { - $date = $dates[$i]; - $value = $data[$date]; - $row = [$date, $value]; - fputcsv($fp, $row); - } - } - exit(); - } - /* The only unique identifier available to determine for which sideload to fetch data is the sideload's name as $profileName. It is used here to find the sideloads' id as only this exists on the sideload usage tables */ - private function getSideloadIdBySideLoadName($name) { + private function getSideloadIdBySideLoadName($name): int { $sideload = new SideLoad(); $sideload->whereAdd('name = "' . $name .'"'); $sideload->selectAdd(); @@ -113,13 +45,16 @@ private function getSideloadIdBySideLoadName($name) { return $sideload->fetch()->id; } - private function getAndSetInterfaceDataSeries($stat, $instanceName, $sideloadId) { + protected function getAndSetInterfaceDataSeries($stat, $instanceName): void { global $interface; $dataSeries = []; $columnLabels = []; $usage = []; + $profileName= $_REQUEST['subSection']; + $sideloadId = $this->getSideloadIdBySideLoadName($profileName); + // for the graph displaying data retrieved from the user_sideload_usage table if ($stat == 'activeUsers') { $usage = new UserSideLoadUsage(); @@ -133,11 +68,7 @@ private function getAndSetInterfaceDataSeries($stat, $instanceName, $sideloadId) $usage->selectAdd('month'); $usage->orderBy('year, month'); - $dataSeries['Active Users'] = [ - 'borderColor' => 'rgba(255, 99, 132, 1)', - 'backgroundColor' => 'rgba(255, 99, 132, 0.2)', - 'data' => [], - ]; + $dataSeries['Active Users'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $usage->selectAdd('COUNT(id) as numUsers'); } @@ -155,11 +86,7 @@ private function getAndSetInterfaceDataSeries($stat, $instanceName, $sideloadId) $usage->selectAdd('month'); $usage->orderBy('year, month'); - $dataSeries['Records Accessed Online'] = [ - 'borderColor' => 'rgba(255, 99, 132, 1)', - 'backgroundColor' => 'rgba(255, 99, 132, 0.2)', - 'data' => [], - ]; + $dataSeries['Records Accessed Online'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $usage->selectAdd('SUM(IF(timesUsed>0,1,0)) as numRecordsUsed'); } @@ -184,7 +111,7 @@ private function getAndSetInterfaceDataSeries($stat, $instanceName, $sideloadId) $interface->assign('translateColumnLabels', false); } - private function assignGraphSpecificTitle($stat) { + protected function assignGraphSpecificTitle($stat): void { global $interface; $title = $interface->getVariable('graphTitle'); if ($stat == 'activeUsers') { diff --git a/code/web/services/Summon/AJAX.php b/code/web/services/Summon/AJAX.php index 04402bc309..d6d65f4664 100644 --- a/code/web/services/Summon/AJAX.php +++ b/code/web/services/Summon/AJAX.php @@ -4,6 +4,6 @@ class Summon_AJAX extends JSON_Action { public function exportUsageData() { require_once ROOT_DIR . '/services/Summon/UsageGraphs.php'; $summonUsageGraph = new Summon_UsageGraphs(); - $summonUsageGraph->buildCSV(); + $summonUsageGraph->buildCSV('Summon'); } } \ No newline at end of file diff --git a/code/web/services/Summon/UsageGraphs.php b/code/web/services/Summon/UsageGraphs.php index 9fe882d614..71644f84a5 100644 --- a/code/web/services/Summon/UsageGraphs.php +++ b/code/web/services/Summon/UsageGraphs.php @@ -1,28 +1,14 @@ assign('graphTitle', $title); - $interface->assign('section', 'Summon'); - $interface->assign('showCSVExportButton', true); - $this->assignGraphSpecificTitle($stat); - $this->getAndSetInterfaceDataSeries($stat, $instanceName); - $interface->assign('stat', $stat); - $this->display('../Admin/usage-graph.tpl', $title); +class Summon_UsageGraphs extends Admin_AbstractUsageGraphs { + function launch(): void { + $this->launchGraph('Summon'); } function getActiveAdminSection(): string { @@ -45,51 +31,7 @@ function getBreadcrumbs(): array { return $breadcrumbs; } - // note that this will only handle tables with one stat (as is needed for Summon usage data) - // to see a version that handle multpile stats, see the Admin/UsageGraphs.php implementation - public function buildCSV() { - global $interface; - $stat = $_REQUEST['stat']; - if (!empty($_REQUEST['instance'])) { - $instanceName = $_REQUEST['instance']; - } else { - $instanceName = ''; - } - $this->getAndSetInterfaceDataSeries($stat, $instanceName); - $dataSeries = $interface->getVariable('dataSeries'); - - $filename = "SummonUsageData_{$stat}.csv"; - header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); - header("Cache-Control: no-store, no-cache, must-revalidate"); - header("Cache-Control: post-check=0, pre-check=0", false); - header("Pragma: no-cache"); - header('Content-Type: text/csv; charset=utf-8'); - header("Content-Disposition: attachment;filename={$filename}"); - $fp = fopen('php://output', 'w'); - - // builds the first row of the table in the CSV - column headers: Dates, and the title of the graph - fputcsv($fp, ['Dates', $stat]); - - // builds each subsequent data row - aka the column value - foreach ($dataSeries as $dataSerie) { - $data = $dataSerie['data']; - $numRows = count($data); - $dates = array_keys($data); - - if( empty($numRows)) { - fputcsv($fp, ['no data found!']); - } - for($i = 0; $i < $numRows; $i++) { - $date = $dates[$i]; - $value = $data[$date]; - $row = [$date, $value]; - fputcsv($fp, $row); - } - } - exit(); - } - - private function getAndSetInterfaceDataSeries($stat, $instanceName) { + protected function getAndSetInterfaceDataSeries($stat, $instanceName): void { global $interface; $dataSeries = []; $columnLabels = []; @@ -106,11 +48,7 @@ private function getAndSetInterfaceDataSeries($stat, $instanceName) { $userSummonUsage->selectAdd('month'); $userSummonUsage->orderBy('year, month'); - $dataSeries['Active Users'] = [ - 'borderColor' => 'rgba(255, 99, 132, 1)', - 'backgroundColor' => 'rgba(255, 99, 132, 0.2)', - 'data' => [], - ]; + $dataSeries['Active Users'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $userSummonUsage->selectAdd('COUNT(DISTINCT userId) as activeUsers'); // Collects results @@ -140,27 +78,15 @@ private function getAndSetInterfaceDataSeries($stat, $instanceName) { $summonRecordUsage->orderBy('year, month'); if ($stat == 'numRecordsViewed') { - $dataSeries['Number of Records Viewed'] = [ - 'borderColor' => 'rgba(255, 99, 132, 1)', - 'backgroundColor' => 'rgba(255, 99, 132, 0.2)', - 'data' => [], - ]; + $dataSeries['Number of Records Viewed'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $summonRecordUsage ->selectAdd('SUM(IF(timesViewedInSearch>0,1,0)) as numRecordsViewed'); } if ($stat == 'numRecordsClicked') { - $dataSeries['Number of Records Clicked'] = [ - 'borderColor' => 'rgba(255, 99, 132, 1)', - 'backgroundColor' => 'rgba(255, 99, 132, 0.2)', - 'data' => [], - ]; + $dataSeries['Number of Records Clicked'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $summonRecordUsage ->selectAdd('SUM(IF(timesUsed>0,1,0)) as numRecordsUsed'); } if ($stat == 'totalClicks') { - $dataSeries['Total Clicks'] = [ - 'borderColor' => 'rgba(255, 99, 132, 1)', - 'backgroundColor' => 'rgba(255, 99, 132, 0.2)', - 'data' => [], - ]; + $dataSeries['Total Clicks'] = GraphingUtils::getDataSeriesArray(count($dataSeries)); $summonRecordUsage ->selectAdd('SUM(timesUsed) as numClicks'); } // Collect results @@ -189,7 +115,7 @@ private function getAndSetInterfaceDataSeries($stat, $instanceName) { $interface->assign('translateColumnLabels', false); } - private function assignGraphSpecificTitle($stat) { + protected function assignGraphSpecificTitle($stat): void { global $interface; $title = $interface->getVariable('graphTitle'); switch ($stat) {