protected function getMostRecent()
 {
     return InstagramPost::get()->sort("Posted DESC")->First();
 }
 public function updatePosts($objectID = '')
 {
     $is = new InstagramService($this);
     $minID = $this->MinID;
     $update = false;
     switch ($this->Type) {
         case "tag":
             if (empty($objectID)) {
                 $objectID = $this->HashTag;
             }
             $update = $is->tagsRecent($objectID, null, $minID);
             if ($update) {
                 $this->MinID = $update->pagination->min_tag_id;
             }
             break;
         case "user":
             if (empty($objectID)) {
                 $objectID = 'self';
             }
             $update = $is->getUserRecent($objectID, null, null, null, $minID);
             if ($update) {
                 $this->MinID = $update->data[0]->created_time;
             }
             break;
     }
     $callbackFunc = (string) Config::inst()->get('Instagram', 'postReceivedCallback');
     if ($update) {
         $this->write();
         foreach ($update->data as $img) {
             if (isset($img->id)) {
                 $p = InstagramPost::get()->Filter(array('PostID' => $img->id));
                 if ($p->Count() == 0) {
                     $p = new InstagramPost();
                 } else {
                     $p = $p->first();
                 }
                 if (!empty($img->tags)) {
                     $p->setTags($img->tags);
                 }
                 $p->Caption = $img->caption->text;
                 $p->Link = $img->link;
                 $p->Posted = $img->created_time;
                 $p->ImageURL = $img->images->standard_resolution->url;
                 $p->PostID = $img->id;
                 $p->Processed = false;
                 $p->OrigMessage = json_encode($img);
                 $p->Type = "Instagram";
                 $p->CommentCount = $img->comments->count;
                 $p->LikeCount = $img->likes->count;
                 $p->SubscriptionID = $this->ID;
                 $p->write();
                 if (!empty($callbackFunc)) {
                     $p->{$callbackFunc}();
                 }
             }
         }
         return true;
     } else {
         return false;
     }
 }