Skip to content

Commit b521532

Browse files
committed
some fixes
1 parent f0a1a62 commit b521532

File tree

7 files changed

+88
-75
lines changed

7 files changed

+88
-75
lines changed

migrations/2020_10_16_005400_create_hessam_categories_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function up()
1919
$table->unsignedInteger("created_by")->nullable()->index()->comment("user id");
2020

2121
//columns related to multi-level categories
22-
$table->integer('parent_id')->nullable()->default(0);
22+
$table->integer('parent_id')->nullable();
2323
$table->integer('lft')->nullable();
2424
$table->integer('rgt')->nullable();
2525
$table->integer('depth')->nullable();

src/Config/hessamcms.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
],
9191

9292
// you can add more fields here, but make sure that you create the relevant database columns too!
93-
// They must be in the same format as the default ones - image_xxxxx (and this db column must exist on the blog_etc_posts table)
93+
// They must be in the same format as the default ones - image_xxxxx (and this db column must exist on the hessam_posts table)
9494

9595
/*
9696
'image_custom_example_size' => [ // << MAKE A DB COLUM WITH THIS NAME.
@@ -104,7 +104,7 @@
104104
],
105105
*/
106106
// Create the custom db table by doing
107-
// php artisan make:migration --table=blog_etc_posts AddCustomBlogImageSize
107+
// php artisan make:migration --table=hessam_posts AddCustomBlogImageSize
108108
// then adding in the up() method:
109109
// $table->string("image_custom_example_size")->nullable();
110110
// and in the down() method:

src/Controllers/HessamReaderController.php

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Http\Controllers\Controller;
66
use Carbon\Carbon;
77
use HessamCMS\Laravel\Fulltext\Search;
8+
use HessamCMS\Models\HessamCategoryTranslation;
89
use Illuminate\Http\Request;
910
use HessamCMS\Captcha\UsesCaptcha;
1011
use HessamCMS\Middleware\DetectLanguage;
@@ -42,32 +43,34 @@ public function index($locale, $category_slug = null, Request $request)
4243
$title = 'Blog Page'; // default title...
4344

4445
$categoryChain = null;
46+
$posts = array();
4547
if ($category_slug) {
46-
$category = HessamCategory::where("slug", $category_slug)->firstOrFail();
48+
$category = HessamCategoryTranslation::where("slug", $category_slug)->with('category')->firstOrFail()->category;
4749
$categoryChain = $category->getAncestorsAndSelf();
48-
$posts = $category->posts()->where("blog_etc_post_categories.blog_etc_category_id", $category->id);
50+
$posts_1 = $category->posts()->where("hessam_post_categories.category_id", $category->id)->with([ 'postTranslations' => function($query) use ($request){
51+
$query->where("lang_id" , '=' , $request->get("lang_id"));
52+
}
53+
])->paginate(config("hessamcms.per_page", 10));
54+
55+
foreach ($posts_1 as $post) {
56+
$trans = $post->postTranslations[0];
57+
$trans->post = $post;
58+
array_push($posts, $trans);
59+
}
4960

5061
// at the moment we handle this special case (viewing a category) by hard coding in the following two lines.
5162
// You can easily override this in the view files.
5263
\View::share('hessamcms_category', $category); // so the view can say "You are viewing $CATEGORYNAME category posts"
5364
$title = 'Posts in ' . $category->category_name . " category"; // hardcode title here...
5465
} else {
55-
$posts = HessamPostTranslation::query();
66+
$posts = HessamPostTranslation::where('lang_id', $request->get("lang_id"))
67+
->with(['post' => function($query){
68+
$query->where("is_published" , '=' , true);
69+
$query->where('posted_at', '<', Carbon::now()->format('Y-m-d H:i:s'));
70+
$query->orderBy("posted_at", "desc");
71+
}])->paginate(config("hessamcms.per_page", 10));
5672
}
5773

58-
// $posts = $posts->where('is_published', '=', 1)
59-
// ->where('posted_at', '<', Carbon::now()->format('Y-m-d H:i:s'))
60-
// ->where('lang_id', $request->get("lang_id"))
61-
// ->orderBy("posted_at", "desc")
62-
// ->paginate(config("hessamcms.per_page", 10));
63-
64-
$posts = HessamPostTranslation::where('lang_id', $request->get("lang_id"))
65-
->with(['post' => function($query){
66-
$query->where("is_published" , '=' , true);
67-
$query->where('posted_at', '<', Carbon::now()->format('Y-m-d H:i:s'));
68-
$query->orderBy("posted_at", "desc");
69-
}])->paginate(config("hessamcms.per_page", 10));
70-
7174
//load category hierarchy
7275
$rootList = HessamCategory::roots()->get();
7376
HessamCategory::loadSiblingsWithList($rootList);
@@ -121,10 +124,10 @@ public function search(Request $request)
121124
* @param $category_slug
122125
* @return mixed
123126
*/
124-
public function view_category($hierarchy)
127+
public function view_category($locale, $hierarchy, Request $request)
125128
{
126129
$categories = explode('/', $hierarchy);
127-
return $this->index(end($categories));
130+
return $this->index($locale, end($categories), $request);
128131
}
129132

130133
/**

src/Views/hessamcms/index.blade.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class='btn border btn-outline-primary btn-sm '>
2727
<div class="row">
2828
<div class="col-md-12">
2929
@forelse($category_chain as $cat)
30-
/ <a href="{{$cat->categoryTranslations[0]->url()}}">
30+
/ <a href="{{$cat->categoryTranslations[0]->url($locale)}}">
3131
<span class="cat1">{{$cat->categoryTranslations[0]['category_name']}}</span>
3232
</a>
3333
@empty @endforelse
@@ -61,17 +61,17 @@ class='btn border btn-outline-primary btn-sm '>
6161
<h6>Blog Categories</h6>
6262
<ul class="hessam-cat-hierarchy">
6363
@if($categories)
64-
@include("hessamcms::partials._category_partial", ['category_tree' => $categories])
64+
@include("hessamcms::partials._category_partial", [
65+
'category_tree' => $categories,
66+
'name_chain' => $nameChain = ""
67+
])
6568
@else
6669
<span>No Categories</span>
6770
@endif
6871
</ul>
6972
</div>
7073
</div>
7174

72-
<div class='text-center col-sm-4 mx-auto'>
73-
{{$posts->appends( [] )->links()}}
74-
</div>
7575
@if (config('hessamcms.search.search_enabled') )
7676
@include('hessamcms::sitewide.search_form')
7777
@endif

src/Views/hessamcms/partials/_category_partial.blade.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@
22
@php $trans = $category->categoryTranslations->where('lang_id',$lang_id)->first();@endphp
33
@if($trans != null)
44
<li class="category-item-wrapper">
5-
<span class="category-item" value='{{$category->category_id}}'>
5+
@php $nameChain = $nameChain .'/'. $trans->slug @endphp
6+
7+
<a href="{{route("hessamcms.view_category",[$locale, $nameChain ])}}">
8+
<span class="category-item" value='{{$category->category_id}}'>
69
{{$trans->category_name}}
710

8-
@if( count($category->siblings) > 0)
9-
<ul>
10-
@include("hessamcms::partials._category_partial", ['category_tree' => $category->siblings])
11+
@if( count($category->siblings) > 0)
12+
<ul>
13+
@include("hessamcms::partials._category_partial", [
14+
'category_tree' => $category->siblings,
15+
'name_chain' => $nameChain
16+
])
1117
</ul>
12-
@endif
13-
</span>
18+
@endif
19+
</span>
20+
</a>
1421
</li>
1522
@endif
1623
@endforeach

src/Views/hessamcms/search.blade.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
<h6>Blog Categories</h6>
2929
<ul class="hessam-cat-hierarchy">
3030
@if($categories)
31-
@include("hessamcms::partials._category_partial", ['category_tree' => $categories])
31+
@include("hessamcms::partials._category_partial", [
32+
'category_tree' => $categories,
33+
'name_chain' => $nameChain = ""
34+
])
3235
@else
3336
<span>No Categories</span>
3437
@endif

0 commit comments

Comments
 (0)