castopod/app/Models/UserModel.php
Yassine Doghri 391c349daa refactor(database): add / update fields to optimize storage
- harmonize field types and use explicit names
- store html value alongside markdown descriptions for better performance
- add duration and bandwidth to podcast analytics
- add new analytics table for podcast hits by hour
- replace visible MAXMIND_LICENCE_KEY with variable
2020-10-29 15:45:19 +00:00

47 lines
1.4 KiB
PHP

<?php
/**
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace App\Models;
class UserModel extends \Myth\Auth\Models\UserModel
{
protected $returnType = \App\Entities\User::class;
public function getPodcastContributors($podcastId)
{
if (!($found = cache("podcast{$podcastId}_contributors"))) {
$found = $this->select('users.*, auth_groups.name as podcast_role')
->join('podcasts_users', 'podcasts_users.user_id = users.id')
->join(
'auth_groups',
'auth_groups.id = podcasts_users.group_id'
)
->where('podcasts_users.podcast_id', $podcastId)
->findAll();
cache()->save("podcast{$podcastId}_contributors", $found, DECADE);
}
return $found;
}
public function getPodcastContributor($user_id, $podcast_id)
{
return $this->select(
'users.*, podcasts_users.podcast_id as podcast_id, auth_groups.name as podcast_role'
)
->join('podcasts_users', 'podcasts_users.user_id = users.id')
->join('auth_groups', 'auth_groups.id = podcasts_users.group_id')
->where([
'users.id' => $user_id,
'podcast_id' => $podcast_id,
])
->first();
}
}