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

115 lines
3.3 KiB
PHP
Raw Normal View History

2020-06-05 09:53:06 +00:00
<?php
2020-06-23 15:01:20 +00:00
namespace Appwrite\Utopia\Response\Model;
2020-06-05 09:53:06 +00:00
2020-06-23 15:01:20 +00:00
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
use Utopia\Database\Document;
2020-06-05 09:53:06 +00:00
2020-06-23 15:01:20 +00:00
class User extends Model
2020-06-05 09:53:06 +00:00
{
public function __construct()
{
$this
2020-06-22 16:25:01 +00:00
->addRule('$id', [
2020-11-07 22:14:48 +00:00
'type' => self::TYPE_STRING,
2020-06-22 16:25:01 +00:00
'description' => 'User ID.',
2021-01-13 15:06:36 +00:00
'default' => '',
2020-06-22 16:25:01 +00:00
'example' => '5e5ea5c16897e',
])
->addRule('name', [
2020-11-07 22:14:48 +00:00
'type' => self::TYPE_STRING,
2020-06-22 16:25:01 +00:00
'description' => 'User name.',
2021-01-13 15:06:36 +00:00
'default' => '',
2020-06-22 16:25:01 +00:00
'example' => 'John Doe',
])
2020-06-22 19:06:57 +00:00
->addRule('registration', [
2020-11-07 22:14:48 +00:00
'type' => self::TYPE_INTEGER,
2020-06-24 11:18:33 +00:00
'description' => 'User registration date in Unix timestamp.',
2021-01-13 15:06:36 +00:00
'default' => 0,
2020-06-24 06:53:13 +00:00
'example' => 1592981250,
2020-06-22 19:06:57 +00:00
])
->addRule('status', [
'type' => self::TYPE_BOOLEAN,
'description' => 'User status. Pass `true` for enabled and `false` for disabled.',
'default' => true,
'example' => true,
2020-06-22 19:06:57 +00:00
])
->addRule('passwordUpdate', [
'type' => self::TYPE_INTEGER,
'description' => 'Unix timestamp of the most recent password update',
'default' => 0,
'example' => 1592981250,
])
2020-06-22 16:25:01 +00:00
->addRule('email', [
2020-11-07 22:14:48 +00:00
'type' => self::TYPE_STRING,
2020-06-22 16:25:01 +00:00
'description' => 'User email address.',
2021-01-13 15:06:36 +00:00
'default' => '',
2020-06-22 16:25:01 +00:00
'example' => 'john@appwrite.io',
])
2022-06-08 09:00:38 +00:00
->addRule('phone', [
'type' => self::TYPE_STRING,
'description' => 'User phone number.',
'default' => '',
'example' => '+49 30 901820',
])
2020-06-22 16:25:01 +00:00
->addRule('emailVerification', [
2020-11-07 22:14:48 +00:00
'type' => self::TYPE_BOOLEAN,
2020-06-22 16:25:01 +00:00
'description' => 'Email verification status.',
'default' => false,
'example' => true,
])
2022-06-08 09:00:38 +00:00
->addRule('phoneVerification', [
'type' => self::TYPE_BOOLEAN,
'description' => 'Phone verification status.',
'default' => false,
'example' => true,
])
2020-06-22 16:25:01 +00:00
->addRule('prefs', [
2021-04-21 13:37:51 +00:00
'type' => Response::MODEL_PREFERENCES,
2020-06-22 16:25:01 +00:00
'description' => 'User preferences as a key-value object',
2022-05-23 14:54:50 +00:00
'default' => new \stdClass(),
'example' => ['theme' => 'pink', 'timezone' => 'UTC'],
2020-06-22 16:25:01 +00:00
])
2020-06-05 09:53:06 +00:00
;
}
/**
* Get Collection
2022-05-23 14:54:50 +00:00
*
* @return string
*/
public function filter(Document $document): Document
{
$prefs = $document->getAttribute('prefs');
2022-05-23 14:54:50 +00:00
if ($prefs instanceof Document) {
$prefs = $prefs->getArrayCopy();
}
2022-05-23 14:54:50 +00:00
if (is_array($prefs) && empty($prefs)) {
$document->setAttribute('prefs', new \stdClass());
}
return $document;
}
2020-06-05 09:53:06 +00:00
/**
* Get Name
*
2020-06-05 09:53:06 +00:00
* @return string
*/
2022-05-23 14:54:50 +00:00
public function getName(): string
2020-06-05 09:53:06 +00:00
{
return 'User';
}
/**
2021-12-15 10:19:29 +00:00
* Get Type
*
2020-06-05 09:53:06 +00:00
* @return string
*/
2022-05-23 14:54:50 +00:00
public function getType(): string
2020-06-05 09:53:06 +00:00
{
2020-06-23 15:01:20 +00:00
return Response::MODEL_USER;
2020-06-05 09:53:06 +00:00
}
}