Skip to content

Commit b5906b5

Browse files
Updated: relation field
1 parent ed13736 commit b5906b5

File tree

6 files changed

+158
-7
lines changed

6 files changed

+158
-7
lines changed

Entities/Content.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,13 @@ public static function getFormGroups(Content $content, $type, array $fields=null
523523
'vh_cms_form_group_index'=> $key])
524524
->first();
525525

526+
if($field->type->slug == 'relation' && $field_content
527+
&& isset($field_content->contentFormRelations)
528+
&& count($field_content->contentFormRelations) > 0){
529+
530+
$field_content->content = $field_content['contentFormRelations']->pluck('relatable_id');
531+
}
532+
526533

527534
if($field_content)
528535
{
@@ -593,9 +600,9 @@ public static function getFormGroupsTest(Content $content,
593600
foreach ($groups as $group)
594601
{
595602

596-
if((count($filter['include_groups']) > 0
603+
if((isset($filter['include_groups']) && count($filter['include_groups']) > 0
597604
&& !in_array($group['slug'], $filter['include_groups']))
598-
|| (count($filter['exclude_groups']) > 0
605+
|| (isset($filter['exclude_groups']) && count($filter['exclude_groups']) > 0
599606
&& in_array($group['slug'], $filter['exclude_groups']))){
600607

601608

@@ -846,8 +853,6 @@ public static function storeFormGroups(Content $content, $groups)
846853

847854
}
848855

849-
$stored_field->content = $field['content'];
850-
851856
}else{
852857
$stored_field->content = $field['content'];
853858
}

Helpers/cms.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ function get_template_field(Content $content, $field_slug,
573573

574574

575575
//-----------------------------------------------------------------------------------
576-
function getContentsHtml($contents,$args)
576+
function getContentsHtml($contents,$args = [])
577577
{
578578
$value = '';
579579

Http/Controllers/Backend/ExtendController.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,23 @@ public static function topLeftMenu()
3333
//----------------------------------------------------------
3434
public static function getCmsContentRelations()
3535
{
36+
/* $taxonomy_option = null;
37+
38+
if(!isset($exclude['Taxonomy']['options']))
39+
{
40+
$taxonomy_option = TaxonomyType::getListInTreeFormat();
41+
42+
}*/
43+
44+
3645
$arr = [
3746
[
3847
"name" => "Taxonomy",
3948
"namespace" => "WebReinvent\\VaahCms\\Entities\\Taxonomy",
4049
"options" => TaxonomyType::getListInTreeFormat(),
4150
"filter_by" => 'vh_taxonomy_type_id',
4251
"add_url" => route('vh.backend')."#/vaah/manage/taxonomies/create",
43-
"display_column" => 'name',
52+
"display_column" => 'slug',
4453
"has_children" => true
4554
],
4655
[

Http/Controllers/Frontend/PublicController.php

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
use Illuminate\Http\Response;
55
use Illuminate\Routing\Controller;
66
use Illuminate\Support\Facades\Auth;
7+
use VaahCms\Modules\Cms\Entities\Content;
8+
use VaahCms\Modules\Cms\Entities\ContentFormField;
9+
use WebReinvent\VaahCms\Entities\Taxonomy;
710

811
class PublicController extends Controller
912
{
@@ -67,6 +70,120 @@ public function content(Request $request, $content_type, $permalink)
6770

6871
}
6972

73+
//----------------------------------------------------------
74+
75+
public function taxonomyContents(Request $request, $taxonomy_type_slug, $taxonomy_slug)
76+
{
77+
78+
$taxonomy = Taxonomy::where('slug',$taxonomy_slug)
79+
->whereHas('type' , function ($t) use ($taxonomy_type_slug){
80+
$t->where('slug',$taxonomy_type_slug);
81+
})
82+
->with(['contentFormRelations'] )->first();
83+
84+
$unique_content_ids = [];
85+
86+
if($taxonomy && count($taxonomy->contentFormRelations) > 0){
87+
88+
$unique_content_ids = $taxonomy->contentFormRelations()
89+
->pluck('vh_cms_content_id')->unique();
90+
91+
}
92+
93+
$contents = Content::whereIn('id',$unique_content_ids)
94+
->with(['fields' => function($t){
95+
$t->with(['contentFormRelations' => function($c){
96+
$c->with(['relatable']);
97+
}]);
98+
},'contentType' => function($q){
99+
$q->with(['groups' => function($g){
100+
$g->with(['fields' => function($f){
101+
$f->with(['type']);
102+
103+
}]);
104+
105+
}]);
106+
}])
107+
->orderBy('id','DESC')
108+
->paginate(config('vaahcms.per_page'));
109+
110+
$content_ids = $contents->pluck('id')->toArray();
111+
112+
$group_fields = ContentFormField::whereIn('vh_cms_content_id',$content_ids)
113+
->get();
114+
115+
$group_fields = collect($group_fields);
116+
117+
foreach ($contents as $key => $content){
118+
119+
$contents[$key]['content_form_groups'] = Content::getFormGroupsTest($content,
120+
'content',$group_fields);
121+
122+
$arr_template = array();
123+
124+
$contents[$key]['template_form_groups'] = $arr_template;
125+
126+
}
127+
128+
129+
return view('bulmablogtheme::frontend.default',['data' => $contents]);
130+
131+
}
132+
133+
//----------------------------------------------------------
134+
135+
public function searchContents(Request $request)
136+
{
137+
138+
139+
140+
141+
$contents = Content::with(['fields' => function($t){
142+
$t->with(['contentFormRelations' => function($c){
143+
$c->with(['relatable']);
144+
}]);
145+
},'contentType' => function($q){
146+
$q->with(['groups' => function($g){
147+
$g->with(['fields' => function($f){
148+
$f->with(['type']);
149+
150+
}]);
151+
152+
}]);
153+
}])
154+
->where(function ($q) use ($request){
155+
$q->where('name', 'LIKE', \DB::raw("'%$request->q%'"))
156+
->orWhere('slug', 'LIKE', \DB::raw("'%$request->q%'"))
157+
->orWhere('permalink', 'LIKE',\DB::raw("'%$request->q%'"));
158+
159+
})
160+
->orderBy('id','DESC')
161+
->paginate(config('vaahcms.per_page'));
162+
163+
164+
$content_ids = $contents->pluck('id')->toArray();
165+
166+
$group_fields = ContentFormField::whereIn('vh_cms_content_id',$content_ids)
167+
->get();
168+
169+
$group_fields = collect($group_fields);
170+
171+
foreach ($contents as $key => $content){
172+
173+
$contents[$key]['content_form_groups'] = Content::getFormGroupsTest($content,
174+
'content',$group_fields);
175+
176+
$arr_template = array();
177+
178+
$contents[$key]['template_form_groups'] = $arr_template;
179+
180+
}
181+
182+
183+
return view('bulmablogtheme::frontend.default',['data' => $contents]);
184+
185+
}
186+
70187
//----------------------------------------------------------
71188
//----------------------------------------------------------
72189
//----------------------------------------------------------

Routes/frontend/routes-cms.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,23 @@ function () {
2323
->name( 'vh.cms.content' );
2424
//------------------------------------------------
2525
});
26+
27+
28+
29+
30+
Route::group(
31+
[
32+
'middleware' => ['web'],
33+
'namespace' => 'Frontend',
34+
],
35+
function () {
36+
//------------------------------------------------
37+
Route::get( '/taxonomy/{taxonomy_type_slug}/{taxonomy_slug}',
38+
'PublicController@taxonomyContents' )
39+
->name( 'vh.cms.taxonomy-content' );
40+
//------------------------------------------------
41+
Route::get( '/search',
42+
'PublicController@searchContents' )
43+
->name( 'vh.cms.search-content' );
44+
//------------------------------------------------
45+
});

0 commit comments

Comments
 (0)