Merge photo comments feature #114
@ -50,6 +50,23 @@ class PermissionsHelper
|
||||
->count() > 0;
|
||||
}
|
||||
|
||||
public function usersWhoCan_Album(Album $album, $permission)
|
||||
{
|
||||
$users = DB::table('album_permissions_cache')
|
||||
->join('permissions', 'permissions.id', '=', 'album_permissions_cache.permission_id')
|
||||
->where([
|
||||
['album_permissions_cache.album_id', $album->id],
|
||||
['permissions.section', 'album'],
|
||||
['permissions.description', $permission]
|
||||
])
|
||||
->get();
|
||||
|
||||
// Include the album's owner (who can do everything)
|
||||
$users->push($album->user);
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
private function rebuildAlbumCache()
|
||||
{
|
||||
// Get a list of albums
|
||||
|
@ -2,11 +2,15 @@
|
||||
|
||||
namespace App\Http\Controllers\Gallery;
|
||||
|
||||
use App\Album;
|
||||
use App\Facade\Theme;
|
||||
use App\Facade\UserConfig;
|
||||
use App\Helpers\DbHelper;
|
||||
use App\Helpers\PermissionsHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\StorePhotoCommentRequest;
|
||||
use App\Mail\ModeratePhotoComment;
|
||||
use App\Permission;
|
||||
use App\Photo;
|
||||
use App\PhotoComment;
|
||||
use App\User;
|
||||
@ -14,6 +18,7 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class PhotoCommentController extends Controller
|
||||
@ -171,6 +176,12 @@ class PhotoCommentController extends Controller
|
||||
$isAutoApproved = true;
|
||||
}
|
||||
|
||||
// Send notification e-mails to moderators or album owner
|
||||
if (!$isAutoApproved)
|
||||
{
|
||||
$this->notifyAlbumModerators($album, $photo, $comment);
|
||||
}
|
||||
|
||||
$comment->save();
|
||||
|
||||
if ($isAutoApproved)
|
||||
@ -241,4 +252,25 @@ class PhotoCommentController extends Controller
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an e-mail notification to an album's moderators that a comment is available to moderate.
|
||||
* @param Album $album
|
||||
* @param Photo $photo
|
||||
* @param PhotoComment $comment
|
||||
*/
|
||||
private function notifyAlbumModerators(Album $album, Photo $photo, PhotoComment $comment)
|
||||
{
|
||||
// Get all users from the cache
|
||||
$helper = new PermissionsHelper();
|
||||
$moderators = $helper->usersWhoCan_Album($album, 'moderate-comments');
|
||||
|
||||
/** @var User $moderator */
|
||||
foreach ($moderators as $moderator)
|
||||
{
|
||||
Mail::to($moderator)->send(new ModeratePhotoComment($moderator, $album, $photo, $comment));
|
||||
}
|
||||
|
||||
dd($moderators);
|
||||
}
|
||||
}
|
52
app/Mail/ModeratePhotoComment.php
Normal file
52
app/Mail/ModeratePhotoComment.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Album;
|
||||
use App\Facade\Theme;
|
||||
use App\Facade\UserConfig;
|
||||
use App\Photo;
|
||||
use App\PhotoComment;
|
||||
use App\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class ModeratePhotoComment extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
private $album;
|
||||
private $comment;
|
||||
private $photo;
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(User $user, Album $album, Photo $photo, PhotoComment $comment)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
$subject = trans('email.change_email_required_subject', ['app_name' => UserConfig::get('app_name')]);
|
||||
|
||||
return $this
|
||||
->subject($subject)
|
||||
->markdown(Theme::viewName('email.user_change_email_required'))
|
||||
->with([
|
||||
'subject' => $subject,
|
||||
'user' => $this->user
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user