Skip to content

Commit 06c9b66

Browse files
committed
wip: add feature helper functions in PostType
1 parent f1202bf commit 06c9b66

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

src/Models/PostType.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Javaabu\Cms\Models;
44

55
use Illuminate\Database\Eloquent\Relations\BelongsTo;
6+
use Illuminate\Support\Str;
7+
use Javaabu\Cms\Enums\PostTypeFeatures;
68
use Javaabu\Helpers\AdminModel\AdminModel;
79
use Javaabu\Helpers\AdminModel\IsAdminModel;
810
use Illuminate\Database\Eloquent\Model;
@@ -62,5 +64,38 @@ public function categoryType(): BelongsTo
6264
{
6365
return $this->belongsTo(CategoryType::class);
6466
}
67+
68+
public function getFeatureName($feature): ?string
69+
{
70+
if (! $this->hasFeature($feature)) {
71+
return null;
72+
}
73+
74+
$feature_title = $this->features[$feature];
75+
76+
if (gettype($feature_title) == 'boolean') {
77+
return PostTypeFeatures::getLabel($feature);
78+
}
79+
80+
if (gettype($feature_title) == 'string') {
81+
return Str::title($feature_title);
82+
}
83+
84+
return null;
85+
}
86+
87+
public function hasFeature($feature): bool
88+
{
89+
return array_key_exists($feature, $this->features);
90+
}
91+
92+
public function getFeatureCollectionName($feature): ?string
93+
{
94+
if (! $this->hasFeature($feature)) {
95+
return null;
96+
}
97+
98+
return PostTypeFeatures::getCollectionName($feature);
99+
}
65100
}
66101

0 commit comments

Comments
 (0)