Beispiel #1
0
 /**
  * After the event is updated in the database make sure the owned entities have the same access_id
  *
  * @param string      $event  the name of the event
  * @param string      $type   the type of the event
  * @param \ElggObject $entity the affected object
  *
  * @return void
  */
 public static function updateEvent($event, $type, $entity)
 {
     if (!$entity instanceof \Event) {
         return;
     }
     $org_attributes = $entity->getOriginalAttributes();
     if (elgg_extract('access_id', $org_attributes) === null) {
         // access wasn't updated
         return;
     }
     // ignore access for this part
     $ia = elgg_set_ignore_access(true);
     $days = $entity->getEventDays();
     if (!empty($days)) {
         foreach ($days as $day) {
             $day->access_id = $entity->access_id;
             $day->save();
             $slots = $day->getEventSlots();
             if (empty($slots)) {
                 continue;
             }
             foreach ($slots as $slot) {
                 $slot->access_id = $entity->access_id;
                 $slot->save();
             }
         }
     }
     $questions = $entity->getRegistrationFormQuestions();
     if (!empty($questions)) {
         foreach ($questions as $question) {
             $question->access_id = $entity->access_id;
             $question->save();
         }
     }
     // restore access
     elgg_set_ignore_access($ia);
 }
Beispiel #2
0
/**
 * Export the event attendees. Returns csv body
 * 
 * @param ElggObject $event the event
 * @param string     $rel   relationship type
 * 
 * @return string
 */
function event_manager_export_attendees($event, $rel = EVENT_MANAGER_RELATION_ATTENDING)
{
    $old_ia = elgg_set_ignore_access(true);
    $headerString = "";
    $dataString = "";
    $headerString .= '"' . elgg_echo('guid') . '";"' . elgg_echo('name') . '";"' . elgg_echo('email') . '";"' . elgg_echo('username') . '";"' . elgg_echo('registration date') . '"';
    if ($event->registration_needed) {
        if ($registration_form = $event->getRegistrationFormQuestions()) {
            foreach ($registration_form as $question) {
                $headerString .= ';"' . $question->title . '"';
            }
        }
    }
    if ($event->with_program) {
        if ($eventDays = $event->getEventDays()) {
            foreach ($eventDays as $eventDay) {
                $date = date(EVENT_MANAGER_FORMAT_DATE_EVENTDAY, $eventDay->date);
                if ($eventSlots = $eventDay->getEventSlots()) {
                    foreach ($eventSlots as $eventSlot) {
                        $start_time = $eventSlot->start_time;
                        $end_time = $eventSlot->end_time;
                        $start_time_hour = date('H', $start_time);
                        $start_time_minutes = date('i', $start_time);
                        $end_time_hour = date('H', $end_time);
                        $end_time_minutes = date('i', $end_time);
                        $headerString .= ';"Event activity: \'' . addslashes($eventSlot->title) . '\' ' . $date . ' (' . $start_time_hour . ':' . $start_time_minutes . ' - ' . $end_time_hour . ':' . $end_time_minutes . ')"';
                    }
                }
            }
        }
    }
    $attendees = $event->exportAttendees($rel);
    if ($attendees) {
        foreach ($attendees as $attendee) {
            $answerString = '';
            $dataString .= '"' . $attendee->guid . '";"' . $attendee->name . '";"' . $attendee->email . '";"' . $attendee->username . '"';
            $relation = check_entity_relationship($event->guid, $rel, $attendee->guid);
            $dataString .= ';"' . date("d-m-Y H:i:s", $relation->time_created) . '"';
            if ($event->registration_needed) {
                if ($registration_form = $event->getRegistrationFormQuestions()) {
                    foreach ($registration_form as $question) {
                        $answer = $question->getAnswerFromUser($attendee->getGUID());
                        $answerString .= '"' . addslashes($answer->value) . '";';
                    }
                }
                $dataString .= ';' . substr($answerString, 0, strlen($answerString) - 1);
            }
            if ($event->with_program) {
                if ($eventDays = $event->getEventDays()) {
                    foreach ($eventDays as $eventDay) {
                        if ($eventSlots = $eventDay->getEventSlots()) {
                            foreach ($eventSlots as $eventSlot) {
                                if (check_entity_relationship($attendee->getGUID(), EVENT_MANAGER_RELATION_SLOT_REGISTRATION, $eventSlot->getGUID())) {
                                    $dataString .= ';"V"';
                                } else {
                                    $dataString .= ';""';
                                }
                            }
                        }
                    }
                }
            }
            $dataString .= PHP_EOL;
        }
    }
    elgg_set_ignore_access($old_ia);
    return $headerString . PHP_EOL . $dataString;
}