@@ -12,7 +12,7 @@ |
||
12 | 12 | private $v2 = '/v2'; |
13 | 13 | |
14 | 14 | protected $headers = [ |
15 | - 'content-type' => 'application/json' |
|
15 | + 'content-type' => 'application/json' |
|
16 | 16 | ]; |
17 | 17 | |
18 | 18 | /** |
@@ -3,5 +3,5 @@ |
||
3 | 3 | namespace Ijeffro\Laralocker\LearningLocker\Downloads; |
4 | 4 | |
5 | 5 | interface DownloadInterface { |
6 | - function get(); |
|
6 | + function get(); |
|
7 | 7 | } |
@@ -3,5 +3,5 @@ |
||
3 | 3 | namespace Ijeffro\Laralocker\LearningLocker\Users; |
4 | 4 | |
5 | 5 | interface UserInterface { |
6 | - function get(); |
|
6 | + function get(); |
|
7 | 7 | } |
@@ -3,5 +3,5 @@ |
||
3 | 3 | namespace Ijeffro\Laralocker\LearningLocker\Roles; |
4 | 4 | |
5 | 5 | interface RoleInterface { |
6 | - function get(); |
|
6 | + function get(); |
|
7 | 7 | } |
@@ -5,68 +5,68 @@ |
||
5 | 5 | |
6 | 6 | class Organisation extends Connection { |
7 | 7 | |
8 | - private $organisation = '/organisation'; |
|
9 | - private $api = '/api'; |
|
10 | - private $v2 = '/v2'; |
|
8 | + private $organisation = '/organisation'; |
|
9 | + private $api = '/api'; |
|
10 | + private $v2 = '/v2'; |
|
11 | 11 | |
12 | - private $headers = [ |
|
12 | + private $headers = [ |
|
13 | 13 | 'content-type' => 'application/json' |
14 | - ]; |
|
14 | + ]; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Get the Learning Locker Statement Forward by ID. |
|
18 | - * |
|
19 | - * @param $id |
|
20 | - * @return $response |
|
21 | - */ |
|
22 | - public function get() { |
|
16 | + /** |
|
17 | + * Get the Learning Locker Statement Forward by ID. |
|
18 | + * |
|
19 | + * @param $id |
|
20 | + * @return $response |
|
21 | + */ |
|
22 | + public function get() { |
|
23 | 23 | try { |
24 | - $url = $this->endpoint . $this->api . $this->v2 . $this->organisation; |
|
25 | - $request = $this->getClient()->get($url, [ |
|
24 | + $url = $this->endpoint . $this->api . $this->v2 . $this->organisation; |
|
25 | + $request = $this->getClient()->get($url, [ |
|
26 | 26 | 'auth' => $this->getAuth(), |
27 | 27 | 'headers' => [ |
28 | - 'content-type' => 'application/json' |
|
28 | + 'content-type' => 'application/json' |
|
29 | 29 | ], |
30 | - ]); |
|
31 | - $response = $request->json(); |
|
32 | - return $response; |
|
30 | + ]); |
|
31 | + $response = $request->json(); |
|
32 | + return $response; |
|
33 | 33 | } catch (Exception $e) { |
34 | - return false; |
|
34 | + return false; |
|
35 | + } |
|
35 | 36 | } |
36 | - } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Get the Learning Locker Organisation Name. |
|
40 | - * |
|
41 | - * @param $org |
|
42 | - * @return $response, false |
|
43 | - */ |
|
44 | - public function id() { |
|
38 | + /** |
|
39 | + * Get the Learning Locker Organisation Name. |
|
40 | + * |
|
41 | + * @param $org |
|
42 | + * @return $response, false |
|
43 | + */ |
|
44 | + public function id() { |
|
45 | 45 | $response = $this->get(); |
46 | 46 | if($response) { |
47 | - $id = $response[0]['_id']; |
|
48 | - $setSetting = LLService::create($this->org, LLService::LL_ID)->setSetting(LLService::ORGANISATION_ID, $id); |
|
49 | - return $id; |
|
47 | + $id = $response[0]['_id']; |
|
48 | + $setSetting = LLService::create($this->org, LLService::LL_ID)->setSetting(LLService::ORGANISATION_ID, $id); |
|
49 | + return $id; |
|
50 | 50 | } |
51 | 51 | return false; |
52 | - } |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Get the Learning Locker Organisation Name. |
|
56 | - * |
|
57 | - * @param $org |
|
58 | - * @return $response, false |
|
59 | - */ |
|
60 | - public function name() |
|
61 | - { |
|
54 | + /** |
|
55 | + * Get the Learning Locker Organisation Name. |
|
56 | + * |
|
57 | + * @param $org |
|
58 | + * @return $response, false |
|
59 | + */ |
|
60 | + public function name() |
|
61 | + { |
|
62 | 62 | $response = $this->get(); |
63 | 63 | if($response) { |
64 | - $name = $response[0]['name']; |
|
65 | - $setSetting = LLService::create($this->org, LLService::LL_ID)->setSetting(LLService::ORGANISATION, $name); |
|
66 | - return $name; |
|
64 | + $name = $response[0]['name']; |
|
65 | + $setSetting = LLService::create($this->org, LLService::LL_ID)->setSetting(LLService::ORGANISATION, $name); |
|
66 | + return $name; |
|
67 | 67 | } |
68 | 68 | return false; |
69 | 69 | |
70 | - } |
|
70 | + } |
|
71 | 71 | |
72 | 72 | } |
@@ -3,5 +3,5 @@ |
||
3 | 3 | namespace Ijeffro\Laralocker\LearningLocker\Organisation; |
4 | 4 | |
5 | 5 | interface OrganisationInterface { |
6 | - function get(); |
|
6 | + function get(); |
|
7 | 7 | } |
@@ -3,5 +3,5 @@ |
||
3 | 3 | namespace Ijeffro\Laralocker\LearningLocker\Journeys; |
4 | 4 | |
5 | 5 | interface JourneyInterface { |
6 | - function get(); |
|
6 | + function get(); |
|
7 | 7 | } |
@@ -15,7 +15,7 @@ |
||
15 | 15 | public $journey_progress; |
16 | 16 | |
17 | 17 | protected $headers = [ |
18 | - 'Content-Type' => 'application/json' |
|
18 | + 'Content-Type' => 'application/json' |
|
19 | 19 | ]; |
20 | 20 | |
21 | 21 | function __construct($id = null) { |
@@ -9,44 +9,44 @@ discard block |
||
9 | 9 | |
10 | 10 | class StatementForward extends Connection { |
11 | 11 | |
12 | - private $statementForward = '/statementforwarding'; |
|
13 | - private $api = '/api'; |
|
14 | - private $v2 = '/v2'; |
|
12 | + private $statementForward = '/statementforwarding'; |
|
13 | + private $api = '/api'; |
|
14 | + private $v2 = '/v2'; |
|
15 | 15 | |
16 | - private $headers = [ |
|
16 | + private $headers = [ |
|
17 | 17 | 'content-type' => 'application/json' |
18 | - ]; |
|
19 | - |
|
20 | - /** |
|
21 | - * Generate the Query for Learning Locker's |
|
22 | - * Statement Forward. |
|
23 | - * |
|
24 | - * @return true |
|
25 | - * @return false |
|
26 | - */ |
|
27 | - public function updateStatementForwardQuery($statementForwardId, $isEnabled) { |
|
18 | + ]; |
|
19 | + |
|
20 | + /** |
|
21 | + * Generate the Query for Learning Locker's |
|
22 | + * Statement Forward. |
|
23 | + * |
|
24 | + * @return true |
|
25 | + * @return false |
|
26 | + */ |
|
27 | + public function updateStatementForwardQuery($statementForwardId, $isEnabled) { |
|
28 | 28 | $query = Query::statementForward($this->org->id); |
29 | 29 | if ($query === false || !$isEnabled) { |
30 | - $message = $query === false && $isEnabled ? '(No objects)' : null; |
|
31 | - return $this->disable($statementForwardId, $message); |
|
30 | + $message = $query === false && $isEnabled ? '(No objects)' : null; |
|
31 | + return $this->disable($statementForwardId, $message); |
|
32 | 32 | } |
33 | 33 | // pass in the query to prevent regeneration in the enable method |
34 | 34 | return $this->enable($statementForwardId, $query); |
35 | - } |
|
35 | + } |
|
36 | 36 | |
37 | - public static function getSigner() { |
|
37 | + public static function getSigner() { |
|
38 | 38 | return new Sha256; |
39 | - } |
|
39 | + } |
|
40 | 40 | |
41 | - public static function getOrgIssuer($org) { |
|
41 | + public static function getOrgIssuer($org) { |
|
42 | 42 | return \Curatr\Helper::getSubdomainURL($org->alias); |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | - public static function getOrgSigningKey($org) { |
|
45 | + public static function getOrgSigningKey($org) { |
|
46 | 46 | return $org->jwt_secret ?? 'default_key'; |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | - public function createSignedBearer() { |
|
49 | + public function createSignedBearer() { |
|
50 | 50 | $signer = self::getSigner(); |
51 | 51 | $issuer = self::getOrgIssuer($this->org); |
52 | 52 | $token = (new Builder())->setIssuer($issuer) // Configures the issuer (iss claim) |
@@ -55,155 +55,155 @@ discard block |
||
55 | 55 | ->sign($signer, self::getOrgSigningKey($this->org)) |
56 | 56 | ->getToken(); // Retrieves the generated token |
57 | 57 | return $token->__toString(); |
58 | - } |
|
58 | + } |
|
59 | 59 | |
60 | - private function title($message = "") { |
|
60 | + private function title($message = "") { |
|
61 | 61 | return trim($this->org->app_name . ' - ' . $this->org->name . ' - Object Completions ' . $message); |
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Enable the Learning Locker Statement Forward. |
|
66 | - * |
|
67 | - * @param $statementForwardId |
|
68 | - * @return $response |
|
69 | - */ |
|
70 | - public function enable($statementForwardId, $query = null) { |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Enable the Learning Locker Statement Forward. |
|
66 | + * |
|
67 | + * @param $statementForwardId |
|
68 | + * @return $response |
|
69 | + */ |
|
70 | + public function enable($statementForwardId, $query = null) { |
|
71 | 71 | $data = [ |
72 | - "active" => true, |
|
73 | - "description" => $this->title(), |
|
74 | - "query" => $query ?: Query::statementForward($this->org->id), |
|
75 | - 'configuration' => [ |
|
72 | + "active" => true, |
|
73 | + "description" => $this->title(), |
|
74 | + "query" => $query ?: Query::statementForward($this->org->id), |
|
75 | + 'configuration' => [ |
|
76 | 76 | 'authType' => 'token', |
77 | 77 | 'secret' => $this->createSignedBearer() |
78 | - ] |
|
78 | + ] |
|
79 | 79 | ]; |
80 | 80 | return $this->update($statementForwardId, $data); |
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Disable the Learning Locker Statement Forward. |
|
85 | - * |
|
86 | - * @param $id |
|
87 | - * @return $response |
|
88 | - */ |
|
89 | - public function disable($statementForwardId, $message) { |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Disable the Learning Locker Statement Forward. |
|
85 | + * |
|
86 | + * @param $id |
|
87 | + * @return $response |
|
88 | + */ |
|
89 | + public function disable($statementForwardId, $message) { |
|
90 | 90 | $message = $message ?? '(Service Disabled)'; |
91 | 91 | $data = array( |
92 | - "active" => false, |
|
93 | - "description" => $this->title($message), |
|
94 | - "query" => json_encode(['$comment' => Query::COMMENT, 'disabled' => $message]) |
|
92 | + "active" => false, |
|
93 | + "description" => $this->title($message), |
|
94 | + "query" => json_encode(['$comment' => Query::COMMENT, 'disabled' => $message]) |
|
95 | 95 | ); |
96 | 96 | return $response = $this->update($statementForwardId, $data); |
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Get the Learning Locker Statement Forward by ID. |
|
101 | - * |
|
102 | - * @param $id |
|
103 | - * @return $response |
|
104 | - */ |
|
105 | - public function check($statementForwardId) { |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Get the Learning Locker Statement Forward by ID. |
|
101 | + * |
|
102 | + * @param $id |
|
103 | + * @return $response |
|
104 | + */ |
|
105 | + public function check($statementForwardId) { |
|
106 | 106 | if (empty($statementForwardId)) return false; |
107 | 107 | return $this->get($statementForwardId); |
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Get the Learning Locker Statement Forward by ID. |
|
112 | - * |
|
113 | - * @param $statementForwardId |
|
114 | - * @return $response |
|
115 | - */ |
|
116 | - public function get($statementForwardId) { |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Get the Learning Locker Statement Forward by ID. |
|
112 | + * |
|
113 | + * @param $statementForwardId |
|
114 | + * @return $response |
|
115 | + */ |
|
116 | + public function get($statementForwardId) { |
|
117 | 117 | try { |
118 | - $url = $this->endpoint . $this->api . $this->v2 . $this->statementForward . '/' . $statementForwardId; |
|
119 | - $request = $this->getClient()->get($url, [ |
|
118 | + $url = $this->endpoint . $this->api . $this->v2 . $this->statementForward . '/' . $statementForwardId; |
|
119 | + $request = $this->getClient()->get($url, [ |
|
120 | 120 | 'auth' => $this->getAuth(), |
121 | 121 | 'headers' => [ |
122 | - 'content-type' => 'application/json' |
|
122 | + 'content-type' => 'application/json' |
|
123 | 123 | ], |
124 | - ]); |
|
124 | + ]); |
|
125 | 125 | |
126 | - if($request->getStatusCode() === 404) { |
|
126 | + if($request->getStatusCode() === 404) { |
|
127 | 127 | throw new GuzzleHttp\Exception\ClientException('There was a issue connecting to Learning Locker.'); |
128 | - } |
|
129 | - return $request->json(); |
|
128 | + } |
|
129 | + return $request->json(); |
|
130 | 130 | } catch (Exception $e) { |
131 | - if ($e instanceof \GuzzleHttp\Exception\ClientException) { |
|
131 | + if ($e instanceof \GuzzleHttp\Exception\ClientException) { |
|
132 | 132 | $responseBody = $e->getResponse()->getBody(true); |
133 | 133 | \Log::error('Error fetching statement forward', [ |
134 | - 'id' => $statementForwardId, |
|
135 | - 'org_id'=>$this->org->id, |
|
136 | - 'responseBody' => $responseBody |
|
134 | + 'id' => $statementForwardId, |
|
135 | + 'org_id'=>$this->org->id, |
|
136 | + 'responseBody' => $responseBody |
|
137 | 137 | ]); |
138 | - } |
|
139 | - return false; |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Store the Learning Locker Statement Forward. |
|
145 | - * |
|
146 | - * @param $data |
|
147 | - * @return $response |
|
148 | - */ |
|
149 | - public function store($data, $startEnabled = true) { |
|
138 | + } |
|
139 | + return false; |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Store the Learning Locker Statement Forward. |
|
145 | + * |
|
146 | + * @param $data |
|
147 | + * @return $response |
|
148 | + */ |
|
149 | + public function store($data, $startEnabled = true) { |
|
150 | 150 | $store = json_encode($data); |
151 | 151 | try { |
152 | - $url = $this->endpoint . $this->api . $this->v2 . $this->statementForward; |
|
153 | - $request = $this->getClient()->post($url, array( |
|
152 | + $url = $this->endpoint . $this->api . $this->v2 . $this->statementForward; |
|
153 | + $request = $this->getClient()->post($url, array( |
|
154 | 154 | 'auth' => $this->getAuth(), |
155 | 155 | 'headers' => $this->headers, |
156 | 156 | 'body' => $store, |
157 | - )); |
|
158 | - $request = $request->json(); |
|
159 | - if (isset($request['_id'])) { |
|
157 | + )); |
|
158 | + $request = $request->json(); |
|
159 | + if (isset($request['_id'])) { |
|
160 | 160 | return $this->updateStatementForwardQuery($request['_id'], $startEnabled); |
161 | - } |
|
162 | - return false; |
|
161 | + } |
|
162 | + return false; |
|
163 | 163 | } catch (Exception $e) { |
164 | - if ($e instanceof \GuzzleHttp\Exception\ClientException) { |
|
164 | + if ($e instanceof \GuzzleHttp\Exception\ClientException) { |
|
165 | 165 | $responseBody = $e->getResponse()->getBody(true); |
166 | 166 | \Log::error('Error creating statement forward', [ |
167 | - 'data' => $data, |
|
168 | - 'org_id'=>$this->org->id, |
|
169 | - 'responseBody' => $responseBody |
|
167 | + 'data' => $data, |
|
168 | + 'org_id'=>$this->org->id, |
|
169 | + 'responseBody' => $responseBody |
|
170 | 170 | ]); |
171 | - } |
|
172 | - return false; |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Update the Learning Locker Statement Forward. |
|
178 | - * |
|
179 | - * @param $statementForwardId, $data |
|
180 | - * @return $response |
|
181 | - */ |
|
182 | - protected function update($statementForwardId, $data) { |
|
171 | + } |
|
172 | + return false; |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Update the Learning Locker Statement Forward. |
|
178 | + * |
|
179 | + * @param $statementForwardId, $data |
|
180 | + * @return $response |
|
181 | + */ |
|
182 | + protected function update($statementForwardId, $data) { |
|
183 | 183 | if (empty($statementForwardId)) return false; |
184 | 184 | $update = json_encode($data); |
185 | 185 | try { |
186 | - $url = $this->endpoint . $this->api . $this->v2 . $this->statementForward . '/' . $statementForwardId; |
|
187 | - $request = $this->getClient()->patch($url, array( |
|
186 | + $url = $this->endpoint . $this->api . $this->v2 . $this->statementForward . '/' . $statementForwardId; |
|
187 | + $request = $this->getClient()->patch($url, array( |
|
188 | 188 | 'auth' => $this->getAuth(), |
189 | 189 | 'headers' => [ |
190 | - 'content-type' => 'application/json' |
|
190 | + 'content-type' => 'application/json' |
|
191 | 191 | ], |
192 | 192 | 'body' => $update, |
193 | - )); |
|
194 | - return $request->json(); |
|
193 | + )); |
|
194 | + return $request->json(); |
|
195 | 195 | } catch (Exception $e) { |
196 | - if ($e instanceof \GuzzleHttp\Exception\ClientException) { |
|
196 | + if ($e instanceof \GuzzleHttp\Exception\ClientException) { |
|
197 | 197 | $responseBody = $e->getResponse()->getBody(true); |
198 | 198 | \Log::error('Error updating statement forward', [ |
199 | - 'id' => $statementForwardId, |
|
200 | - 'data' => $data, |
|
201 | - 'org_id'=>$this->org->id, |
|
202 | - 'responseBody' => $responseBody |
|
199 | + 'id' => $statementForwardId, |
|
200 | + 'data' => $data, |
|
201 | + 'org_id'=>$this->org->id, |
|
202 | + 'responseBody' => $responseBody |
|
203 | 203 | ]); |
204 | - } |
|
205 | - return false; |
|
204 | + } |
|
205 | + return false; |
|
206 | + } |
|
206 | 207 | } |
207 | - } |
|
208 | 208 | |
209 | 209 | } |