public function onUpdateStatus(GenericEvent $event) { // Update recentlyApprovedListings $recentlyApprovedListingService = new RecentlyApprovedListingService(); $recentlyApprovedListingService->setEntityManager($this->em); $recentlyApprovedListingService->updateInstitutionMedicalCenterListing($event->getSubject()); // End of Update recentlyApprovedListing }
/** * @param InstitutionMedicalCenter $center */ function updateInstitutionMedicalCenterListing(InstitutionMedicalCenter $center) { $institution = $center->getInstitution(); $criteria = array('institution' => $institution->getId(), 'institutionMedicalCenter' => $center->getId()); $recentlyApprovedListing = $this->em->getRepository('AdminBundle:RecentlyApprovedListing')->findOneBy($criteria); if ($recentlyApprovedListing) { if ($center->getStatus() == InstitutionMedicalCenterStatus::APPROVED) { $recentlyApprovedListing->setDateUpdated(new \DateTime()); $this->em->persist($recentlyApprovedListing); } else { $this->em->remove($recentlyApprovedListing); } $this->em->flush(); } else { if ($center->getStatus() == InstitutionMedicalCenterStatus::APPROVED) { $recentlyApprovedListingService = new RecentlyApprovedListingService(); $recentlyApprovedListingService->setEntityManager($this->em); $recentlyApprovedListing = new RecentlyApprovedListing(); $recentlyApprovedListing->setInstitution($institution); $recentlyApprovedListing->setInstitutionMedicalCenter($center); $recentlyApprovedListing->setDateUpdated(new \DateTime()); $recentlyApprovedListing->setStatus(1); $this->em->persist($recentlyApprovedListing); $this->em->flush($recentlyApprovedListing); } } }