summaryrefslogtreecommitdiff
path: root/app/Libraries/AnimeSchedule.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Libraries/AnimeSchedule.php')
-rw-r--r--app/Libraries/AnimeSchedule.php56
1 files changed, 49 insertions, 7 deletions
diff --git a/app/Libraries/AnimeSchedule.php b/app/Libraries/AnimeSchedule.php
index 4c16f11..3b22494 100644
--- a/app/Libraries/AnimeSchedule.php
+++ b/app/Libraries/AnimeSchedule.php
@@ -16,19 +16,22 @@ class AnimeSchedule {
private $animeSchedule = array();
private $jikan;
- private $userProfile;
private $animeList;
private $animeInfo;
private const STATUS_WATCHING = 1;
- public function __construct( $username ) {
+ public function __construct( $username = "", $autoparse = true ) {
+
+ if ( $autoparse && "" != $username ) {
+ $this->parse( $username );
+ }
+ }
+
+ public function parse( $username ) {
$this->jikan = new MalClient;
- $this->userProfile = $this->jikan->getUserProfile(
- new \Jikan\Request\User\UserProfileRequest( $username )
- );
$this->animeList = $this->jikan->getUserAnimelist(
- new \Jikan\Request\User\UserAnimeListRequest( $this->userProfile->getUsername(), 1 )
+ new \Jikan\Request\User\UserAnimeListRequest( $username, 1, 1 )
);
foreach ( $this->animeList as $entry ) {
@@ -50,6 +53,8 @@ class AnimeSchedule {
$anime = new AnimeWatching( $entry->getMalID(), false );
+ $anime->url = $entry->getUrl();
+
$anime->title_eng = $data->title->english;
$anime->title_rom = $data->title->romaji;
$anime->title_nat = $data->title->native;
@@ -89,7 +94,7 @@ class AnimeSchedule {
->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 .")" );
+ ->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);
}
@@ -135,4 +140,41 @@ class AnimeSchedule {
$data = json_decode( $response->getBody() )->data->Media;
return $data;
}
+
+ protected function getIsWatching( $username ) {
+ $animeList = $this->getUserAnimeList( $username );
+
+ $anime = array();
+
+ foreach ( $animeList as $entry ) {
+ // currently watching
+ if ( $this::STATUS_WATCHING != $entry->getAiringStatus() ){
+ continue;
+ }
+
+ $anime[] = array(
+ "mal_id" => $entry->getMalID(),
+ "episodes_watched" => $entry->getWatchedEpisodes(),
+ "score_user" => $entry->getScore(),
+ );
+ }
+
+ return $anime;
+ }
+
+
+ protected function getUserAnimeList( $username ) {
+ $jikan = new MalClient;
+
+ $animeList = $jikan->getUserAnimelist(
+ new \Jikan\Request\User\UserAnimeListRequest( $username, 1, 1 )
+ );
+
+ return $animeList;
+ }
+
+ public function test() {
+ echo "<pre>";
+ var_dump( $this->getIsWatching('ll-') );
+ }
}