private function mapToEntity($data) { $entity = new Weather(); $entity->setLocation($data->channel->location->city); $entity->setTemperature($data->channel->item->condition->temp); $entity->setConditions($data->channel->item->condition->text); return $entity; }
/** * Queries database for last existing weather entry and returns console output message * @param $location * @return array */ public function findCurrentWeather($location) { // just the output for console $output_array = array(); // get the full location name from Yahoo API $fullLocation = $this->yahooClient->getLocation($location); // get the last weather for this location from database if (!isset($this->currentWeather)) { $output_array[] = "Quering database for weather entries for: " . $fullLocation; $lastWeather = $this->entityManager->getRepository('AppBundle:Weather')->findOneBy(array('location' => $fullLocation), array('id' => 'DESC')); if (isset($lastWeather)) { $this->setCurrentWeather($lastWeather); $output_array[] = sprintf("Last weather entry in database for %s:", $fullLocation); $output_array[] = sprintf("Conditions in %s are %s", $this->currentWeather->getLocation(), $this->currentWeather->getConditions()); $output_array[] = sprintf("Temperature in %s is %s", $this->currentWeather->getLocation(), $this->currentWeather->getTemperature()); } else { $output_array[] = "Not found any weather entries in database for: " . $fullLocation; } } return $output_array; }