<?php
namespace Claromentis\Projects\Comments;

$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"] = (@$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"] ?: array()) + array("_dadf790baf241afac94282" . "4c1e6e37c4" => base64_decode("dHlwZ" . "Q=="), "_93939227a8e7cf780e" . "faa642c3da9723" => base64_decode("YnlfdXN" . "lcl9pZA" . "=="), "_d50d529d5739d103bc48e65a4b51" . "3fe3" => base64_decode("Q29tbWVudEFkZGVkRXZlb" . "nRSZWNlaXZlcg=="), "_9bb5cca7404" . "240f9068ffc9" . "838b77be1" => base64_decode("Q29tbWVudEF0dGFjaG1lbnRzQWRkZWRFdmVudFJl" . "Y2VpdmVy"), "_00f2055c7cb" . "d408ef56949f" . "35c62b721" => base64_decode("ZmlsZX" . "M="), "_2d876b122533fac9677b1" . "6ea6c640aa6" => base64_decode("b2JqZ" . "WN0X2" . "lk"), "_e3037a4609" . "adf1f69b1e8" . "dc9813b51ec" => base64_decode("dGFza19" . "pZA=="), "_191a9c694701b5e98f9b" . "02b73105f5cf" => base64_decode("Q29tbWVudERlbGV0ZWRFdmVu" . "dFJlY2VpdmVy"), "_31767d7ad5" . "8e706dbf47b" . "7a51a0fe6c4" => base64_decode("Y291" . "bnQ="), "_3877cdf57a61e49b56ae" . "ab7af930ee82" => base64_decode("dXNlcl9pZ" . "A=="), "_76b1e0edd" . "97786ed9dd" . "b7b7f6083c" . "218" => base64_decode("cHJvamVjdHMu" . "cHJvamVjdHNf" . "cHJvdmlkZXI="), "_db618ca8e79" . "f97b4dff753e" . "c837942cf" => base64_decode("cHJva" . "mVjdF" . "9pZA=" . "="), "_e06da3ffba2e84b8e6f94" . "bd2d6ca3c52" => base64_decode("Y3JlYXRlX" . "2ludGVybm" . "FsX2xpbms" . "="), "_077e27168673cad4e72653c" . "8730129b5" => base64_decode("ZmlsZW5" . "hbWU="), "_c927258f5322288a992c" . "77be40ae0b53" => base64_decode("d" . "X" . "J" . "s"), "_699cd46f386ae1974722616" . "ce651a3a1" => base64_decode("YWdncmVnYXR" . "pb24="));
use Claromentis\Comments\Events\CommentAddedEvent;
use Claromentis\Comments\Events\CommentAttachmentsAddedEvent;
use Claromentis\Comments\Events\CommentDeletedEvent;
use Claromentis\Comments\Model\Attachment;
use Claromentis\Comments\Model\Comment;
use Claromentis\Core\Services;
use Claromentis\Projects\Entity\Topic;
use Claromentis\Core\Security\SecurityContext;
use Claromentis\Projects\Service\NotificationService;
use Claromentis\Projects\Service\FilesService;
use Claromentis\Projects\Permissions;
use Claromentis\Projects\Exceptions\ProjectsFolderException;
use Claromentis\Projects\ProjectEvent;
use Claromentis\Projects\Repository\ProjectRepository;
use Claromentis\Projects\Repository\TopicRepository;
use Claromentis\Projects\Repository\TaskRepository;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;






class CommentsSubscriber implements EventSubscriberInterface
{
    
    
    protected $project_repository;
    
    
    protected $task_repository;
    
    
    protected $files_service;
    
    
    protected $context;
    public function __construct(ProjectRepository $_3df6a3ee29561bd6e42ae4d5e62ba1be, TaskRepository $_21f780f08a9470c494fb6a449b8f20bd, FilesService $_b45408acf432d2f575dd658b48fcb432, SecurityContext $_0f4808db75324a12fb1768e785daadb7, TopicRepository $_018eed6448abbc8c4aae90cde2897af1)
    {
        $this->project_repository = $_3df6a3ee29561bd6e42ae4d5e62ba1be;
        $this->task_repository = $_21f780f08a9470c494fb6a449b8f20bd;
        $this->files_service = $_b45408acf432d2f575dd658b48fcb432;
        $this->context = $_0f4808db75324a12fb1768e785daadb7;
        $this->topic_repository = $_018eed6448abbc8c4aae90cde2897af1;
    }
    
    
    
    
    protected $topic_repository;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    public static function getSubscribedEvents()
    {
        return [CommentAddedEvent::EVENT_NAME => $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_d50d529d5739d103bc48" . "e65a4b513fe3"], CommentDeletedEvent::EVENT_NAME => $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_191a9c694701" . "b5e98f9b02b73" . "105f5cf"], CommentAttachmentsAddedEvent::EVENT_NAME => $GLOBALS["__65da1b1ec2d6653e8a0ab7" . "848e536215"]["_9bb5cca7404240f9068ffc9838b7" . "7be1"]];
    }
    public function CommentAddedEventReceiver(CommentAddedEvent $_e62ca7bbb93b52cafc82da1c2aefe9ec, $_5693d84b45564f912e36404cbe8957e8, EventDispatcherInterface $_b497ce6f2af10f67516aed0ecf34d8cf)
    {
        
        
        $_e8d840684607f6c2bbef523090642168 = $_e62ca7bbb93b52cafc82da1c2aefe9ec->getComment();
        switch ($_e8d840684607f6c2bbef523090642168->aggregation) {
            case Topic::AGGREGATION:
                
                
                $_9a3559422c29efc571cba589ffa1a59f = $this->topic_repository->find($_e8d840684607f6c2bbef523090642168->object_id);
                
                
                $_9a3559422c29efc571cba589ffa1a59f->modified = new \Date();
                $this->topic_repository->store($_9a3559422c29efc571cba589ffa1a59f);
                
                
                $_f4a2686c1ded90204b914f133dc57722 = Services::I()->{$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_76b1e0edd9" . "7786ed9ddb7" . "b7f6083c218"]};
                $_f4a2686c1ded90204b914f133dc57722->IncrementCommentCount($_9a3559422c29efc571cba589ffa1a59f->project_id);
                if ($_e8d840684607f6c2bbef523090642168->parent_id === 0) {
                    
                    
                    $_b497ce6f2af10f67516aed0ecf34d8cf->dispatch(NotificationService::PROJECT_DISCUSSION_POSTED, new ProjectEvent($_e8d840684607f6c2bbef523090642168));
                } else {
                    
                    
                    $_b497ce6f2af10f67516aed0ecf34d8cf->dispatch(NotificationService::PROJECT_REPLY_POSTED, new ProjectEvent($_e8d840684607f6c2bbef523090642168));
                }
                $_e62ca7bbb93b52cafc82da1c2aefe9ec->stopPropagation();
            case Permissions::TASK_AGGREGATION:
                $this->task_repository->IncrementCommentCount($_e8d840684607f6c2bbef523090642168->object_id);
                if ($_e8d840684607f6c2bbef523090642168->parent_id === 0) {
                    
                    
                    $_b497ce6f2af10f67516aed0ecf34d8cf->dispatch(NotificationService::TASK_DISCUSSION_POSTED, new ProjectEvent($_e8d840684607f6c2bbef523090642168));
                } else {
                    
                    
                    $_b497ce6f2af10f67516aed0ecf34d8cf->dispatch(NotificationService::TASK_REPLY_POSTED, new ProjectEvent($_e8d840684607f6c2bbef523090642168));
                }
                $_e62ca7bbb93b52cafc82da1c2aefe9ec->stopPropagation();
                break;
        }
    }
    public function CommentDeletedEventReceiver(CommentDeletedEvent $_e62ca7bbb93b52cafc82da1c2aefe9ec)
    {
        
        
        $_e8d840684607f6c2bbef523090642168 = $_e62ca7bbb93b52cafc82da1c2aefe9ec->getComment();
        switch ($_e8d840684607f6c2bbef523090642168->aggregation) {
            case Permissions::TASK_AGGREGATION:
                $this->task_repository->DecrementCommentCount($_e8d840684607f6c2bbef523090642168->object_id);
                $_e62ca7bbb93b52cafc82da1c2aefe9ec->stopPropagation();
                break;
        }
    }
    public function CommentAttachmentsAddedEventReceiver(CommentAttachmentsAddedEvent $_e62ca7bbb93b52cafc82da1c2aefe9ec, $_5693d84b45564f912e36404cbe8957e8, EventDispatcherInterface $_b497ce6f2af10f67516aed0ecf34d8cf)
    {
        $_4e7ab34a53ffb13eb0838003f33034d4 = $_e62ca7bbb93b52cafc82da1c2aefe9ec->GetAttachments();
        $_e8d840684607f6c2bbef523090642168 = $_e62ca7bbb93b52cafc82da1c2aefe9ec->GetComment();
        
        
        $_2d876b122533fac9677b16ea6c640aa6 = $_e8d840684607f6c2bbef523090642168->GetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_2d876b122533fac967" . "7b16ea6c640aa6"]);
        $_696b535739055ed7d827709916d07dea = null;
        $_0a3f284de65e596869ef47aa9e91f906 = null;
        switch ($_e8d840684607f6c2bbef523090642168->GetProperty($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_699cd46f386ae1974722616ce651" . "a3a1"])) {
            case Permissions::TASK_AGGREGATION:
                $_696b535739055ed7d827709916d07dea = $this->task_repository->LoadTask($_2d876b122533fac9677b16ea6c640aa6);
                $_db618ca8e79f97b4dff753ec837942cf = $_696b535739055ed7d827709916d07dea->GetProject();
                $_0a3f284de65e596869ef47aa9e91f906 = $this->project_repository->GetProject($_db618ca8e79f97b4dff753ec837942cf);
                break;
            case Topic::AGGREGATION:
                $_9a3559422c29efc571cba589ffa1a59f = $this->topic_repository->findOrFail($_2d876b122533fac9677b16ea6c640aa6);
                $_0a3f284de65e596869ef47aa9e91f906 = $this->project_repository->GetProject($_9a3559422c29efc571cba589ffa1a59f->project_id);
                break;
            default:
                
                
                return;
        }
        $_00f2055c7cbd408ef56949f35c62b721 = array();
        foreach ($_4e7ab34a53ffb13eb0838003f33034d4 as $_5feede65e7cfe8f0b3d9854c0363d548) {
            
            
            $_dadf790baf241afac942824c1e6e37c4 = $_5feede65e7cfe8f0b3d9854c0363d548->GetProperty($GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_dadf790baf241afac942" . "824c1e6e37c4"]);
            if ($_dadf790baf241afac942824c1e6e37c4 != Attachment::TYPE_FILE) {
                continue;
            }
            if ($_696b535739055ed7d827709916d07dea === null) {
                $_09f61d3133f39f8e5aff0eb6a7d185a1 = $this->files_service->CopyCommentFileToProject($_5feede65e7cfe8f0b3d9854c0363d548, $_0a3f284de65e596869ef47aa9e91f906);
            } else {
                try {
                    $_09f61d3133f39f8e5aff0eb6a7d185a1 = $this->files_service->CopyCommentFileToTask($_5feede65e7cfe8f0b3d9854c0363d548, $_696b535739055ed7d827709916d07dea, $_0a3f284de65e596869ef47aa9e91f906);
                } catch (ProjectsFolderException $_c35473364fa7a050299058f332ec29c1) {
                    continue;
                }
            }
            $_00f2055c7cbd408ef56949f35c62b721[] = $_09f61d3133f39f8e5aff0eb6a7d185a1;
        }
        $this->files_service->SendNotifications();
        
        
        if ($GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_31767d7ad58e706dbf47b7a51a0fe6c" . "4"]($_00f2055c7cbd408ef56949f35c62b721) === 0) {
            return;
        }
        if ($_696b535739055ed7d827709916d07dea === null) {
            $_c927258f5322288a992c77be40ae0b53 = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_e06da3ffba2e84b" . "8e6f94bd2d6ca3c5" . "2"]($_0a3f284de65e596869ef47aa9e91f906->GetUrl());
        } else {
            $_c927258f5322288a992c77be40ae0b53 = $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_e06da3ffba2e84b8e6f94bd2" . "d6ca3c52"]($_696b535739055ed7d827709916d07dea->GetUrl());
        }
        $_8248f758e7baf777ae70aa7fe7eb48d0 = array();
        
        
        foreach ($_00f2055c7cbd408ef56949f35c62b721 as $_6ae3783b9ad544a6c31a979683fed870) {
            $_8248f758e7baf777ae70aa7fe7eb48d0[] = array($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_077e27168673cad" . "4e72653c8730129b" . "5"] => $_6ae3783b9ad544a6c31a979683fed870->GetTitle(), $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_c927258f5322288a" . "992c77be40ae0b53"] => $_6ae3783b9ad544a6c31a979683fed870->GetDetailsURL(true));
        }
        
        
        $_a71dc9333bd8ad95d55d6624b477875f = array($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_db618ca8e79f97b4dff753ec83" . "7942cf"] => $_0a3f284de65e596869ef47aa9e91f906 !== null ? $_0a3f284de65e596869ef47aa9e91f906->GetId() : 0, $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_e3037a4609adf1f6" . "9b1e8dc9813b51ec"] => $_696b535739055ed7d827709916d07dea !== null ? $_696b535739055ed7d827709916d07dea->GetId() : 0, $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_00f2055c7cbd408" . "ef56949f35c62b72" . "1"] => $_8248f758e7baf777ae70aa7fe7eb48d0, $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_3877cdf57a61e49b56a" . "eab7af930ee82"] => $this->context->GetUserId(), $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_c927258f5322288a992c77b" . "e40ae0b53"] => $_c927258f5322288a992c77be40ae0b53, $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_93939227a8e7cf780" . "efaa642c3da9723"] => \AuthUser::I()->GetId());
        $_e62ca7bbb93b52cafc82da1c2aefe9ec->stopPropagation();
        $_e62ca7bbb93b52cafc82da1c2aefe9ec = new ProjectEvent($_a71dc9333bd8ad95d55d6624b477875f);
        if ($_696b535739055ed7d827709916d07dea === null) {
            $_b497ce6f2af10f67516aed0ecf34d8cf->dispatch(NotificationService::PROJECT_FILE_ADDED, $_e62ca7bbb93b52cafc82da1c2aefe9ec);
        } else {
            $_b497ce6f2af10f67516aed0ecf34d8cf->dispatch(NotificationService::TASK_FILE_ADDED, $_e62ca7bbb93b52cafc82da1c2aefe9ec);
        }
    }
}