/**
  * Load events from churchtools api based on calendar settings
  * Deletes all events in databse, so temporary changes will get lost
  *
  * @param /DataContainer $dc
  */
 public static function loadAndParseEvents($dc)
 {
     $calendar = \CalendarModel::findByPk($dc->id);
     $arrCategoryIds = deserialize($calendar->churchtoolsCalendars);
     $api = new ChurchtoolsApi();
     $events = $api->loadEvents($arrCategoryIds, $calendar->churchtoolsDaysFrom, $calendar->churchtoolsDaysTo);
     //Clear Database
     $collection = \CalendarEventsModel::findByPid($dc->id);
     if (isset($collection)) {
         while ($collection->next()) {
             $collection->delete();
         }
     }
     foreach ($events as $event) {
         $startdate = new \DateTime($event->startdate);
         $enddate = new \DateTime($event->enddate);
         $fullDayEvent = $startdate->format('His') == 00 && $enddate->format('His') == 00 ? true : false;
         $model = new \CalendarEventsModel();
         $model->pid = $dc->id;
         $model->tstamp = time();
         $model->title = $event->bezeichnung;
         //$model->alias =
         //$model->author =
         if (!$fullDayEvent) {
             $model->addTime = 1;
             $model->startTime = $startdate->getTimestamp();
             $model->endTime = $enddate->getTimestamp();
         } else {
             $model->startTime = $startdate->getTimestamp();
             $model->endTime = $enddate->getTimestamp();
         }
         $model->startDate = $startdate->getTimestamp();
         if ($startdate != $enddate) {
             $model->endDate = $enddate->getTimestamp();
         }
         //$model->location =
         //$model->teaser =
         $model->published = 1;
         $model->save();
     }
     if (\Input::get('key')) {
         \Controller::redirect(preg_replace('/(&(amp;)?|\\?)key=[^& ]*/i', '', \Environment::get('request')));
     }
 }