2020-06-08 20:32:42 +00:00
|
|
|
<?php
|
2020-06-10 15:00:12 +00:00
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
2020-06-08 20:32:42 +00:00
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
|
|
|
|
class EpisodeModel extends Model
|
|
|
|
{
|
|
|
|
protected $table = 'episodes';
|
|
|
|
protected $primaryKey = 'id';
|
|
|
|
|
|
|
|
protected $allowedFields = [
|
2020-06-10 15:00:12 +00:00
|
|
|
'podcast_id',
|
2020-06-08 20:32:42 +00:00
|
|
|
'title',
|
2020-06-10 15:00:12 +00:00
|
|
|
'slug',
|
2020-06-26 14:34:52 +00:00
|
|
|
'enclosure_uri',
|
2020-06-08 20:32:42 +00:00
|
|
|
'enclosure_length',
|
|
|
|
'enclosure_type',
|
|
|
|
'pub_date',
|
|
|
|
'description',
|
|
|
|
'duration',
|
2020-06-26 14:34:52 +00:00
|
|
|
'image_uri',
|
2020-06-08 20:32:42 +00:00
|
|
|
'explicit',
|
2020-06-12 19:31:10 +00:00
|
|
|
'number',
|
2020-06-08 20:32:42 +00:00
|
|
|
'season_number',
|
2020-06-26 14:34:52 +00:00
|
|
|
'author_name',
|
|
|
|
'author_email',
|
2020-06-08 20:32:42 +00:00
|
|
|
'type',
|
|
|
|
'block',
|
|
|
|
];
|
|
|
|
|
|
|
|
protected $returnType = 'App\Entities\Episode';
|
|
|
|
|
2020-06-30 18:17:41 +02:00
|
|
|
protected $useSoftDeletes = true;
|
2020-06-08 20:32:42 +00:00
|
|
|
protected $useTimestamps = true;
|
2020-06-30 18:17:41 +02:00
|
|
|
|
|
|
|
protected $afterInsert = [
|
|
|
|
'writeEnclosureMetadata',
|
|
|
|
'clearPodcastFeedCache',
|
|
|
|
];
|
|
|
|
protected $afterUpdate = [
|
|
|
|
'writeEnclosureMetadata',
|
|
|
|
'clearPodcastFeedCache',
|
|
|
|
];
|
|
|
|
|
|
|
|
protected function writeEnclosureMetadata(array $data)
|
|
|
|
{
|
|
|
|
helper('id3');
|
|
|
|
|
|
|
|
$episode = $this->find(
|
|
|
|
is_array($data['id']) ? $data['id'][0] : $data['id']
|
|
|
|
);
|
|
|
|
|
|
|
|
write_enclosure_tags($episode);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function clearPodcastFeedCache(array $data)
|
|
|
|
{
|
|
|
|
$episode = $this->find(
|
|
|
|
is_array($data['id']) ? $data['id'][0] : $data['id']
|
|
|
|
);
|
|
|
|
|
|
|
|
$cache = \Config\Services::cache();
|
|
|
|
|
|
|
|
$cache->delete(md5($episode->podcast->feed_url));
|
|
|
|
}
|
2020-06-08 20:32:42 +00:00
|
|
|
}
|