1
0
Fork 0
mirror of synced 2024-09-21 20:11:15 +12:00
appwrite/src/Appwrite/Utopia/Response/Model/BaseList.php

82 lines
2.2 KiB
PHP
Raw Normal View History

2020-06-24 17:14:42 +12:00
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
class BaseList extends Model
2020-06-24 17:14:42 +12:00
{
/**
* @var string
*/
protected $name = '';
/**
* @var string
*/
protected $type = '';
/**
* @param string $name
* @param string $type
* @param string $key
* @param string $model
* @param bool $paging
* @param bool $public
*/
public function __construct(string $name, string $type, string $key, string $model, bool $paging = true, bool $public = true)
2020-06-24 17:14:42 +12:00
{
$this->name = $name;
$this->type = $type;
$this->public = $public;
2020-10-30 11:44:01 +13:00
if ($paging) {
2022-02-27 22:57:09 +13:00
$namesWithCap = [
'documents', 'collections', 'users', 'files', 'buckets', 'functions',
'deployments', 'executions', 'projects', 'webhooks', 'keys',
'platforms', 'domains', 'memberships', 'teams'
];
2022-02-27 23:05:20 +13:00
if (\in_array($name, $namesWithCap)) {
2022-03-01 06:06:25 +13:00
$description = 'Total number of ' . $key . ' documents that matched your query used as reference for offset pagination. When the `total` number of ' . $key . ' documents available is greater than 5000, total returned will be capped at 5000, and cursor pagination should be used. Read more about [pagination](https://appwrite.io/docs/pagination).';
2022-02-27 22:57:09 +13:00
} else {
$description = 'Total number of ' . $key . ' documents that matched your query.';
}
$this->addRule('total', [
2020-11-08 11:14:48 +13:00
'type' => self::TYPE_INTEGER,
2022-02-27 22:57:09 +13:00
'description' => $description,
2020-11-14 09:38:47 +13:00
'default' => 0,
'example' => 5,
]);
}
$this->addRule($key, [
'type' => $model,
'description' => 'List of '.$key.'.',
2020-11-14 09:38:47 +13:00
'default' => [],
'array' => true,
]);
2020-06-24 17:14:42 +12:00
}
/**
* Get Name
*
2020-06-24 17:14:42 +12:00
* @return string
*/
public function getName():string
{
return $this->name;
2020-06-24 17:14:42 +12:00
}
/**
2021-12-15 23:19:29 +13:00
* Get Type
*
2020-06-24 17:14:42 +12:00
* @return string
*/
public function getType():string
{
return $this->type;
2020-06-24 17:14:42 +12:00
}
}