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\Entities;
|
|
|
|
|
2020-06-26 16:34:52 +02:00
|
|
|
use App\Models\CategoryModel;
|
2021-05-06 16:00:48 +02:00
|
|
|
use CodeIgniter\Entity\Entity;
|
2020-05-29 18:25:17 +02:00
|
|
|
|
2021-05-12 16:00:25 +02:00
|
|
|
/**
|
|
|
|
* @property int $id
|
|
|
|
* @property int $parent_id
|
|
|
|
* @property Category|null $parent
|
|
|
|
* @property string $code
|
|
|
|
* @property string $apple_category
|
|
|
|
* @property string $google_category
|
|
|
|
*/
|
2020-05-29 18:25:17 +02:00
|
|
|
class Category extends Entity
|
|
|
|
{
|
2020-08-05 19:26:04 +02:00
|
|
|
/**
|
2021-05-06 16:00:48 +02:00
|
|
|
* @var Category|null
|
2020-08-05 19:26:04 +02:00
|
|
|
*/
|
2020-06-26 16:34:52 +02:00
|
|
|
protected $parent;
|
|
|
|
|
2021-05-06 16:00:48 +02:00
|
|
|
/**
|
|
|
|
* @var array<string, string>
|
|
|
|
*/
|
2020-05-29 18:25:17 +02:00
|
|
|
protected $casts = [
|
2020-12-07 21:13:46 +01:00
|
|
|
'id' => 'integer',
|
2021-05-12 16:00:25 +02:00
|
|
|
'parent_id' => '?integer',
|
2020-06-26 16:34:52 +02:00
|
|
|
'code' => 'string',
|
2020-05-29 18:25:17 +02:00
|
|
|
'apple_category' => 'string',
|
|
|
|
'google_category' => 'string',
|
|
|
|
];
|
2020-06-26 16:34:52 +02:00
|
|
|
|
2021-05-06 16:00:48 +02:00
|
|
|
public function getParent(): ?Category
|
2020-06-26 16:34:52 +02:00
|
|
|
{
|
2021-05-06 16:00:48 +02:00
|
|
|
if (empty($this->parent_id)) {
|
|
|
|
return null;
|
|
|
|
}
|
2020-06-26 16:34:52 +02:00
|
|
|
|
2021-05-06 16:00:48 +02:00
|
|
|
return (new CategoryModel())->getCategoryById($this->parent_id);
|
2020-06-26 16:34:52 +02:00
|
|
|
}
|
2020-05-29 18:25:17 +02:00
|
|
|
}
|