Commit d42b5a4e authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

Merge branch 'fix/14312_max_results_display_to_branch_2_5' into 'Support/2.5.X'

Fix/14312 max results display to branch 2 5

See merge request !546
parents dc29e2d4 ee1fdb21
Pipeline #8990 failed with stage
......@@ -5,7 +5,7 @@
@include menu.ini
; Default max result in search screens
maxResults = 200
maxResults = 500
; Public archive mode
publicArchives = false
......
......@@ -206,17 +206,88 @@ class event
/**
* Get result of search form
* @param timestamp $toDate
*
* @param timestamp $fromDate
* @param timestamp $toDate
* @param string $event
* @param string $accountId
* @param string $status
* @param string $term Term to search
* @param string $wording Wording to search
* @param string $term Term to search
* @param string $wording Wording to search
* @param integer $maxResults Max results to display
*
* @return audit/event[] Array of audit/event object
*/
public function search($toDate = null, $fromDate = null, $event = null, $accountId = null, $status = null, $term = null, $wording = null)
public function search($fromDate = null, $toDate = null, $event = null, $accountId = null, $status = null, $term = null, $wording = null, $maxResults = null)
{
list($queryString, $queryParams) = $this->queryBuilder($fromDate, $toDate, $event, $accountId, $status, $term, $wording);
$events = $this->sdoFactory->find("audit/event", $queryString, $queryParams, ">eventDate", 0, $maxResults);
$userAccountController = \laabs::newController('auth/userAccount');
$users = $userAccountController->index();
foreach ($users as $i => $user) {
$users[(string) $user->accountId] = $user;
unset($users[$i]);
}
$serviceAccountController = \laabs::newController('auth/serviceAccount');
$services = $serviceAccountController->index();
foreach ($services as $i => $service) {
$services[(string) $service->accountId] = $service;
unset($services[$i]);
}
foreach ($events as $i => $event) {
if (isset($event->accountId) && isset($users[(string) $event->accountId])) {
$event->accountName = $users[(string) $event->accountId]->accountName;
} elseif (isset($event->accountId) && isset($services[(string) $event->accountId])) {
$event->accountName = $services[(string) $event->accountId]->accountName;
} else {
$event->accountName = "__system__";
}
$event->origin = strtok($event->path, LAABS_URI_SEPARATOR);
$event->typeCode = strtok(LAABS_URI_SEPARATOR);
}
return $events;
}
/**
* Get count result of search form
*
* @param timestamp $fromDate
* @param timestamp $toDate
* @param string $event
* @param string $accountId
* @param string $status
* @param string $term Term to search
* @param string $wording Wording to search
*
* @return integer Count of max results from query
*/
public function count($fromDate = null, $toDate = null, $event = null, $accountId = null, $status = null, $term = null, $wording = null)
{
list($queryString, $queryParams) = $this->queryBuilder($fromDate, $toDate, $event, $accountId, $status, $term, $wording);
$count = $this->sdoFactory->count("audit/event", $queryString, $queryParams, ">eventDate");
return $count;
}
/**
* Build query
*
* @param timestamp $fromDate
* @param timestamp $toDate
* @param string $event
* @param string $accountId
* @param string $status
* @param string $term Term to search
* @param string $wording Wording to search
*/
private function queryBuilder($fromDate = null, $toDate = null, $event = null, $accountId = null, $status = null, $term = null, $wording = null)
{
$queryParts = array();
$queryParams = array();
......@@ -246,7 +317,7 @@ class event
if ($term) {
$wordings = explode(",", $wording);
$queryParts['term'] = null;
foreach ($wordings as $wording) {
if($wording == 'all') {
$queryParts['term'] = "(info ='*".$term."*' OR input = '*".$term."*' OR variables = '*".$term."*')";
......@@ -258,7 +329,7 @@ class event
}
}
}
if ($wording != 'all') {
$queryParts['term'] .= ")";
}
......@@ -268,57 +339,20 @@ class event
}
$queryString = implode(' AND ', $queryParts );
//$length = \laabs::getRequestMaxCount();
$length = 400;
$events = $this->sdoFactory->find("audit/event", $queryString, $queryParams, ">eventDate", 0, $length);
$userAccountController = \laabs::newController('auth/userAccount');
$users = $userAccountController->index();
foreach ($users as $i => $user) {
$users[(string) $user->accountId] = $user;
unset($users[$i]);
}
$serviceAccountController = \laabs::newController('auth/serviceAccount');
$services = $serviceAccountController->index();
foreach ($services as $i => $service) {
$services[(string) $service->accountId] = $service;
unset($services[$i]);
}
foreach ($events as $i => $event) {
if (isset($event->accountId) && isset($users[(string) $event->accountId])) {
$event->accountName = $users[(string) $event->accountId]->accountName;
} elseif (isset($event->accountId) && isset($services[(string) $event->accountId])) {
$event->accountName = $services[(string) $event->accountId]->accountName;
} else {
$event->accountName = "__system__";
}
$event->origin = strtok($event->path, LAABS_URI_SEPARATOR);
$event->typeCode = strtok(LAABS_URI_SEPARATOR);
}
/*if (count($events) >= $length) {
$count = $this->sdoFactory->count("audit/event", $queryString, $queryParams);
\laabs::setResponseCode(206);
\laabs::setResponseCount($count);
}*/
return $events;
return [$queryString, $queryParams];
}
/**
* Get event
* @param string $eventId
*
*
* @return audit/event Object
*/
public function getEvent($eventId)
{
$event = $this->sdoFactory->read("audit/event", $eventId);
return $event;
}
}
......@@ -39,17 +39,34 @@ interface eventInterface
/**
* Get search form for entries
* @param string $eventType Type of event
* @param timestamp $fromDate Start date
* @param timestamp $toDate End date
* @param string $accountId Id of account
* @param string $event Variables
* @param string $term Term to search
* @param string $wording Wording to search
*
* @param timestamp $fromDate Start date
* @param timestamp $toDate End date
* @param string $event Variables
* @param string $accountId Id of account
* @param string $status
* @param string $term Term to search
* @param string $wording Wording to search
* @param integer $maxResults Max results to display
*
* @action audit/event/search
*/
public function readSearch($eventType = null, $fromDate = null, $toDate = null, $accountId = null, $event = null, $status = null, $term = null, $wording = null);
public function readSearch($fromDate = null, $toDate = null, $event = null, $accountId = null, $status = null, $term = null, $wording = null, $maxResults = null);
/**
* Get count search for entries
*
* @param timestamp $fromDate Start date
* @param timestamp $toDate End date
* @param string $event Variables
* @param string $accountId Id of account
* @param string $status
* @param string $term Term to search
* @param string $wording Wording to search
*
* @action audit/event/count
*/
public function readCount($fromDate = null, $toDate = null, $event = null, $accountId = null, $status = null, $term = null, $wording = null);
/**
* Get search form for entries
......
......@@ -313,8 +313,8 @@ class journal
* @param string $objectId The identifier of the object
* @param timestamp $minDate The minimum date of the event
* @param timestamp $maxDate The maximum date of the event
* @param sring $sortBy The event sorting request
* @param int $numberOfResult The number of result
* @param string $sortBy The event sorting request
* @param int $maxResults The number of result
*
* @throws \Exception
*
......@@ -327,10 +327,64 @@ class journal
$minDate = null,
$maxDate = null,
$sortBy = ">timestamp",
$numberOfResult = null
$maxResults = null
) {
$query = array();
$queryParams = array();
list($queryParams, $queryString) = $this->queryBuilder($eventType, $objectClass, $objectId, $minDate, $maxDate);
$events = $this->sdoFactory->find(
'lifeCycle/event',
$queryString,
$queryParams,
$sortBy,
null,
$maxResults
);
$userAccountController = \laabs::newController('auth/userAccount');
$users = $userAccountController->index();
foreach ($users as $i => $user) {
$users[(string) $user->accountId] = $user;
unset($users[$i]);
}
$serviceAccountController = \laabs::newController('auth/serviceAccount');
$services = $serviceAccountController->index();
foreach ($services as $i => $service) {
$services[(string) $service->accountId] = $service;
unset($services[$i]);
}
foreach ($events as $i => $event) {
if (isset($event->accountId) && isset($users[(string) $event->accountId])) {
$event->accountName = $users[(string) $event->accountId]->accountName;
} elseif (isset($event->accountId) && isset($services[(string) $event->accountId])) {
$event->accountName = $services[(string) $event->accountId]->accountName;
} else {
$event->accountName = "__system__";
}
}
return $events;
}
/**
* Build a search sql query
*
* @param string $eventType The type of the event
* @param string $objectClass The object class
* @param string $objectId The identifier of the object
* @param timestamp $minDate The minimum date of the event
* @param timestamp $maxDate The maximum date of the event
*/
protected function queryBuilder(
$eventType = null,
$objectClass = null,
$objectId = null,
$minDate = null,
$maxDate = null
) {
$query = [];
$queryParams = [];
if ($this->separateInstance) {
$queryParams['instanceName'] = \laabs::getInstanceName();
......@@ -364,46 +418,42 @@ class journal
$queryString = implode(' AND ', $query);
if (!$numberOfResult) {
$numberOfResult = \laabs::configuration('presentation.maarchRM')['maxResults'];
}
return [$queryParams, $queryString];
}
$events = $this->sdoFactory->find(
/**
* Count journal events
*
* @param string $eventType The type of the event
* @param string $objectClass The object class
* @param string $objectId The identifier of the object
* @param timestamp $minDate The minimum date of the event
* @param timestamp $maxDate The maximum date of the event
* @param string $sortBy The event sorting request
*
* @throws \Exception
*
* @return integer Count results of request
*/
public function searchCount(
$eventType = null,
$objectClass = null,
$objectId = null,
$minDate = null,
$maxDate = null,
$sortBy = ">timestamp"
) {
list($queryParams, $queryString) = $this->queryBuilder($eventType, $objectClass, $objectId, $minDate, $maxDate);
$count = $this->sdoFactory->count(
'lifeCycle/event',
$queryString,
$queryParams,
$sortBy,
null,
$numberOfResult
$sortBy
);
$userAccountController = \laabs::newController('auth/userAccount');
$users = $userAccountController->index();
foreach ($users as $i => $user) {
$users[(string) $user->accountId] = $user;
unset($users[$i]);
}
$serviceAccountController = \laabs::newController('auth/serviceAccount');
$services = $serviceAccountController->index();
foreach ($services as $i => $service) {
$services[(string) $service->accountId] = $service;
unset($services[$i]);
}
foreach ($events as $i => $event) {
if (isset($event->accountId) && isset($users[(string) $event->accountId])) {
$event->accountName = $users[(string) $event->accountId]->accountName;
} elseif (isset($event->accountId) && isset($services[(string) $event->accountId])) {
$event->accountName = $services[(string) $event->accountId]->accountName;
} else {
$event->accountName = "__system__";
}
}
return $events;
return $count;
}
/**
* Load a journal
* @param string $journalReference The id of the journal or the journal object
......
......@@ -34,6 +34,8 @@ interface eventInterface
* @param string $objectId The identifier of the object
* @param timestamp $minDate The minimum date of the event
* @param timestamp $maxDate The maximum date of the event
* @param string $sortBy The event sorting request
* @param integer $maxResults Maximum number of results to search
*
* @action lifeCycle/journal/searchEvent
*/
......@@ -42,7 +44,31 @@ interface eventInterface
$objectClass = false,
$objectId = false,
$minDate = false,
$maxDate = false
$maxDate = false,
$sortBy = ">timestamp",
$maxResults = null
);
/**
* Search a journal event
* @param string $eventType The type of the event
* @param string $objectClass The class of the object
* @param string $objectId The identifier of the object
* @param timestamp $minDate The minimum date of the event
* @param timestamp $maxDate The maximum date of the event
* @param string $sortBy The event sorting request
* @param integer $maxResults Maximum number of results to search
*
* @action lifeCycle/journal/searchCount
*/
public function readCount(
$eventType = false,
$objectClass = false,
$objectId = false,
$minDate = false,
$maxDate = false,
$sortBy = ">timestamp",
$maxResults = null
);
/**
......
......@@ -2,18 +2,18 @@
/*
* Copyright (C) 2017 Maarch
*
*
* This file is part of bundle XXXX.
* Bundle recordsManagement is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* Bundle recordsManagement is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with bundle recordsManagement. If not, see <http://www.gnu.org/licenses/>.
*/
......@@ -29,30 +29,31 @@ trait archiveAccessTrait
{
/**
* Search archives by profile / dates / agreement
* @param string $archiveId
* @param string $profileReference
* @param string $status
* @param string $archiveName
* @param string $agreementReference
* @param string $archiveExpired
* @param string $finalDisposition
* @param string $originatorOrgRegNumber
* @param string $originatorOwnerOrgId
* @param string $originatorArchiveId
* @param array $originatingDate
* @param string $filePlanPosition
* @param bool $hasParent
* @param string $description
* @param string $text
* @param bool $partialRetentionRule
* @param string $retentionRuleCode
* @param string $depositStartDate
* @param string $depositEndDate
* @param string $originatingStartDate
* @param string $originatingEndDate
* @param string $archiverArchiveId
* @param string $processingStatus
* @param bool $checkAccess
* @param string $archiveId
* @param string $profileReference
* @param string $status
* @param string $archiveName
* @param string $agreementReference
* @param string $archiveExpired
* @param string $finalDisposition
* @param string $originatorOrgRegNumber
* @param string $originatorOwnerOrgId
* @param string $originatorArchiveId
* @param array $originatingDate
* @param string $filePlanPosition
* @param bool $hasParent
* @param string $description
* @param string $text
* @param bool $partialRetentionRule
* @param string $retentionRuleCode
* @param string $depositStartDate
* @param string $depositEndDate
* @param string $originatingStartDate
* @param string $originatingEndDate
* @param string $archiverArchiveId
* @param string $processingStatus
* @param bool $checkAccess
* @param integer $maxResults
*
* @return recordsManagement/archive[] Array of recordsManagement/archive object
*/
......@@ -80,13 +81,163 @@ trait archiveAccessTrait
$originatingEndDate = null,
$archiverArchiveId = null,
$processingStatus = null,
$checkAccess = true
$checkAccess = true,
$maxResults = null
) {
$accountController = \laabs::newController('auth/userAccount');
$accountController->isAuthorized('user');
$archives = [];
list($searchClasses, $archiveArgs) = $this->getClassesAndArchiveArgsForSearch(
$archiveId,
$profileReference,
$status,
$archiveName,
$agreementReference,
$archiveExpired,
$finalDisposition,
$originatorOrgRegNumber,
$originatorOwnerOrgId,
$originatorArchiveId,
$originatingDate,
$filePlanPosition,
$hasParent,
$partialRetentionRule,
$retentionRuleCode,
$depositStartDate,
$depositEndDate,
$originatingStartDate,
$originatingEndDate,
$archiverArchiveId,
$processingStatus
);
foreach ($searchClasses as $descriptionClass => $descriptionController) {
$archives = array_merge($archives, $descriptionController->search($description, $text, $archiveArgs, $checkAccess, $maxResults));
}
return $archives;
}
/**
* Count archives by profile / dates / agreement
*
* @param string $archiveId
* @param string $profileReference
* @param string $status
* @param string $archiveName
* @param string $agreementReference
* @param string $archiveExpired
* @param string $finalDisposition
* @param string $originatorOrgRegNumber
* @param string $originatorOwnerOrgId
* @param string $originatorArchiveId
* @param array $originatingDate
* @param string $filePlanPosition
* @param bool $hasParent
* @param string $description
* @param string $text
* @param bool $partialRetentionRule
* @param string $retentionRuleCode
* @param string $depositStartDate
* @param string $depositEndDate
* @param string $originatingStartDate
* @param string $originatingEndDate
* @param string $archiverArchiveId
* @param string $processingStatus
* @param bool $checkAccess
* @param integer $maxResults
*
* @return integer $count Count of archives from search
*/
public function count(
$archiveId = null,
$profileReference = null,
$status = null,
$archiveName = null,
$agreementReference = null,
$archiveExpired = null,
$finalDisposition = null,
$originatorOrgRegNumber = null,
$originatorOwnerOrgId = null,
$originatorArchiveId = null,
$originatingDate = null,
$filePlanPosition = null,
$hasParent = null,
$description = null,
$text = null,
$partialRetentionRule = null,
$retentionRuleCode = null,
$depositStartDate = null,
$depositEndDate = null,
$originatingStartDate = null,
$originatingEndDate = null,
$archiverArchiveId = null,
$processingStatus = null,
$checkAccess = true,
$maxResults = null
) {