2020-05-29 16:25:17 +00:00
|
|
|
<?php
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-06-10 15:00:12 +00:00
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2020 Ad Aures
|
2020-06-10 15:00:12 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
2020-05-29 16:25:17 +00:00
|
|
|
|
|
|
|
namespace App\Entities;
|
|
|
|
|
2020-06-26 14:34:52 +00:00
|
|
|
use App\Models\CategoryModel;
|
2021-05-06 14:00:48 +00:00
|
|
|
use CodeIgniter\Entity\Entity;
|
2020-05-29 16:25:17 +00:00
|
|
|
|
2021-05-12 14:00:25 +00: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 16:25:17 +00:00
|
|
|
class Category extends Entity
|
|
|
|
{
|
2021-05-17 17:11:23 +00:00
|
|
|
protected ?Category $parent = null;
|
2020-06-26 14:34:52 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
|
|
|
* @var array<string, string>
|
|
|
|
*/
|
2020-05-29 16:25:17 +00:00
|
|
|
protected $casts = [
|
2023-06-12 14:47:38 +00:00
|
|
|
'id' => 'integer',
|
|
|
|
'parent_id' => '?integer',
|
|
|
|
'code' => 'string',
|
|
|
|
'apple_category' => 'string',
|
2020-05-29 16:25:17 +00:00
|
|
|
'google_category' => 'string',
|
|
|
|
];
|
2020-06-26 14:34:52 +00:00
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
public function getParent(): ?self
|
2020-06-26 14:34:52 +00:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->parent_id === null) {
|
2021-05-06 14:00:48 +00:00
|
|
|
return null;
|
|
|
|
}
|
2020-06-26 14:34:52 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
return (new CategoryModel())->getCategoryById($this->parent_id);
|
2020-06-26 14:34:52 +00:00
|
|
|
}
|
2020-05-29 16:25:17 +00:00
|
|
|
}
|