tags
This commit is contained in:
parent
1bc7662be0
commit
745707ee09
@ -2,12 +2,14 @@
|
|||||||
|
|
||||||
namespace app\modules\tag;
|
namespace app\modules\tag;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use itguild\forms\builders\TextInputBuilder;
|
use itguild\forms\builders\TextInputBuilder;
|
||||||
use kernel\app_modules\tag\models\Tag;
|
use kernel\app_modules\tag\models\Tag;
|
||||||
use kernel\helpers\Debug;
|
use kernel\helpers\Debug;
|
||||||
use kernel\helpers\Slug;
|
use kernel\helpers\Slug;
|
||||||
use kernel\Module;
|
use kernel\Module;
|
||||||
use kernel\modules\menu\service\MenuService;
|
use kernel\modules\menu\service\MenuService;
|
||||||
|
use kernel\modules\option\service\OptionService;
|
||||||
use kernel\Request;
|
use kernel\Request;
|
||||||
use kernel\services\MigrationService;
|
use kernel\services\MigrationService;
|
||||||
|
|
||||||
@ -34,29 +36,50 @@ class TagModule extends Module
|
|||||||
"url" => "/admin/tag",
|
"url" => "/admin/tag",
|
||||||
"slug" => "tag",
|
"slug" => "tag",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$this->menuService->createItem([
|
||||||
|
"label" => "Тэги",
|
||||||
|
"url" => "/admin/settings/tag",
|
||||||
|
"slug" => "tag_settings",
|
||||||
|
"parent_slug" => "settings"
|
||||||
|
]);
|
||||||
|
|
||||||
|
OptionService::createFromParams("entity_tag_list", "{}", "Список тегов");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deactivate(): void
|
public function deactivate(): void
|
||||||
{
|
{
|
||||||
$this->menuService->removeItemBySlug("tag");
|
$this->menuService->removeItemBySlug("tag");
|
||||||
|
OptionService::removeOptionByKey("entity_tag_list");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function formInputs(): void
|
public function formInputs(string $entity, Model $model = null): void
|
||||||
{
|
{
|
||||||
$input = TextInputBuilder::build("tag", ['class' => 'form-control', 'placeholder' => 'Теги']);
|
$tag = Tag::where("entity", $entity)->where("entity_id", $model->id)->first();
|
||||||
|
|
||||||
|
$input = TextInputBuilder::build("tag", [
|
||||||
|
'class' => 'form-control',
|
||||||
|
'placeholder' => 'Теги',
|
||||||
|
'value' => $tag->label ?? ""
|
||||||
|
]);
|
||||||
$input->setLabel("Теги");
|
$input->setLabel("Теги");
|
||||||
$input->create()->render();
|
$input->create()->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveInputs(string $entity, Request $request): void
|
public function saveInputs(string $entity, Model $model, Request $request): void
|
||||||
{
|
{
|
||||||
$model = new Tag();
|
$tag = new Tag();
|
||||||
$model->entity = $entity;
|
$tag->entity = $entity;
|
||||||
Debug::dd($request->post());
|
$tag->entity_id = $model->id;
|
||||||
$model->entity_id = 1;
|
$tag->label = $request->post('tag');
|
||||||
$model->label = $request->post('tag');
|
$tag->status = Tag::ACTIVE_STATUS;
|
||||||
$model->status = Tag::ACTIVE_STATUS;
|
$tag->slug = Slug::createSlug($request->post('tag'), $model);
|
||||||
$model->slug = Slug::createSlug($request->post('tag'), $model);
|
$tag->save();
|
||||||
$model->save();
|
}
|
||||||
|
|
||||||
|
public function getInputs(string $entity, Model $model)
|
||||||
|
{
|
||||||
|
|
||||||
|
Debug::dd($tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace kernel;
|
namespace kernel;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use kernel\helpers\Debug;
|
use kernel\helpers\Debug;
|
||||||
use kernel\models\Option;
|
use kernel\models\Option;
|
||||||
use kernel\modules\option\service\OptionService;
|
use kernel\modules\option\service\OptionService;
|
||||||
@ -148,38 +149,38 @@ class EntityRelation
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderFormInputsBySlug(string $slug): void
|
public function renderFormInputsBySlug(string $entity, string $slug, Model $model): void
|
||||||
{
|
{
|
||||||
$moduleClass = $this->getAdditionalPropertyClassBySlug($slug);
|
$moduleClass = $this->getAdditionalPropertyClassBySlug($slug);
|
||||||
if ($moduleClass and method_exists($moduleClass, "formInputs")) {
|
if ($moduleClass and method_exists($moduleClass, "formInputs")) {
|
||||||
$moduleClass->formInputs();
|
$moduleClass->formInputs($entity, $model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderEntityAdditionalPropertyFormBySlug(string $slug): void
|
public function renderEntityAdditionalPropertyFormBySlug(string $entity, Model $model = null): void
|
||||||
{
|
|
||||||
$relations = $this->getEntityRelationsBySlug($slug);
|
|
||||||
if ($relations){
|
|
||||||
foreach ($relations as $relation){
|
|
||||||
$this->renderFormInputsBySlug($relation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function saveEntityRelationBySlug(string $slug, string $entity, Request $request): void
|
|
||||||
{
|
|
||||||
$moduleClass = $this->getAdditionalPropertyClassBySlug($slug);
|
|
||||||
if ($moduleClass and method_exists($moduleClass, "saveInputs")) {
|
|
||||||
$moduleClass->saveInputs($entity, $request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function saveEntityRelation(string $entity, Request $request): void
|
|
||||||
{
|
{
|
||||||
$relations = $this->getEntityRelationsBySlug($entity);
|
$relations = $this->getEntityRelationsBySlug($entity);
|
||||||
if ($relations){
|
if ($relations){
|
||||||
foreach ($relations as $relation){
|
foreach ($relations as $relation){
|
||||||
$this->saveEntityRelationBySlug($relation, $entity, $request);
|
$this->renderFormInputsBySlug($entity, $relation, $model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveEntityRelationBySlug(string $slug, string $entity, Model $model, Request $request): void
|
||||||
|
{
|
||||||
|
$moduleClass = $this->getAdditionalPropertyClassBySlug($slug);
|
||||||
|
if ($moduleClass and method_exists($moduleClass, "saveInputs")) {
|
||||||
|
$moduleClass->saveInputs($entity, $model, $request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveEntityRelation(string $entity, Model $model, Request $request): void
|
||||||
|
{
|
||||||
|
$relations = $this->getEntityRelationsBySlug($entity);
|
||||||
|
if ($relations){
|
||||||
|
foreach ($relations as $relation){
|
||||||
|
$this->saveEntityRelationBySlug($relation, $entity, $model, $request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,4 +98,9 @@ class TagController extends AdminController
|
|||||||
$this->redirect("/admin/tag/");
|
$this->redirect("/admin/tag/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function actionSettings(): void
|
||||||
|
{
|
||||||
|
echo "tag settings";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -11,8 +11,6 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
* @property int $entity_id
|
* @property int $entity_id
|
||||||
* @property string $slug
|
* @property string $slug
|
||||||
* @property int $status
|
* @property int $status
|
||||||
* @method static where(int[] $array)
|
|
||||||
* @method static find($id)
|
|
||||||
*/
|
*/
|
||||||
class Tag extends Model
|
class Tag extends Model
|
||||||
{
|
{
|
||||||
@ -21,13 +19,14 @@ class Tag extends Model
|
|||||||
|
|
||||||
protected $table = 'tag';
|
protected $table = 'tag';
|
||||||
|
|
||||||
protected $fillable = ['label', 'entity', 'slug', 'status'];
|
protected $fillable = ['label', 'entity', 'entity_id', 'slug', 'status'];
|
||||||
|
|
||||||
public static function labels(): array
|
public static function labels(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'label' => 'Заголовок',
|
'label' => 'Заголовок',
|
||||||
'entity' => 'Сущность',
|
'entity' => 'Сущность',
|
||||||
|
'entity_id' => 'Идентификатор сущность',
|
||||||
'slug' => 'Slug',
|
'slug' => 'Slug',
|
||||||
'status' => 'Статус',
|
'status' => 'Статус',
|
||||||
];
|
];
|
||||||
|
@ -15,4 +15,7 @@ App::$collector->group(["prefix" => "admin"], function (CgRouteCollector $router
|
|||||||
App::$collector->any("/edit/{id}", [\app\modules\tag\controllers\TagController::class, 'actionEdit']);
|
App::$collector->any("/edit/{id}", [\app\modules\tag\controllers\TagController::class, 'actionEdit']);
|
||||||
App::$collector->get('/delete/{id}', [\app\modules\tag\controllers\TagController::class, 'actionDelete']);
|
App::$collector->get('/delete/{id}', [\app\modules\tag\controllers\TagController::class, 'actionDelete']);
|
||||||
});
|
});
|
||||||
|
App::$collector->group(["prefix" => "settings"], function (CGRouteCollector $router){
|
||||||
|
App::$collector->get('/tag', [\app\modules\tag\controllers\TagController::class, 'actionSettings']);
|
||||||
|
});
|
||||||
});
|
});
|
@ -35,7 +35,7 @@ class OptionService
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createFromParams(string $key, string $value, string $label): false|Option
|
public static function createFromParams(string $key, string $value, string $label): false|Option
|
||||||
{
|
{
|
||||||
$model = new Option();
|
$model = new Option();
|
||||||
$model->key = $key;
|
$model->key = $key;
|
||||||
@ -63,6 +63,17 @@ class OptionService
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function removeOptionByKey(string $key): bool
|
||||||
|
{
|
||||||
|
$option = Option::where("key", $key)->first();
|
||||||
|
if (!$option){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$option->delete();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// public function createOptionArr(): array
|
// public function createOptionArr(): array
|
||||||
// {
|
// {
|
||||||
// foreach (Option::all()->toArray() as $option) {
|
// foreach (Option::all()->toArray() as $option) {
|
||||||
|
@ -36,7 +36,7 @@ class PostController extends AdminController
|
|||||||
$post = $this->postService->create($postForm);
|
$post = $this->postService->create($postForm);
|
||||||
|
|
||||||
$entityRelation = new EntityRelation();
|
$entityRelation = new EntityRelation();
|
||||||
$entityRelation->saveEntityRelation("post", new Request());
|
$entityRelation->saveEntityRelation(entity: "post", model: $post, request: new Request());
|
||||||
|
|
||||||
if ($post) {
|
if ($post) {
|
||||||
$this->redirect("/admin/post/view/" . $post->id);
|
$this->redirect("/admin/post/view/" . $post->id);
|
||||||
|
@ -34,7 +34,7 @@ $form->field(class: \itguild\forms\inputs\Select::class, name: "user_id", params
|
|||||||
->render();
|
->render();
|
||||||
|
|
||||||
$entityRelations = new \kernel\EntityRelation();
|
$entityRelations = new \kernel\EntityRelation();
|
||||||
$entityRelations->renderEntityAdditionalPropertyFormBySlug("post");
|
$entityRelations->renderEntityAdditionalPropertyFormBySlug("post", $model);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
Loading…
Reference in New Issue
Block a user