From ec413ac734c6d119a1538103424480db6e96b948 Mon Sep 17 00:00:00 2001 From: Kerim Date: Wed, 11 Jan 2023 17:05:36 +0500 Subject: [PATCH] awtor filter backend --- .../blog/controllers/posts/config_filter.yaml | 14 ++++++++++++++ plugins/rainlab/blog/models/Post.php | 7 +++++++ plugins/rainlab/blog/models/post/columns.yaml | 6 ++++++ 3 files changed, 27 insertions(+) diff --git a/plugins/rainlab/blog/controllers/posts/config_filter.yaml b/plugins/rainlab/blog/controllers/posts/config_filter.yaml index 9629fa832..50c87e7fd 100644 --- a/plugins/rainlab/blog/controllers/posts/config_filter.yaml +++ b/plugins/rainlab/blog/controllers/posts/config_filter.yaml @@ -73,3 +73,17 @@ scopes: ru: RU en: EN tm: TM + + awtor: + + # Filter name + label: Awtor + + # Model Class name + modelClass: Tps\Tps\Models\Authors + + # Model attribute to display for the name + nameFrom: name + + # Apply query scope + scope: FilterAuthors diff --git a/plugins/rainlab/blog/models/Post.php b/plugins/rainlab/blog/models/Post.php index 40aad264f..51b0e642f 100644 --- a/plugins/rainlab/blog/models/Post.php +++ b/plugins/rainlab/blog/models/Post.php @@ -546,6 +546,13 @@ class Post extends Model }); } + public function scopeFilterAuthors($query, $authors) + { + return $query->whereHas('awtor', function($q) use ($authors) { + $q->where('id', $authors); + }); + } + public function scopeFilterId($query, $id) { return $query->where('id', $id); diff --git a/plugins/rainlab/blog/models/post/columns.yaml b/plugins/rainlab/blog/models/post/columns.yaml index 88bf255dc..d8052b16a 100644 --- a/plugins/rainlab/blog/models/post/columns.yaml +++ b/plugins/rainlab/blog/models/post/columns.yaml @@ -53,3 +53,9 @@ columns: sortable: true select: name relation: category_groups + author_id: + label: Awtor + type: text + sortable: false + select: name + relation: awtor