/** * @param Activity $activity * * @return bool */ public function isRemovable(Activity $activity) { //Deletion should only be possible if the activity is not closed if ($activity->getStatus() == 'closed') { return false; } /** @var Activity $activity */ $activity = $this->em->getRepository('CampaignChainCoreBundle:Activity')->createQueryBuilder('a')->select('a, f, o, sr, cta')->leftJoin('a.facts', 'f')->leftJoin('a.operations', 'o')->leftJoin('o.scheduledReports', 'sr')->leftJoin('o.outboundCTAs', 'cta')->where('a.id = :id')->setParameter('id', $activity)->getQuery()->getOneOrNullResult(); if (!$activity->getFacts()->isEmpty()) { return false; } /** @var Operation[] $operations */ $operations = new ArrayCollection(); foreach ($activity->getOperations() as $op) { $operations->add($op); } //Check if there are scheduled reports or cta data for the operation foreach ($operations as $op) { if (!$op->getScheduledReports()->isEmpty() or !$op->getOutboundCTAs()->isEmpty()) { return false; } } $schedulerReportsActivities = $this->em->getRepository('CampaignChainCoreBundle:SchedulerReportActivity')->findBy(['endActivity' => $activity]); $ctaActivities = $this->em->getRepository('CampaignChainCoreBundle:ReportCTA')->findBy(['activity' => $activity]); if (!empty($schedulerReportsActivities) or !empty($ctaActivities)) { return false; } return true; }