iDiarioService.php
3.12 KB
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
<?php
namespace App\Services;
use App\Models\LegacyInstitution;
use Exception;
use GuzzleHttp\Client;
use RuntimeException;
class iDiarioService
{
/**
* @var Client
*/
protected $http;
/**
* @var LegacyInstitution
*/
protected $institution;
/**
* @var string
*/
protected $apiUrl;
/**
* @var string
*/
protected $apiToken;
/**
* @param LegacyInstitution $institution
* @param Client $http
*
* @return void
*/
public function __construct(LegacyInstitution $institution, Client $http)
{
$this->institution = $institution;
$configs = $institution->generalConfiguration;
if (empty($configs->url_novo_educacao) || empty($configs->token_novo_educacao)) {
throw new RuntimeException('É necessário configurar a URL e Token de integração com o i-Diário.');
}
$this->http = $http;
$this->apiUrl = trim($configs->url_novo_educacao, '/');
$this->apiToken = trim($configs->token_novo_educacao);
}
/**
* @param int $unitId
* @param int $step
*
* @return bool
*/
public function getStepActivityByUnit(int $unitId, int $year, int $step): bool
{
try {
$response = $this->get('/api/v2/step_activity', [
'unity_id' => $unitId,
'year' => $year,
'step_number' => $step
]);
$body = trim((string)$response->getBody());
if ($body === 'true') {
return true;
}
} catch (Exception $e) {
return false;
}
return false;
}
/**
* @param int $classroomId
* @param int $step
*
* @return bool
*/
public function getStepActivityByClassroom(int $classroomId, int $year, int $step): bool
{
try {
$response = $this->get('/api/v2/step_activity', [
'classroom_id' => $classroomId,
'year' => $year,
'step_number' => $step
]);
$body = trim((string)$response->getBody());
if ($body === 'true') {
return true;
}
} catch (Exception $e) {
return false;
}
return false;
}
public function getTeacherClassroomsActivity(int $teacherId, int $classroomId): bool
{
try {
$response = $this->get('/api/v2/teacher_classrooms/has_activities', ['teacher_id' => $teacherId, 'classroom_id' => $classroomId]);
$body = trim((string)$response->getBody());
if ($body === 'true') {
return true;
}
} catch (Exception $e) {
return false;
}
return false;
}
/**
* @param string $path
* @param array $query
*
* @return mixed
*/
protected function get(string $path, array $query)
{
return $this->http->request('GET', $this->apiUrl . $path, [
'query' => $query,
'headers' => [
'token' => $this->apiToken
]
]);
}
}