2020-05-29 18:25:17 +02:00
|
|
|
<?php
|
2020-08-04 13:25:22 +02:00
|
|
|
|
2021-06-08 11:52:11 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
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
|
|
|
|
{
|
2021-05-17 19:11:23 +02:00
|
|
|
protected ?Category $parent = null;
|
2020-06-26 16:34:52 +02:00
|
|
|
|
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-20 19:13:13 +02:00
|
|
|
/**
|
|
|
|
* @noRector ReturnTypeDeclarationRector
|
|
|
|
*/
|
2021-05-19 18:35:13 +02:00
|
|
|
public function getParent(): ?self
|
2020-06-26 16:34:52 +02:00
|
|
|
{
|
2021-05-18 19:16:36 +02:00
|
|
|
if ($this->parent_id === null) {
|
2021-05-06 16:00:48 +02:00
|
|
|
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
|
|
|
}
|