@@ -13,7 +13,7 @@ |
||
13 | 13 | private $v2 = '/v2'; |
14 | 14 | |
15 | 15 | protected $headers = [ |
16 | - 'Content-Type' => 'application/json' |
|
16 | + 'Content-Type' => 'application/json' |
|
17 | 17 | ]; |
18 | 18 | |
19 | 19 | public function __construct($id = null) { |
@@ -3,5 +3,5 @@ |
||
3 | 3 | namespace Ijeffro\Laralocker\LearningLocker\Dashboards; |
4 | 4 | |
5 | 5 | interface DashboardInterface { |
6 | - function get(); |
|
6 | + function get(); |
|
7 | 7 | } |
@@ -18,16 +18,16 @@ discard block |
||
18 | 18 | |
19 | 19 | class Connection { |
20 | 20 | |
21 | - protected $org; |
|
22 | - protected $url; |
|
23 | - protected $key; |
|
24 | - protected $secret; |
|
25 | - protected $headers; |
|
26 | - protected $settings; |
|
27 | - protected $endpoint; |
|
28 | - protected $connection; |
|
29 | - |
|
30 | - public function __construct($key = null, $secret = null, $url = null) { |
|
21 | + protected $org; |
|
22 | + protected $url; |
|
23 | + protected $key; |
|
24 | + protected $secret; |
|
25 | + protected $headers; |
|
26 | + protected $settings; |
|
27 | + protected $endpoint; |
|
28 | + protected $connection; |
|
29 | + |
|
30 | + public function __construct($key = null, $secret = null, $url = null) { |
|
31 | 31 | // $this->org = $org; |
32 | 32 | // $this->settings = $settings; |
33 | 33 | // $this->endpoint = $settings[LearningLocker::URL] ?? null; |
@@ -43,17 +43,17 @@ discard block |
||
43 | 43 | 'Content-Type' => 'application/json' |
44 | 44 | ]; |
45 | 45 | |
46 | - } |
|
46 | + } |
|
47 | 47 | |
48 | - protected function client() { |
|
48 | + protected function client() { |
|
49 | 49 | return new Client(); |
50 | - } |
|
50 | + } |
|
51 | 51 | |
52 | - protected function auth() { |
|
52 | + protected function auth() { |
|
53 | 53 | return [$this->key, $this->secret]; |
54 | - } |
|
54 | + } |
|
55 | 55 | |
56 | - protected function headers() { |
|
56 | + protected function headers() { |
|
57 | 57 | return $this->headers; |
58 | - } |
|
58 | + } |
|
59 | 59 | } |
@@ -6,39 +6,39 @@ |
||
6 | 6 | |
7 | 7 | class Client extends Connection { |
8 | 8 | |
9 | - private $client = '/client'; |
|
10 | - private $api = '/api'; |
|
11 | - private $v2 = '/v2'; |
|
9 | + private $client = '/client'; |
|
10 | + private $api = '/api'; |
|
11 | + private $v2 = '/v2'; |
|
12 | 12 | |
13 | - private $headers = [ |
|
13 | + private $headers = [ |
|
14 | 14 | 'content-type' => 'application/json' |
15 | - ]; |
|
15 | + ]; |
|
16 | 16 | |
17 | 17 | |
18 | - public function check() { |
|
18 | + public function check() { |
|
19 | 19 | try { |
20 | - $request = $this->get(); |
|
20 | + $request = $this->get(); |
|
21 | 21 | } catch (Exception $e) { |
22 | - return false; |
|
22 | + return false; |
|
23 | 23 | } |
24 | 24 | return true; |
25 | - } |
|
25 | + } |
|
26 | 26 | |
27 | - public function get() { |
|
27 | + public function get() { |
|
28 | 28 | $url = $this->endpoint . $this->api . $this->v2 . $this->client . '/'; |
29 | 29 | $request = $this->getClient()->get($url, [ |
30 | - 'auth' => $this->getAuth(), |
|
31 | - 'headers' => [ |
|
30 | + 'auth' => $this->getAuth(), |
|
31 | + 'headers' => [ |
|
32 | 32 | 'content-type' => 'application/json' |
33 | - ], |
|
33 | + ], |
|
34 | 34 | ]); |
35 | 35 | |
36 | 36 | if($request->getStatusCode() === 404) { |
37 | - throw new Exception('There was a issue connecting to Learning Locker.'); |
|
37 | + throw new Exception('There was a issue connecting to Learning Locker.'); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | $response = $request->json(); |
41 | 41 | |
42 | 42 | return true; |
43 | - } |
|
43 | + } |
|
44 | 44 | } |
@@ -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 | function __construct($id = null) { |
@@ -3,5 +3,5 @@ |
||
3 | 3 | namespace Ijeffro\Laralocker\LearningLocker\Exports; |
4 | 4 | |
5 | 5 | interface ExportInterface { |
6 | - function get(); |
|
6 | + function get(); |
|
7 | 7 | } |
@@ -34,26 +34,26 @@ discard block |
||
34 | 34 | |
35 | 35 | public function __construct( $endpoints=array() ) { |
36 | 36 | |
37 | - $this->log = \App::make('xapi.log'); |
|
38 | - $this->endpoints = $endpoints; |
|
37 | + $this->log = \App::make('xapi.log'); |
|
38 | + $this->endpoints = $endpoints; |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | - * Checks a passed array has a defined key, returns a default if not set |
|
43 | - * @param array $array The array to check |
|
44 | - * @param string $key Key to check |
|
45 | - * @param type $default Default to return if key is not set |
|
46 | - * @return mixed |
|
47 | - */ |
|
42 | + * Checks a passed array has a defined key, returns a default if not set |
|
43 | + * @param array $array The array to check |
|
44 | + * @param string $key Key to check |
|
45 | + * @param type $default Default to return if key is not set |
|
46 | + * @return mixed |
|
47 | + */ |
|
48 | 48 | private static function checkKey( $array, $key, $default='' ){ |
49 | 49 | return (isset($array[$key]) && !empty($array[$key])) ? $array[$key] : $default; |
50 | 50 | } |
51 | 51 | |
52 | - /** |
|
53 | - * Creates a statement from an array, with defaults if needed |
|
54 | - * @param Array $data Holds the actor, verb and object information |
|
55 | - */ |
|
56 | - public function buildStatement($data) { |
|
52 | + /** |
|
53 | + * Creates a statement from an array, with defaults if needed |
|
54 | + * @param Array $data Holds the actor, verb and object information |
|
55 | + */ |
|
56 | + public function buildStatement($data) { |
|
57 | 57 | |
58 | 58 | $actor = $this->checkKey($data, 'actor'); |
59 | 59 | $verb = $this->checkKey($data, 'verb', self::getVerb('experienced') ); |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | $timestamp = $this->checkKey($data, 'timestamp', Carbon::now()->format("c") ); |
65 | 65 | |
66 | 66 | $this->statement = array( |
67 | - 'actor' => $actor, |
|
68 | - 'verb' => $verb, |
|
69 | - 'object' => $object, |
|
70 | - 'timestamp' => $timestamp |
|
67 | + 'actor' => $actor, |
|
68 | + 'verb' => $verb, |
|
69 | + 'object' => $object, |
|
70 | + 'timestamp' => $timestamp |
|
71 | 71 | ); |
72 | 72 | |
73 | 73 | if( isset($result) && !empty($result) ){ |
@@ -81,24 +81,24 @@ discard block |
||
81 | 81 | if( isset($context) && !empty($context) ){ |
82 | 82 | $this->statement['context'] = $context; |
83 | 83 | } else { |
84 | - $this->statement['context'] = $this->createContext(); |
|
84 | + $this->statement['context'] = $this->createContext(); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | //Add the org to the contextActivites |
88 | 88 | $org = \Organisation::userCurrent(); |
89 | 89 | if( $org ){ |
90 | - if( !isset($this->statement['context']['contextActivities']) ){ |
|
90 | + if( !isset($this->statement['context']['contextActivities']) ){ |
|
91 | 91 | $this->statement['context']['contextActivities'] = []; |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | - if( !isset($this->statement['context']['contextActivities']['grouping']) ){ |
|
94 | + if( !isset($this->statement['context']['contextActivities']['grouping']) ){ |
|
95 | 95 | $this->statement['context']['contextActivities']['grouping'] = []; |
96 | - } elseif( !isset($this->statement['context']['contextActivities']['grouping'][0])){ |
|
96 | + } elseif( !isset($this->statement['context']['contextActivities']['grouping'][0])){ |
|
97 | 97 | $val = $this->statement['context']['contextActivities']['grouping']; |
98 | 98 | $this->statement['context']['contextActivities']['grouping'] = [ $val ]; |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - $this->statement['context']['contextActivities']['grouping'][] = $org->tcExtension(); |
|
101 | + $this->statement['context']['contextActivities']['grouping'][] = $org->tcExtension(); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | // remove context.platform if NOT an activity (xAPI 4.1.6) |
@@ -107,25 +107,25 @@ discard block |
||
107 | 107 | && isset($this->statement['object'], $this->statement['object']['objectType']) |
108 | 108 | && strtolower($this->statement['object']['objectType']) !== strtolower('activity') |
109 | 109 | ) { |
110 | - if (isset($this->statement['context']['platform'])) { |
|
110 | + if (isset($this->statement['context']['platform'])) { |
|
111 | 111 | unset($this->statement['context']['platform']); |
112 | - } |
|
113 | - if (isset($this->statement['context']['revision'])) { |
|
112 | + } |
|
113 | + if (isset($this->statement['context']['revision'])) { |
|
114 | 114 | unset($this->statement['context']['revision']); |
115 | - } |
|
115 | + } |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | |
119 | 119 | return $this->statement; |
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Static method |
|
124 | - * Generates the actor part of the statement |
|
125 | - * @param string $name |
|
126 | - * @param string $email |
|
127 | - * @return array |
|
128 | - */ |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Static method |
|
124 | + * Generates the actor part of the statement |
|
125 | + * @param string $name |
|
126 | + * @param string $email |
|
127 | + * @return array |
|
128 | + */ |
|
129 | 129 | public static function createMboxActor( $name, $email ){ |
130 | 130 | return array( |
131 | 131 | 'name' => $name, |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | * @return array |
144 | 144 | */ |
145 | 145 | public static function createAccountActor( $name, $homepage, $ref ){ |
146 | - return [ |
|
147 | - 'name' => $name, |
|
148 | - 'account' => ['homePage' => $homepage, 'name' => $ref], |
|
149 | - 'objectType' => 'Agent' |
|
150 | - ]; |
|
146 | + return [ |
|
147 | + 'name' => $name, |
|
148 | + 'account' => ['homePage' => $homepage, 'name' => $ref], |
|
149 | + 'objectType' => 'Agent' |
|
150 | + ]; |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | ); |
190 | 190 | |
191 | 191 | if( !empty($extensions) ){ |
192 | - $context['extensions'] = $extensions; |
|
192 | + $context['extensions'] = $extensions; |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | if( !is_null($additional) ){ |
@@ -200,12 +200,12 @@ discard block |
||
200 | 200 | |
201 | 201 | } |
202 | 202 | |
203 | - /** |
|
204 | - * Static method |
|
205 | - * Returns a predefined verb or 'experienced' if not found |
|
206 | - * @param string $key The verb to use |
|
207 | - * @return array |
|
208 | - */ |
|
203 | + /** |
|
204 | + * Static method |
|
205 | + * Returns a predefined verb or 'experienced' if not found |
|
206 | + * @param string $key The verb to use |
|
207 | + * @return array |
|
208 | + */ |
|
209 | 209 | public static function getVerb( $key ){ |
210 | 210 | |
211 | 211 | $verbs = array(); |
@@ -369,128 +369,128 @@ discard block |
||
369 | 369 | |
370 | 370 | |
371 | 371 | |
372 | - public function sendRequests() { |
|
372 | + public function sendRequests() { |
|
373 | 373 | foreach( $this->endpoints as $name => $ep ){ |
374 | 374 | |
375 | - $username = $ep->username; |
|
376 | - $password = $ep->key; |
|
377 | - $url = $ep->url; |
|
375 | + $username = $ep->username; |
|
376 | + $password = $ep->key; |
|
377 | + $url = $ep->url; |
|
378 | 378 | |
379 | - if(substr($url, -1) !== '/') { |
|
379 | + if(substr($url, -1) !== '/') { |
|
380 | 380 | $url .= '/'; |
381 | - } |
|
381 | + } |
|
382 | 382 | |
383 | - \Queue::push('\HT2\Queues\XAPIService', [ |
|
383 | + \Queue::push('\HT2\Queues\XAPIService', [ |
|
384 | 384 | 'endpoint' => $url, |
385 | 385 | 'type' => 'basic', |
386 | 386 | 'username' => $username, |
387 | 387 | 'password' => $password, |
388 | 388 | 'statement' => $this->statement |
389 | - ]); |
|
389 | + ]); |
|
390 | 390 | |
391 | 391 | } |
392 | - } |
|
392 | + } |
|
393 | 393 | |
394 | - /** |
|
395 | - * Send the request to all end points defined in the endpoints array |
|
396 | - * @return array An array of all requests sent and their responses |
|
397 | - */ |
|
394 | + /** |
|
395 | + * Send the request to all end points defined in the endpoints array |
|
396 | + * @return array An array of all requests sent and their responses |
|
397 | + */ |
|
398 | 398 | public function sendRequestsOld(){ |
399 | - $error = $this->checkError(); |
|
400 | - if( $error ) return false; |
|
399 | + $error = $this->checkError(); |
|
400 | + if( $error ) return false; |
|
401 | 401 | |
402 | - $results = array(); |
|
402 | + $results = array(); |
|
403 | 403 | |
404 | 404 | |
405 | - foreach( $this->endpoints as $name => $ep ){ |
|
405 | + foreach( $this->endpoints as $name => $ep ){ |
|
406 | 406 | |
407 | - $username = $ep->username; |
|
408 | - $password = $ep->key; |
|
409 | - $url = $ep->url; |
|
410 | - $auth = base64_encode( $username.':'.$password ); |
|
407 | + $username = $ep->username; |
|
408 | + $password = $ep->key; |
|
409 | + $url = $ep->url; |
|
410 | + $auth = base64_encode( $username.':'.$password ); |
|
411 | 411 | |
412 | - $result = $this->make_request($auth, $url, $this->statement); |
|
413 | - $error = false; |
|
414 | - $error_type = ""; |
|
415 | - $body = ""; |
|
412 | + $result = $this->make_request($auth, $url, $this->statement); |
|
413 | + $error = false; |
|
414 | + $error_type = ""; |
|
415 | + $body = ""; |
|
416 | 416 | |
417 | - if( isset($result['error']) ){ |
|
417 | + if( isset($result['error']) ){ |
|
418 | 418 | $error = true; |
419 | 419 | $error_type = "cURL error"; |
420 | - } else { |
|
420 | + } else { |
|
421 | 421 | |
422 | 422 | $body = isset($result['body']) ? json_decode($result['body']) : ""; |
423 | 423 | |
424 | 424 | if( isset($body->success) ){ |
425 | - if( $body->success == false ){ |
|
425 | + if( $body->success == false ){ |
|
426 | 426 | $error = true; |
427 | 427 | $error_type = "LRS returned success as false"; |
428 | - } |
|
428 | + } |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | if( isset($body->error) ){ |
432 | - if( $body->error == true ){ |
|
432 | + if( $body->error == true ){ |
|
433 | 433 | $error = true; |
434 | 434 | $error_type = "LRS returned error as true"; |
435 | - } |
|
435 | + } |
|
436 | 436 | } |
437 | 437 | if( isset($result['status']) ){ |
438 | - $status = $result['status']; |
|
438 | + $status = $result['status']; |
|
439 | 439 | |
440 | - switch( intval($status) ){ |
|
440 | + switch( intval($status) ){ |
|
441 | 441 | case 400: |
442 | 442 | case 404: |
443 | 443 | case 500: |
444 | 444 | $error = true; |
445 | - $error_type = "LRS returned HTTP code ".$status; |
|
445 | + $error_type = "LRS returned HTTP code ".$status; |
|
446 | 446 | break; |
447 | - } |
|
447 | + } |
|
448 | + } |
|
448 | 449 | } |
449 | - } |
|
450 | 450 | |
451 | - if( $error ){ |
|
451 | + if( $error ){ |
|
452 | 452 | $this->log->error( 'Statement Failed', array( |
453 | - 'curl_result' => $result, |
|
454 | - 'type' => $error_type, |
|
455 | - 'url' => $ep->url, |
|
456 | - 'statement' => $this->statement |
|
453 | + 'curl_result' => $result, |
|
454 | + 'type' => $error_type, |
|
455 | + 'url' => $ep->url, |
|
456 | + 'statement' => $this->statement |
|
457 | 457 | )); |
458 | - } else { |
|
458 | + } else { |
|
459 | 459 | $this->log->info( 'Sent', array( |
460 | - 'url' => $ep->url, |
|
461 | - 'statement' => $this->statement |
|
460 | + 'url' => $ep->url, |
|
461 | + 'statement' => $this->statement |
|
462 | 462 | )); |
463 | - } |
|
463 | + } |
|
464 | 464 | |
465 | - $results[$url] = $body; |
|
466 | - } |
|
465 | + $results[$url] = $body; |
|
466 | + } |
|
467 | 467 | |
468 | 468 | |
469 | - return array( |
|
470 | - 'statement' => $this->statement, |
|
471 | - 'endpoints' => $this->endpoints, |
|
472 | - 'results' => $results |
|
473 | - ); |
|
474 | - } |
|
469 | + return array( |
|
470 | + 'statement' => $this->statement, |
|
471 | + 'endpoints' => $this->endpoints, |
|
472 | + 'results' => $results |
|
473 | + ); |
|
474 | + } |
|
475 | 475 | |
476 | - /** |
|
477 | - * Send statement |
|
478 | - * @param string $auth The base64 basic auth info for the request |
|
479 | - * @param string $url The endpoint |
|
480 | - * @param array $statement The statement to be encoded |
|
481 | - * @return boolean/array Returns false on fail, array of details on success |
|
482 | - */ |
|
483 | - public function make_request( $auth, $url, $statement ) { |
|
476 | + /** |
|
477 | + * Send statement |
|
478 | + * @param string $auth The base64 basic auth info for the request |
|
479 | + * @param string $url The endpoint |
|
480 | + * @param array $statement The statement to be encoded |
|
481 | + * @return boolean/array Returns false on fail, array of details on success |
|
482 | + */ |
|
483 | + public function make_request( $auth, $url, $statement ) { |
|
484 | 484 | |
485 | 485 | $headers = array( |
486 | - 'Authorization: Basic '.$auth, |
|
487 | - 'Content-Type: application/json; charset=UTF-8', |
|
488 | - 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', |
|
489 | - 'X-Experience-API-Version: 1.0.0' |
|
486 | + 'Authorization: Basic '.$auth, |
|
487 | + 'Content-Type: application/json; charset=UTF-8', |
|
488 | + 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', |
|
489 | + 'X-Experience-API-Version: 1.0.0' |
|
490 | 490 | ); |
491 | 491 | |
492 | 492 | if(substr($url, -1) !== '/') { |
493 | - $url .= '/'; |
|
493 | + $url .= '/'; |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | $ch = curl_init( $url . 'statements' ); |
@@ -502,26 +502,26 @@ discard block |
||
502 | 502 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers ); |
503 | 503 | |
504 | 504 | if( substr($url, 0, 5) == "https" ){ |
505 | - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|
506 | - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); |
|
507 | - curl_setopt ($ch, CURLOPT_CAINFO, storage_path()."/cacert.pem"); |
|
505 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|
506 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); |
|
507 | + curl_setopt ($ch, CURLOPT_CAINFO, storage_path()."/cacert.pem"); |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | $response = curl_exec( $ch ); |
511 | 511 | if( $response === false ){ |
512 | - return array('error'=>true, 'curl_error'=>curl_error($ch)); |
|
512 | + return array('error'=>true, 'curl_error'=>curl_error($ch)); |
|
513 | 513 | } else { |
514 | - $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); |
|
515 | - $header = substr($response, 0, $header_size); |
|
516 | - $body = substr($response, $header_size); |
|
517 | - return array( |
|
514 | + $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); |
|
515 | + $header = substr($response, 0, $header_size); |
|
516 | + $body = substr($response, $header_size); |
|
517 | + return array( |
|
518 | 518 | 'ch' => $ch, |
519 | 519 | 'status' => curl_getinfo($ch, CURLINFO_HTTP_CODE), |
520 | 520 | 'header' => $header, |
521 | 521 | 'body' => $body |
522 | - ); |
|
522 | + ); |
|
523 | + } |
|
523 | 524 | } |
524 | - } |
|
525 | 525 | |
526 | 526 | private function checkError(){ |
527 | 527 | if( empty($this->statement) ){ |
@@ -16,7 +16,7 @@ |
||
16 | 16 | public $statement_forwarding; |
17 | 17 | |
18 | 18 | protected $headers = [ |
19 | - 'Content-Type' => 'application/json' |
|
19 | + 'Content-Type' => 'application/json' |
|
20 | 20 | ]; |
21 | 21 | |
22 | 22 | function __construct($id = null) { |
@@ -11,12 +11,12 @@ |
||
11 | 11 | use TinCan\LanguageMap; |
12 | 12 | |
13 | 13 | interface StatementInterface { |
14 | - function getAuthCredentials(); |
|
15 | - function send( Agent $agent, $verb, $object, Carbon $timestamp=null, Context $context, Result $result ); |
|
16 | - function makeStatement( Agent $agent, Verb $verb, $object, Carbon $timestamp, Context $context, Result $result ); |
|
14 | + function getAuthCredentials(); |
|
15 | + function send( Agent $agent, $verb, $object, Carbon $timestamp=null, Context $context, Result $result ); |
|
16 | + function makeStatement( Agent $agent, Verb $verb, $object, Carbon $timestamp, Context $context, Result $result ); |
|
17 | 17 | |
18 | - function getVerb($id, $display); |
|
18 | + function getVerb($id, $display); |
|
19 | 19 | |
20 | - function getVersion(); |
|
21 | - function setVersion($version); |
|
20 | + function getVersion(); |
|
21 | + function setVersion($version); |
|
22 | 22 | } |