SetLastCommentWhenCommentPosted.php 844 Bytes
<?php

namespace FootyRoom\Core\ForumPost;

use FootyRoom\Queries\PostQuery;

class SetLastCommentWhenCommentPosted
{
    /**
     * @var \FootyRoom\Queries\PostQuery
     */
    protected $postQuery;

    /**
     * Constructor.
     *
     * @param \FootyRoom\Queries\PostQuery $postRepo
     */
    public function __construct(PostQuery $postQuery)
    {
        $this->postQuery = $postQuery;
    }

    /**
     * Handler.
     *
     * @param \FootyRoom\Core\ForumPost\ForumPostCommentPosted $event
     */
    public function handle(ForumPostCommentPosted $event)
    {
        $this->postQuery->updateLastComment(
            (int) explode(':', $event->comment->getDiscussionId())[1],
            $event->comment->getAuthor()->getUserId(),
            $event->comment->getId(),
            $event->comment->getDate()
        );
    }
}