/** * @dataProvider dataProviderForTestIsLocationOpen2 */ public function testIsLocationOpen_working_hours_empty($expected, $date) { $location = new Paysera_WalletApi_Entity_Location(); //working days not defined at all: $location->setWorkingHours(array()); //any day, any time: $this->assertEquals($expected, $this->service->isLocationOpen($location, $date)); }
/** * @param Paysera_WalletApi_Entity_Location $location * @param DateTime $date * @return bool */ public function isLocationOpen(Paysera_WalletApi_Entity_Location $location, DateTime $date = null) { if (!$location->getWorkingHours()) { return true; } if ($date === null) { $date = new DateTime(); } $dateYesterday = clone $date; $dateYesterday->sub(new DateInterval('P1D')); $dayOfWeek = strtolower(date('l', $date->getTimestamp())); $dayOfWeekYesterday = strtolower(date('l', $dateYesterday->getTimestamp())); foreach ($location->getWorkingHours() as $workingHours) { if ($workingHours->getDay() === $dayOfWeek && $this->isWorkingHoursActiveByDate($workingHours, $date, $date)) { return true; } if ($workingHours->getDay() === $dayOfWeekYesterday && $this->isWorkingHoursActiveByDate($workingHours, $dateYesterday, $date)) { return true; } } return false; }
/** * Updates location * * @param Paysera_WalletApi_Entity_Location $location * * @return Paysera_WalletApi_Entity_Location * @throws Paysera_WalletApi_Exception_LogicException */ public function updateLocation(Paysera_WalletApi_Entity_Location $location) { if ($location->getId() === null) { throw new Paysera_WalletApi_Exception_LogicException("Location id has been not provided"); } $responseData = $this->put('location/' . $location->getId(), $this->mapper->encodeLocation($location)); return $this->mapper->decodeLocation($responseData); }
/** * Decodes location * * @param array $data * * @return Paysera_WalletApi_Entity_Location */ public function decodeLocation(array $data) { $location = new Paysera_WalletApi_Entity_Location(); $location->setId($data['id']); $location->setTitle($data['title']); if (!empty($data['description'])) { $location->setDescription($data['description']); } $location->setAddress($data['address']); $location->setRadius($data['radius']); if (!empty($data['lat'])) { $location->setLat((double) $data['lat']); } if (!empty($data['lng'])) { $location->setLng((double) $data['lng']); } if (!empty($data['prices'])) { $result = array(); foreach ($data['prices'] as $price) { $result[] = $this->decodeLocationPrice($price); } $location->setPrices($result); } if (!empty($data['working_hours'])) { foreach ($data['working_hours'] as $day => $dayWorkingHour) { $location->addWorkingHours($this->decodeDayWorkingHours($day, $dayWorkingHour)); } } if (!empty($data['images']['pin_open'])) { $location->setImagePinOpen($data['images']['pin_open']); } if (!empty($data['images']['pin_closed'])) { $location->setImagePinClosed($data['images']['pin_closed']); } if (!empty($data['services'])) { $services = array(); foreach ($data['services'] as $key => $val) { if (!empty($val['available']) && $val['available'] === true) { $services[] = $key; } } $location->setServices($services); if (!empty($data['services']['pay']['categories'])) { $location->setPayCategories($data['services']['pay']['categories']); } } if (!empty($data['status'])) { $location->setStatus($data['status']); } if (isset($data['public'])) { $location->setPublic((bool) $data['public']); } return $location; }