summaryrefslogtreecommitdiff
path: root/app/Libraries/Helper.php
diff options
context:
space:
mode:
authorhorus2020-03-05 16:02:10 +0100
committerhorus2020-03-05 16:02:10 +0100
commit5dda561d73c9a5698386d643d56a142aa4bbdeec (patch)
tree55afe2db98d0fa15fc845cc3da3afe6b517bbd3d /app/Libraries/Helper.php
parent420e44e0fe4623a439e26dfd0526ee5ef606a170 (diff)
downloadsenpai-5dda561d73c9a5698386d643d56a142aa4bbdeec.tar.gz
Committing intermediate state.
Diffstat (limited to 'app/Libraries/Helper.php')
-rw-r--r--app/Libraries/Helper.php89
1 files changed, 89 insertions, 0 deletions
diff --git a/app/Libraries/Helper.php b/app/Libraries/Helper.php
new file mode 100644
index 0000000..0652570
--- /dev/null
+++ b/app/Libraries/Helper.php
@@ -0,0 +1,89 @@
+<?php
+namespace App\Libraries;
+
+use Carbon\Carbon;
+
+use App\Libraries\AnimeSchedule;
+use App\Libraries\AnimeSeason;
+use App\Anime;
+use App\AnimeStats;
+use App\MALUser;
+use App\Calendar;
+use App\Airing;
+
+use Eluceo\iCal\Component\Calendar as iCalendar;
+use Eluceo\iCal\Component\Event;
+
+class Helper {
+ public function getCalendar( $username ) {
+ echo "<pre>";
+ $user = MALUser::where('username', $username)->get()->first();
+
+ $vCalendar = new iCalendar('animes.iamfabulous.de');
+ $vCalendar->setName('Anime Schedule');
+
+ foreach( $user->calendar()->get() as $anime ) {
+
+ if ( is_null($anime->episodes_completes) ) {
+ $episodes_complete = '?';
+ } else {
+ $episodes_complete = $anime->episodes_completes;
+ }
+
+ $vEvent = new Event();
+
+ $vEvent
+ ->setDtStart(new \DateTime($anime->airing_at))
+ ->setDtEnd( new \DateTime(Carbon::create($anime->airing_at)->add($anime->duration, 'minutes')) )
+ ->setNoTime(false)
+ ->setSummary( $anime->title . " (" . $anime->episode . "/" . $episodes_complete . ")" )
+ ->setUrl( env("APP_URL") )
+ ->setDescription( "(Episode " . $anime->episode . "/" . $episodes_complete . ") You have watched " . $anime->episodes_watched . " episodes of " . $anime->title . " and scored it with " . $anime->score_user . ". (Public score: ". $anime->score .")\n\n" . $anime->url );
+
+ $vCalendar->addComponent($vEvent);
+ }
+
+ return $vCalendar->render();
+
+ }
+
+ public function setCalendar($username) {
+ #$this->setAiring(); return;
+ $user = MALUser::where('username', $username)->get()->first();
+ echo "<pre>";
+ foreach( $user->IsWatching as $anime ) {
+ $stats = $anime->getStats()->get()->first();
+ $airing = $anime->getAiring()->get()->first();
+
+ /**
+ * Check for duplicate entry.
+ */
+ $check = Calendar::where('mal_id', $anime->mal_id)->where('user_id', $user->id)->where(
+ function($q) use ($airing){
+ $q->where('episode', $airing->episode)->orWhere('airing_at', $airing->aired_at);
+ })->get()->first();
+
+ if ( ! is_null( $check ) ) {
+ echo "duplicate entry. ".$anime->mal_id." continue\n"; continue;
+ }
+
+ $calendar = new Calendar();
+ $calendar->mal_id = $anime->mal_id;
+ $calendar->user_id = $anime->Watching->user_id;
+ $calendar->username = $username;
+ $calendar->airing_at = $airing->aired_at;
+ $calendar->duration = $airing->duration;
+ $calendar->episode = $airing->episode;
+ $calendar->episodes_watched = $anime->Watching->episodes_watched;
+ $calendar->episodes_complete = $anime->episodes;
+ $calendar->score = $stats->score;
+ $calendar->score_user = $anime->Watching->score_user;
+ $calendar->title = $anime->title_pref;
+ $calendar->mal_url = $anime->url;
+
+ $calendar->save();
+ }
+ }
+
+
+}