/** * Run the database seeds. * * @return void */ public function run() { $file = fopen('https://app.kinhr.com/app/api/dataexports/calendarsubscription/kinhr.ics?token=a14747c6-9455-4820-a886-b321160b1990', "r") or fopen("error.txt", "w", "error getting KIN information"); $iCal = Reader::read($file, 'r'); $calIds = CalendarEvent::pluck('uid'); $users = User::all(); foreach ($iCal->VEVENT as $event) { if ($calIds != null && !$calIds->contains($event->uid)) { foreach ($event->SUMMARY as $summary) { $type = "Other Event"; if (str_contains($summary, "Weeks Off")) { $type = "Weeks Off"; } else { if (str_contains($summary, "Personal Days")) { $type = "Personal Days"; } else { if (str_contains($summary, "Birthday")) { $type = "Birthday"; } else { if (str_contains($summary, "Anniversary")) { $type = "Anniversary"; } else { if (str_contains(strtolower($summary), 'conf')) { $type = "Conference"; } } } } } $summary = $this->stripAccents($summary); $userId = $users->filter(function ($user) use($summary) { return strpos($user->name, preg_filter("/\\.(.*?)\$/", "", $summary)) !== false; })->first(); try { CalendarEvent::create(['uid' => $event->UID, 'user_id' => $userId ? $userId->id : $userId, 'summary' => $event->SUMMARY, 'description' => $event->DESCRIPTION, 'starts_at' => Carbon::parse($event->DTSTART)->setTimezone('America/Montreal'), 'ends_at' => Carbon::parse($event->DTEND)->setTimezone('America/Montreal'), 'type' => $type]); } catch (Exception $e) { echo $summary . "\n"; } } } } }