diff --git a/.gitignore b/.gitignore index 7ed14b6..0e4ae5a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ vendor/* composer.lock composer.phar .token -.school \ No newline at end of file +.school +.idea \ No newline at end of file diff --git a/readme.md b/readme.md index 69f5573..0fec0eb 100644 --- a/readme.md +++ b/readme.md @@ -145,6 +145,60 @@ foreach ($school->achievements->all() as $achievement) { echo $achievement->comment . PHP_EOL; } ``` + +### POST Achievements + +```php +$client = new \Wonde\Client('TOKEN_GOES_HERE'); +$school = $client->school('SCHOOL_ID_GOES_HERE'); + +$array = [ + 'students' => [ + [ + 'student_id' => 'A1039521228', + 'points' => 200, + 'award' => 'TROP', + 'award_date' => '2016-04-05', + ], + ], + 'employee_id' => 'A1375078684', + 'date' => '2016-04-04', + 'type' => 'NYPA', + 'comment' => 'A4', + 'activity_type' => 'RE', +]; + +try { + $response = $school->achievements->create($array); +} catch (\Wonde\Exceptions\ValidationError $error) { + $errors = $error->getErrors(); +} +``` + +### DELETE Achievements + +```php +$client = new \Wonde\Client('TOKEN_GOES_HERE'); + +$school = $client->school('SCHOOL_ID_GOES_HERE'); + +$school->achievements->delete('WONDE_ACHIEVEMENTS_ID_HERE'); +``` + +### Achievements Attributes + +```php +$client = new \Wonde\Client('TOKEN_GOES_HERE'); + +$school = $client->school('SCHOOL_ID_GOES_HERE'); + +// Get achievement attributes +foreach ($school->achievementsAttributes->all() as $achievement) { + echo $achievement->id . PHP_EOL; +} +``` + + ### Assessment - (BETA) This endpoint is included in the stable release but is likely to change in the future. Please contact support for more information. @@ -245,6 +299,68 @@ foreach ($school->behaviours->all() as $behaviour) { } ``` +### POST Behaviours + +```php +$client = new \Wonde\Client('TOKEN_GOES_HERE'); +$school = $client->school('SCHOOL_ID_GOES_HERE'); + +$array = [ + 'students' => [ + [ + 'student_id' => 'A1039521228', + 'role' => 'AG', + 'action' => 'COOL', + 'action_date' => '2016-04-01', + 'points' => 200, + ], + [ + 'student_id' => 'A870869351', + 'role' => 'TA', + 'points' => 2, + ], + ], + 'employee_id' => 'A1375078684', + 'date' => '2016-03-31', + 'status' => 'REV2', + 'type' => 'BULL', + 'bullying_type' => 'B_INT', + 'comment' => 'Bulling incident', + 'activity_type' => 'RE', + 'location' => 'CORR', + 'time' => 'LUN', +]; + +try { + $response = $school->behaviours->create($array); +} catch (\Wonde\Exceptions\ValidationError $error) { + $errors = $error->getErrors(); +} +``` + +### DELETE Behaviours + +```php +$client = new \Wonde\Client('TOKEN_GOES_HERE'); + +$school = $client->school('SCHOOL_ID_GOES_HERE'); + +$school->behaviours->delete('WONDE_BEHAVIOUR_ID_HERE'); +``` + +### Behaviours Attributes + +```php +$client = new \Wonde\Client('TOKEN_GOES_HERE'); + +$school = $client->school('SCHOOL_ID_GOES_HERE'); + +// Get behaviours +foreach ($school->behavioursAttributes->all() as $behaviour) { + echo $behaviour->id . PHP_EOL; +} +``` + ### Classes ```php diff --git a/src/Client.php b/src/Client.php index 29fa91e..85b443f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -71,7 +71,7 @@ public function revokeAccess($schoolId) { $uri = 'schools/' . $schoolId . '/revoke-access'; - return (new BootstrapEndpoint($this->token, $uri))->delete(); + return (new BootstrapEndpoint($this->token, $uri))->deleteRequestReturnBody($uri); } } diff --git a/src/Endpoints/Achievements.php b/src/Endpoints/Achievements.php index 9551cf6..06be90b 100644 --- a/src/Endpoints/Achievements.php +++ b/src/Endpoints/Achievements.php @@ -1,9 +1,33 @@ uri . $id); + } + + /** + * Create a achievement record + * + * @param $array + * @return \stdClass + */ + public function create($array) + { + return parent::post($array); + } } \ No newline at end of file diff --git a/src/Endpoints/AchievementsAttributes.php b/src/Endpoints/AchievementsAttributes.php new file mode 100644 index 0000000..3063a6c --- /dev/null +++ b/src/Endpoints/AchievementsAttributes.php @@ -0,0 +1,9 @@ +uri . $id); + } + + /** + * Create a behaviour record + * + * @param $array + * @return \stdClass + */ + public function create($array) + { + return parent::post($array); + } } \ No newline at end of file diff --git a/src/Endpoints/BehavioursAttributes.php b/src/Endpoints/BehavioursAttributes.php new file mode 100644 index 0000000..e2ec33e --- /dev/null +++ b/src/Endpoints/BehavioursAttributes.php @@ -0,0 +1,9 @@ +client()->delete($url, $body); + /** @var Response $response */ + $response = $this->deleteUrl(self::endpoint . $endpoint, $body); + return json_decode($response->getBody()->getContents()); } /** - * Make a delete request and decode the response + * Make a delete request to url * + * @param $url * @param array $body - * @return \stdClass + * @return mixed|\Psr\Http\Message\ResponseInterface */ - public function delete($body = []) + private function deleteUrl($url, $body = []) { - $body = ['body' => json_encode($body)]; - $body['headers']['Content-Type'] = 'application/json'; - - try { - $delete = $this->deleteRequest($this->uri, $body); - } catch ( ClientException $exception ) { - return $this->throwError($exception); - } - - $response = $delete->getBody()->getContents(); - - $decoded = json_decode($response); - - return $decoded; + return $this->client()->delete($url, $body); } } \ No newline at end of file diff --git a/src/Endpoints/Schools.php b/src/Endpoints/Schools.php index ae85c5c..2cb058f 100644 --- a/src/Endpoints/Schools.php +++ b/src/Endpoints/Schools.php @@ -109,6 +109,7 @@ class Schools extends BootstrapEndpoint /** * Schools constructor. + * * @param string $uri */ public function __construct($token, $id = false) @@ -119,26 +120,28 @@ public function __construct($token, $id = false) $this->uri = $this->uri . $id . '/'; } - $this->achievements = new Achievements($token, $this->uri); - $this->assessment = new Assessment($token, $this->uri); - $this->attendance = new Attendance($token, $this->uri); - $this->behaviours = new Behaviours($token, $this->uri); - $this->classes = new Classes($token, $this->uri); - $this->contacts = new Contacts($token, $this->uri); - $this->counts = new Counts($token, $this->uri); - $this->deletions = new Deletions($token, $this->uri); - $this->employees = new Employees($token, $this->uri); - $this->events = new Events($token, $this->uri); - $this->groups = new Groups($token, $this->uri); - $this->lessons = new Lessons($token, $this->uri); - $this->lessonAttendance = new LessonAttendance($token, $this->uri); - $this->medicalConditions = new MedicalConditions($token, $this->uri); - $this->medicalEvents = new MedicalEvents($token, $this->uri); - $this->periods = new Periods($token, $this->uri); - $this->photos = new Photos($token, $this->uri); - $this->rooms = new Rooms($token, $this->uri); - $this->students = new Students($token, $this->uri); - $this->subjects = new Subjects($token, $this->uri); + $this->achievements = new Achievements($token, $this->uri); + $this->achievementsAttributes = new AchievementsAttributes($token, $this->uri); + $this->assessment = new Assessment($token, $this->uri); + $this->attendance = new Attendance($token, $this->uri); + $this->behaviours = new Behaviours($token, $this->uri); + $this->behavioursAttributes = new BehavioursAttributes($token, $this->uri); + $this->classes = new Classes($token, $this->uri); + $this->contacts = new Contacts($token, $this->uri); + $this->counts = new Counts($token, $this->uri); + $this->deletions = new Deletions($token, $this->uri); + $this->employees = new Employees($token, $this->uri); + $this->events = new Events($token, $this->uri); + $this->groups = new Groups($token, $this->uri); + $this->lessons = new Lessons($token, $this->uri); + $this->lessonAttendance = new LessonAttendance($token, $this->uri); + $this->medicalConditions = new MedicalConditions($token, $this->uri); + $this->medicalEvents = new MedicalEvents($token, $this->uri); + $this->periods = new Periods($token, $this->uri); + $this->photos = new Photos($token, $this->uri); + $this->rooms = new Rooms($token, $this->uri); + $this->students = new Students($token, $this->uri); + $this->subjects = new Subjects($token, $this->uri); } /** diff --git a/tests/AssessmentTest.php b/tests/AssessmentTest.php new file mode 100644 index 0000000..f3bbeee --- /dev/null +++ b/tests/AssessmentTest.php @@ -0,0 +1,71 @@ +school = $client->school(file_get_contents(__DIR__ . '/../.school')); + } + + public function test_templates() + { + $items = []; + foreach ($this->school->assessment->templates->all() as $row) { + $items[] = $row; + $this->assertTrue($row instanceof stdClass); + $this->assertNotEmpty($row); + } + $this->assertTrue($items > 10); + } + + public function test_aspects() + { + $items = []; + foreach ($this->school->assessment->aspects->all() as $row) { + $items[] = $row; + $this->assertTrue($row instanceof stdClass); + $this->assertNotEmpty($row); + } + $this->assertTrue($items > 10); + } + + public function test_results() + { + $items = []; + foreach ($this->school->assessment->results->all() as $row) { + $items[] = $row; + $this->assertTrue($row instanceof stdClass); + $this->assertNotEmpty($row); + } + $this->assertTrue($items > 10); + } + + public function test_resultsets() + { + $items = []; + foreach ($this->school->assessment->resultsets->all() as $row) { + $items[] = $row; + $this->assertTrue($row instanceof stdClass); + $this->assertNotEmpty($row); + } + $this->assertTrue($items > 10); + } + + public function test_marksheets() + { + $items = []; + foreach ($this->school->assessment->marksheets->all() as $row) { + $items[] = $row; + $this->assertTrue($row instanceof stdClass); + $this->assertNotEmpty($row); + } + $this->assertTrue($items > 10); + } +} \ No newline at end of file diff --git a/tests/ClientTest.php b/tests/ClientTest.php deleted file mode 100644 index f3beccf..0000000 --- a/tests/ClientTest.php +++ /dev/null @@ -1,12 +0,0 @@ -school = $client->school(file_get_contents(__DIR__ . '/../.school')); - - } -} \ No newline at end of file diff --git a/tests_full/MiscEndPointsTest.php b/tests/MiscEndPointsTest.php similarity index 54% rename from tests_full/MiscEndPointsTest.php rename to tests/MiscEndPointsTest.php index 3746364..0a06031 100644 --- a/tests_full/MiscEndPointsTest.php +++ b/tests/MiscEndPointsTest.php @@ -7,11 +7,38 @@ class MiscEndPointsTest extends PHPUnit_Framework_TestCase */ public $school; + private $token; + + private $schoolId; + + /** + * @var \Wonde\Client + */ + private $client; + public function setUp() { - ini_set('memory_limit','3000M'); - $client = new \Wonde\Client(file_get_contents(__DIR__ . '/../.token')); - $this->school = $client->school(file_get_contents(__DIR__ . '/../.school')); + ini_set('memory_limit', '3000M'); + $this->token = file_get_contents(__DIR__ . '/../.token'); + $this->client = new \Wonde\Client($this->token); + $this->schoolId = file_get_contents(__DIR__ . '/../.school'); + $this->school = $this->client->school($this->schoolId); + } + + public function test_request_access() + { + $response = $this->client->requestAccess($this->schoolId); + } + + public function test_revoke_access() + { + $response = $this->client->revokeAccess($this->schoolId); + } + + public function test_single_school() + { + $school = $this->client->schools->get(file_get_contents(__DIR__ . '/../.school')); + $this->assertTrue($school instanceof stdClass); } public function tests_students() @@ -157,6 +184,17 @@ public function test_achievements() $this->assertTrue($items > 10); } + public function test_achievements_attributes() + { + $items = []; + foreach ($this->school->achievementsAttributes->all() as $row) { + $items[] = $row; + $this->assertTrue($row instanceof stdClass); + $this->assertNotEmpty($row); + } + $this->assertTrue($items > 10); + } + public function test_behaviour() { $items = []; @@ -167,4 +205,88 @@ public function test_behaviour() } $this->assertTrue($items > 10); } -} \ No newline at end of file + + public function test_behaviour_attributes() + { + $items = []; + foreach ($this->school->behavioursAttributes->all() as $row) { + $items[] = $row; + $this->assertTrue($row instanceof stdClass); + $this->assertNotEmpty($row); + } + $this->assertTrue($items > 10); + } + + public function test_delete_behaviour() + { + $response = $this->school->behaviours->delete('A1971302099'); + $this->assertTrue($response instanceof stdClass); + } + + public function test_delete_achievement() + { + $response = $this->school->achievements->delete('A125747323'); + $this->assertTrue($response instanceof stdClass); + } + + public function test_behaviour_post() + { + $array = [ + 'students' => [ + [ + 'student_id' => 'A1039521228', + 'role' => 'AG', + 'action' => 'COOL', + 'action_date' => '2016-04-01', + 'points' => 200, + ], + [ + 'student_id' => 'A870869351', + 'role' => 'TA', + 'points' => 2, + ], + ], + 'employee_id' => 'A1375078684', + 'date' => '2016-03-31', + 'status' => 'REV2', + 'type' => 'BULL', + 'bullying_type' => 'B_INT', + 'comment' => 'Bulling incident', + 'activity_type' => 'RE', + 'location' => 'CORR', + 'time' => 'LUN', + ]; + + try { + $response = $this->school->behaviours->create($array); + } catch ( \Wonde\Exceptions\ValidationError $error ) { + $errors = $error->getErrors(); + } + } + + public function test_achievement_post() + { + $array = [ + 'students' => [ + [ + 'student_id' => 'A1039521228', + 'points' => 200, + 'award' => 'TROP', + 'award_date' => '2016-04-05', + ], + ], + 'employee_id' => 'A1375078684', + 'date' => '2016-04-04', + 'type' => 'NYPA', + 'comment' => 'A4', + 'activity_type' => 'RE', + ]; + + try { + $response = $this->school->achievements->create($array); + } catch ( \Wonde\Exceptions\ValidationError $error ) { + $errors = $error->getErrors(); + } + } +} + diff --git a/tests_full/AssessmentTest.php b/tests_full/AssessmentTest.php deleted file mode 100644 index e118831..0000000 --- a/tests_full/AssessmentTest.php +++ /dev/null @@ -1,71 +0,0 @@ -school = $client->school(file_get_contents(__DIR__ . '/../.school')); -// } -// -// public function test_templates() -// { -// $items = []; -// foreach ($this->school->assessment->templates->all() as $row) { -// $items[] = $row; -// $this->assertTrue($row instanceof stdClass); -// $this->assertNotEmpty($row); -// } -// $this->assertTrue($items > 10); -// } -// -// public function test_aspects() -// { -// $items = []; -// foreach ($this->school->assessment->aspects->all() as $row) { -// $items[] = $row; -// $this->assertTrue($row instanceof stdClass); -// $this->assertNotEmpty($row); -// } -// $this->assertTrue($items > 10); -// } -// -// public function test_results() -// { -// $items = []; -// foreach ($this->school->assessment->results->all() as $row) { -// $items[] = $row; -// $this->assertTrue($row instanceof stdClass); -// $this->assertNotEmpty($row); -// } -// $this->assertTrue($items > 10); -// } -// -// public function test_resultsets() -// { -// $items = []; -// foreach ($this->school->assessment->resultsets->all() as $row) { -// $items[] = $row; -// $this->assertTrue($row instanceof stdClass); -// $this->assertNotEmpty($row); -// } -// $this->assertTrue($items > 10); -// } -// -// public function test_marksheets() -// { -// $items = []; -// foreach ($this->school->assessment->marksheets->all() as $row) { -// $items[] = $row; -// $this->assertTrue($row instanceof stdClass); -// $this->assertNotEmpty($row); -// } -// $this->assertTrue($items > 10); -// } -//} \ No newline at end of file