2020-08-04 11:25:22 +00:00
|
|
|
<?php
|
2020-07-31 16:05:10 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
class UserModel extends \Myth\Auth\Models\UserModel
|
|
|
|
{
|
2020-08-04 11:25:22 +00:00
|
|
|
protected $returnType = \App\Entities\User::class;
|
2020-07-31 16:05:10 +00:00
|
|
|
|
2020-09-04 09:09:26 +00:00
|
|
|
public function getPodcastContributors($podcastId)
|
2020-07-31 16:05:10 +00:00
|
|
|
{
|
2020-09-04 09:09:26 +00:00
|
|
|
if (!($found = cache("podcast{$podcastId}_contributors"))) {
|
|
|
|
$found = $this->select('users.*, auth_groups.name as podcast_role')
|
|
|
|
->join('users_podcasts', 'users_podcasts.user_id = users.id')
|
|
|
|
->join(
|
|
|
|
'auth_groups',
|
|
|
|
'auth_groups.id = users_podcasts.group_id'
|
|
|
|
)
|
|
|
|
->where('users_podcasts.podcast_id', $podcastId)
|
|
|
|
->findAll();
|
|
|
|
|
|
|
|
cache()->save("podcast{$podcastId}_contributors", $found, DECADE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $found;
|
2020-07-31 16:05:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getPodcastContributor($user_id, $podcast_id)
|
|
|
|
{
|
2020-08-05 16:10:39 +00:00
|
|
|
return $this->select(
|
|
|
|
'users.*, users_podcasts.podcast_id as podcast_id, auth_groups.name as podcast_role'
|
|
|
|
)
|
2020-07-31 16:05:10 +00:00
|
|
|
->join('users_podcasts', 'users_podcasts.user_id = users.id')
|
2020-08-05 16:10:39 +00:00
|
|
|
->join('auth_groups', 'auth_groups.id = users_podcasts.group_id')
|
2020-07-31 16:05:10 +00:00
|
|
|
->where([
|
|
|
|
'users.id' => $user_id,
|
|
|
|
'podcast_id' => $podcast_id,
|
|
|
|
])
|
|
|
|
->first();
|
|
|
|
}
|
|
|
|
}
|