2020-05-29 18:25:17 +02:00
|
|
|
<?php
|
2020-08-04 13:25:22 +02:00
|
|
|
|
2020-06-10 17:00:12 +02:00
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
2020-05-29 18:25:17 +02:00
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
|
|
|
|
class CategoryModel extends Model
|
|
|
|
{
|
2020-05-31 21:15:52 +02:00
|
|
|
protected $table = 'categories';
|
2020-05-29 18:25:17 +02:00
|
|
|
protected $primaryKey = 'id';
|
|
|
|
|
2020-06-26 16:34:52 +02:00
|
|
|
protected $allowedFields = [
|
|
|
|
'parent_id',
|
|
|
|
'code',
|
|
|
|
'apple_category',
|
|
|
|
'google_category',
|
|
|
|
];
|
2020-05-29 18:25:17 +02:00
|
|
|
|
2020-08-04 13:25:22 +02:00
|
|
|
protected $returnType = \App\Entities\Category::class;
|
2020-05-29 18:25:17 +02:00
|
|
|
protected $useSoftDeletes = false;
|
|
|
|
|
2020-05-31 21:15:52 +02:00
|
|
|
protected $useTimestamps = false;
|
2020-08-04 13:25:22 +02:00
|
|
|
|
|
|
|
public function findParent($parentId)
|
|
|
|
{
|
|
|
|
return $this->find($parentId);
|
|
|
|
}
|
2020-09-04 11:09:26 +02:00
|
|
|
|
|
|
|
public function getCategoryOptions()
|
|
|
|
{
|
|
|
|
if (!($options = cache('category_options'))) {
|
|
|
|
$categories = $this->findAll();
|
|
|
|
|
|
|
|
$options = array_reduce(
|
|
|
|
$categories,
|
|
|
|
function ($result, $category) {
|
|
|
|
$result[$category->id] = lang(
|
|
|
|
'Podcast.category_options.' . $category->code
|
|
|
|
);
|
|
|
|
return $result;
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
|
|
|
cache()->save('category_options', $options, DECADE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $options;
|
|
|
|
}
|
2020-05-29 18:25:17 +02:00
|
|
|
}
|