Esempio n. 1
0
 public static function fromPostData($data)
 {
     CL_Loader::get_instance()->library('PostDataFormatException');
     $poi = new POI();
     $poi->id = (int) $data['id'];
     $poi->name = (string) $data['name'];
     $poi->label = (string) $data['label'];
     $poi->url = (string) $data['url'];
     $poi->lat = (double) $data['lat'];
     $poi->lng = (double) $data['lng'];
     // Description
     if (key_exists("description", $data)) {
         $poi->description = (string) $data['description'];
     }
     // Approach
     if (isset($data['approach'])) {
         if (!isset($data['approach']['text']) || !isset($data['approach']['drying']['value']) || !isset($data['approach']['drying']['details'])) {
             throw new PostDataFormatException("Approach");
         }
         $poi->approach['text'] = (string) $data['approach']['text'];
         $poi->approach['drying']['value'] = (string) $data['approach']['drying']['value'];
         $poi->approach['drying']['details'] = (string) $data['approach']['drying']['details'];
     }
     // Contact
     if (isset($data['contact']['type']) && isset($data['contact']['value'])) {
         // Make sure all attributes have the same length
         if (count($data['contact']['type']) === count($data['contact']['value'])) {
             for ($i = 0; $i < count($data['contact']['type']); $i++) {
                 $poi->contact[] = ['type' => (string) $data['contact']['type'][$i], 'value' => (string) $data['contact']['value'][$i]];
             }
         }
     }
     // Anchoring
     if (key_exists("anchoring", $data)) {
         // Depth
         $poi->anchoring['depth']['from'] = (double) $data['anchoring']['depth']['from'];
         $poi->anchoring['depth']['to'] = (double) $data['anchoring']['depth']['to'];
         // Holding
         $poi->anchoring['holding']['values'] = [];
         foreach ((array) @$data['anchoring']['holding']['values'] as $value) {
             $poi->anchoring['holding']['values'][] = $value;
         }
         $poi->anchoring['holding']['details'] = (string) $data['anchoring']['holding']['details'];
         // Price
         $poi->anchoring['cost'] = Cost::fromPostData($data['anchoring']['cost']);
         // Soujourn
         $poi->anchoring['tax'] = Tax::fromPostData($data['anchoring']['tax']);
     }
     // Charts
     if (key_exists("charts", $data)) {
         foreach ($data['charts'] as $chart) {
             if ($chart !== "") {
                 $poi->charts[] = (string) $chart;
             }
         }
     }
     // Sources
     if (key_exists("sources", $data)) {
         foreach ($data['sources'] as $source) {
             if ($source !== "") {
                 $poi->sources[] = (string) $source;
             }
         }
     }
     // Exposure
     if (key_exists("exposure", $data)) {
         // Wind
         $poi->exposure['wind']['value'] = (string) $data['exposure']['wind']['value'];
         foreach ((array) @$data['exposure']['wind']['dir'] as $wind) {
             if ($wind !== "") {
                 $poi->exposure['wind']['dir'][] = (string) $wind;
             }
         }
         // Swell
         $poi->exposure['swell']['value'] = (string) $data['exposure']['swell']['value'];
         foreach ((array) @$data['exposure']['swell']['dir'] as $swell) {
             if ($swell !== "") {
                 $poi->exposure['swell']['dir'][] = (string) $swell;
             }
         }
     }
     // Attractions
     if (key_exists("attractions", $data)) {
         $poi->attractions = (string) $data['attractions'];
     }
     // Nightlife
     if (key_exists("nightlife", $data)) {
         $poi->nightlife = (string) $data['nightlife'];
     }
     return $poi;
 }