Example #1
0
 private function _attachPlaces()
 {
     if (!($this->status == self::SCRAPED || $this->status == self::NOADDRESS)) {
         throw new ArticleScrapeException(sprintf("Article expected status %s or %s, got %s", self::SCRAPED, self::NOADDRESS, $this->status));
     }
     //search for an address
     if (!preg_match_all("/(Via|Viale|Piazza) (.*),(\\ )?(\\w+).(\\ )?(\\w+).|(Via|Viale|Piazza) (.*),(\\ )?(\\w+).(\\ )?(\\w+).|(Via|Viale|Piazza) (.*)(\\w33n+),?\\ ?(\\w+)/i", $this->content, $addresses, PREG_SET_ORDER)) {
         $this->status = self::NOADDRESS;
         $this->save();
         return $this;
     }
     foreach ($addresses as $address) {
         $place = Place::getByAddress($address[0]);
         $this->places()->attach($place->id);
     }
     $this->status = self::PLACEATTACHED;
     $this->save();
     return $this;
 }