Esempio n. 1
0
 /**
  * Will import an attendee from a VObject to a given event. If the attendee
  * already exists it will update it.
  * 
  * @param Event $event
  * @param Sabre\VObject\Property $vattendee
  * @param boolean $isOrganizer
  * @return Participant 
  */
 public function importVObjectAttendee(Event $event, Sabre\VObject\Property $vattendee, $isOrganizer = false)
 {
     $attributes = $this->_vobjectAttendeeToParticipantAttributes($vattendee);
     $attributes['is_organizer'] = $isOrganizer;
     if ($isOrganizer) {
         $attributes['status'] = Participant::STATUS_ACCEPTED;
     }
     $p = Participant::model()->findSingleByAttributes(array('event_id' => $event->id, 'email' => $attributes['email']));
     if (!$p) {
         $p = new Participant();
         $p->is_organizer = $isOrganizer;
         $p->event_id = $event->id;
         if (\GO::modules()->email) {
             $account = \GO\Email\Model\Account::model()->findByEmail($attributes['email']);
             if ($account) {
                 $p->user_id = $account->user_id;
             }
         }
         if (!$p->user_id) {
             $user = \GO\Base\Model\User::model()->findSingleByAttribute('email', $attributes['email']);
             if ($user) {
                 $p->user_id = $user->id;
             }
         }
     } else {
         //the organizer might be added as a participant too. We don't want to
         //import that a second time but we shouldn't update the is_organizer flag if
         //we found an existing participant.
         unset($attributes['is_organizer']);
     }
     $p->setAttributes($attributes);
     $p->save();
     return $p;
 }