2020-08-04 11:25:22 +00:00
|
|
|
<?php
|
|
|
|
|
2020-10-02 15:38:16 +00:00
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
2020-08-04 11:25:22 +00:00
|
|
|
namespace App\Entities;
|
2020-07-31 16:05:10 +00:00
|
|
|
|
|
|
|
use App\Models\PodcastModel;
|
2021-05-12 14:00:25 +00:00
|
|
|
use Myth\Auth\Entities\User as MythAuthUser;
|
2021-05-19 16:35:13 +00:00
|
|
|
use RuntimeException;
|
2020-07-31 16:05:10 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
/**
|
|
|
|
* @property int $id
|
|
|
|
* @property string $username
|
|
|
|
* @property string $email
|
|
|
|
* @property string $password
|
|
|
|
* @property bool $active
|
|
|
|
* @property bool $force_pass_reset
|
|
|
|
* @property int|null $podcast_id
|
|
|
|
* @property string|null $podcast_role
|
|
|
|
*
|
|
|
|
* @property Podcast[] $podcasts All podcasts the user is contributing to
|
|
|
|
*/
|
|
|
|
class User extends MythAuthUser
|
2020-07-31 16:05:10 +00:00
|
|
|
{
|
|
|
|
/**
|
2021-05-17 17:11:23 +00:00
|
|
|
* @var Podcast[]|null
|
2020-07-31 16:05:10 +00:00
|
|
|
*/
|
2021-05-17 17:11:23 +00:00
|
|
|
protected ?array $podcasts = null;
|
2020-07-31 16:05:10 +00:00
|
|
|
|
|
|
|
/**
|
2021-05-19 16:35:13 +00:00
|
|
|
* Array of field names and the type of value to cast them as when they are accessed.
|
2021-05-06 14:00:48 +00:00
|
|
|
*
|
|
|
|
* @var array<string, string>
|
2020-07-31 16:05:10 +00:00
|
|
|
*/
|
|
|
|
protected $casts = [
|
2020-12-07 20:13:46 +00:00
|
|
|
'id' => 'integer',
|
2020-07-31 16:05:10 +00:00
|
|
|
'active' => 'boolean',
|
|
|
|
'force_pass_reset' => 'boolean',
|
2020-08-05 16:10:39 +00:00
|
|
|
'podcast_id' => '?integer',
|
2021-05-12 14:00:25 +00:00
|
|
|
'podcast_role' => '?string',
|
2020-07-31 16:05:10 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the podcasts the user is contributing to
|
|
|
|
*
|
2021-05-06 14:00:48 +00:00
|
|
|
* @return Podcast[]
|
2020-07-31 16:05:10 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getPodcasts(): array
|
2020-07-31 16:05:10 +00:00
|
|
|
{
|
2021-05-12 14:00:25 +00:00
|
|
|
if ($this->id === null) {
|
2021-05-19 16:35:13 +00:00
|
|
|
throw new RuntimeException('Users must be created before getting podcasts.',);
|
2020-07-31 16:05:10 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
if ($this->podcasts === null) {
|
2020-07-31 16:05:10 +00:00
|
|
|
$this->podcasts = (new PodcastModel())->getUserPodcasts($this->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->podcasts;
|
|
|
|
}
|
|
|
|
}
|