/** * @param ZoneInterface $zone * @param ProvinceInterface $province * * @return boolean Province is contained in zone */ public function isProvinceContainedInZone(ZoneInterface $zone, ProvinceInterface $province) { return $zone->getMembers()->filter(function (ZoneMemberInterface $zoneMember) { return $zoneMember instanceof ZoneProvinceMemberInterface; })->exists(function ($_, ZoneProvinceMemberInterface $zoneProvinceMember) use($province) { return $province->equals($zoneProvinceMember->getProvince()); }); }
/** * Get siblings * * @return Collection siblings */ public function getSiblings() { return $this->province->getCities(); }
/** * Return if a province is equal than current * * @param ProvinceInterface $province Province to be compared with * * @return boolean Provinces are the same */ public function equals(ProvinceInterface $province) { return $province->getId() === $this->getId(); }
/** * Add a city with the premise that the province has to be added already * * @param ProvinceInterface $province Province * @param string $cityName City name * * @return CityInterface */ public function addCity(ProvinceInterface $province, $cityName) { $cityName = trim($cityName); $cityId = $province->getId() . '_' . preg_replace('/[^\\da-z]/i', '', strtolower($cityName)); if (!isset($this->cities[$cityId])) { $city = $this->cityFactory->create(); $city->setId($cityId)->setName($cityName)->setProvince($province)->setPostalCodes(new ArrayCollection())->setEnabled(true); $province->addCity($city); $this->cities[$cityId] = $city; } return $this->cities[$cityId]; }