Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.json
#	src/Models/Partner.php
#	src/Models/PartnerTranslation.php
  • Loading branch information
sdebacker committed Aug 31, 2017
2 parents 92af8fc + e9c2670 commit 9fb71f9
Show file tree
Hide file tree
Showing 28 changed files with 192 additions and 330 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
],
"require": {
"typicms/core": "~2.9.0"
"laravel/framework": "~5.5.0"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 7 additions & 5 deletions src/Composers/SidebarViewComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ class SidebarViewComposer
{
public function compose(View $view)
{
$view->sidebar->group(trans('global.menus.content'), function (SidebarGroup $group) {
$group->addItem(trans('partners::global.name'), function (SidebarItem $item) {
if (Gate::denies('see-all-partners')) {
return;
}
$view->sidebar->group(__('Content'), function (SidebarGroup $group) {
$group->id = 'content';
$group->weight = 30;
$group->addItem(__('Partners'), function (SidebarItem $item) {
$item->id = 'partners';
$item->icon = config('typicms.partners.sidebar.icon', 'icon fa fa-fw fa-cubes');
$item->weight = config('typicms.partners.sidebar.weight');
$item->route('admin::index-partners');
$item->append('admin::create-partner');
$item->authorize(
Gate::allows('index-partners')
);
});
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/Facades/Facade.php → src/Facades/Partners.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace TypiCMS\Modules\Partners\Facades;

use Illuminate\Support\Facades\Facade as MainFacade;
use Illuminate\Support\Facades\Facade;

class Facade extends MainFacade
class Partners extends Facade
{
/**
* Get the registered name of the component.
Expand All @@ -13,6 +13,6 @@ class Facade extends MainFacade
*/
protected static function getFacadeAccessor()
{
return 'TypiCMS\Modules\Partners\Repositories\PartnerInterface';
return 'Partners';
}
}
29 changes: 24 additions & 5 deletions src/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
use TypiCMS\Modules\Core\Http\Controllers\BaseAdminController;
use TypiCMS\Modules\Partners\Http\Requests\FormRequest;
use TypiCMS\Modules\Partners\Models\Partner;
use TypiCMS\Modules\Partners\Repositories\PartnerInterface;
use TypiCMS\Modules\Partners\Repositories\EloquentPartner;

class AdminController extends BaseAdminController
{
public function __construct(PartnerInterface $partner)
public function __construct(EloquentPartner $partner)
{
parent::__construct($partner);
}
Expand All @@ -21,7 +21,7 @@ public function __construct(PartnerInterface $partner)
*/
public function index()
{
$models = $this->repository->all([], true);
$models = $this->repository->with('image')->findAll();
app('JavaScript')->put('models', $models);

return view('partners::admin.index');
Expand All @@ -34,7 +34,8 @@ public function index()
*/
public function create()
{
$model = $this->repository->getModel();
$model = $this->repository->createModel();
app('JavaScript')->put('model', $model);

return view('partners::admin.create')
->with(compact('model'));
Expand All @@ -49,6 +50,8 @@ public function create()
*/
public function edit(Partner $partner)
{
app('JavaScript')->put('model', $partner);

return view('partners::admin.edit')
->with(['model' => $partner]);
}
Expand Down Expand Up @@ -77,8 +80,24 @@ public function store(FormRequest $request)
*/
public function update(Partner $partner, FormRequest $request)
{
$this->repository->update($request->all());
$this->repository->update($request->id, $request->all());

return $this->redirect($request, $partner);
}

/**
* Remove the specified resource from storage.
*
* @param \TypiCMS\Modules\Partners\Models\Partner $partner
*
* @return \Illuminate\Http\JsonResponse
*/
public function destroy(Partner $partner)
{
$deleted = $this->repository->delete($partner);

return response()->json([
'error' => !$deleted,
]);
}
}
64 changes: 0 additions & 64 deletions src/Http/Controllers/ApiController.php

This file was deleted.

8 changes: 4 additions & 4 deletions src/Http/Controllers/PublicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace TypiCMS\Modules\Partners\Http\Controllers;

use TypiCMS\Modules\Core\Http\Controllers\BasePublicController;
use TypiCMS\Modules\Partners\Repositories\PartnerInterface;
use TypiCMS\Modules\Partners\Repositories\EloquentPartner;

class PublicController extends BasePublicController
{
public function __construct(PartnerInterface $partner)
public function __construct(EloquentPartner $partner)
{
parent::__construct($partner);
}
Expand All @@ -19,7 +19,7 @@ public function __construct(PartnerInterface $partner)
*/
public function index()
{
$models = $this->repository->all();
$models = $this->repository->published()->findAll();

return view('partners::public.index')
->with(compact('models'));
Expand All @@ -32,7 +32,7 @@ public function index()
*/
public function show($slug)
{
$model = $this->repository->bySlug($slug);
$model = $this->repository->published()->bySlug($slug);

return view('partners::public.show')
->with(compact('model'));
Expand Down
10 changes: 5 additions & 5 deletions src/Http/Requests/FormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class FormRequest extends AbstractFormRequest
public function rules()
{
return [
'position' => 'required|integer|min:1',
'image' => 'image|max:2000',
'*.title' => 'max:255',
'*.slug' => 'max:255',
'*.website' => 'url',
'position' => 'required|integer|min:1',
'image_id' => 'nullable|integer',
'title.*' => 'nullable|max:255',
'slug.*' => 'nullable|alpha_dash|max:255',
'website.*' => 'nullable|url',
];
}
}
61 changes: 30 additions & 31 deletions src/Models/Partner.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,24 @@

namespace TypiCMS\Modules\Partners\Models;

use Dimsav\Translatable\Translatable;
use Laracasts\Presenter\PresentableTrait;
use Spatie\Translatable\HasTranslations;
use TypiCMS\Modules\Core\Models\Base;
use TypiCMS\Modules\Files\Models\File;
use TypiCMS\Modules\History\Traits\Historable;
use TypiCMS\Modules\Partners\Presenters\ModulePresenter;

class Partner extends Base
{
use HasTranslations;
use Historable;
use PresentableTrait;
use Translatable;

protected $presenter = 'TypiCMS\Modules\Partners\Presenters\ModulePresenter';
protected $presenter = ModulePresenter::class;

protected $fillable = [
'image',
'position',
'homepage',
];
protected $guarded = ['id', 'exit'];

/**
* Translatable model configs.
*
* @var array
*/
public $translatedAttributes = [
public $translatable = [
'title',
'slug',
'status',
Expand All @@ -35,35 +28,41 @@ class Partner extends Base
'body',
];

protected $appends = ['status', 'title', 'thumb', 'website'];
protected $appends = ['thumb', 'title_translated', 'website_translated', 'status_translated'];

/**
* Columns that are file.
* Append title_translated attribute.
*
* @var array
* @return string
*/
public $attachments = [
'image',
];
public function getTitleTranslatedAttribute()
{
$locale = config('app.locale');

return $this->translate('title', config('typicms.content_locale', $locale));
}

/**
* Append status attribute from translation table.
* Append status_translated attribute.
*
* @return string
*/
public function getStatusAttribute($value)
public function getStatusTranslatedAttribute()
{
return $value;
$locale = config('app.locale');

return $this->translate('status', config('typicms.content_locale', $locale));
}

/**
* Append title attribute from translation table.
* Append website_translated attribute.
*
* @return string title
* @return string
*/
public function getTitleAttribute($value)
public function getWebsiteTranslatedAttribute()
{
return $value;
$locale = config('app.locale');
return $this->translate('website', config('typicms.content_locale', $locale));
}

/**
Expand All @@ -77,12 +76,12 @@ public function getThumbAttribute()
}

/**
* Append website attribute from translation table.
* This model belongs to one image.
*
* @return string
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function getWebsiteAttribute($value)
public function image()
{
return $value;
return $this->belongsTo(File::class, 'image_id');
}
}
25 changes: 0 additions & 25 deletions src/Models/PartnerTranslation.php

This file was deleted.

Loading

0 comments on commit 9fb71f9

Please sign in to comment.