Skip to content

Commit

Permalink
Merge pull request #4 from Weebly/authors-list
Browse files Browse the repository at this point in the history
getting authors with posts
  • Loading branch information
eaperezc authored Nov 16, 2018
2 parents c0601f4 + 30ba781 commit a0e5613
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 58 deletions.
121 changes: 65 additions & 56 deletions src/Entities/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,66 @@

class Post extends JsonSerializableObject
{
protected $id;
protected $uuid;
protected $title;
protected $slug;
protected $markdown;
protected $html;
protected $id;
protected $uuid;
protected $title;
protected $slug;
protected $markdown;
protected $html;
protected $plaintext;
protected $featured;
protected $page;
protected $status;
protected $locale;
protected $metaTitle;
protected $metaDescription;
protected $createdAt;
protected $createdBy;
protected $updatedAt;
protected $updatedBy;
protected $publishedAt;
protected $publishedBy;
protected $author;
protected $url;
protected $language;
protected $visibility;
protected $featureImage;
protected $tags;


/**
protected $image;
protected $featured;
protected $page;
protected $status;
protected $locale;
protected $metaTitle;
protected $metaDescription;
protected $createdAt;
protected $createdBy;
protected $updatedAt;
protected $updatedBy;
protected $publishedAt;
protected $publishedBy;
protected $authors;
protected $url;
protected $language;
protected $visibility;
protected $featureImage;
protected $tags;


/**
* Constructor. We want to make sure that when we send data to it, it will
* add those values to the property of the object.
* @param array $data Data for the object
* @param array $data Data for the object
*/
function __construct($data = null)
{
if ($data) {
foreach ($data as $key => $value) {

// Here we will create the tags collection of all the
// tags that are related to this post
if ($key == 'tags') {

// Cleanup the data into objects
$tagCollection = new Collection();
foreach ($value as $tagData) {
$tag = new Tag($tagData);
$tagCollection->add($tag);
}

$this->tags = $tagCollection;
continue;
}

$key = str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
$key = lcfirst($key);

$this->{$key} = $value;
}
}
}
{
if ($data) {
foreach ($data as $key => $value) {

// Here we will create the tags collection of all the
// tags that are related to this post
if ($key == 'tags') {

// Cleanup the data into objects
$tagCollection = new Collection();
foreach ($value as $tagData) {
$tag = new Tag($tagData);
$tagCollection->add($tag);
}

$this->tags = $tagCollection;
continue;
}

$key = str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
$key = lcfirst($key);

$this->{$key} = $value;
}
}
}


/**
Expand Down Expand Up @@ -116,6 +117,14 @@ public function getHtml()
return $this->html;
}

/**
* @return string
*/
public function getImage()
{
return $this->image;
}

/**
* @return string
*/
Expand Down Expand Up @@ -215,9 +224,9 @@ public function getPublishedBy()
/**
* @return string
*/
public function getAuthor()
public function getAuthors()
{
return $this->author;
return $this->authors;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/PostProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function getAll(array $fields = [], $limit = 15)
'query' => [
'limit' => $limit,
'formats' => ['html', 'plaintext'],
'include' => [ 'tags' ] // We include all the tag information by default
'include' => [ 'tags', 'authors' ] // We include all the tag information by default
]
];

Expand Down
2 changes: 1 addition & 1 deletion tests/Providers/PostProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function testProvidersCanGetAllPostsWithFieldsParameter()
'fields' => ['id', 'html'],
'limit' => 15,
'formats' => ['html', 'plaintext'],
'include' => ['tags']
'include' => ['tags', 'authors']
]
]
)
Expand Down

0 comments on commit a0e5613

Please sign in to comment.