appwrite/src/Appwrite/Utopia/Response/Model/Row.php

102 lines
3 KiB
PHP
Raw Normal View History

<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
2022-01-17 16:25:20 +00:00
use Utopia\Database\Document as DatabaseDocument;
class Row extends Any
{
/**
* Get Name
*
* @return string
*/
public function getName(): string
{
return 'Row';
}
/**
2021-12-15 10:19:29 +00:00
* Get Type
*
* @return string
*/
public function getType(): string
{
return Response::MODEL_ROW;
}
public function __construct()
{
$this
->addRule('$id', [
'type' => self::TYPE_STRING,
'description' => 'Row ID.',
'default' => '',
'example' => '5e5ea5c16897e',
])
2025-06-12 11:44:50 +00:00
->addRule('$sequence', [
'type' => self::TYPE_INTEGER,
'description' => 'Row automatically incrementing ID.',
'default' => 0,
'example' => 1,
'readOnly' => true,
2025-06-12 11:44:50 +00:00
])
->addRule('$tableId', [
'type' => self::TYPE_STRING,
'description' => 'Table ID.',
'default' => '',
'example' => '5e5ea5c15117e',
'readOnly' => true,
])
->addRule('$databaseId', [
'type' => self::TYPE_STRING,
'description' => 'Database ID.',
'default' => '',
'example' => '5e5ea5c15117e',
'readOnly' => true,
])
->addRule('$createdAt', [
2022-07-04 09:55:11 +00:00
'type' => self::TYPE_DATETIME,
'description' => 'Row creation date in ISO 8601 format.',
2022-07-04 09:55:11 +00:00
'default' => '',
2022-08-14 10:27:07 +00:00
'example' => self::TYPE_DATETIME_EXAMPLE,
])
->addRule('$updatedAt', [
2022-07-04 09:55:11 +00:00
'type' => self::TYPE_DATETIME,
'description' => 'Row update date in ISO 8601 format.',
2022-07-04 09:55:11 +00:00
'default' => '',
2022-08-14 10:27:07 +00:00
'example' => self::TYPE_DATETIME_EXAMPLE,
])
->addRule('$permissions', [
'type' => self::TYPE_STRING,
'description' => 'Row permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).',
'default' => '',
2022-08-14 10:33:36 +00:00
'example' => ['read("any")'],
'array' => true,
]);
}
2022-01-17 16:25:20 +00:00
public function filter(DatabaseDocument $document): DatabaseDocument
{
2024-09-05 02:25:11 +00:00
$document->removeAttribute('$collection');
$document->removeAttribute('$tenant');
$document->setAttribute('$sequence', (int)$document->getAttribute('$sequence', 0));
2022-01-17 16:25:20 +00:00
foreach ($document->getAttributes() as $column) {
if (\is_array($column)) {
foreach ($column as $subAttribute) {
if ($subAttribute instanceof DatabaseDocument) {
$this->filter($subAttribute);
}
}
} elseif ($column instanceof DatabaseDocument) {
$this->filter($column);
}
}
2022-01-17 16:25:20 +00:00
return $document;
}
}