public function select($hash = null) { $statement = 'SELECT * FROM `cfp`'; $values = []; if ($hash !== null) { $statement .= ' WHERE `hash`= :hash'; $values['hash'] = $hash; } $statement = $this->pdo->prepare($statement); $list = new \Callingallpapers\Api\Entity\CfpList(); $statement->execute($values); $content = $statement->fetchAll(); if (count($content) < 1) { throw new \UnexpectedValueException('No CFPs found', 404); } foreach ($content as $item) { $cfp = new \Callingallpapers\Api\Entity\Cfp(); $cfp->setName($item['name']); $cfp->setDateCfpEnd(new \DateTimeImmutable($item['dateCfpEnd'])); $cfp->setDateCfpStart(new \DateTimeImmutable($item['dateCfpStart'])); $cfp->setUri($item['uri']); $cfp->setTimezone(new \DateTimeZone($item['timezone'])); $cfp->setDateEventStart(new \DateTimeImmutable($item['dateEventStart'])); $cfp->setDateEventEnd(new \DateTimeImmutable($item['dateEventEnd'])); $cfp->setDescription($item['description']); $cfp->setEventUri($item['eventUri']); $cfp->setIconUri($item['iconUri']); $cfp->setLatitude($item['latitude']); $cfp->setLongitude($item['longitude']); $cfp->setLocation($item['location']); $cfp->setTags(explode(',', $item['tags'])); $cfp->setLastUpdated(new \DateTimeImmutable($item['lastUpdate'])); $list->add($cfp); } return $list; }
public static function setGeolocation(Cfp $cfp, array $array) { if (!isset($array['latitude'])) { return; } if (!isset($array['longitude'])) { return; } $latitude = filter_var($array['latitude'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); $longitude = filter_var($array['longitude'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); if ($latitude > 90 || $latitude < -90) { throw new \UnexpectedValueException(sprintf('latitude has to be within a range of -90.0 to 90.0 bus is %1$f', $latitude), 400); } if ($longitude > 180 || $longitude < -180) { throw new \UnexpectedValueException(sprintf('longitude has to be within a range of -180.0 to 180.0 but is %1$f', $longitude), 400); } // TODO: Rewrite lat and long to be in the correct range $cfp->setLatitude($latitude); $cfp->setLongitude($longitude); }