@@ -27,7 +27,7 @@ |
||
27 | 27 | * |
28 | 28 | * @return $response |
29 | 29 | */ |
30 | - public function get($selected = []) { |
|
30 | + public function get($selected = [ ]) { |
|
31 | 31 | try { |
32 | 32 | $url = $this->url . $this->api . $this->v2 . $this->store . '/' . $this->id ?? $this->id; |
33 | 33 | $response = $this->request($url); |
@@ -32,7 +32,9 @@ |
||
32 | 32 | $url = $this->url . $this->api . $this->v2 . $this->store . '/' . $this->id ?? $this->id; |
33 | 33 | $response = $this->request($url); |
34 | 34 | |
35 | - if ($selected) $response = $this->select($selected, $response); |
|
35 | + if ($selected) { |
|
36 | + $response = $this->select($selected, $response); |
|
37 | + } |
|
36 | 38 | |
37 | 39 | return $response; |
38 | 40 |
@@ -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 | } |
@@ -50,7 +50,7 @@ |
||
50 | 50 | } |
51 | 51 | |
52 | 52 | protected function auth() { |
53 | - return [$this->key, $this->secret]; |
|
53 | + return [ $this->key, $this->secret ]; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | protected function headers() { |
@@ -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 | } |
@@ -33,7 +33,7 @@ |
||
33 | 33 | ], |
34 | 34 | ]); |
35 | 35 | |
36 | - if($request->getStatusCode() === 404) { |
|
36 | + if ($request->getStatusCode() === 404) { |
|
37 | 37 | throw new Exception('There was a issue connecting to Learning Locker.'); |
38 | 38 | } |
39 | 39 |
@@ -28,7 +28,7 @@ |
||
28 | 28 | * |
29 | 29 | * @return $response |
30 | 30 | */ |
31 | - public function get($selected = []) { |
|
31 | + public function get($selected = [ ]) { |
|
32 | 32 | try { |
33 | 33 | $url = $this->url . $this->api . $this->v2 . $this->client . '/' . $this->id ?? $this->id; |
34 | 34 | $response = $this->request($url); |
@@ -33,7 +33,9 @@ |
||
33 | 33 | $url = $this->url . $this->api . $this->v2 . $this->client . '/' . $this->id ?? $this->id; |
34 | 34 | $response = $this->request($url); |
35 | 35 | |
36 | - if ($selected) $response = $this->select($selected, $response); |
|
36 | + if ($selected) { |
|
37 | + $response = $this->select($selected, $response); |
|
38 | + } |
|
37 | 39 | |
38 | 40 | return $response; |
39 | 41 | } catch (Exception $e) { |
@@ -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) ){ |
@@ -7,12 +7,12 @@ discard block |
||
7 | 7 | |
8 | 8 | class StatementGenerator { |
9 | 9 | |
10 | - const LL_COURSE_EXTENSION = 'http://learninglocker.net/extensions/course'; |
|
11 | - const COMMENT_EXTENSION = 'http://curatr3.com/define/extension/commentText'; |
|
12 | - const BADGE_EXTENSION = 'http://specification.openbadges.org/xapi/extensions/badgeassertion'; |
|
13 | - const MCQ_SINGLE_EXTENSION = 'http://curatr3.com/define/extension/single-mcq-option'; |
|
14 | - const MCQ_MULTIPLE_EXTENSION = 'http://curatr3.com/define/extension/multiple-mcq-options'; |
|
15 | - const CONTRIBUTION_OBJECT = 'http://curatr3.com/define/extension/contribution-object'; |
|
10 | + const LL_COURSE_EXTENSION = 'http://learninglocker.net/extensions/course'; |
|
11 | + const COMMENT_EXTENSION = 'http://curatr3.com/define/extension/commentText'; |
|
12 | + const BADGE_EXTENSION = 'http://specification.openbadges.org/xapi/extensions/badgeassertion'; |
|
13 | + const MCQ_SINGLE_EXTENSION = 'http://curatr3.com/define/extension/single-mcq-option'; |
|
14 | + const MCQ_MULTIPLE_EXTENSION = 'http://curatr3.com/define/extension/multiple-mcq-options'; |
|
15 | + const CONTRIBUTION_OBJECT = 'http://curatr3.com/define/extension/contribution-object'; |
|
16 | 16 | const BADGE_TYPE = 'http://activitystrea.ms/schema/1.0/badge'; |
17 | 17 | const CATEGORY_TYPE = 'http://activitystrea.ms/schema/1.0/collection'; |
18 | 18 | const COLLECTION_TYPE = 'http://curatr3.com/define/type/collection'; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | |
33 | 33 | public $url, $statement, $endpoints, $log; |
34 | 34 | |
35 | - public function __construct( $endpoints=array() ) { |
|
35 | + public function __construct($endpoints = array()) { |
|
36 | 36 | |
37 | 37 | $this->log = \App::make('xapi.log'); |
38 | 38 | $this->endpoints = $endpoints; |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | * @param type $default Default to return if key is not set |
46 | 46 | * @return mixed |
47 | 47 | */ |
48 | - private static function checkKey( $array, $key, $default='' ){ |
|
49 | - return (isset($array[$key]) && !empty($array[$key])) ? $array[$key] : $default; |
|
48 | + private static function checkKey($array, $key, $default = '') { |
|
49 | + return (isset($array[ $key ]) && !empty($array[ $key ])) ? $array[ $key ] : $default; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -56,12 +56,12 @@ discard block |
||
56 | 56 | public function buildStatement($data) { |
57 | 57 | |
58 | 58 | $actor = $this->checkKey($data, 'actor'); |
59 | - $verb = $this->checkKey($data, 'verb', self::getVerb('experienced') ); |
|
59 | + $verb = $this->checkKey($data, 'verb', self::getVerb('experienced')); |
|
60 | 60 | $object = $this->checkKey($data, 'object'); |
61 | - $authority = $this->checkKey($data, 'authority', []); |
|
62 | - $context = $this->checkKey($data, 'context', [] ); |
|
63 | - $result = $this->checkKey($data, 'result', [] ); |
|
64 | - $timestamp = $this->checkKey($data, 'timestamp', Carbon::now()->format("c") ); |
|
61 | + $authority = $this->checkKey($data, 'authority', [ ]); |
|
62 | + $context = $this->checkKey($data, 'context', [ ]); |
|
63 | + $result = $this->checkKey($data, 'result', [ ]); |
|
64 | + $timestamp = $this->checkKey($data, 'timestamp', Carbon::now()->format("c")); |
|
65 | 65 | |
66 | 66 | $this->statement = array( |
67 | 67 | 'actor' => $actor, |
@@ -70,48 +70,48 @@ discard block |
||
70 | 70 | 'timestamp' => $timestamp |
71 | 71 | ); |
72 | 72 | |
73 | - if( isset($result) && !empty($result) ){ |
|
74 | - $this->statement['result'] = $result; |
|
73 | + if (isset($result) && !empty($result)) { |
|
74 | + $this->statement[ 'result' ] = $result; |
|
75 | 75 | } |
76 | 76 | |
77 | - if( isset($authority) && !empty($authority) ){ |
|
78 | - $this->statement['authority'] = $authority; |
|
77 | + if (isset($authority) && !empty($authority)) { |
|
78 | + $this->statement[ 'authority' ] = $authority; |
|
79 | 79 | } |
80 | 80 | |
81 | - if( isset($context) && !empty($context) ){ |
|
82 | - $this->statement['context'] = $context; |
|
81 | + if (isset($context) && !empty($context)) { |
|
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 | - if( $org ){ |
|
90 | - if( !isset($this->statement['context']['contextActivities']) ){ |
|
91 | - $this->statement['context']['contextActivities'] = []; |
|
89 | + if ($org) { |
|
90 | + if (!isset($this->statement[ 'context' ][ 'contextActivities' ])) { |
|
91 | + $this->statement[ 'context' ][ 'contextActivities' ] = [ ]; |
|
92 | 92 | } |
93 | 93 | |
94 | - if( !isset($this->statement['context']['contextActivities']['grouping']) ){ |
|
95 | - $this->statement['context']['contextActivities']['grouping'] = []; |
|
96 | - } elseif( !isset($this->statement['context']['contextActivities']['grouping'][0])){ |
|
97 | - $val = $this->statement['context']['contextActivities']['grouping']; |
|
98 | - $this->statement['context']['contextActivities']['grouping'] = [ $val ]; |
|
94 | + if (!isset($this->statement[ 'context' ][ 'contextActivities' ][ 'grouping' ])) { |
|
95 | + $this->statement[ 'context' ][ 'contextActivities' ][ 'grouping' ] = [ ]; |
|
96 | + } elseif (!isset($this->statement[ 'context' ][ 'contextActivities' ][ 'grouping' ][ 0 ])) { |
|
97 | + $val = $this->statement[ 'context' ][ 'contextActivities' ][ 'grouping' ]; |
|
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) |
105 | 105 | if ( |
106 | - isset($this->statement['context']) |
|
107 | - && isset($this->statement['object'], $this->statement['object']['objectType']) |
|
108 | - && strtolower($this->statement['object']['objectType']) !== strtolower('activity') |
|
106 | + isset($this->statement[ 'context' ]) |
|
107 | + && isset($this->statement[ 'object' ], $this->statement[ 'object' ][ 'objectType' ]) |
|
108 | + && strtolower($this->statement[ 'object' ][ 'objectType' ]) !== strtolower('activity') |
|
109 | 109 | ) { |
110 | - if (isset($this->statement['context']['platform'])) { |
|
111 | - unset($this->statement['context']['platform']); |
|
110 | + if (isset($this->statement[ 'context' ][ 'platform' ])) { |
|
111 | + unset($this->statement[ 'context' ][ 'platform' ]); |
|
112 | 112 | } |
113 | - if (isset($this->statement['context']['revision'])) { |
|
114 | - unset($this->statement['context']['revision']); |
|
113 | + if (isset($this->statement[ 'context' ][ 'revision' ])) { |
|
114 | + unset($this->statement[ 'context' ][ 'revision' ]); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @param string $email |
127 | 127 | * @return array |
128 | 128 | */ |
129 | - public static function createMboxActor( $name, $email ){ |
|
129 | + public static function createMboxActor($name, $email) { |
|
130 | 130 | return array( |
131 | 131 | 'name' => $name, |
132 | 132 | 'mbox' => 'mailto:' . $email, |
@@ -142,10 +142,10 @@ discard block |
||
142 | 142 | * @param string $ref |
143 | 143 | * @return array |
144 | 144 | */ |
145 | - public static function createAccountActor( $name, $homepage, $ref ){ |
|
145 | + public static function createAccountActor($name, $homepage, $ref) { |
|
146 | 146 | return [ |
147 | 147 | 'name' => $name, |
148 | - 'account' => ['homePage' => $homepage, 'name' => $ref], |
|
148 | + 'account' => [ 'homePage' => $homepage, 'name' => $ref ], |
|
149 | 149 | 'objectType' => 'Agent' |
150 | 150 | ]; |
151 | 151 | } |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @param string $email |
158 | 158 | * @return array |
159 | 159 | */ |
160 | - public static function createAuthority( $name, $email ){ |
|
160 | + public static function createAuthority($name, $email) { |
|
161 | 161 | return array( |
162 | 162 | 'name' => $name, |
163 | 163 | 'mbox' => 'mailto:' . $email, |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * Generates the result part of the statement |
171 | 171 | * @return array |
172 | 172 | */ |
173 | - public static function createResult( $result=array() ){ |
|
173 | + public static function createResult($result = array()) { |
|
174 | 174 | |
175 | 175 | return $result; |
176 | 176 | |
@@ -182,18 +182,18 @@ discard block |
||
182 | 182 | * @todo hardcoded for now |
183 | 183 | * @return array |
184 | 184 | */ |
185 | - public static function createContext( $extensions = array(), $additional=null ){ |
|
185 | + public static function createContext($extensions = array(), $additional = null) { |
|
186 | 186 | |
187 | 187 | $context = array( |
188 | 188 | 'platform' => 'Curatr' |
189 | 189 | ); |
190 | 190 | |
191 | - if( !empty($extensions) ){ |
|
192 | - $context['extensions'] = $extensions; |
|
191 | + if (!empty($extensions)) { |
|
192 | + $context[ 'extensions' ] = $extensions; |
|
193 | 193 | } |
194 | 194 | |
195 | - if( !is_null($additional) ){ |
|
196 | - $context = array_merge($context, $additional ); |
|
195 | + if (!is_null($additional)) { |
|
196 | + $context = array_merge($context, $additional); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | return $context; |
@@ -206,119 +206,119 @@ discard block |
||
206 | 206 | * @param string $key The verb to use |
207 | 207 | * @return array |
208 | 208 | */ |
209 | - public static function getVerb( $key ){ |
|
209 | + public static function getVerb($key) { |
|
210 | 210 | |
211 | 211 | $verbs = array(); |
212 | 212 | |
213 | 213 | $available_verbs = self::returnAvailableVerbs(); |
214 | 214 | |
215 | 215 | // add all official verbs |
216 | - foreach( $available_verbs as $v ){ |
|
217 | - $verbs[$v] = array( |
|
216 | + foreach ($available_verbs as $v) { |
|
217 | + $verbs[ $v ] = array( |
|
218 | 218 | "id" => "http://adlnet.gov/expapi/verbs/{$v}", |
219 | - "display" => array( "en-GB" => $v ), |
|
219 | + "display" => array("en-GB" => $v), |
|
220 | 220 | ); |
221 | 221 | } |
222 | 222 | |
223 | 223 | // Standard Verbs |
224 | - $verbs['commented'] = array( |
|
224 | + $verbs[ 'commented' ] = array( |
|
225 | 225 | "id" => "http://adlnet.gov/expapi/verbs/commented", |
226 | - "display" => array( "en-GB" => "commented on" ) |
|
226 | + "display" => array("en-GB" => "commented on") |
|
227 | 227 | ); |
228 | - $verbs['coached'] = array( |
|
228 | + $verbs[ 'coached' ] = array( |
|
229 | 229 | "id" => "http://learninglocker.net/verbs/coached-in", |
230 | - "display" => array( "en-GB" => "coached in" ) |
|
230 | + "display" => array("en-GB" => "coached in") |
|
231 | 231 | ); |
232 | - $verbs['mentored'] = array( |
|
232 | + $verbs[ 'mentored' ] = array( |
|
233 | 233 | "id" => "http://learninglocker.net/verbs/mentored-in", |
234 | - "display" => array( "en-GB" => "mentored in" ) |
|
234 | + "display" => array("en-GB" => "mentored in") |
|
235 | 235 | ); |
236 | - $verbs['observed'] = array( |
|
236 | + $verbs[ 'observed' ] = array( |
|
237 | 237 | "id" => "http://learninglocker.net/verbs/observed-in", |
238 | - "display" => array( "en-GB" => "observed in" ) |
|
238 | + "display" => array("en-GB" => "observed in") |
|
239 | 239 | ); |
240 | - $verbs['trained'] = array( |
|
240 | + $verbs[ 'trained' ] = array( |
|
241 | 241 | "id" => "http://learninglocker.net/verbs/trained-in", |
242 | - "display" => array( "en-GB" => "trained in" ) |
|
242 | + "display" => array("en-GB" => "trained in") |
|
243 | 243 | ); |
244 | - $verbs['endorsed'] = array( |
|
244 | + $verbs[ 'endorsed' ] = array( |
|
245 | 245 | "id" => "http://learninglocker.net/verbs/endorsed-in", |
246 | - "display" => array( "en-GB" => "endorsed in" ) |
|
246 | + "display" => array("en-GB" => "endorsed in") |
|
247 | 247 | ); |
248 | - $verbs['posted'] = array( |
|
248 | + $verbs[ 'posted' ] = array( |
|
249 | 249 | "id" => "http://curatr3.com/define/verb/posted", |
250 | - "display" => array( "en-GB" => "posted" ) |
|
250 | + "display" => array("en-GB" => "posted") |
|
251 | 251 | ); |
252 | - $verbs['published'] = array( |
|
252 | + $verbs[ 'published' ] = array( |
|
253 | 253 | "id" => "http://curatr3.com/define/verb/published", |
254 | - "display" => array( "en-GB" => "published" ) |
|
254 | + "display" => array("en-GB" => "published") |
|
255 | 255 | ); |
256 | - $verbs['read'] = array( |
|
256 | + $verbs[ 'read' ] = array( |
|
257 | 257 | "id" => "http://curatr3.com/define/verb/read", |
258 | - "display" => array( "en-GB" => "read" ) |
|
258 | + "display" => array("en-GB" => "read") |
|
259 | 259 | ); |
260 | - $verbs['liked'] = array( |
|
260 | + $verbs[ 'liked' ] = array( |
|
261 | 261 | "id" => "http://curatr3.com/define/verb/liked", |
262 | - "display" => array( "en-GB" => "liked" ) |
|
262 | + "display" => array("en-GB" => "liked") |
|
263 | 263 | ); |
264 | - $verbs['bookmarked'] = array( |
|
264 | + $verbs[ 'bookmarked' ] = array( |
|
265 | 265 | "id" => "http://curatr3.com/define/verb/bookmarked", |
266 | - "display" => array( "en-GB" => "bookmarked" ) |
|
266 | + "display" => array("en-GB" => "bookmarked") |
|
267 | 267 | ); |
268 | - $verbs['earned'] = array( |
|
268 | + $verbs[ 'earned' ] = array( |
|
269 | 269 | "id" => "http://curatr3.com/define/verb/earned", |
270 | - "display" => array( "en-GB" => "earned" ) |
|
270 | + "display" => array("en-GB" => "earned") |
|
271 | 271 | ); |
272 | - $verbs['badge_earned'] = array( |
|
272 | + $verbs[ 'badge_earned' ] = array( |
|
273 | 273 | "id" => "http://specification.openbadges.org/xapi/verbs/earned", |
274 | - "display" => array( "en-GB" => "earned" ) |
|
274 | + "display" => array("en-GB" => "earned") |
|
275 | 275 | ); |
276 | - $verbs['login'] = array( |
|
276 | + $verbs[ 'login' ] = array( |
|
277 | 277 | "id" => "https://brindlewaye.com/xAPITerms/verbs/loggedin/", |
278 | - "display" => array( "en-GB" => "logged in to" ) |
|
278 | + "display" => array("en-GB" => "logged in to") |
|
279 | 279 | ); |
280 | - $verbs['logout'] = array( |
|
280 | + $verbs[ 'logout' ] = array( |
|
281 | 281 | "id" => "http://curatr3.com/define/verb/logout", |
282 | - "display" => array( "en-GB" => "logged out of" ) |
|
282 | + "display" => array("en-GB" => "logged out of") |
|
283 | 283 | ); |
284 | - $verbs['edited'] = array( |
|
284 | + $verbs[ 'edited' ] = array( |
|
285 | 285 | "id" => "http://curatr3.com/define/verb/edited", |
286 | - "display" => array( "en-GB" => "edited" ) |
|
286 | + "display" => array("en-GB" => "edited") |
|
287 | 287 | ); |
288 | - $verbs['uploaded'] = array( |
|
288 | + $verbs[ 'uploaded' ] = array( |
|
289 | 289 | "id" => "http://curatr3.com/define/verb/uploaded", |
290 | - "display" => array( "en-GB" => "uploaded" ) |
|
290 | + "display" => array("en-GB" => "uploaded") |
|
291 | 291 | ); |
292 | - $verbs['accessed'] = array( |
|
292 | + $verbs[ 'accessed' ] = array( |
|
293 | 293 | "id" => "http://activitystrea.ms/schema/1.0/access", |
294 | - "display" => array( "en-GB" => "accessed" ) |
|
294 | + "display" => array("en-GB" => "accessed") |
|
295 | 295 | ); |
296 | - $verbs['voted-up'] = array( |
|
296 | + $verbs[ 'voted-up' ] = array( |
|
297 | 297 | "id" => "http://curatr3.com/define/verb/voted-up", |
298 | - "display" => array( "en-GB" => "voted up" ) |
|
298 | + "display" => array("en-GB" => "voted up") |
|
299 | 299 | ); |
300 | - $verbs['voted-down'] = array( |
|
300 | + $verbs[ 'voted-down' ] = array( |
|
301 | 301 | "id" => "http://curatr3.com/define/verb/voted-down", |
302 | - "display" => array( "en-GB" => "voted down" ) |
|
302 | + "display" => array("en-GB" => "voted down") |
|
303 | 303 | ); |
304 | - $verbs['flag-as-inappropriate'] = array( |
|
304 | + $verbs[ 'flag-as-inappropriate' ] = array( |
|
305 | 305 | "id" => "http://activitystrea.ms/schema/1.0/flag-as-inappropriate", |
306 | - "display" => array( "en-GB" => "flagged as inappropriate" ) |
|
306 | + "display" => array("en-GB" => "flagged as inappropriate") |
|
307 | 307 | ); |
308 | - $verbs['join'] = array( |
|
308 | + $verbs[ 'join' ] = array( |
|
309 | 309 | "id" => "http://activitystrea.ms/schema/1.0/join", |
310 | - "display" => array( "en-GB" => "joined" ) |
|
310 | + "display" => array("en-GB" => "joined") |
|
311 | 311 | ); |
312 | - $verbs['leave'] = array( |
|
312 | + $verbs[ 'leave' ] = array( |
|
313 | 313 | "id" => "http://activitystrea.ms/schema/1.0/leave", |
314 | - "display" => array( "en-GB" => "left" ) |
|
314 | + "display" => array("en-GB" => "left") |
|
315 | 315 | ); |
316 | - $verbs['opened'] = array( |
|
316 | + $verbs[ 'opened' ] = array( |
|
317 | 317 | "id" => "http://activitystrea.ms/schema/1.0/open", |
318 | - "display" => array( "en-GB" => "opened" ) |
|
318 | + "display" => array("en-GB" => "opened") |
|
319 | 319 | ); |
320 | 320 | |
321 | - return self::checkKey( $verbs, $key, $verbs['experienced']); |
|
321 | + return self::checkKey($verbs, $key, $verbs[ 'experienced' ]); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | * @return array |
332 | 332 | * |
333 | 333 | */ |
334 | - public static function createObject( $id, $name=null, $description=null, $type=null, $extensions = array() ) |
|
334 | + public static function createObject($id, $name = null, $description = null, $type = null, $extensions = array()) |
|
335 | 335 | { |
336 | 336 | $object = array( |
337 | 337 | 'objectType' => 'Activity', |
@@ -341,27 +341,27 @@ discard block |
||
341 | 341 | $definition = array(); |
342 | 342 | |
343 | 343 | if (!empty($name)) { |
344 | - $definition['name'] = [ |
|
344 | + $definition[ 'name' ] = [ |
|
345 | 345 | 'en-GB' => $name |
346 | 346 | ]; |
347 | 347 | } |
348 | 348 | |
349 | - if( !empty($description)){ |
|
350 | - $definition['description'] = [ |
|
349 | + if (!empty($description)) { |
|
350 | + $definition[ 'description' ] = [ |
|
351 | 351 | 'en-GB'=>$description |
352 | 352 | ]; |
353 | 353 | } |
354 | 354 | |
355 | - if( !empty($type)){ |
|
356 | - $definition['type'] = $type; |
|
355 | + if (!empty($type)) { |
|
356 | + $definition[ 'type' ] = $type; |
|
357 | 357 | } |
358 | 358 | |
359 | - if( !empty($extensions) ){ |
|
360 | - $definition['extensions'] = $extensions; |
|
359 | + if (!empty($extensions)) { |
|
360 | + $definition[ 'extensions' ] = $extensions; |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | if (!empty($definition)) { |
364 | - $object['definition'] = $definition; |
|
364 | + $object[ 'definition' ] = $definition; |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | return $object; |
@@ -370,13 +370,13 @@ discard block |
||
370 | 370 | |
371 | 371 | |
372 | 372 | public function sendRequests() { |
373 | - foreach( $this->endpoints as $name => $ep ){ |
|
373 | + foreach ($this->endpoints as $name => $ep) { |
|
374 | 374 | |
375 | 375 | $username = $ep->username; |
376 | 376 | $password = $ep->key; |
377 | 377 | $url = $ep->url; |
378 | 378 | |
379 | - if(substr($url, -1) !== '/') { |
|
379 | + if (substr($url, -1) !== '/') { |
|
380 | 380 | $url .= '/'; |
381 | 381 | } |
382 | 382 | |
@@ -395,74 +395,74 @@ discard block |
||
395 | 395 | * Send the request to all end points defined in the endpoints array |
396 | 396 | * @return array An array of all requests sent and their responses |
397 | 397 | */ |
398 | - public function sendRequestsOld(){ |
|
398 | + public function sendRequestsOld() { |
|
399 | 399 | $error = $this->checkError(); |
400 | - if( $error ) return false; |
|
400 | + if ($error) return false; |
|
401 | 401 | |
402 | 402 | $results = array(); |
403 | 403 | |
404 | 404 | |
405 | - foreach( $this->endpoints as $name => $ep ){ |
|
405 | + foreach ($this->endpoints as $name => $ep) { |
|
406 | 406 | |
407 | 407 | $username = $ep->username; |
408 | 408 | $password = $ep->key; |
409 | 409 | $url = $ep->url; |
410 | - $auth = base64_encode( $username.':'.$password ); |
|
410 | + $auth = base64_encode($username . ':' . $password); |
|
411 | 411 | |
412 | 412 | $result = $this->make_request($auth, $url, $this->statement); |
413 | 413 | $error = false; |
414 | 414 | $error_type = ""; |
415 | 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 | 420 | } else { |
421 | 421 | |
422 | - $body = isset($result['body']) ? json_decode($result['body']) : ""; |
|
422 | + $body = isset($result[ 'body' ]) ? json_decode($result[ 'body' ]) : ""; |
|
423 | 423 | |
424 | - if( isset($body->success) ){ |
|
425 | - if( $body->success == false ){ |
|
424 | + if (isset($body->success)) { |
|
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 | - if( isset($body->error) ){ |
|
432 | - if( $body->error == true ){ |
|
431 | + if (isset($body->error)) { |
|
432 | + if ($body->error == true) { |
|
433 | 433 | $error = true; |
434 | 434 | $error_type = "LRS returned error as true"; |
435 | 435 | } |
436 | 436 | } |
437 | - if( isset($result['status']) ){ |
|
438 | - $status = $result['status']; |
|
437 | + if (isset($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 ){ |
|
452 | - $this->log->error( 'Statement Failed', array( |
|
451 | + if ($error) { |
|
452 | + $this->log->error('Statement Failed', array( |
|
453 | 453 | 'curl_result' => $result, |
454 | 454 | 'type' => $error_type, |
455 | 455 | 'url' => $ep->url, |
456 | 456 | 'statement' => $this->statement |
457 | 457 | )); |
458 | 458 | } else { |
459 | - $this->log->info( 'Sent', array( |
|
459 | + $this->log->info('Sent', array( |
|
460 | 460 | 'url' => $ep->url, |
461 | 461 | 'statement' => $this->statement |
462 | 462 | )); |
463 | 463 | } |
464 | 464 | |
465 | - $results[$url] = $body; |
|
465 | + $results[ $url ] = $body; |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | |
@@ -480,35 +480,35 @@ discard block |
||
480 | 480 | * @param array $statement The statement to be encoded |
481 | 481 | * @return boolean/array Returns false on fail, array of details on success |
482 | 482 | */ |
483 | - public function make_request( $auth, $url, $statement ) { |
|
483 | + public function make_request($auth, $url, $statement) { |
|
484 | 484 | |
485 | - $headers = array( |
|
486 | - 'Authorization: Basic '.$auth, |
|
485 | + $headers = array( |
|
486 | + 'Authorization: Basic ' . $auth, |
|
487 | 487 | 'Content-Type: application/json; charset=UTF-8', |
488 | 488 | 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', |
489 | 489 | 'X-Experience-API-Version: 1.0.0' |
490 | 490 | ); |
491 | 491 | |
492 | - if(substr($url, -1) !== '/') { |
|
492 | + if (substr($url, -1) !== '/') { |
|
493 | 493 | $url .= '/'; |
494 | 494 | } |
495 | 495 | |
496 | - $ch = curl_init( $url . 'statements' ); |
|
497 | - curl_setopt( $ch, CURLOPT_POST, 1); |
|
498 | - curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode($statement) ); |
|
499 | - curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1); |
|
500 | - curl_setopt( $ch, CURLOPT_HEADER, 1); |
|
501 | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); |
|
502 | - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers ); |
|
496 | + $ch = curl_init($url . 'statements'); |
|
497 | + curl_setopt($ch, CURLOPT_POST, 1); |
|
498 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($statement)); |
|
499 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
|
500 | + curl_setopt($ch, CURLOPT_HEADER, 1); |
|
501 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
502 | + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
|
503 | 503 | |
504 | - if( substr($url, 0, 5) == "https" ){ |
|
504 | + if (substr($url, 0, 5) == "https") { |
|
505 | 505 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
506 | 506 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); |
507 | - curl_setopt ($ch, CURLOPT_CAINFO, storage_path()."/cacert.pem"); |
|
507 | + curl_setopt($ch, CURLOPT_CAINFO, storage_path() . "/cacert.pem"); |
|
508 | 508 | } |
509 | 509 | |
510 | - $response = curl_exec( $ch ); |
|
511 | - if( $response === false ){ |
|
510 | + $response = curl_exec($ch); |
|
511 | + if ($response === false) { |
|
512 | 512 | return array('error'=>true, 'curl_error'=>curl_error($ch)); |
513 | 513 | } else { |
514 | 514 | $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); |
@@ -523,23 +523,23 @@ discard block |
||
523 | 523 | } |
524 | 524 | } |
525 | 525 | |
526 | - private function checkError(){ |
|
527 | - if( empty($this->statement) ){ |
|
526 | + private function checkError() { |
|
527 | + if (empty($this->statement)) { |
|
528 | 528 | $this->error("No data set"); |
529 | 529 | return true; |
530 | 530 | } |
531 | 531 | |
532 | - if( !isset($this->statement['actor']) ){ |
|
532 | + if (!isset($this->statement[ 'actor' ])) { |
|
533 | 533 | $this->error("No actor set"); |
534 | 534 | return true; |
535 | 535 | } |
536 | 536 | |
537 | - if( !isset($this->statement['verb']) ){ |
|
537 | + if (!isset($this->statement[ 'verb' ])) { |
|
538 | 538 | $this->error("No verb set"); |
539 | 539 | return true; |
540 | 540 | } |
541 | 541 | |
542 | - if( !isset($this->statement['object']) ){ |
|
542 | + if (!isset($this->statement[ 'object' ])) { |
|
543 | 543 | $this->error("No object set"); |
544 | 544 | return true; |
545 | 545 | } |
@@ -547,15 +547,15 @@ discard block |
||
547 | 547 | return false; |
548 | 548 | } |
549 | 549 | |
550 | - private function error( $message ){ |
|
551 | - $this->log->error( "Statement Generator Error: ".$message ); |
|
550 | + private function error($message) { |
|
551 | + $this->log->error("Statement Generator Error: " . $message); |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | /** |
555 | 555 | * We will probably move this to the db, or hook into an existing service? |
556 | 556 | * |
557 | 557 | **/ |
558 | - private static function returnAvailableVerbs(){ |
|
558 | + private static function returnAvailableVerbs() { |
|
559 | 559 | return array( |
560 | 560 | 'answered', |
561 | 561 | 'asked', |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | 'voided'); |
585 | 585 | } |
586 | 586 | |
587 | - public static function makeEndpoint( $url, $username, $password ){ |
|
587 | + public static function makeEndpoint($url, $username, $password) { |
|
588 | 588 | $ep = new \stdClass; |
589 | 589 | $ep->url = $url; |
590 | 590 | $ep->username = $username; |
@@ -397,7 +397,9 @@ |
||
397 | 397 | */ |
398 | 398 | public function sendRequestsOld(){ |
399 | 399 | $error = $this->checkError(); |
400 | - if( $error ) return false; |
|
400 | + if( $error ) { |
|
401 | + return false; |
|
402 | + } |
|
401 | 403 | |
402 | 404 | $results = array(); |
403 | 405 |