<?php
namespace Claromentis\Projects\Comments;

$GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"] = (@$GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"] ?: array()) + array("_76b1e0edd97786ed9d" . "db7b7f6083c218" => base64_decode("cHJvamVjdHMucHJvamVjdHNfcHJvdm" . "lkZXI="), "_c927258f5322288a992c77" . "be40ae0b53" => base64_decode("dX" . "Js"), "_d50d529d5" . "739d103bc4" . "8e65a4b513" . "fe3" => base64_decode("Q29tbWVudEFk" . "ZGVkRXZlbnRS" . "ZWNlaXZlcg=="), "_191a9c69" . "4701b5e98" . "f9b02b731" . "05f5cf" => base64_decode("Q29tbWVudERlbGV0ZWRFdmVudFJlY2Vp" . "dmVy"), "_3877cdf57a61e49" . "b56aeab7af930ee8" . "2" => base64_decode("dXN" . "lcl" . "9pZ" . "A=="), "_9bb5cca7404240f906" . "8ffc9838b77be1" => base64_decode("Q29tbWVudEF0dGFjaG1lbn" . "RzQWRkZWRFdmVudFJlY2Vp" . "dmVy"), "_db618ca8e79f97b4dff753e" . "c837942cf" => base64_decode("cHJvamVjdF9pZA=" . "="), "_699cd46f38" . "6ae19747226" . "16ce651a3a1" => base64_decode("YWdncmV" . "nYXRpb2" . "4="), "_dadf790baf241afac" . "942824c1e6e37c4" => base64_decode("dHl" . "wZQ" . "=="), "_e3037a4609adf1f69b1e8dc" . "9813b51ec" => base64_decode("dGFz" . "a19p" . "ZA=="), "_00f2055c7cbd408ef56949f3" . "5c62b721" => base64_decode("ZmlsZX" . "M="), "_31767d7ad58e706dbf47b7a51a0f" . "e6c4" => base64_decode("Y291bn" . "Q="), "_93939227a" . "8e7cf780ef" . "aa642c3da9" . "723" => base64_decode("YnlfdXN" . "lcl9pZA" . "=="), "_e06da3ffba2e84b8e6f94bd2" . "d6ca3c52" => base64_decode("Y3JlYXRlX2ludGVybmFsX2xpb" . "ms="), "_077e27168673cad4e72653c8730" . "129b5" => base64_decode("ZmlsZ" . "W5hbW" . "U="), "_2d876b1225" . "33fac9677b1" . "6ea6c640aa6" => base64_decode("b2JqZWN0X2" . "lk"));
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["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_d50d529d5739d10" . "3bc48e65a4b513fe" . "3"], CommentDeletedEvent::EVENT_NAME => $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_191a9c694701b5e98f9b" . "02b73105f5cf"], CommentAttachmentsAddedEvent::EVENT_NAME => $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_9bb5cca7404240f9068ff" . "c9838b77be1"]];
    }
    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["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_76b1e0edd977" . "86ed9ddb7b7f6" . "083c218"]};
                $_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["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_2d876b122533fac9677b16e" . "a6c640aa6"]);
        $_696b535739055ed7d827709916d07dea = null;
        $_0a3f284de65e596869ef47aa9e91f906 = null;
        switch ($_e8d840684607f6c2bbef523090642168->GetProperty($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_699cd46f386ae1974722616ce65" . "1a3a1"])) {
            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["__65da1b1ec2d6653e8a0ab7848e536" . "215"]["_dadf790baf241afac942824c1e6" . "e37c4"]);
            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["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_31767d7ad58e" . "706dbf47b7a51" . "a0fe6c4"]($_00f2055c7cbd408ef56949f35c62b721) === 0) {
            return;
        }
        if ($_696b535739055ed7d827709916d07dea === null) {
            $_c927258f5322288a992c77be40ae0b53 = $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_e06da3ffba2e84b" . "8e6f94bd2d6ca3c5" . "2"]($_0a3f284de65e596869ef47aa9e91f906->GetUrl());
        } else {
            $_c927258f5322288a992c77be40ae0b53 = $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_e06da3ffba2e84b8e6f94bd2d6" . "ca3c52"]($_696b535739055ed7d827709916d07dea->GetUrl());
        }
        $_8248f758e7baf777ae70aa7fe7eb48d0 = array();
        
        
        foreach ($_00f2055c7cbd408ef56949f35c62b721 as $_6ae3783b9ad544a6c31a979683fed870) {
            $_8248f758e7baf777ae70aa7fe7eb48d0[] = array($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_077e2716" . "8673cad4e" . "72653c873" . "0129b5"] => $_6ae3783b9ad544a6c31a979683fed870->GetTitle(), $GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_c927258f5322288a" . "992c77be40ae0b53"] => $_6ae3783b9ad544a6c31a979683fed870->GetDetailsURL(true));
        }
        
        
        $_a71dc9333bd8ad95d55d6624b477875f = array($GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_db618ca8e79f97b4dff75" . "3ec837942cf"] => $_0a3f284de65e596869ef47aa9e91f906 !== null ? $_0a3f284de65e596869ef47aa9e91f906->GetId() : 0, $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_e3037a4609adf1f69b1e8d" . "c9813b51ec"] => $_696b535739055ed7d827709916d07dea !== null ? $_696b535739055ed7d827709916d07dea->GetId() : 0, $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_00f2055c7" . "cbd408ef56" . "949f35c62b" . "721"] => $_8248f758e7baf777ae70aa7fe7eb48d0, $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_3877cdf57a61e49b" . "56aeab7af930ee82"] => $this->context->GetUserId(), $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_c927258f53222" . "88a992c77be40a" . "e0b53"] => $_c927258f5322288a992c77be40ae0b53, $GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_93939227a8e7c" . "f780efaa642c3d" . "a9723"] => \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);
        }
    }
}