username = $username; } public function get() { return $this->username; } public function IsWatching() { return $this->belongsToMany('App\Anime', 'is_watching', 'user_id', 'mal_id', '', 'mal_id') ->as('Watching') ->withPivot('episodes_watched', 'score_user') ->withTimestamps(); } public function calendar() { return $this->belongsTo('App\Calendar', 'id', 'user_id'); } public function getIsWatching() { $jikan = new MalClient; $animeList = $jikan->getUserAnimelist( new \Jikan\Request\User\UserAnimeListRequest( $this->username, 1, 1 ) ); $anime = array(); foreach ( $animeList as $entry ) { // currently watching if ( 1 != $entry->getAiringStatus() ){ continue; } $anime[] = array( "user_id" => $this->id, "mal_id" => $entry->getMalID(), "episodes_watched" => $entry->getWatchedEpisodes(), "score_user" => $entry->getScore(), ); } return $anime; } public function createCalendar() { } public function getCalendar() { $vCalendar = new Calendar('animes.iamfabulous.de'); $vCalendar->setName('Anime Schedule'); foreach ( $this->animeSchedule as $anime ) { $vEvent = new Event(); $vEvent ->setDtStart(new \DateTime($anime->airing_at)) ->setDtEnd( new \DateTime($anime->airing_at->add($anime->duration, 'minutes')) ) ->setNoTime(false) ->setSummary( $anime->title_pref . " (" . $anime->episode . "/" . $anime->episodes_complete . ")" ) ->setUrl( env("APP_URL") ) ->setDescription( "(Episode " . $anime->episode . "/" . $anime->episodes_complete . ") You have watched " . $anime->episodes_watched . " episodes of " . $anime->title_pref . " and scored it with " . $anime->score_user . ". (Public score: ". $anime->score .")\n\n" . $anime->url ); $vCalendar->addComponent($vEvent); } return $vCalendar->render(); } public function test() { echo "
"; var_dump( $this->getIsWatching() ); } }