FEATURE: more translations
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Modules\Blog\Article\Events;
|
||||
|
||||
use App\Events\Event;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Modules\Blog\Article\Entities\Comment;
|
||||
|
||||
class ApprovedComment extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
/**
|
||||
* @var Comment
|
||||
*/
|
||||
public $comment;
|
||||
|
||||
public function __construct(Comment $comment)
|
||||
{
|
||||
$this->comment = $comment;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Modules\Blog\Article\Events;
|
||||
|
||||
use App\Events\Event;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Modules\Blog\Article\Entities\Comment;
|
||||
|
||||
class CreatedComment extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
/**
|
||||
* @var Comment
|
||||
*/
|
||||
public $comment;
|
||||
|
||||
public function __construct(Comment $comment)
|
||||
{
|
||||
$this->comment = $comment;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace Modules\Blog\Article\Events;
|
||||
|
||||
use App\Events\Event;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Modules\Blog\Article\Entities\Comment;
|
||||
|
||||
class DeletedComment extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
/**
|
||||
* @var Comment
|
||||
*/
|
||||
public $comment;
|
||||
|
||||
public function __construct(Comment $comment)
|
||||
{
|
||||
$this->comment = $comment;
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,17 @@
|
||||
namespace Modules\Blog\Article\Handlers;
|
||||
|
||||
use App\Enumerations\ModulesHandlerToId;
|
||||
use App\Handlers\Contracts\ContentTitles;
|
||||
use App\Handlers\Handler;
|
||||
use App\Http\Controllers\Admin\EditContent;
|
||||
use App\Http\Controllers\Admin\Contents\EditContent;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\ActionLogType;
|
||||
use App\Models\Content;
|
||||
use App\Models\User;
|
||||
use Modules\Blog\Article\Entities\Comment;
|
||||
|
||||
class Article extends Handler
|
||||
class Article extends Handler implements ContentTitles
|
||||
{
|
||||
/**
|
||||
* Render given module into visitor area.
|
||||
@@ -30,7 +32,7 @@ class Article extends Handler
|
||||
->get();
|
||||
}
|
||||
|
||||
return Controller::VisitorsView($content->template, ['page' => $content]);
|
||||
return Controller::VisitorsView($content->template, ['page' => $content, 'extra' => $parameters]);
|
||||
}
|
||||
|
||||
public static function getExtendedFormInputsCreate()
|
||||
@@ -88,12 +90,8 @@ class Article extends Handler
|
||||
return $changedColumns;
|
||||
}
|
||||
|
||||
public static function getOverviewTitle()
|
||||
{
|
||||
return trans('article::module.allArticles');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register admin menu
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
@@ -130,10 +128,63 @@ class Article extends Handler
|
||||
|
||||
/**
|
||||
* Install module
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function install()
|
||||
{
|
||||
$types = [
|
||||
[
|
||||
'string_id' => 'commentCreated',
|
||||
'name' => 'article::comments.events.names.commentCreated',
|
||||
'value' => 'article::comments.events.descriptions.commentCreated',
|
||||
],
|
||||
[
|
||||
'string_id' => 'commentDeleted',
|
||||
'name' => 'article::comments.events.names.commentDeleted',
|
||||
'value' => 'article::comments.events.descriptions.commentDeleted',
|
||||
],
|
||||
[
|
||||
'string_id' => 'commentApproved',
|
||||
'name' => 'article::comments.events.names.commentApproved',
|
||||
'value' => 'article::comments.events.descriptions.commentApproved',
|
||||
],
|
||||
|
||||
];
|
||||
foreach ($types as $type) {
|
||||
ActionLogType::create($type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get translated title for pages overview of given type.
|
||||
*
|
||||
* This value is used for rendering list of all content pages of given type in administration.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getOverviewTitle()
|
||||
{
|
||||
return trans('article::module.allArticles');
|
||||
}
|
||||
|
||||
/**
|
||||
* Title displayed above for for creating new content page
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getCreateNewTitle()
|
||||
{
|
||||
return trans('article::module.newArticle');
|
||||
}
|
||||
|
||||
/**
|
||||
* Title for form displayed for editin content page
|
||||
*
|
||||
* @param Content $content
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getEditTitle(Content $content)
|
||||
{
|
||||
return trans('article::module.editArticle');
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ class CommentsOverview extends Controller
|
||||
->with('author')
|
||||
->orderBy('approved')
|
||||
->orderBy('created_at', 'DESC')
|
||||
->paginate(20);
|
||||
->paginate(25);
|
||||
|
||||
return view('article::admin/comments.overview', ['comments' => $comments]);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
<?php
|
||||
namespace Modules\Blog\Article\Http\Controllers\Admin;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Modules\Blog\Article\Entities\Comment;
|
||||
use Modules\Blog\Article\Events\ApprovedComment;
|
||||
use Modules\Blog\Article\Events\DeletedComment;
|
||||
use Pingpong\Modules\Routing\Controller;
|
||||
|
||||
class EditComment extends Controller
|
||||
@@ -12,7 +15,7 @@ class EditComment extends Controller
|
||||
$comment->approved = 1;
|
||||
$comment->save();
|
||||
|
||||
// Event::fire(ApprovedComment);
|
||||
Event::fire(new ApprovedComment($comment));
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
@@ -22,9 +25,10 @@ class EditComment extends Controller
|
||||
public function delete($id)
|
||||
{
|
||||
$comment = Comment::findOrFail($id);
|
||||
$comment->delete();
|
||||
|
||||
// Event::fire(DeletedComment);
|
||||
Event::fire(new DeletedComment($comment));
|
||||
|
||||
$comment->delete();
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
|
||||
@@ -3,7 +3,9 @@ namespace Modules\Blog\Article\Http\Controllers\Visitor;
|
||||
|
||||
use App\Models\Content;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Modules\Blog\Article\Entities\Comment;
|
||||
use Modules\Blog\Article\Events\CreatedComment;
|
||||
use Modules\Blog\Article\Handlers\Article;
|
||||
use Pingpong\Modules\Routing\Controller;
|
||||
|
||||
@@ -33,7 +35,7 @@ class CreateNewComment extends Controller
|
||||
$email = $request->email;
|
||||
}
|
||||
|
||||
Comment::create([
|
||||
$comment = Comment::create([
|
||||
'user_id' => $user ? $user->id : null,
|
||||
'content_id' => $article->id,
|
||||
'name' => $name,
|
||||
@@ -41,6 +43,9 @@ class CreateNewComment extends Controller
|
||||
'content' => $content
|
||||
]);
|
||||
|
||||
// fire event about new comment
|
||||
Event::fire(new CreatedComment($comment));
|
||||
|
||||
return redirect()
|
||||
->route('page.content', ['url' => $article->url])
|
||||
->with('success', trans('article::comments.saved'));
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
<?php
|
||||
// routes for comments
|
||||
|
||||
Route::group([
|
||||
'middleware' => ['web', 'auth', 'adminMenu'],
|
||||
'prefix' => 'admin/comments',
|
||||
'prefix' => LaravelLocalization::setLocale(),
|
||||
'middleware' => ['localeSessionRedirect', 'localizationRedirect'],
|
||||
'namespace' => 'Modules\Blog\Article\Http\Controllers\Admin'
|
||||
], function () {
|
||||
Route::group([
|
||||
'middleware' => ['web', 'auth', 'adminMenu'],
|
||||
'prefix' => 'admin/comments',
|
||||
], function () {
|
||||
|
||||
Route::get('/', 'CommentsOverview@getOverview')
|
||||
->name('comments.overview');
|
||||
Route::get('/', 'CommentsOverview@getOverview')
|
||||
->name('comments.overview');
|
||||
|
||||
Route::get('/delete/{id}', 'EditComment@delete')
|
||||
->name('comments.delete');
|
||||
Route::get('/delete/{id}', 'EditComment@delete')
|
||||
->name('comments.delete');
|
||||
|
||||
Route::get('/approve/{id}', 'EditComment@approve')
|
||||
->name('comments.approve');
|
||||
});
|
||||
Route::get('/approve/{id}', 'EditComment@approve')
|
||||
->name('comments.approve');
|
||||
});
|
||||
|
||||
Route::group([
|
||||
'middleware' => ['web'],
|
||||
'prefix' => 'comments',
|
||||
'namespace' => 'Modules\Blog\Article\Http\Controllers\Visitor'
|
||||
], function () {
|
||||
// public routes
|
||||
Route::group(['middleware' => ['web']], function () {
|
||||
|
||||
Route::post('/new/{id}', 'CreateNewComment@postNew')
|
||||
->name('comments.new');
|
||||
Route::post('comments/new/{id}', 'CreateNewComment@postNew')
|
||||
->name('comments.new');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Blog\Article\Listeners;
|
||||
|
||||
use App\Listeners\Logger;
|
||||
use Modules\Blog\Article\Events\ApprovedComment;
|
||||
|
||||
class LogCommentApproval extends Logger
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param ApprovedComment $event
|
||||
*/
|
||||
public function handle(ApprovedComment $event)
|
||||
{
|
||||
$parameters = [
|
||||
'author' => $event->comment->name,
|
||||
'email' => $event->comment->email,
|
||||
'content' => $event->comment->content
|
||||
];
|
||||
|
||||
$this->saveLog($parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for action name. Used only internally
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getName()
|
||||
{
|
||||
return 'commentApproved';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Blog\Article\Listeners;
|
||||
|
||||
use App\Listeners\Logger;
|
||||
use Modules\Blog\Article\Events\ApprovedComment;
|
||||
use Modules\Blog\Article\Events\DeletedComment;
|
||||
|
||||
class LogDeletedComment extends Logger
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param DeletedComment $event
|
||||
*/
|
||||
public function handle(DeletedComment $event)
|
||||
{
|
||||
$parameters = [
|
||||
'author' => $event->comment->name,
|
||||
'email' => $event->comment->email,
|
||||
'content' => $event->comment->content
|
||||
];
|
||||
|
||||
$this->saveLog($parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for action name. Used only internally
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getName()
|
||||
{
|
||||
return 'commentDeleted';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Blog\Article\Listeners;
|
||||
|
||||
use App\Listeners\Logger;
|
||||
use Modules\Blog\Article\Events\CreatedComment;
|
||||
|
||||
class LogNewComment extends Logger
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param CreatedComment $event
|
||||
*/
|
||||
public function handle(CreatedComment $event)
|
||||
{
|
||||
// log only logged-in users
|
||||
if (!$event->comment->user_id)
|
||||
return;
|
||||
|
||||
$parameters = [
|
||||
'author' => $event->comment->name,
|
||||
'email' => $event->comment->email,
|
||||
'content' => $event->comment->content
|
||||
];
|
||||
|
||||
$this->saveLog($parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for action name. Used only internally
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getName()
|
||||
{
|
||||
return 'commentCreated';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Blog\Article\Providers;
|
||||
|
||||
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Modules\Blog\Article\Events\ApprovedComment;
|
||||
use Modules\Blog\Article\Events\CreatedComment;
|
||||
use Modules\Blog\Article\Events\DeletedComment;
|
||||
use Modules\Blog\Article\Listeners\LogCommentApproval;
|
||||
use Modules\Blog\Article\Listeners\LogDeletedComment;
|
||||
|
||||
class ArticleEventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event listener mappings for the application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $listen = [
|
||||
ApprovedComment::class => [LogCommentApproval::class],
|
||||
DeletedComment::class => [LogDeletedComment::class],
|
||||
CreatedComment::class => [LogNewComment::class],
|
||||
];
|
||||
|
||||
public function boot(DispatcherContract $events)
|
||||
{
|
||||
parent::boot($events); // TODO: Change the autogenerated stub
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,8 @@ class ArticleServiceProvider extends ServiceProvider {
|
||||
$this->registerTranslations();
|
||||
$this->registerConfig();
|
||||
$this->registerViews();
|
||||
|
||||
$this->app->register(ArticleEventServiceProvider::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,7 +59,7 @@ class ArticleServiceProvider extends ServiceProvider {
|
||||
$viewPath = base_path('resources/views/modules/article');
|
||||
$sourcePath = __DIR__.'/../Resources/views';
|
||||
|
||||
$this->publishes([$sourcePath => $viewPath]);
|
||||
$this->publishes([$sourcePath => $viewPath], 'module-views');
|
||||
|
||||
$this->loadViewsFrom(array_merge(array_map(function ($path) {
|
||||
return $path . '/modules/article';
|
||||
|
||||
@@ -5,4 +5,14 @@ return [
|
||||
"commentedArticle" => "Komentovaný článek",
|
||||
"createdAt" => "Vloženo :date",
|
||||
"deleted" => "Komentář smazán",
|
||||
"events" => ["descriptions" => ["commentApproved" => "Schválen komentář od autora :authro (:email) s následujícím obsahem: :content",
|
||||
"commentCreated" => "Přidán komentář od autora :author (e-mail :e-mail) s následujícím obsahem: :content",
|
||||
"commentDeleted" => "Smazán komentář od autora :author (:email) s následujícím obsahem: :content",
|
||||
],
|
||||
"names" => ["commentApproved" => "Komentář schválen",
|
||||
"commentCreated" => "Komentář úspěšně přidán.",
|
||||
"commentDeleted" => "Smazán komentář",
|
||||
],
|
||||
],
|
||||
"noComments" => "Nejsou dostupné žádné komentáře",
|
||||
];
|
||||
|
||||
@@ -5,5 +5,7 @@ return [
|
||||
"comments" => "Komentáře",
|
||||
"commentsOverview" => "Všechny komentáře",
|
||||
"description" => "Základní submodul pro blog. Tento modul umožňuje psát články.",
|
||||
"editArticle" => "Upravuji článek",
|
||||
"name" => "Články",
|
||||
"newArticle" => "Napsat nový článek",
|
||||
];
|
||||
|
||||
@@ -4,5 +4,18 @@ return [
|
||||
'commentedArticle' => 'Article',
|
||||
'approve' => 'Approve comment',
|
||||
'approved' => 'Comment successfully approved',
|
||||
'deleted' => 'Comment deleted'
|
||||
'deleted' => 'Comment deleted',
|
||||
'noComments' => 'No comments available',
|
||||
'events' => [
|
||||
'names' => [
|
||||
'commentCreated' => 'Added comment',
|
||||
'commentApproved' => 'Approved comment',
|
||||
'commentDeleted' => 'Deleted comment',
|
||||
],
|
||||
'descriptions' => [
|
||||
'commentCreated' => 'Added comment from author :author with e-mail :email and following content: :content',
|
||||
'commentApproved' => 'Approved comment from author :author with e-mail :email and following content: :content',
|
||||
'commentDeleted' => 'Deleted comment from author :author with e-mail :email and following content: :content',
|
||||
],
|
||||
]
|
||||
];
|
||||
@@ -4,6 +4,8 @@ return [
|
||||
'description' => 'Base submodule for blog',
|
||||
'comments' => 'Comments',
|
||||
'commentsOverview' => 'All comments',
|
||||
'allArticles' => 'All articles',
|
||||
'blog' => 'Blog'
|
||||
'blog' => 'Blog',
|
||||
'allArticles' => 'All articles',
|
||||
'newArticle' => 'Write new article',
|
||||
'editArticle' => 'Editing article'
|
||||
];
|
||||
@@ -23,8 +23,6 @@
|
||||
<div class="card-footer">
|
||||
@lang('article::comments.createdAt', ['date' => \App\Helpers\Template::date($comment->created_at)]) |
|
||||
|
||||
|
||||
|
||||
@lang('article::comments.commentedArticle'): <a href="{{route('page.content', ['url' => $comment->article->url])}}" target="_blank">
|
||||
{{$comment->article->title}}
|
||||
</a>
|
||||
@@ -35,30 +33,11 @@
|
||||
data-toggle="tooltip"><i class="fa fa-fw fa-check"></i></a>
|
||||
@endif
|
||||
|
||||
<a href="{{route('comments.delete', ['id' => $comment->id])}}" class="btn btn-sm btn-warning"><i class="fa fa-fw fa-trash"></i></a>
|
||||
<a href="{{route('comments.delete', ['id' => $comment->id])}}" class="btn btn-sm confirm btn-warning"><i class="fa fa-fw fa-trash"></i></a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
{{--<div class="comment row">--}}
|
||||
{{--<div class="col-lg-2">--}}
|
||||
{{--<img class="img-rounded" src="@gravatar($comment->author->email)" alt="">--}}
|
||||
|
||||
{{--{{$comment->author->name}}--}}
|
||||
|
||||
{{--@date($comment->created_at)--}}
|
||||
|
||||
{{--</div>--}}
|
||||
{{--<div class="col-lg-10">{{$comment->content}}</div>--}}
|
||||
{{--<div class="col-lg2">--}}
|
||||
|
||||
|
||||
|
||||
{{--</div>--}}
|
||||
{{--</div>--}}
|
||||
@endforeach
|
||||
@else
|
||||
<div class="alert alert-info">
|
||||
|
||||
@@ -98,7 +98,7 @@ class ArticleList extends Handler
|
||||
$articles = $articles->orderBy('created_at', 'DESC')
|
||||
->paginate(20);
|
||||
|
||||
return Controller::VisitorsView($content->template, ['page' => $content, 'articles' => $articles]);
|
||||
return Controller::VisitorsView($content->template, ['page' => $content, 'articles' => $articles, 'extra' => $parameters]);
|
||||
}
|
||||
|
||||
public static function getModuleId()
|
||||
|
||||
@@ -1,6 +1 @@
|
||||
<?php
|
||||
|
||||
Route::group(['middleware' => 'web', 'prefix' => 'articlelist', 'namespace' => 'Modules\Blog\ArticleList\Http\Controllers'], function()
|
||||
{
|
||||
Route::get('/', 'ArticleListController@index');
|
||||
});
|
||||
Reference in New Issue
Block a user