/** * @param Department $department * * @return $this */ public function addDepartment($department) { $em = $this->entityManager; /** @var HotelRepository $hotelRepo */ $hotelRepo = $em->getRepository('SehBundle:Hotel'); $cities = $department->getCities(); $cityIds = array(); $brands = array(); foreach (array_keys($this->context->getValues('brand')) as $brand) { $brands[$brand] = (int) 0; } /** @var City $city */ foreach ($cities as $city) { $cityIds[] = $city->getId(); } unset($brands['seh']); $nbForDepartment = $hotelRepo->findNbForDepartment($department); foreach ($nbForDepartment as $nbPerBrand) { $brands[strtolower($nbPerBrand['artsysID'])] = (int) $nbPerBrand['nbHotels']; } $data = array('id' => $department->getId(), 'brands' => $brands, 'citiesIds' => $cityIds); $document = $this->departmentType->createDocument($department->getId()); $document->setData($data); $this->departmentType->addDocument($document); $this->updateDepartment($department); return $this; }