Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

development to main #107

Merged
merged 14 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/Db/AuditTrailMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/**
* The AuditTrailMapper class
*
*
* @package OCA\OpenRegister\Db
*/
class AuditTrailMapper extends QBMapper
Expand Down Expand Up @@ -125,7 +125,7 @@ public function createFromArray(array $object): Log

return $this->insert(entity: $log);
}

/**
* Creates an audit trail for object changes
*
Expand All @@ -152,7 +152,7 @@ public function createAuditTrail(?ObjectEntity $old = null, ?ObjectEntity $new =
if ($action !== 'delete') {
$oldArray = $old ? $old->jsonSerialize() : [];
$newArray = $new->jsonSerialize();

// Compare old and new values to detect changes
foreach ($newArray as $key => $value) {
if (!isset($oldArray[$key]) || $oldArray[$key] !== $value) {
Expand All @@ -162,7 +162,7 @@ public function createAuditTrail(?ObjectEntity $old = null, ?ObjectEntity $new =
];
}
}

// For updates, check for removed fields
if ($action === 'update') {
foreach ($oldArray as $key => $value) {
Expand All @@ -185,8 +185,8 @@ public function createAuditTrail(?ObjectEntity $old = null, ?ObjectEntity $new =
$auditTrail->setObject($objectEntity->getId());
$auditTrail->setAction($action);
$auditTrail->setChanged($changed);
$auditTrail->setUser($user->getUID());
$auditTrail->setUserName($user->getDisplayName());
$auditTrail->setUser(($user !== null) ? $user->getUID() : 'System');
$auditTrail->setUserName(($user !== null) ? $user->getDisplayName() : 'System');
$auditTrail->setSession(session_id());
$auditTrail->setRequest(\OC::$server->getRequest()->getId());
$auditTrail->setIpAddress(\OC::$server->getRequest()->getRemoteAddress());
Expand Down
6 changes: 5 additions & 1 deletion lib/Service/FileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
use Psr\Log\LoggerInterface;

/**
* Service class for handling file operations in OpenCatalogi
* Service for handling file operations in OpenRegister.
*
* This service provides functionalities for managing files and folders within the NextCloud environment,
* including creation, deletion, sharing, and file updates. It integrates with NextCloud's file and
* sharing APIs to provide seamless file management for the application.
*/
class FileService
{
Expand Down
79 changes: 79 additions & 0 deletions lib/Service/ObjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,31 @@ public function findMultiple(array $ids): array
return $result;
}

/**
* Find subobjects for a certain property with given ids
*
* @param array $ids The IDs to fetch the subobjects for
* @param string $property The property in which the objects reside.
*
* @return array The resulting subobjects.
*/
public function findSubObjects(array $ids, string $property): array
{
$schemaObject = $this->schemaMapper->find($this->schema);
$property = $schemaObject->getProperties()[$property];

if (isset($property['items'])) {
$ref = explode('/', $property['items']['$ref']);
} else {
$subSchema = explode('/', $property['$ref']);
}
$subSchema = end($ref);

$subSchemaMapper = $this->getMapper(register: $this->getRegister(), schema: $subSchema);

return $subSchemaMapper->findMultiple($ids);
}

/**
* Get aggregations for objects matching filters
*
Expand Down Expand Up @@ -312,6 +337,60 @@ private function getDataFromObject(mixed $object, ?array $extend = []): mixed
return $object->getObject();
}

/**
* Find all objects conforming to the request parameters, surrounded with pagination data.
*
* @param array $requestParams The request parameters to search with.
*
* @return array The result including pagination data.
*/
public function findAllPaginated(array $requestParams): array
{
// Extract specific parameters
$limit = $requestParams['limit'] ?? $requestParams['_limit'] ?? null;
$offset = $requestParams['offset'] ?? $requestParams['_offset'] ?? null;
$order = $requestParams['order'] ?? $requestParams['_order'] ?? [];
$extend = $requestParams['extend'] ?? $requestParams['_extend'] ?? null;
$page = $requestParams['page'] ?? $requestParams['_page'] ?? null;
$search = $requestParams['_search'] ?? null;

if ($page !== null && isset($limit)) {
$page = (int) $page;
$offset = $limit * ($page - 1);
}

// Ensure order and extend are arrays
if (is_string($order)) {
$order = array_map('trim', explode(',', $order));
}
if (is_string($extend)) {
$extend = array_map('trim', explode(',', $extend));
}

// Remove unnecessary parameters from filters
$filters = $requestParams;
unset($filters['_route']); // TODO: Investigate why this is here and if it's needed
unset($filters['_extend'], $filters['_limit'], $filters['_offset'], $filters['_order'], $filters['_page'], $filters['_search']);
unset($filters['extend'], $filters['limit'], $filters['offset'], $filters['order'], $filters['page']);

$objects = $this->findAll(limit: $limit, offset: $offset, filters: $filters, sort: $order, search: $search, extend: $extend);
$total = $this->count($filters);
$pages = $limit !== null ? ceil($total/$limit) : 1;

$facets = $this->getAggregations(
filters: $filters,
search: $search
);

return [
'results' => $objects,
'facets' => $facets,
'total' => $total,
'page' => $page ?? 1,
'pages' => $pages,
];
}

/**
* Gets all objects of a specific type.
*
Expand Down
Loading