diff --git a/classes/components/forms/counter/CounterReportForm.php b/classes/components/forms/counter/CounterReportForm.php new file mode 100644 index 00000000000..25cc67f4b0b --- /dev/null +++ b/classes/components/forms/counter/CounterReportForm.php @@ -0,0 +1,66 @@ +reportFields['PR'] = array_map(function ($field) { + $field->groupId = 'default'; + return $field; + }, $formFieldsPR); + + $formFieldsPR_P1 = PR_P1::getReportSettingsFormFields(); + $this->reportFields['PR_P1'] = array_map(function ($field) { + $field->groupId = 'default'; + return $field; + }, $formFieldsPR_P1); + + $formFieldsTR = TR::getReportSettingsFormFields(); + $this->reportFields['TR'] = array_map(function ($field) { + $field->groupId = 'default'; + return $field; + }, $formFieldsTR); + + $formFieldsTR_J3 = TR_J3::getReportSettingsFormFields(); + $this->reportFields['TR_J3'] = array_map(function ($field) { + $field->groupId = 'default'; + return $field; + }, $formFieldsTR_J3); + + $formFieldsIR = IR::getReportSettingsFormFields(); + $this->reportFields['IR'] = array_map(function ($field) { + $field->groupId = 'default'; + return $field; + }, $formFieldsIR); + + $formFieldsIR_A1 = IR_A1::getReportSettingsFormFields(); + $this->reportFields['IR_A1'] = array_map(function ($field) { + $field->groupId = 'default'; + return $field; + }, $formFieldsIR_A1); + } +} diff --git a/classes/sushi/IR.php b/classes/sushi/IR.php index 16684ba7a08..293589a7917 100644 --- a/classes/sushi/IR.php +++ b/classes/sushi/IR.php @@ -18,6 +18,9 @@ namespace APP\sushi; use APP\facades\Repo; +use Illuminate\Support\Collection; +use PKP\components\forms\FieldOptions; +use PKP\components\forms\FieldText; use PKP\statistics\PKPStatisticsHelper; use PKP\sushi\CounterR5Report; @@ -93,7 +96,8 @@ public function getSupportedParams(): array 'attributes_to_show', 'include_component_details', 'include_parent_details', - 'granularity' + 'granularity', + '_', // for ajax requests ]; } @@ -203,10 +207,8 @@ public function setAttributes(array $attributes): void } } - /** - * Get report items - */ - public function getReportItems(): array + /** Get DB query results for the report */ + protected function getQueryResults(): Collection { $params['contextIds'] = [$this->context->getId()]; $params['institutionId'] = $this->customerId; @@ -214,7 +216,7 @@ public function getReportItems(): array $params['dateEnd'] = $this->endDate; $params['yearsOfPublication'] = $this->yearsOfPublication; if ($this->itemId > 0) { - $allowedParams['submissionIds'] = [$this->itemId]; + $params['submissionIds'] = [$this->itemId]; } // do not consider metric_type filter now, but for display @@ -242,11 +244,16 @@ public function getReportItems(): array 'Data' => __('sushi.exception.3030', ['beginDate' => $this->beginDate, 'endDate' => $this->endDate]) ]); } + return $results; + } - $resultsGroupedBySubmission = $items = []; - foreach ($results as $result) { - $resultsGroupedBySubmission[$result->submission_id][] = $result; - } + /** Get report items */ + public function getReportItems(): array + { + $results = $this->getQueryResults(); + + $items = []; + $resultsGroupedBySubmission = $results->groupBy('submission_id'); foreach ($resultsGroupedBySubmission as $submissionId => $submissionResults) { // Get the submission properties @@ -316,7 +323,7 @@ public function getReportItems(): array $itemContributor['Type'] = 'Author'; $itemContributor['Name'] = $author->getFullName(true, false, $submissionLocale); $orcid = $author->getOrcid(); - if (isset($orcid) && !empty($orcid)) { + if (!empty($orcid)) { $itemContributor['Identifier'] = $orcid; } $itemContributors[] = $itemContributor; @@ -370,4 +377,254 @@ public function getReportItems(): array return $items; } + + /** Get TSV report column names */ + public function getTSVColumnNames(): array + { + $columnRow = ['Item', 'Publisher', 'Publisher ID', 'Platform']; + + if (in_array('Authors', $this->attributesToShow)) { + array_push($columnRow, 'Authors'); + } + if (in_array('Publication_Date', $this->attributesToShow)) { + array_push($columnRow, 'Publication_Date'); + } + if (in_array('Article_Version', $this->attributesToShow)) { + array_push($columnRow, 'Article_Version'); + } + + array_push($columnRow, 'DOI', 'Proprietary_ID', 'ISBN', 'Print_ISSN', 'Online_ISSN', 'URI'); + + if ($this->includeParentDetails == 'True') { + array_push( + $columnRow, + 'Parent_Title', + 'Parent_Authors', + 'Parent_Publication_Date', + 'Parent_Article_Version', + 'Parent_Data_Type', + 'Parent_DOI', + 'Parent_Proprietary_ID', + 'Parent_ISBN', + 'Parent_Print_ISSN', + 'Parent_Online_ISSN', + 'Parent_URI' + ); + } + + if (in_array('Data_Type', $this->attributesToShow)) { + array_push($columnRow, 'Data_Type'); + } + if (in_array('YOP', $this->attributesToShow)) { + array_push($columnRow, 'YOP'); + } + if (in_array('Access_Type', $this->attributesToShow)) { + array_push($columnRow, 'Access_Type'); + } + if (in_array('Access_Method', $this->attributesToShow)) { + array_push($columnRow, 'Access_Method'); + } + + array_push($columnRow, 'Metric_Type', 'Reporting_Period_Total'); + + if ($this->granularity == 'Month') { + $period = $this->getMonthlyDatePeriod(); + foreach ($period as $dt) { + array_push($columnRow, $dt->format('M-Y')); + } + } + + return [$columnRow]; + } + + /** Get TSV report rows */ + public function getTSVReportItems(): array + { + $results = $this->getQueryResults(); + + $resultRows = []; + $resultsGroupedBySubmission = $results->groupBy('submission_id'); + + foreach ($resultsGroupedBySubmission as $submissionId => $submissionResults) { + $results = collect($submissionResults); + + // get total numbers for every metric type + $metricsTotal['Total_Item_Investigations'] = $results->pluck('metric_investigations')->sum(); + $metricsTotal['Unique_Item_Investigations'] = $results->pluck('metric_investigations_unique')->sum(); + $metricsTotal['Total_Item_Requests'] = $results->pluck('metric_requests')->sum(); + $metricsTotal['Unique_Item_Requests'] = $results->pluck('metric_requests_unique')->sum(); + + // filter here by requested metric types + foreach ($this->metricTypes as $metricType) { + // if the total numbers for the given metric type > 0, + // construct the result row + if ($metricsTotal[$metricType] > 0) { + $submission = Repo::submission()->get($submissionId); + if (!$submission || !$submission->getOriginalPublication()) { + break; + } + $currentPublication = $submission->getCurrentPublication(); + $submissionLocale = $submission->getData('locale'); + $datePublished = $submission->getOriginalPublication()->getData('datePublished'); + + $resultRow = [ + $currentPublication->getLocalizedTitle($submissionLocale), // Item + $this->context->getData('publisherInstitution'), // Publisher + '', // Publisher ID + $this->platformName, // Platform + ]; + + if (in_array('Authors', $this->attributesToShow)) { + $authors = $currentPublication->getData('authors'); + $authorRowValue = ''; + foreach ($authors as $author) { + $authorRowValue = $author->getFullName(true, false, $submissionLocale); + $orcid = $author->getOrcid(); + if (!empty($orcid)) { + $authorRowValue .= '(ORCID:' . $orcid . ')'; + } + } + array_push($resultRow, $authorRowValue); // Authors + } + + if (in_array('Publication_Date', $this->attributesToShow)) { + array_push($resultRow, $datePublished); // Publication_Date + } + + if (in_array('Article_Version', $this->attributesToShow)) { + array_push($resultRow, 'VoR'); // Article_Version + } + + $doi = $currentPublication->getDoi() ?? ''; + array_push($resultRow, $doi); // DOI + + array_push($resultRow, $this->platformId . ':' . $submissionId); // Proprietary_ID + array_push($resultRow, '', '', '', ''); // ISBN, Print_ISSN, Online_ISSN, URI + + if ($this->includeParentDetails == 'True') { + array_push( + $resultRow, + $this->context->getName($this->context->getPrimaryLocale()), // Parent_Title + '', // Parent_Authors + '', // Parent_Publication_Date + '', // Parent_Article_Version + self::PARENT_DATA_TYPE, // Parent_Data_Type + '', // Parent_DOI + $this->platformId . ':' . $this->context->getId(), // Parent_Proprietary_ID + '', //Parent_ISBN + ); + $printIssn = $this->context->getData('printIssn') ?? ''; + array_push($resultRow, $printIssn); // Parent_Print_ISSN + + $onlineIssn = $this->context->getData('onlineIssn') ?? ''; + array_push($resultRow, $onlineIssn); // Parent_Online_ISSN + + array_push($resultRow, ''); // Parent_URI + } + + if (in_array('Data_Type', $this->attributesToShow)) { + array_push($resultRow, self::DATA_TYPE); // Data_Type + } + if (in_array('YOP', $this->attributesToShow)) { + array_push($resultRow, date('Y', strtotime($datePublished))); // YOP + } + if (in_array('Access_Type', $this->attributesToShow)) { + array_push($resultRow, self::ACCESS_TYPE); // Access_Type + } + if (in_array('Access_Method', $this->attributesToShow)) { + array_push($resultRow, self::ACCESS_METHOD); // Access_Method + } + + array_push($resultRow, $metricType); // Metric_Type + array_push($resultRow, $metricsTotal[$metricType]); // Reporting_Period_Total + if ($this->granularity == 'Month') { // metrics for each month in the given period + $period = $this->getMonthlyDatePeriod(); + foreach ($period as $dt) { + $month = $dt->format('Ym'); + $result = $submissionResults->firstWhere('month', '=', $month); + if ($result === null) { + array_push($resultRow, '0'); + } else { + $metrics['Total_Item_Investigations'] = $result->metric_investigations; + $metrics['Unique_Item_Investigations'] = $result->metric_investigations_unique; + $metrics['Total_Item_Requests'] = $result->metric_requests; + $metrics['Unique_Item_Requests'] = $result->metric_requests_unique; + array_push($resultRow, $metrics[$metricType]); + } + } + } + $resultRows[] = $resultRow; + } + } + } + + return $resultRows; + } + + /** Get report specific form fields */ + public static function getReportSettingsFormFields(): array + { + $formFields = parent::getCommonReportSettingsFormFields(); + + $metricTypes = ['Total_Item_Investigations', 'Unique_Item_Investigations', 'Total_Item_Requests', 'Unique_Item_Requests']; + $metricTypeOptions = []; + foreach ($metricTypes as $metricType) { + $metricTypeOptions[] = ['value' => $metricType, 'label' => $metricType]; + } + $formFields[] = new FieldOptions('metric_type', [ + 'label' => __('manager.statistics.counterR5Report.settings.metricType'), + 'options' => $metricTypeOptions, + 'value' => $metricTypes, + 'groupId' => 'default', + ]); + + $attributesToShow = ['Article_Version', 'Authors', 'Access_Method', 'Access_Type', 'Data_Type', 'Publication_Date', 'YOP']; + $attributesToShowOptions = []; + foreach ($attributesToShow as $attributeToShow) { + $attributesToShowOptions[] = ['value' => $attributeToShow, 'label' => $attributeToShow]; + } + $formFields[] = new FieldOptions('attributes_to_show', [ + 'label' => __('manager.statistics.counterR5Report.settings.attributesToShow'), + 'options' => $attributesToShowOptions, + 'value' => [], + 'groupId' => 'default', + ]); + + $formFields[] = new FieldText('yop', [ + 'label' => __('manager.statistics.counterR5Report.settings.yop'), + 'description' => __('manager.statistics.counterR5Report.settings.date.yop.description'), + 'size' => 'small', + 'isMultilingual' => false, + 'isRequired' => false, + 'groupId' => 'default', + ]); + + $formFields[] = new FieldText('item_id', [ + 'label' => __('manager.statistics.counterR5Report.settings.itemId'), + 'size' => 'small', + 'isMultilingual' => false, + 'isRequired' => false, + 'groupId' => 'default', + ]); + + $formFields[] = new FieldOptions('include_parent_details', [ + 'label' => __('manager.statistics.counterR5Report.settings.includeParentDetails'), + 'options' => [ + ['value' => true, 'label' => __('manager.statistics.counterR5Report.settings.includeParentDetails')], + ], + 'value' => false, + 'groupId' => 'default', + ]); + + $formFields[] = new FieldOptions('granularity', [ + 'label' => __('manager.statistics.counterR5Report.settings.excludeMonthlyDetails'), + 'options' => [ + ['value' => true, 'label' => __('manager.statistics.counterR5Report.settings.excludeMonthlyDetails')], + ], + 'value' => false, + 'groupId' => 'default', + ]); + + return $formFields; + } } diff --git a/classes/sushi/IR_A1.php b/classes/sushi/IR_A1.php index c2a28ef2b7e..3708dffc7e7 100644 --- a/classes/sushi/IR_A1.php +++ b/classes/sushi/IR_A1.php @@ -60,7 +60,8 @@ public function getSupportedParams(): array 'customer_id', 'begin_date', 'end_date', - 'platform' + 'platform', + '_', // for ajax requests ]; } @@ -135,4 +136,10 @@ public function setAttributes(array $attributes): void ]; parent::setAttributes($predefinedAttributes); } + + /** Get report specific form fields */ + public static function getReportSettingsFormFields(): array + { + return parent::getCommonReportSettingsFormFields(); + } } diff --git a/classes/sushi/PR.php b/classes/sushi/PR.php index 7d8069c89f3..d88ec808077 100644 --- a/classes/sushi/PR.php +++ b/classes/sushi/PR.php @@ -17,6 +17,8 @@ namespace APP\sushi; +use Illuminate\Support\Collection; +use PKP\components\forms\FieldOptions; use PKP\statistics\PKPStatisticsHelper; use PKP\sushi\CounterR5Report; @@ -71,7 +73,8 @@ public function getSupportedParams(): array 'data_type', 'access_method', 'attributes_to_show', - 'granularity' + 'granularity', + '_', // for ajax requests ]; } @@ -123,10 +126,8 @@ public function getSupportedAttributes(): array ]; } - /** - * Get report items - */ - public function getReportItems(): array + /** Get DB query results for the report */ + protected function getQueryResults(): Collection { $params['contextIds'] = [$this->context->getId()]; $params['institutionId'] = $this->customerId; @@ -158,6 +159,13 @@ public function getReportItems(): array 'Data' => __('sushi.exception.3030', ['beginDate' => $this->beginDate, 'endDate' => $this->endDate]) ]); } + return $results; + } + + /** Get report items */ + public function getReportItems(): array + { + $results = $this->getQueryResults(); // There is only one platform, so there will be only one report item $item['Platform'] = $this->platformName; @@ -207,4 +215,115 @@ public function getReportItems(): array $items = [$item]; return $items; } + + /** Get TSV report column names */ + public function getTSVColumnNames(): array + { + $columnRow = ['Platform']; + if (in_array('Data_Type', $this->attributesToShow)) { + array_push($columnRow, 'Data_Type'); + } + if (in_array('Access_Method', $this->attributesToShow)) { + array_push($columnRow, 'Access_Method'); + } + array_push($columnRow, 'Metric_Type', 'Reporting_Period_Total'); + if ($this->granularity == 'Month') { + $period = $this->getMonthlyDatePeriod(); + foreach ($period as $dt) { + array_push($columnRow, $dt->format('M-Y')); + } + } + return [$columnRow]; + } + + /** Get TSV report rows */ + public function getTSVReportItems(): array + { + $results = $this->getQueryResults(); + + // get total numbers for every metric type + $metricsTotal['Total_Item_Investigations'] = $results->pluck('metric_investigations')->sum(); + $metricsTotal['Unique_Item_Investigations'] = $results->pluck('metric_investigations_unique')->sum(); + $metricsTotal['Total_Item_Requests'] = $results->pluck('metric_requests')->sum(); + $metricsTotal['Unique_Item_Requests'] = $results->pluck('metric_requests_unique')->sum(); + + $resultRows = []; + // filter here by requested metric types + foreach ($this->metricTypes as $metricType) { + // if the total numbers for the given metric type > 0 + if ($metricsTotal[$metricType] > 0) { + // construct the result row + $resultRow = []; + array_push($resultRow, $this->platformName); // Platform + if (in_array('Data_Type', $this->attributesToShow)) { + array_push($resultRow, self::DATA_TYPE); // Data_Type + } + if (in_array('Access_Method', $this->attributesToShow)) { + array_push($resultRow, self::ACCESS_METHOD); // Access_Method + } + array_push($resultRow, $metricType); // Metric_Type + array_push($resultRow, $metricsTotal[$metricType]); // Reporting_Period_Total + if ($this->granularity == 'Month') { // metrics for each month in the given period + $period = $this->getMonthlyDatePeriod(); + foreach ($period as $dt) { + $month = $dt->format('Ym'); + $result = $results->firstWhere('month', '=', $month); + if ($result === null) { + array_push($resultRow, '0'); + } else { + $metrics['Total_Item_Investigations'] = $result->metric_investigations; + $metrics['Unique_Item_Investigations'] = $result->metric_investigations_unique; + $metrics['Total_Item_Requests'] = $result->metric_requests; + $metrics['Unique_Item_Requests'] = $result->metric_requests_unique; + array_push($resultRow, $metrics[$metricType]); + } + } + } + $resultRows[] = $resultRow; + } + } + + return $resultRows; + } + + /** Get report specific form fields */ + public static function getReportSettingsFormFields(): array + { + $formFields = parent::getCommonReportSettingsFormFields(); + + $metricTypes = ['Total_Item_Investigations', 'Unique_Item_Investigations', 'Total_Item_Requests', 'Unique_Item_Requests']; + $metricTypeOptions = []; + foreach ($metricTypes as $metricType) { + $metricTypeOptions[] = ['value' => $metricType, 'label' => $metricType]; + } + $formFields[] = new FieldOptions('metric_type', [ + 'label' => __('manager.statistics.counterR5Report.settings.metricType'), + 'options' => $metricTypeOptions, + 'value' => $metricTypes, + 'groupId' => 'default', + ]); + + $attributesToShow = ['Data_Type', 'Access_Method']; + $attributesToShowOptions = []; + foreach ($attributesToShow as $attributeToShow) { + $attributesToShowOptions[] = ['value' => $attributeToShow, 'label' => $attributeToShow]; + } + $formFields[] = new FieldOptions('attributes_to_show', [ + 'label' => __('manager.statistics.counterR5Report.settings.attributesToShow'), + 'options' => $attributesToShowOptions, + 'value' => [], + 'groupId' => 'default', + ]); + + $formFields[] = new FieldOptions('granularity', [ + 'label' => __('manager.statistics.counterR5Report.settings.excludeMonthlyDetails'), + 'options' => [ + ['value' => true, 'label' => __('manager.statistics.counterR5Report.settings.excludeMonthlyDetails')], + ], + 'value' => false, + 'groupId' => 'default', + ]); + + return $formFields; + } } diff --git a/classes/sushi/PR_P1.php b/classes/sushi/PR_P1.php index c8c6459584b..d2a98af711a 100644 --- a/classes/sushi/PR_P1.php +++ b/classes/sushi/PR_P1.php @@ -66,7 +66,8 @@ public function getSupportedParams(): array 'customer_id', 'begin_date', 'end_date', - 'platform' + 'platform', + '_', // for ajax requests ]; } @@ -113,4 +114,10 @@ public function setAttributes(array $attributes): void { $this->attributes = []; } + + /** Get report specific form fields */ + public static function getReportSettingsFormFields(): array + { + return parent::getCommonReportSettingsFormFields(); + } } diff --git a/classes/sushi/TR.php b/classes/sushi/TR.php index 5eb36d1c95a..8eb14b6ed75 100644 --- a/classes/sushi/TR.php +++ b/classes/sushi/TR.php @@ -17,6 +17,9 @@ namespace APP\sushi; +use Illuminate\Support\Collection; +use PKP\components\forms\FieldOptions; +use PKP\components\forms\FieldText; use PKP\statistics\PKPStatisticsHelper; use PKP\sushi\CounterR5Report; @@ -78,7 +81,8 @@ public function getSupportedParams(): array 'access_type', 'access_method', 'attributes_to_show', - 'granularity' + 'granularity', + '_', // for ajax requests ]; } @@ -165,10 +169,8 @@ public function setFilters(array $filters): void } } - /** - * Get report items - */ - public function getReportItems(): array + /** Get DB query results for the report */ + protected function getQueryResults(): Collection { $params['contextIds'] = [$this->context->getId()]; $params['institutionId'] = $this->customerId; @@ -205,17 +207,20 @@ public function getReportItems(): array 'Data' => __('sushi.exception.3030', ['beginDate' => $this->beginDate, 'endDate' => $this->endDate]) ]); } + return $results; + } + + /** Get report items */ + public function getReportItems(): array + { + $results = $this->getQueryResults(); // If YOP is requested attribute to show, // group results by YOP $resultsGroupedByYOP = $yearsOfPublication = $items = []; if (in_array('YOP', $this->attributesToShow)) { - foreach ($results as $result) { - if (!in_array($result->YOP, $yearsOfPublication)) { - $yearsOfPublication[] = $result->YOP; - } - $resultsGroupedByYOP[$result->YOP][] = $result; - } + $yearsOfPublication = $results->pluck('YOP')->unique(); + $resultsGroupedByYOP = $results->groupBy('YOP'); } // Apply the loop at least once: @@ -302,4 +307,175 @@ public function getReportItems(): array return $items; } + + /** Get TSV report column names */ + public function getTSVColumnNames(): array + { + $columnRow = ['Title', 'Publisher', 'Publisher ID', 'Platform', 'DOI', 'Proprietary_ID', 'ISBN', 'Print_ISSN', 'Online_ISSN', 'URI']; + + if (in_array('Data_Type', $this->attributesToShow)) { + array_push($columnRow, 'Data_Type'); + } + if (in_array('Section_Type', $this->attributesToShow)) { + array_push($columnRow, 'Section_Type'); + } + if (in_array('YOP', $this->attributesToShow)) { + array_push($columnRow, 'YOP'); + } + if (in_array('Access_Type', $this->attributesToShow)) { + array_push($columnRow, 'Access_Type'); + } + if (in_array('Access_Method', $this->attributesToShow)) { + array_push($columnRow, 'Access_Method'); + } + + array_push($columnRow, 'Metric_Type', 'Reporting_Period_Total'); + + if ($this->granularity == 'Month') { + $period = $this->getMonthlyDatePeriod(); + foreach ($period as $dt) { + array_push($columnRow, $dt->format('M-Y')); + } + } + + return [$columnRow]; + } + + /** Get TSV report rows */ + public function getTSVReportItems(): array + { + $results = $this->getQueryResults(); + + // get total numbers for every metric type + $metricsTotal['Total_Item_Investigations'] = $results->pluck('metric_investigations')->sum(); + $metricsTotal['Unique_Item_Investigations'] = $results->pluck('metric_investigations_unique')->sum(); + $metricsTotal['Total_Item_Requests'] = $results->pluck('metric_requests')->sum(); + $metricsTotal['Unique_Item_Requests'] = $results->pluck('metric_requests_unique')->sum(); + + // If YOP is requested attribute to show, + // group results by YOP + $resultsGroupedByYOP = $yearsOfPublication = $resultRows = []; + if (in_array('YOP', $this->attributesToShow)) { + $yearsOfPublication = $results->pluck('YOP')->unique(); + $resultsGroupedByYOP = $results->groupBy('YOP'); + } + + // Apply the loop at least once: + // if there is no grouping by YOP, there will be one item + // else there will be one item per YOP + $i = 0; + do { + if (isset($yearsOfPublication[$i])) { + $yearOfPublication = $yearsOfPublication[$i]; + $results = collect($resultsGroupedByYOP[$yearOfPublication]); + } + + // filter here by requested metric types + foreach ($this->metricTypes as $metricType) { + // if the total numbers for the given metric type > 0 + if ($metricsTotal[$metricType] > 0) { + // construct the result row + $resultRow = [ + $this->context->getName($this->context->getPrimaryLocale()), // Title + $this->context->getData('publisherInstitution'), // Publisher + '', // Publisher ID + $this->platformName, // Platform + '', // DOI + $this->platformId . ':' . $this->context->getId(), // Proprietary_ID + '', // ISBN + $this->context->getData('printIssn') ?? '', // Print_ISSN + $this->context->getData('onlineIssn') ?? '', // Online_ISSN + '', // URI + ]; + if (in_array('Data_Type', $this->attributesToShow)) { + array_push($resultRow, self::DATA_TYPE); // Data_Type + } + if (in_array('Section_Type', $this->attributesToShow)) { + array_push($resultRow, self::SECTION_TYPE); // Section_Type + } + if (in_array('YOP', $this->attributesToShow)) { + array_push($resultRow, $yearOfPublication); // YOP + } + if (in_array('Access_Type', $this->attributesToShow)) { + array_push($resultRow, self::ACCESS_TYPE); // Access_Type + } + if (in_array('Access_Method', $this->attributesToShow)) { + array_push($resultRow, self::ACCESS_METHOD); // Access_Method + } + array_push($resultRow, $metricType); // Metric_Type + array_push($resultRow, $metricsTotal[$metricType]); // Reporting_Period_Total + if ($this->granularity == 'Month') { // metrics for each month in the given period + $period = $this->getMonthlyDatePeriod(); + foreach ($period as $dt) { + $month = $dt->format('Ym'); + $result = $results->firstWhere('month', '=', $month); + if ($result === null) { + array_push($resultRow, '0'); + } else { + $metrics['Total_Item_Investigations'] = $result->metric_investigations; + $metrics['Unique_Item_Investigations'] = $result->metric_investigations_unique; + $metrics['Total_Item_Requests'] = $result->metric_requests; + $metrics['Unique_Item_Requests'] = $result->metric_requests_unique; + array_push($resultRow, $metrics[$metricType]); + } + } + } + $resultRows[] = $resultRow; + } + } + $i++; + } while ($i < count($yearsOfPublication)); + + return $resultRows; + } + + /** Get report specific form fields */ + public static function getReportSettingsFormFields(): array + { + $formFields = parent::getCommonReportSettingsFormFields(); + + $metricTypes = ['Total_Item_Investigations', 'Unique_Item_Investigations', 'Total_Item_Requests', 'Unique_Item_Requests']; + $metricTypeOptions = []; + foreach ($metricTypes as $metricType) { + $metricTypeOptions[] = ['value' => $metricType, 'label' => $metricType]; + } + $formFields[] = new FieldOptions('metric_type', [ + 'label' => __('manager.statistics.counterR5Report.settings.metricType'), + 'options' => $metricTypeOptions, + 'groupId' => 'default', + 'value' => $metricTypes, + ]); + + $attributesToShow = ['Data_Type', 'Access_Method', 'Section_Type', 'Access_Type', 'YOP']; + $attributesToShowOptions = []; + foreach ($attributesToShow as $attributeToShow) { + $attributesToShowOptions[] = ['value' => $attributeToShow, 'label' => $attributeToShow]; + } + $formFields[] = new FieldOptions('attributes_to_show', [ + 'label' => __('manager.statistics.counterR5Report.settings.attributesToShow'), + 'options' => $attributesToShowOptions, + 'groupId' => 'default', + 'value' => [], + ]); + + $formFields[] = new FieldText('yop', [ + 'label' => __('manager.statistics.counterR5Report.settings.yop'), + 'description' => __('manager.statistics.counterR5Report.settings.date.yop.description'), + 'size' => 'small', + 'isMultilingual' => false, + 'isRequired' => false, + 'groupId' => 'default', + ]); + + $formFields[] = new FieldOptions('granularity', [ + 'label' => __('manager.statistics.counterR5Report.settings.excludeMonthlyDetails'), + 'options' => [ + ['value' => true, 'label' => __('manager.statistics.counterR5Report.settings.excludeMonthlyDetails')], + ], + 'value' => false, + 'groupId' => 'default', + ]); + + return $formFields; + } } diff --git a/classes/sushi/TR_J3.php b/classes/sushi/TR_J3.php index 2dddd2d8bd9..f4ec3c434e9 100644 --- a/classes/sushi/TR_J3.php +++ b/classes/sushi/TR_J3.php @@ -60,10 +60,27 @@ public function getSupportedParams(): array 'customer_id', 'begin_date', 'end_date', - 'platform' + 'platform', + '_', // for ajax requests ]; } + /** + * Get filters supported by this report. + */ + public function getSupportedFilters(): array + { + return []; + } + + /** + * Get attributes supported by this report. + */ + public function getSupportedAttributes(): array + { + return []; + } + /** * Set filters based on the requested parameters. */ @@ -105,4 +122,10 @@ public function setAttributes(array $attributes): void { $this->attributes = []; } + + /** Get report specific form fields */ + public static function getReportSettingsFormFields(): array + { + return parent::getCommonReportSettingsFormFields(); + } } diff --git a/js/load.js b/js/load.js index f117672e779..11aeaa9d2db 100644 --- a/js/load.js +++ b/js/load.js @@ -21,6 +21,7 @@ import PageOJS from '@/components/Container/PageOJS.vue'; import AccessPage from '@/components/Container/AccessPage.vue'; import AddContextContainer from '@/components/Container/AddContextContainer.vue'; import AdminPage from '@/components/Container/AdminPage.vue'; +import CounterReportsPage from '@/components/Container/CounterReportsPage.vue'; import DoiPage from '@/components/Container/DoiPageOJS.vue'; import DecisionPage from '@/components/Container/DecisionPage.vue'; import ImportExportPage from '@/components/Container/ImportExportPage.vue'; @@ -47,6 +48,7 @@ window.pkp = Object.assign(PkpLoad, window.pkp || {}, { AdminPage, AdvancedSearchReviewerContainer, Container, + CounterReportsPage, DoiPage, DecisionPage, ImportExportPage,