From 13116a17d0b7ae9008b31150adca50cff4074379 Mon Sep 17 00:00:00 2001 From: vgrem Date: Sat, 9 Oct 2021 11:59:50 +0300 Subject: [PATCH] Reports namespace operations & unit tests --- composer.json | 2 +- examples/Reports/getReports.php | 3 + src/GraphServiceClient.php | 2 +- src/Reports/ReportRoot.php | 76 ++++++++++++++++++++- src/Runtime/OData/ODataRequest.php | 1 + src/Runtime/OData/{ => V4}/JsonFormat.php | 4 +- src/SharePoint/Taxonomy/TaxonomyService.php | 2 +- tests/reports/ReportsTest.php | 18 +++++ 8 files changed, 103 insertions(+), 5 deletions(-) rename src/Runtime/OData/{ => V4}/JsonFormat.php (92%) create mode 100644 tests/reports/ReportsTest.php diff --git a/composer.json b/composer.json index 3550b2d9..02697bf4 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ }, "autoload-dev": { "psr-4": { - "Office365\\": ["tests/", "tests/common/", "tests/sharepoint/", "tests/onenote/", "tests/onedrive/", "tests/outlookservices/", "tests/directory/", "tests/teams/"] + "Office365\\": ["tests/", "tests/common/", "tests/sharepoint/", "tests/onenote/", "tests/onedrive/", "tests/outlookservices/", "tests/directory/", "tests/teams/", "tests/reports/"] } }, "autoload": { diff --git a/examples/Reports/getReports.php b/examples/Reports/getReports.php index 186d1e7d..d688f44b 100644 --- a/examples/Reports/getReports.php +++ b/examples/Reports/getReports.php @@ -21,6 +21,9 @@ function acquireToken() $result = $client->getReports()->getOffice365ActivationCounts()->executeQuery(); var_dump($result->getValue()); +$result = $client->getReports()->getOffice365ActiveUserDetail("D7")->executeQuery(); +var_dump($result->getValue()); + diff --git a/src/GraphServiceClient.php b/src/GraphServiceClient.php index 036f8edd..b42a3704 100644 --- a/src/GraphServiceClient.php +++ b/src/GraphServiceClient.php @@ -15,7 +15,7 @@ use Office365\Runtime\ClientRuntimeContext; use Office365\Runtime\Actions\DeleteEntityQuery; use Office365\Runtime\Http\HttpMethod; -use Office365\Runtime\OData\JsonFormat; +use Office365\Runtime\OData\V4\JsonFormat; use Office365\Runtime\OData\ODataMetadataLevel; use Office365\Runtime\OData\ODataRequest; use Office365\Runtime\Office365Version; diff --git a/src/Reports/ReportRoot.php b/src/Reports/ReportRoot.php index 1959d8b9..43f5d6b3 100644 --- a/src/Reports/ReportRoot.php +++ b/src/Reports/ReportRoot.php @@ -15,10 +15,13 @@ class ReportRoot extends Entity /** * @param $name string + * @param $period string * @return ClientResult */ - private function addReportQuery($name){ + private function addReportQuery($name,$period=null){ $qry = new InvokeMethodQuery($this, $name); + if(!is_null($period)) + $qry->MethodParameters = array("period" => $period); $this->getContext()->getPendingRequest()->beforeExecuteRequestOnce(function (RequestOptions $request){ $request->FollowLocation = true; }); @@ -51,4 +54,75 @@ function getOffice365ActivationCounts(){ function getOffice365ActivationsUserCounts(){ return $this->addReportQuery("getOffice365ActivationsUserCounts"); } + + + /** + * Get details about Microsoft 365 active users. + * @return ClientResult + */ + function getOffice365ActiveUserDetail($period){ + return $this->addReportQuery("getOffice365ActiveUserDetail",$period); + } + + + /** + * Get the count of daily active users in the reporting period by product. + * @return ClientResult + */ + function getOffice365ActiveUserCounts($period){ + return $this->addReportQuery("getOffice365ActiveUserCounts",$period); + } + + + /** + * Get the count of users by activity type and service. + * @return ClientResult + */ + function getOffice365ServicesUserCounts($period){ + return $this->addReportQuery("getOffice365ServicesUserCounts",$period); + } + + /** + * Get details about Microsoft 365 groups activity by group. + * @return ClientResult + */ + function getOffice365GroupsActivityDetail($period){ + return $this->addReportQuery("getOffice365GroupsActivityDetail",$period); + } + + /** + * Get the number of group activities across group workloads. + * @return ClientResult + */ + function getOffice365GroupsActivityCounts($period){ + return $this->addReportQuery("getOffice365GroupsActivityCounts",$period); + } + + /** + * Get the daily total number of groups and how many of them were active based on email conversations, + * Yammer posts, and SharePoint file activities. + * @return ClientResult + */ + function getOffice365GroupsActivityGroupCounts($period){ + return $this->addReportQuery("getOffice365GroupsActivityGroupCounts",$period); + } + + /** + * Get the total storage used across all group mailboxes and group sites. + * @return ClientResult + */ + function getOffice365GroupsActivityStorage($period){ + return $this->addReportQuery("getOffice365GroupsActivityStorage",$period); + } + + /** + * Get the total number of files and how many of them were active across all group sites associated with + * a Microsoft 365 group. + * @return ClientResult + */ + function getOffice365GroupsActivityFileCounts($period){ + return $this->addReportQuery("getOffice365GroupsActivityFileCounts",$period); + } + + } \ No newline at end of file diff --git a/src/Runtime/OData/ODataRequest.php b/src/Runtime/OData/ODataRequest.php index 04d73f95..021efd31 100644 --- a/src/Runtime/OData/ODataRequest.php +++ b/src/Runtime/OData/ODataRequest.php @@ -19,6 +19,7 @@ use Office365\Runtime\Actions\InvokeMethodQuery; use Office365\Runtime\Actions\InvokePostMethodQuery; use Office365\Runtime\OData\V3\JsonLightFormat; +use Office365\Runtime\OData\V4\JsonFormat; use Office365\SharePoint\ClientContext; diff --git a/src/Runtime/OData/JsonFormat.php b/src/Runtime/OData/V4/JsonFormat.php similarity index 92% rename from src/Runtime/OData/JsonFormat.php rename to src/Runtime/OData/V4/JsonFormat.php index 7ad902ad..2ab00121 100644 --- a/src/Runtime/OData/JsonFormat.php +++ b/src/Runtime/OData/V4/JsonFormat.php @@ -1,10 +1,12 @@ getReports()->getOffice365ActiveUserCounts("D180")->executeQuery(); + self::assertNotNull($result->getValue()); + self::assertInstanceOf(Report::class,$result->getValue()); + } + +} \ No newline at end of file