/** * 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"; } } } } }
public function canDoRecycling() { return CalendarEvent::where('user_id', $this->id)->whereRaw('WEEKOFYEAR(starts_at) = WEEKOFYEAR(NOW())')->whereRaw('2 BETWEEN WEEKDAY(starts_at) and WEEKDAY(ends_at)')->whereRaw('HOUR(starts_at) < 10')->count() == 0; // is starting at more than the time requred to do the recycling }
/** * Run the database seeds. * * @return void */ public function run() { foreach ($this->events as $event) { CalendarEvent::create(array('title' => $event['title'], 'description' => $event['description'], 'location' => $event['location'], 'start' => (new DateTime($event['start'], new DateTimeZone('America/Los_Angeles')))->setTimezone(new DateTimeZone('UTC'))->format('Y-m-d H:i:s'), 'end' => (new DateTime($event['end'], new DateTimeZone('America/Los_Angeles')))->setTimezone(new DateTimeZone('UTC'))->format('Y-m-d H:i:s'))); } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { return CalendarEvent::destroy($id); }