2020-08-04 11:25:22 +00:00
|
|
|
<?php
|
2020-07-31 16:05:10 +00:00
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-09-04 09:09:26 +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\Models;
|
2020-07-31 16:05:10 +00:00
|
|
|
|
2021-08-23 11:05:16 +00:00
|
|
|
use Modules\Auth\Entities\User;
|
2021-05-12 14:00:25 +00:00
|
|
|
use Myth\Auth\Models\UserModel as MythAuthUserModel;
|
|
|
|
|
|
|
|
class UserModel extends MythAuthUserModel
|
2020-07-31 16:05:10 +00:00
|
|
|
{
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $returnType = User::class;
|
2020-07-31 16:05:10 +00:00
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
/**
|
|
|
|
* @return User[]
|
|
|
|
*/
|
|
|
|
public function getPodcastContributors(int $podcastId): array
|
2020-07-31 16:05:10 +00:00
|
|
|
{
|
2021-04-20 13:43:38 +00:00
|
|
|
$cacheName = "podcast#{$podcastId}_contributors";
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! ($found = cache($cacheName))) {
|
2020-09-04 09:09:26 +00:00
|
|
|
$found = $this->select('users.*, auth_groups.name as podcast_role')
|
2020-10-29 15:45:19 +00:00
|
|
|
->join('podcasts_users', 'podcasts_users.user_id = users.id')
|
2021-06-09 12:40:22 +00:00
|
|
|
->join('auth_groups', 'auth_groups.id = podcasts_users.group_id')
|
2020-10-29 15:45:19 +00:00
|
|
|
->where('podcasts_users.podcast_id', $podcastId)
|
2020-09-04 09:09:26 +00:00
|
|
|
->findAll();
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
cache()
|
|
|
|
->save($cacheName, $found, DECADE);
|
2020-09-04 09:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $found;
|
2020-07-31 16:05:10 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function getPodcastContributor(int $userId, int $podcastId): ?User
|
2020-07-31 16:05:10 +00:00
|
|
|
{
|
2021-06-09 12:40:22 +00:00
|
|
|
return $this->select('users.*, podcasts_users.podcast_id as podcast_id, auth_groups.name as podcast_role')
|
2020-10-29 15:45:19 +00:00
|
|
|
->join('podcasts_users', 'podcasts_users.user_id = users.id')
|
|
|
|
->join('auth_groups', 'auth_groups.id = podcasts_users.group_id')
|
2020-07-31 16:05:10 +00:00
|
|
|
->where([
|
2021-05-14 17:59:35 +00:00
|
|
|
'users.id' => $userId,
|
|
|
|
'podcast_id' => $podcastId,
|
2020-07-31 16:05:10 +00:00
|
|
|
])
|
|
|
|
->first();
|
|
|
|
}
|
|
|
|
}
|