public function isPublicationValid(ExecutionContextInterface $context)
    {
        // No start publication date specified for the end publication date
        if (!$this->getStartedAt() && $this->getEndedAt()) {
            $context->addViolationAt('startedAt', 'Start publication date is required when setting end publication date.');
        }
        // Start publication date is equal or later than end publication date
        if ($this->getEndedAt() && $this->getStartedAt() && $this->getStartedAt()->getTimestamp() >= $this->getEndedAt()->getTimestamp()) {
            $context->addViolationAt('endedAt', 'End publication date must be later than start publication date.');
        }
    }
public function isPublicationValid(ExecutionContextInterface $context)
    {
        // No start publication date specified for the end publication date
        if (!$this->getStartedAt() && $this->getEndedAt()) {
            $context->addViolationAt('startedAt', 'Start publication date is required when setting end publication date.');
        }
        // Start publication date is equal or later than end publication date
        if ($this->getEndedAt() && $this->getStartedAt() && $this->getStartedAt()->getTimestamp() >= $this->getEndedAt()->getTimestamp()) {
            $context->addViolationAt('endedAt', 'End publication date must be later than start publication date.');
        }
    }
public function isPublicationValid ( ExecutionContextInterface $ context ) { // No start publication date specified for the end publication date if ( ! $ this -> getStartedAt ( ) && $ this -> getEndedAt ( ) ) { $ context -> addViolationAt ( 'startedAt' , 'Start publication date is required when setting end publication date.' ) ; } // Start publication date is equal or later than end publication date if ( $ this -> getEndedAt ( ) && $ this -> getStartedAt ( ) && $ this -> getStartedAt ( ) -> getTimestamp ( ) >= $ this -> getEndedAt ( ) -> getTimestamp ( ) ) { $ context -> addViolationAt ( 'endedAt' , 'End publication date must be later than start publication date.' ) ; } }
Check if publication is correct

@author Vincent CHALAMON <vincentchalamon@gmail.com>

@param ExecutionContextInterface $context

@Assert\Callback
Check if publication is correct