Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function preFlush(Room $room, PreFlushEventArgs $args)
- {
- $em = $args->getEntityManager();
- $parent = $room->getStore()->getParent();
- $rsm = new ResultSetMapping();
- $rsm->addScalarResult('COUNT(product_id)', 'count');
- $query = $em->createNativeQuery(
- 'select COUNT(product_id)
- from room_product where `room_id` in
- (select id from room where store_id in
- (select id from store where parent_id = :parentId))', $rsm);
- $query->setParameter('parentId', $parent->getId());
- $result = $query->getOneOrNullResult();
- $parent->setNumberOfServices($result['count']);
- $em->persist($parent);
- $em->flush();
- }
- public function preFlush(Room $room, PreFlushEventArgs $args)
- {
- $em = $args->getEntityManager();
- $numOfProducts = 0;
- $parent = $room->getStore()->getParent();
- foreach($parent->getStores() as $store) {
- foreach($store->getRooms() as $room) {
- $numOfServices += count($room->getProducts());
- }
- }
- $parent->setNumberOfProducts($numOfProducts);
- $classMetadata = $em->getClassMetadata(get_class($parent));
- $em->getUnitOfWork()->computeChangeSet($classMetadata, $parent);
- }
Add Comment
Please, Sign In to add comment