Skip to content
Merged

Dev #25

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions app/Broadcasting/AdminChatChannel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Broadcasting;

use App\User;

class AdminChatChannel
{
/**
* Create a new channel instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Authenticate the user's access to the channel.
*
* @param \App\User $user
* @return array|bool
*/
public function join(User $user)
{
return $user->hasRole('admin');
}
}
35 changes: 35 additions & 0 deletions app/Events/ChannelEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class ChannelEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $user;
public $data;

public function __construct($user, $data)
{
$this->user = $user;
$this->data = $data;
}

/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('test-channel');
}
}
28 changes: 28 additions & 0 deletions app/Events/PostUpdatedAdminChat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class PostUpdatedAdminChat implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $post;
public $data;

public function __construct($post, $data)
{
$this->post = $post;
$this->data = $data;
}

public function broadcastOn()
{
return new PrivateChannel('admin-chat-channel');
}
}
12 changes: 12 additions & 0 deletions app/Http/Controllers/AdministrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\News;
use App\Post;
use Illuminate\Http\Request;

class AdministrationController extends Controller
{
Expand All @@ -25,4 +26,15 @@ public function news() {
$news = News::latest()->get();
return view('/admin.news', compact('news'));
}

public function orders() {
return view('/admin.orders');
}

public function ordersStore(Request $request) {

\App\Jobs\GenerateResultingOrder::dispatch($request->all(), auth()->user());

return back();
}
}
66 changes: 66 additions & 0 deletions app/Jobs/GenerateResultingOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace App\Jobs;

use App\Comment;
use App\Mail\ResultingOrderSend;
use App\News;
use App\Post;
use App\Tag;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;
use Throwable;

class GenerateResultingOrder implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

protected $requestData;
protected $user;

public function __construct($requestData, $user)
{
$this->requestData = $requestData;
$this->user = $user;
}

public function handle()
{
$data = [];

if ($this->requestData) {
if (array_key_exists ( 'news' , $this->requestData )) {
$data['news'] = 'Новостей: ' . News::count() . PHP_EOL;
}

if (array_key_exists ( 'posts' , $this->requestData )) {
$data['posts'] = 'Статей: ' . Post::count() . PHP_EOL;
}

if (array_key_exists ( 'comments' , $this->requestData )) {
$data['comments'] = 'Комментариев: ' . Comment::count() . PHP_EOL;
}

if (array_key_exists ( 'tags' , $this->requestData )) {
$data['tags'] = 'Тегов: ' . Tag::count() . PHP_EOL;
}

if (array_key_exists ( 'users' , $this->requestData )) {
$data['users'] = 'Пользователей: ' . News::count() . PHP_EOL;
}
}

Mail::to($this->user->email)->send(
new ResultingOrderSend($data)
);
}

public function failed(Throwable $exception)
{
// Send user notification of failure, etc...
}
}
3 changes: 3 additions & 0 deletions app/Listeners/AddHistoryOnUpdatePost.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Listeners;

use App\Events\PostUpdated;
use App\Events\PostUpdatedAdminChat;

class AddHistoryOnUpdatePost
{
Expand Down Expand Up @@ -33,5 +34,7 @@ public function handle(PostUpdated $event)
];

$event->post->history()->create($values);

event(new PostUpdatedAdminChat($event->post, $result));
}
}
31 changes: 31 additions & 0 deletions app/Mail/ResultingOrderSend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use phpDocumentor\Reflection\Types\This;

class ResultingOrderSend extends Mailable
{
use Queueable, SerializesModels;

protected $data;

public function __construct($data)
{
$this->data = $data;
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->markdown('mail.order-send', ['data' => $this->data]);
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"laravel/helpers": "^1.3",
"laravel/telescope": "^4.0",
"laravel/tinker": "^2.0",
"laravel/ui": "^2.1"
"laravel/ui": "^2.1",
"predis/predis": "^1.1"
},
"require-dev": {
"facade/ignition": "^2.0",
Expand Down
Loading