Skip to content

Commit

Permalink
Merge pull request #34 from bookboon/hotfix/book-type
Browse files Browse the repository at this point in the history
Hotfix/book type
  • Loading branch information
lkm committed Jan 31, 2019
2 parents e9df690 + 9ccd486 commit 05e474c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/Entity/AudioTalkBook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Bookboon\Api\Entity;

class AudioTalkBook extends Book
{
const _OWN_TYPE = Book::TYPE_AUDIOTALK;
}
13 changes: 10 additions & 3 deletions src/Entity/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
use Bookboon\Api\Client\ClientInterface;
use Bookboon\Api\Exception\UsageException;

class Book extends Entity
abstract class Book extends Entity
{
const _OWN_TYPE = '';

const TYPE_AUDIO = 'audio';
const TYPE_PDF = 'pdf';
const TYPE_VIDEO = 'video';
const TYPE_AUDIOTALK = 'audioTalk';

const FORMAT_PDF = 'pdf';
const FORMAT_EPUB = 'epub';
Expand Down Expand Up @@ -111,7 +112,7 @@ public static function getAll(
* @param array $objectArray
* @return Book
*/
private static function objectTransformer(array $objectArray)
public static function objectTransformer(array $objectArray)
{
$className = 'Bookboon\Api\Entity\\' . ucfirst($objectArray['_type']) . 'Book';
return new $className($objectArray);
Expand All @@ -125,7 +126,13 @@ public static function getEntitiesFromArray(array $array)
{
$entities = [];
foreach ($array as $object) {
$entities[] = self::objectTransformer($object);
if (in_array(
$object['_type'],
[self::TYPE_PDF, self::TYPE_AUDIO, self::TYPE_VIDEO, self::TYPE_AUDIOTALK],
true)
) {
$entities[] = self::objectTransformer($object);
}
}

return $entities;
Expand Down
3 changes: 1 addition & 2 deletions src/Entity/Exam.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,10 @@ public function getTimeSeconds()
* Return book to which the exam is related
*
* @return Book
* @throws \Bookboon\Api\Exception\EntityDataException
*/
public function getBook()
{
return new Book($this->safeGet('book', []));
return Book::objectTransformer($this->safeGet('book', []));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Entity/BookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function testHasPdf()
*/
public function testInvalidBook()
{
$book = new Book(['blah']);
$book = new PdfBook(['blah']);
}

public function testBookDownloadOauth()
Expand Down

0 comments on commit 05e474c

Please sign in to comment.