Skip to content

Commit 9cfe3a3

Browse files
committed
Merge branch 'dev'
# Conflicts: # composer.json # src/Models/Place.php # src/Models/PlaceTranslation.php
2 parents 665c11b + b5773c5 commit 9cfe3a3

31 files changed

+327
-581
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010
],
1111
"require": {
12-
"typicms/core": "~2.9.0"
12+
"laravel/framework": "~5.5.0"
1313
},
1414
"autoload": {
1515
"psr-4": {

public/.gitkeep

Whitespace-only changes.

src/Composers/SidebarViewComposer.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ class SidebarViewComposer
1111
{
1212
public function compose(View $view)
1313
{
14-
$view->sidebar->group(trans('global.menus.content'), function (SidebarGroup $group) {
15-
$group->addItem(trans('places::global.name'), function (SidebarItem $item) {
14+
if (Gate::denies('see-all-places')) {
15+
return;
16+
}
17+
$view->sidebar->group(__('Content'), function (SidebarGroup $group) {
18+
$group->id = 'content';
19+
$group->weight = 30;
20+
$group->addItem(__('Places'), function (SidebarItem $item) {
1621
$item->id = 'places';
1722
$item->icon = config('typicms.places.sidebar.icon', 'icon fa fa-fw fa-map-marker');
1823
$item->weight = config('typicms.places.sidebar.weight');
1924
$item->route('admin::index-places');
2025
$item->append('admin::create-place');
21-
$item->authorize(
22-
Gate::allows('index-places')
23-
);
2426
});
2527
});
2628
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace TypiCMS\Modules\Places\Facades;
44

5-
use Illuminate\Support\Facades\Facade as MainFacade;
5+
use Illuminate\Support\Facades\Facade;
66

7-
class Facade extends MainFacade
7+
class Places extends Facade
88
{
99
/**
1010
* Get the registered name of the component.
@@ -13,6 +13,6 @@ class Facade extends MainFacade
1313
*/
1414
protected static function getFacadeAccessor()
1515
{
16-
return 'TypiCMS\Modules\Places\Repositories\PlaceInterface';
16+
return 'Places';
1717
}
1818
}

src/Http/Controllers/AdminController.php

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
use TypiCMS\Modules\Core\Http\Controllers\BaseAdminController;
66
use TypiCMS\Modules\Places\Http\Requests\FormRequest;
77
use TypiCMS\Modules\Places\Models\Place;
8-
use TypiCMS\Modules\Places\Repositories\PlaceInterface;
8+
use TypiCMS\Modules\Places\Repositories\EloquentPlace;
99

1010
class AdminController extends BaseAdminController
1111
{
12-
public function __construct(PlaceInterface $place)
12+
public function __construct(EloquentPlace $place)
1313
{
1414
parent::__construct($place);
1515
}
@@ -21,7 +21,7 @@ public function __construct(PlaceInterface $place)
2121
*/
2222
public function index()
2323
{
24-
$models = $this->repository->all([], true);
24+
$models = $this->repository->with('files')->findAll();
2525
app('JavaScript')->put('models', $models);
2626

2727
return view('places::admin.index');
@@ -34,7 +34,8 @@ public function index()
3434
*/
3535
public function create()
3636
{
37-
$model = $this->repository->getModel();
37+
$model = $this->repository->createModel();
38+
app('JavaScript')->put('model', $model);
3839

3940
return view('places::admin.create')
4041
->with(compact('model'));
@@ -49,6 +50,8 @@ public function create()
4950
*/
5051
public function edit(Place $place)
5152
{
53+
app('JavaScript')->put('model', $place);
54+
5255
return view('places::admin.edit')
5356
->with(['model' => $place]);
5457
}
@@ -77,8 +80,38 @@ public function store(FormRequest $request)
7780
*/
7881
public function update(Place $place, FormRequest $request)
7982
{
80-
$this->repository->update($request->all());
83+
$this->repository->update($request->id, $request->all());
8184

8285
return $this->redirect($request, $place);
8386
}
87+
88+
/**
89+
* Remove the specified resource from storage.
90+
*
91+
* @param \TypiCMS\Modules\Places\Models\Place $place
92+
*
93+
* @return \Illuminate\Http\JsonResponse
94+
*/
95+
public function destroy(Place $place)
96+
{
97+
$deleted = $this->repository->delete($place);
98+
99+
return response()->json([
100+
'error' => !$deleted,
101+
]);
102+
}
103+
104+
/**
105+
* List models.
106+
*
107+
* @return \Illuminate\View\View
108+
*/
109+
public function files(Place $place)
110+
{
111+
$data = [
112+
'models' => $place->files,
113+
];
114+
115+
return response()->json($data, 200);
116+
}
84117
}

src/Http/Controllers/ApiController.php

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/Http/Controllers/PublicController.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
namespace TypiCMS\Modules\Places\Http\Controllers;
44

5-
use Illuminate\Support\Facades\Request;
65
use TypiCMS\Modules\Core\Http\Controllers\BasePublicController;
7-
use TypiCMS\Modules\Places\Repositories\PlaceInterface;
6+
use TypiCMS\Modules\Places\Repositories\EloquentPlace;
87

98
class PublicController extends BasePublicController
109
{
11-
public function __construct(PlaceInterface $place)
10+
public function __construct(EloquentPlace $place)
1211
{
1312
parent::__construct($place);
1413
}
@@ -20,8 +19,8 @@ public function __construct(PlaceInterface $place)
2019
*/
2120
public function index()
2221
{
23-
$models = $this->repository->all();
24-
if (Request::ajax()) {
22+
$models = $this->repository->published()->findAll();
23+
if (request()->wantsJson()) {
2524
return $models;
2625
}
2726

@@ -36,8 +35,8 @@ public function index()
3635
*/
3736
public function search()
3837
{
39-
$models = $this->repository->all();
40-
if (Request::ajax()) {
38+
$models = $this->repository->published()->findAll();
39+
if (request()->wantsJson()) {
4140
return $models;
4241
}
4342

@@ -52,8 +51,8 @@ public function search()
5251
*/
5352
public function show($slug)
5453
{
55-
$model = $this->repository->bySlug($slug);
56-
if (Request::ajax()) {
54+
$model = $this->repository->published()->bySlug($slug);
55+
if (request()->wantsJson()) {
5756
return $model;
5857
}
5958

src/Http/Requests/FormRequest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class FormRequest extends AbstractFormRequest
99
public function rules()
1010
{
1111
return [
12-
'email' => 'email|max:255',
13-
'website' => 'url|max:255',
14-
'image' => 'image|max:2000',
15-
'*.title' => 'max:255',
16-
'*.slug' => 'alpha_dash|max:255',
12+
'email' => 'nullable|email|max:255',
13+
'website' => 'nullable|url|max:255',
14+
'image_id' => 'nullable|integer',
15+
'title.*' => 'nullable|max:255',
16+
'slug.*' => 'nullable|alpha_dash|max:255',
1717
];
1818
}
1919
}

src/Models/Place.php

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,65 @@
22

33
namespace TypiCMS\Modules\Places\Models;
44

5-
use Dimsav\Translatable\Translatable;
65
use Laracasts\Presenter\PresentableTrait;
6+
use Spatie\Translatable\HasTranslations;
77
use TypiCMS\Modules\Core\Models\Base;
8+
use TypiCMS\Modules\Files\Models\File;
89
use TypiCMS\Modules\History\Traits\Historable;
10+
use TypiCMS\Modules\Places\Presenters\ModulePresenter;
911

1012
class Place extends Base
1113
{
14+
use HasTranslations;
1215
use Historable;
13-
use Translatable;
1416
use PresentableTrait;
1517

16-
protected $presenter = 'TypiCMS\Modules\Places\Presenters\ModulePresenter';
18+
protected $presenter = ModulePresenter::class;
1719

18-
protected $fillable = [
19-
'address',
20-
'email',
21-
'phone',
22-
'fax',
23-
'website',
24-
'image',
25-
'latitude',
26-
'longitude',
27-
];
20+
protected $guarded = ['id', 'exit'];
2821

29-
/**
30-
* Translatable model configs.
31-
*
32-
* @var array
33-
*/
34-
public $translatedAttributes = [
22+
public $translatable = [
3523
'title',
3624
'slug',
3725
'summary',
3826
'body',
3927
'status',
4028
];
4129

42-
protected $appends = ['status', 'title', 'thumb'];
30+
protected $appends = ['image', 'thumb', 'title_translated', 'status_translated'];
4331

4432
/**
45-
* Append status attribute from translation table.
33+
* Append title_translated attribute.
4634
*
4735
* @return string
4836
*/
49-
public function getStatusAttribute($value)
37+
public function getTitleTranslatedAttribute()
5038
{
51-
return $value;
39+
$locale = config('app.locale');
40+
41+
return $this->translate('title', config('typicms.content_locale', $locale));
5242
}
5343

5444
/**
55-
* Append title attribute from translation table.
45+
* Append status_translated attribute.
5646
*
57-
* @return string title
47+
* @return string
5848
*/
59-
public function getTitleAttribute($value)
49+
public function getStatusTranslatedAttribute()
6050
{
61-
return $value;
51+
$locale = config('app.locale');
52+
53+
return $this->translate('status', config('typicms.content_locale', $locale));
54+
}
55+
56+
/**
57+
* Append image attribute.
58+
*
59+
* @return string
60+
*/
61+
public function getImageAttribute()
62+
{
63+
return $this->files->first();
6264
}
6365

6466
/**
@@ -72,11 +74,13 @@ public function getThumbAttribute()
7274
}
7375

7476
/**
75-
* Columns that are file.
77+
* A news can have many files.
7678
*
77-
* @var array
79+
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
7880
*/
79-
public $attachments = [
80-
'image',
81-
];
81+
public function files()
82+
{
83+
return $this->morphToMany(File::class, 'model', 'model_has_files', 'model_id', 'file_id')
84+
->orderBy('model_has_files.position');
85+
}
8286
}

0 commit comments

Comments
 (0)