mirror of
https://code.castopod.org/adaures/castopod
synced 2025-04-23 01:01:20 +00:00

- update CI process to include quality stage (tests + code review) - add captainhook to install git pre-commit & pre-push hooks - remove .devcontainer Dockerfile to use project's docker-compose services: all services can now be started automatically using vscode - update docs/setup-development.md
83 lines
1.8 KiB
PHP
83 lines
1.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @copyright 2020 Podlibre
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
* @link https://castopod.org/
|
|
*/
|
|
|
|
namespace App\Entities;
|
|
|
|
use RuntimeException;
|
|
use App\Models\PodcastModel;
|
|
|
|
class User extends \Myth\Auth\Entities\User
|
|
{
|
|
/**
|
|
* Per-user podcasts
|
|
* @var Podcast[]
|
|
*/
|
|
protected $podcasts = [];
|
|
|
|
/**
|
|
* The podcast the user is contributing to
|
|
*
|
|
* @var Podcast|null
|
|
*/
|
|
protected $podcast;
|
|
|
|
/**
|
|
* Array of field names and the type of value to cast them as
|
|
* when they are accessed.
|
|
*
|
|
* @var array<string, string>
|
|
*/
|
|
protected $casts = [
|
|
'id' => 'integer',
|
|
'active' => 'boolean',
|
|
'force_pass_reset' => 'boolean',
|
|
'podcast_role' => '?string',
|
|
'podcast_id' => '?integer',
|
|
];
|
|
|
|
/**
|
|
* Returns the podcasts the user is contributing to
|
|
*
|
|
* @return Podcast[]
|
|
*/
|
|
public function getPodcasts(): array
|
|
{
|
|
if (empty($this->id)) {
|
|
throw new RuntimeException(
|
|
'Users must be created before getting podcasts.',
|
|
);
|
|
}
|
|
|
|
if (empty($this->podcasts)) {
|
|
$this->podcasts = (new PodcastModel())->getUserPodcasts($this->id);
|
|
}
|
|
|
|
return $this->podcasts;
|
|
}
|
|
|
|
/**
|
|
* Returns a podcast the user is contributing to
|
|
*/
|
|
public function getPodcast(): Podcast
|
|
{
|
|
if (empty($this->podcast_id)) {
|
|
throw new RuntimeException(
|
|
'Podcast_id must be set before getting podcast.',
|
|
);
|
|
}
|
|
|
|
if (empty($this->podcast)) {
|
|
$this->podcast = (new PodcastModel())->getPodcastById(
|
|
$this->podcast_id,
|
|
);
|
|
}
|
|
|
|
return $this->podcast;
|
|
}
|
|
}
|