Esempio n. 1
0
 /**
  * 
  * @param Participant $participant
  * @return Event 
  */
 public function createCopyForParticipant(Participant $participant)
 {
     //		$calendar = Calendar::model()->getDefault($user);
     //
     //		return $this->duplicate(array(
     //			'user_id'=>$user->id,
     //			'calendar_id'=>$calendar->id,
     //			'is_organizer'=>false
     //		));
     \GO::debug("Creating event copy for " . $participant->name);
     //create event in participant's default calendar if the current user has the permission to do that
     $calendar = $participant->getDefaultCalendar();
     if ($calendar && $calendar->userHasCreatePermission()) {
         //find if an event for this exception already exists.
         $exceptionDate = $this->exception_for_event_id != 0 ? $this->start_time : false;
         $existing = Event::model()->findByUuid($this->uuid, 0, $calendar->id, $exceptionDate);
         if (!$existing) {
             //ignore acl permissions because we allow users to schedule events directly when they have access through
             //the special freebusypermissions module.
             $participantEvent = $this->duplicate(array('calendar_id' => $calendar->id, 'user_id' => $participant->user_id, 'is_organizer' => false), true, true);
             return $participantEvent;
         } else {
             \GO::debug("Found existing event: " . $existing->id . ' - ' . $existing->getAttribute('start_time', 'formatted'));
             //correct errors that somehow occurred.
             $attributes = $this->getAttributeSelection(array('name', 'start_time', 'end_time', 'rrule', 'repeat_end_time', 'location', 'description', 'private'), 'raw');
             $existing->setAttributes($attributes, false);
             if ($existing->isModified()) {
                 $existing->updatingRelatedEvent = true;
                 $existing->save(true);
             }
             return $existing;
         }
     }
     return false;
 }