Ejemplo n.º 1
0
 public function loadFromMeetup($meetup_response = NULL)
 {
     global $meetup_group_id, $meetup_group_urlname, $meetup_api_key;
     $client = DMS\Service\Meetup\MeetupKeyAuthClient::factory(array('key' => $meetup_api_key));
     if (!$meetup_response) {
         $response = $client->getMember(array('id' => $this->meetup_id));
     } else {
         $response = $meetup_response;
     }
     $this->name = $response["name"];
     $this->meetup_id = $response["id"];
     $this->location = $response["city"] . ", " . $response["country"];
     $this->meetup_url = $response["link"];
     $this->lat = $response["lat"];
     $this->lon = $response["lon"];
     $this->name = $response["name"];
     if (isset($response["photo"])) {
         if (isset($response["photo"]["highres_link"])) {
             $this->photo_url = $response["photo"]["highres_link"];
         } elseif (isset($response["photo"]["photo_link"])) {
             $this->photo_url = $response["photo"]["photo_link"];
         } elseif (isset($response["photo"]["thumb_link"])) {
             $this->photo_url = $response["photo"]["thumb_link"];
         }
     } elseif (isset($response["photo_url"])) {
         $this->photo_url = $response["photo_url"];
     } else {
         $email = strtolower($this->meetup_id . "@gmail.com");
         $this->photo_url = "http://www.gravatar.com/avatar/" . md5($email);
     }
     if (isset($response["other_services"]) && is_array($response["other_services"])) {
         foreach ($response["other_services"] as $key => $service) {
             $s = $service["identifier"];
             switch ($key) {
                 case "twitter":
                     $this->twitter_url = $s;
                     break;
                 case "flickr":
                     $this->flickr_url = $s;
                     break;
                 case "facebook":
                     $this->facebook_url = $s;
                     break;
                 case "linkedin":
                     $this->linkedin_url = $s;
                     break;
             }
         }
     }
     $service = new Skill();
     if (isset($response["topics"]) && is_array($response["topics"])) {
         foreach ($response["topics"] as $topic) {
             $s = $service->find(array("meetup_skill_id" => $topic["id"]));
             if ($s) {
                 $this->skills[$s["id"]] = $s;
             } else {
                 $this->skills["new_" . $topic["id"]] = array("meetup_skill_id" => $topic["id"], "is_gis" => 0, "synonyms" => NULL, "name" => $topic["name"], "slug" => $topic["urlkey"]);
             }
         }
     }
     $options = array('group_urlname' => $meetup_group_urlname, 'group_id' => $meetup_group_id, 'member_id' => $this->meetup_id);
     $profiles = $client->getProfiles($options);
     if ($profiles->count() > 0) {
         // Find relevant skills in open answers and add them to the profile
         foreach ($profiles as $p) {
             $answers = "";
             foreach ($p["answers"] as $a) {
                 if (isset($a["answer"])) {
                     $answers .= $a["answer"] . " ";
                 }
             }
             $answers = strtolower($answers);
             $r = $service->extractRelevantSkills($answers);
             $this->merge_skills($r);
             //When user joined
             $this->joined = $this->parseEpoch($p["created"]);
             $this->last_visit = $this->parseEpoch($p["visited"]);
             if (isset($p["bio"])) {
                 $this->bio = $p["bio"];
             }
             if (isset($p["photo"])) {
                 if (isset($p["photo"]["highres_link"])) {
                     $this->photo_url = $p["photo"]["highres_link"];
                 } elseif (isset($p["photo"]["photo_link"])) {
                     $this->photo_url = $p["photo"]["photo_link"];
                 } elseif (isset($p["photo"]["thumb_link"])) {
                     $this->photo_url = $p["photo"]["thumb_link"];
                 }
             } elseif (isset($p["photo_url"])) {
                 $this->photo_url = $p["photo_url"];
             }
             if (isset($p["profile_url"])) {
                 $this->meetup_url = $p["profile_url"];
             }
             //TODO: check if other services
         }
     }
 }