2020-06-24 17:14:42 +12:00
< ? php
namespace Appwrite\Utopia\Response\Model ;
use Appwrite\Utopia\Response ;
use Appwrite\Utopia\Response\Model ;
2020-10-30 02:07:56 +13:00
class BaseList extends Model
2020-06-24 17:14:42 +12:00
{
2020-10-30 02:07:56 +13:00
/**
* @ var string
*/
protected $name = '' ;
/**
* @ var string
*/
protected $type = '' ;
2020-11-12 18:12:14 +13:00
/**
* @ 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
{
2020-10-30 02:07:56 +13:00
$this -> name = $name ;
$this -> type = $type ;
2020-11-12 18:12:14 +13:00
$this -> public = $public ;
2020-10-30 02:07:56 +13:00
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'
];
if ( \in_array ( $namesWithCap , $name )) {
$description = 'Total number of ' . $key . ' documents that matched your query used as reference for offset pagination. When the `total` is more than 5000, it will be capped at 5000, and cursor pagination should be used. Read more about [pagination](https://appwrite.io/docs/pagination).' ;
} 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 ,
2020-10-30 02:07:56 +13:00
]);
}
$this -> addRule ( $key , [
'type' => $model ,
'description' => 'List of ' . $key . '.' ,
2020-11-14 09:38:47 +13:00
'default' => [],
2020-10-30 02:07:56 +13:00
'array' => true ,
]);
2020-06-24 17:14:42 +12:00
}
/**
* Get Name
2021-10-07 03:22:38 +13:00
*
2020-06-24 17:14:42 +12:00
* @ return string
*/
public function getName () : string
{
2020-10-30 02:07:56 +13:00
return $this -> name ;
2020-06-24 17:14:42 +12:00
}
/**
2021-12-15 23:19:29 +13:00
* Get Type
2021-10-07 03:22:38 +13:00
*
2020-06-24 17:14:42 +12:00
* @ return string
*/
public function getType () : string
{
2020-10-30 02:07:56 +13:00
return $this -> type ;
2020-06-24 17:14:42 +12:00
}
2021-10-07 03:22:38 +13:00
}