function importEvent(\App\Module $module, \DateTime $starttijd, \DateTime $eindtijd, string $uid, string $ruimte, array $groepcodes) { $starttijd->setTimezone(new \DateTimeZone(ini_get('date.timezone'))); $eindtijd->setTimezone(new \DateTimeZone(ini_get('date.timezone'))); $contactmoment = \App\Contactmoment::where('ical_uid', $uid)->first(); if ($contactmoment === null) { $contactmoment = \App\Contactmoment::firstOrNew(['starttijd' => $starttijd]); } $contactmoment->ical_uid = $uid; $contactmoment->starttijd = $starttijd; $contactmoment->eindtijd = $eindtijd; $contactmoment->ruimte = $ruimte; if ($contactmoment->les === null) { // try to find lesplan $lesplan = $module->lessen()->firstOrNew(['jaar' => $contactmoment->starttijd->format('Y'), 'kalenderweek' => (int) $contactmoment->starttijd->format('W')]); if ($lesplan->naam === null) { $lesplan->naam = ""; } $lesplan->doelgroep()->associate(\App\Doelgroep::find(1)); $lesplan->save(); $contactmoment->les()->associate($lesplan); } foreach ($groepcodes as $groepcode) { $blokgroep = \App\Blokgroep::firstOrNew(['code' => $groepcode]); $blokgroep->collegejaar = '1516'; if (preg_match('/42IN(?<bloknummer>\\d+)SO\\w/', $groepcode, $matches) !== 1) { continue; } $blokgroep->nummer = (int) $matches['bloknummer']; $blokgroep->save(); } $contactmoment->save(); }