summaryrefslogtreecommitdiff
path: root/app/Http/Controllers/IndexController.php
blob: c595b4eabdb24338c3b2d1e8bdb34d6a5da41b99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php

namespace App\Http\Controllers;
use Illuminate\Support\Facades\Cache;
use Illuminate\Http\Request;

use App\Libraries\AnimeSchedule;
use App\Libraries\AnimeSeason;
use App\Anime;
use App\AnimeStats;
use App\MALUser;
use App\Libraries\Helper;

use App\Jobs\AddNewCalUser;
use Imtigger\LaravelJobStatus\JobStatus;

class IndexController extends Controller {
	/**
        * Shows the index page.
        *
        * @return Response
        */
        public function showPage() {

		return view('index', [ ]);
	}

	#public function iCal(Request $request) {
	public function iCal($username) {
		
		if ( ! Cache::has('xschedule_' . $username)) {
			$helper = new Helper();
			$schedule = $helper->getCalendar($username);
			Cache::put('schedule_' . $username, $schedule, 360);
		} else {
			$schedule = Cache::get('schedule_' . $username);
		}

		header('Content-Type: text/calendar; charset=utf-8');
		#var_dump($schedule);
		echo $schedule;
	}

	public function test($param = null) {
		echo "<pre>";
		#$season = new AnimeSeason();
		#$stats = new AnimeScore( 21 );

		#var_dump($stats);
		#echo "<pre>";
		#var_dump($season);
		#
		#$test = new AnimeSchedule("", false);

		#var_dump( Anime::where('mal_id', 38408)->with('user')->get() );
		#var_dump( MALUser::where('username', 'll-')->with('anime')->toSql() );
		#var_dump( MALUser::find(10)->anime()->get() );
		$test = MALUser::where('username', 'll-')->get()->first();
		#$test = MALUser::where('username', 'll-')->with('IsWatching')->first();
		#var_dump($test);
		#var_dump( MALUser::where('username', 'll-')->with('IsWatching')->firstOrFail() );
		#var_dump( $test );
		#var_dump( MALUser::with('IsWatching')->firstOrFail() );
		echo "<pre>";
		foreach( $test->IsWatching as $anime ) {
			echo $anime->title_pref . "\n";
		}
		#var_dump($test->IsWatching);

	}

	public function saveWatchingAnime() {
		$test = MALUser::where('username', 'll-')->get()->first();

		$is_watching= $test->getIsWatching();
		foreach( $is_watching as $anime_details ) {
			$anime = Anime::where('mal_id', $anime_details["mal_id"])->get()->first();
			#$anime->fill( $is_watching["mal_id"] );
			$test->IsWatching()->save( $anime, $anime_details );
			#var_dump($anime);
			#exit;
		}
		#echo $test->test();
		echo "OK";
	}

	public function _createUser( $username ) {
		$helper = new Helper();
		$helper->createUser( $username );
		if ( false === $helper->setIsWatching( $username ) ) {
			echo "not ok"; return;
		}
		$helper->setCalendar( $username );
		echo "OK. https://animes.iamfabulous.de/ical/" . $username;
		return;

		$user = MALUser::where('username', $username)->get()->first();
		var_dump( $user );

		if ( is_null($user) ) {
			$user = new MALUser();
			$user->set( $username );

			var_dump( $user );

			$user->save();
		}

		echo $user->get();
	}

	public function createUser( $username ) {

		$job = new AddNewCalUser( $username );
		#$job = AddNewCalUser::create();
		$id = $job::dispatch( $username );

		echo "<pre>";
		#var_dump($job->id);
		var_dump($job);
		var_dump($id);
		#$jobStatusId = $job->getJobStatusId();
		#echo "https://anistats.com/status/" . $jobStatusId;
	}

	public function showJobStatus( $jobStatusId ) {
		$jobStatus = JobStatus::find($jobStatusId);

		echo "<pre>";
		/*
		while ( "queued" == $jobStatus->status || "executing" == $jobStatus->status ) {
			echo $jobStatus->status;
			echo "";
			$jobStatus = JobStatus::find($jobStatusId);
			sleep(1);
		}
		 */

		var_dump($jobStatus);
		var_dump($jobStatus->output);

	}
}