summaryrefslogtreecommitdiff
path: root/app/MALUser.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/MALUser.php')
-rw-r--r--app/MALUser.php90
1 files changed, 90 insertions, 0 deletions
diff --git a/app/MALUser.php b/app/MALUser.php
new file mode 100644
index 0000000..6c62e30
--- /dev/null
+++ b/app/MALUser.php
@@ -0,0 +1,90 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+use Jikan\MyAnimeList\MalClient;
+
+class MALUser extends Model
+{
+ protected $table = 'malusers';
+ protected $fillable = 'username';
+
+ public function __construct() {
+ }
+
+ public function set( $username ) {
+ $this->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 "<pre>";
+ var_dump( $this->getIsWatching() );
+ }
+}