src/AppBundle/Entity/Paper.php
/**
     * Set the appropriate fields in response to an event. Eg, if the event is an instanceof 'InsightDecisionMade',
     * update the insight decision field on this snapshot. Also, always update the _version field to the event sequence
     * so that we know which events we've already processed.
     *
     * @param PaperEvent $event
     */
Set the appropriate fields in response to an event. Eg, if the event is an instanceof 'InsightDecisionMade',
update the insight decision field on this snapshot. Also, always update the _version field to the event sequence
so that we know which events we've already processed.


Set the appropriate fields in response to an event . Eg if the event is an instanceof ' InsightDecisionMade ' update the insight decision field on this snapshot . Also always update the _version field to the event sequence so that we know which events we ' ve already processed .
public function applyEvent(PaperEvent $event, EntityManager $em)
    {
        if ($event->getSequence() === 1) {
            $this->dateAdded = $event->getTime();
            $this->insightUpdatedDate = $event->getTime();
        }
        if ($event instanceof PaperAdded || $event instanceof EjpPaperImported) {
            $articleType = $em->getReference(ArticleType::class, $event->getArticleTypeCode());
            $subjectArea1 = $subjectArea2 = null;
            $subjectAreaIds = $event->getSubjectAreaIds();
            if (isset($subjectAreaIds[0])) {
                $subjectArea1 = $em->getReference(SubjectArea::class, $subjectAreaIds[0]);
            }
            if (isset($subjectAreaIds[1])) {
                $subjectArea2 = $em->getReference(SubjectArea::class, $subjectAreaIds[1]);
            }
            $this->manuscriptNo = $event->getManuscriptNo();
            $this->correspondingAuthor = $event->getCorrespondingAuthor();
            $this->articleType = $articleType;
            $this->revision = $event->getRevision();
            $this->hadAppeal = $event->getHadAppeal();
            $this->subjectArea1 = $subjectArea1;
            $this->subjectArea2 = $subjectArea2;
            if ($event instanceof EjpPaperImported) {
                if ($this->insightDecision !== $event->getInsightDecision() ||
                    $this->insightComment !== $event->getInsightComment()
                ) {
                    $this->insightUpdatedDate = $event->getTime();
                }
            }
            $this->insightDecision = $event->getInsightDecision();
            $this->insightComment = $event->getInsightComment();
        }
        if ($event instanceof PaperAcceptedEvent) {
            $this->accepted = true;
            $this->acceptedDate = $event->getAcceptedDate();
            $this->digestQuestionsAsked = $event->getDigestQuestionsAsked();
            $this->digestAnswersGiven = $event->getDigestAnswersGiven();
            $this->impactStatement = $event->getImpactStatement();
            $this->abstract = $event->getAbstract();
        }
        if ($event instanceof NoDigestDecided) {
            $this->noDigestStatus = $event->getNoDigestReason();
        }
        if ($event instanceof NoDigestDecidedUndone) {
            $this->noDigestStatus = null;
        }
        if ($event instanceof AnswersReceived) {
            $this->answersStatus = $event->getAnswersQuality();
            $this->answersInDigestForm = $event->getIsInDigestForm();
        }
        if ($event instanceof AnswersReceivedUndone) {
            $this->answersStatus = null;
            $this->answersInDigestForm = false;
        }
        if ($event instanceof DigestWriterAssigned) {
            $this->digestWrittenBy = $em->getReference(DigestWriter::class, $event->getDigestWriterAssigned());
            $this->digestDueDate = $event->getDigestDueDate();
        }
        if ($event instanceof DigestReceived) {
            $this->digestReceived = $event->getDigestReceived();
        }
        if ($event instanceof DigestSignedOff) {
            $this->digestSignedOff = $event->getDigestSignedOff();
        }
        if ($event instanceof InsightCommissioned){
            $this->insightCommissioned = true;
            $this->insightDueDate = $event->getInsightDueDate();
        }
        if ($event instanceof NoInsightDecided){
            $this->insightCommissioned = false;
        }
        if ($event instanceof InsightAuthorAsked){
            $this->insightAuthor = $event->getInsightAuthor();
        }
        if ($event instanceof InsightAuthorRefused){
            $this->insightRefusalComment = $event->getinsightAuthorRefusalReason();
        }
        if ($event instanceof InsightAcknowledged){
            $this->insightAcknowledged = true;
        }
        if ($event instanceof InsightEditorAssigned){
            $this->editor = $event->getInsightEditorAssigned();
        }
        if ($event instanceof InsightToAuthorSent){
            $this->insightAuthorChecking = true;
            $this->insightEditsDueDate = $event->getInsightEditsDueDate();
        }
        if ($event instanceof InsightSignedOff){
            $this->insightSignedOff = true;
        }
        $this->_version = $event->getSequence();
    }
public function applyEvent ( PaperEvent $ event , EntityManager $ em ) { if ( $ event -> getSequence ( ) === 1 ) { $ this -> dateAdded = $ event -> getTime ( ) ; $ this -> insightUpdatedDate = $ event -> getTime ( ) ; } if ( $ event instanceof PaperAdded || $ event instanceof EjpPaperImported ) { $ articleType = $ em -> getReference ( ArticleType :: class , $ event -> getArticleTypeCode ( ) ) ; $ subjectArea1 = $ subjectArea2 = null ; $ subjectAreaIds = $ event -> getSubjectAreaIds ( ) ; if ( isset ( $ subjectAreaIds [ 0 ] ) ) { $ subjectArea1 = $ em -> getReference ( SubjectArea :: class , $ subjectAreaIds [ 0 ] ) ; } if ( isset ( $ subjectAreaIds [ 1 ] ) ) { $ subjectArea2 = $ em -> getReference ( SubjectArea :: class , $ subjectAreaIds [ 1 ] ) ; } $ this -> manuscriptNo = $ event -> getManuscriptNo ( ) ; $ this -> correspondingAuthor = $ event -> getCorrespondingAuthor ( ) ; $ this -> articleType = $ articleType ; $ this -> revision = $ event -> getRevision ( ) ; $ this -> hadAppeal = $ event -> getHadAppeal ( ) ; $ this -> subjectArea1 = $ subjectArea1 ; $ this -> subjectArea2 = $ subjectArea2 ; if ( $ event instanceof EjpPaperImported ) { if ( $ this -> insightDecision !== $ event -> getInsightDecision ( ) || $ this -> insightComment !== $ event -> getInsightComment ( ) ) { $ this -> insightUpdatedDate = $ event -> getTime ( ) ; } } $ this -> insightDecision = $ event -> getInsightDecision ( ) ; $ this -> insightComment = $ event -> getInsightComment ( ) ; } if ( $ event instanceof PaperAcceptedEvent ) { $ this -> accepted = true ; $ this -> acceptedDate = $ event -> getAcceptedDate ( ) ; $ this -> digestQuestionsAsked = $ event -> getDigestQuestionsAsked ( ) ; $ this -> digestAnswersGiven = $ event -> getDigestAnswersGiven ( ) ; $ this -> impactStatement = $ event -> getImpactStatement ( ) ; $ this -> abstract = $ event -> getAbstract ( ) ; } if ( $ event instanceof NoDigestDecided ) { $ this -> noDigestStatus = $ event -> getNoDigestReason ( ) ; } if ( $ event instanceof NoDigestDecidedUndone ) { $ this -> noDigestStatus = null ; } if ( $ event instanceof AnswersReceived ) { $ this -> answersStatus = $ event -> getAnswersQuality ( ) ; $ this -> answersInDigestForm = $ event -> getIsInDigestForm ( ) ; } if ( $ event instanceof AnswersReceivedUndone ) { $ this -> answersStatus = null ; $ this -> answersInDigestForm = false ; } if ( $ event instanceof DigestWriterAssigned ) { $ this -> digestWrittenBy = $ em -> getReference ( DigestWriter :: class , $ event -> getDigestWriterAssigned ( ) ) ; $ this -> digestDueDate = $ event -> getDigestDueDate ( ) ; } if ( $ event instanceof DigestReceived ) { $ this -> digestReceived = $ event -> getDigestReceived ( ) ; } if ( $ event instanceof DigestSignedOff ) { $ this -> digestSignedOff = $ event -> getDigestSignedOff ( ) ; } if ( $ event instanceof InsightCommissioned ) { $ this -> insightCommissioned = true ; $ this -> insightDueDate = $ event -> getInsightDueDate ( ) ; } if ( $ event instanceof NoInsightDecided ) { $ this -> insightCommissioned = false ; } if ( $ event instanceof InsightAuthorAsked ) { $ this -> insightAuthor = $ event -> getInsightAuthor ( ) ; } if ( $ event instanceof InsightAuthorRefused ) { $ this -> insightRefusalComment = $ event -> getinsightAuthorRefusalReason ( ) ; } if ( $ event instanceof InsightAcknowledged ) { $ this -> insightAcknowledged = true ; } if ( $ event instanceof InsightEditorAssigned ) { $ this -> editor = $ event -> getInsightEditorAssigned ( ) ; } if ( $ event instanceof InsightToAuthorSent ) { $ this -> insightAuthorChecking = true ; $ this -> insightEditsDueDate = $ event -> getInsightEditsDueDate ( ) ; } if ( $ event instanceof InsightSignedOff ) { $ this -> insightSignedOff = true ; } $ this -> _version = $ event -> getSequence ( ) ; }
Set the appropriate fields in response to an event.
Set the appropriate fields in response to an event .