add allow comments meta prop to collection

This commit is contained in:
Jacson Passold 2018-08-28 00:19:39 -03:00
parent b028752b28
commit eacd65d68d
4 changed files with 31 additions and 5 deletions

View File

@ -34,7 +34,8 @@ class Collection extends Entity {
$header_image_id,
$header_image,
$moderators_ids,
$comment_status;
$comment_status,
$allow_comments;
/**
* {@inheritDoc}
@ -502,6 +503,14 @@ class Collection extends Entity {
return $this->get_mapped_property('comment_status');
}
/**
* Checks if comments are allowed for the current Collection Items.
* @return bool
*/
public function get_allow_comments() {
return $this->get_mapped_property('allow_comments');
}
/**
* Set the collection name
*
@ -703,6 +712,15 @@ class Collection extends Entity {
$this->set_mapped_property('comment_status', $value);
}
/**
* Sets if comments are allowed for the current Collection Items.
*
* @param $value bool
*/
public function set_allow_comments( $value ) {
$this->set_mapped_property('allow_comments', $value );
}
// Moderators methods
/**

View File

@ -154,7 +154,7 @@ class Entity {
* @return mixed property value
*/
public function get_mapped_property($prop) {
if (isset($this->$prop) ){
if ( isset($this->$prop) ){
return $this->$prop;
}

View File

@ -199,9 +199,17 @@ class Collections extends Repository {
'map' => 'comment_status',
'title' => __( 'Comment Status', 'tainacan' ),
'type' => 'string',
'description' => __( 'The status of collection comment, if is "open" the comments are allowed for collection items, or is "closed" for deny comments to items.', 'tainacan' ),
'description' => __( 'The status of collection comment, if is "open" the comments are allowed, or is "closed" for deny comments.', 'tainacan' ),
'default' => get_default_comment_status(Entities\Collection::get_post_type()),
'validation' => v::optional(v::stringType()->in( [ 'open', 'closed' ] )),
],
'allow_comments' => [
'map' => 'meta',
'title' => __( 'Allow Items Comments', 'tainacan' ),
'type' => 'string',
'description' => __( 'Collection items comment is allowed, if is "open" the comments are allowed for collection items, or is "closed" for deny comments to items.', 'tainacan' ),
'default' => 'open',
'validation' => v::optional(v::stringType()->in( [ 'open', 'closed' ] )),
]
] );

View File

@ -398,7 +398,7 @@ class Items extends Repository {
/**
* Get a default thumbnail ID from the item document.
*
* @param EntitiesItem $item The item
* @param Entities\Item $item The item
*
* @return int|null The thumbnail ID or null if it was not possible to find a thumbnail
*/
@ -491,7 +491,7 @@ class Items extends Repository {
if($item != false && $item instanceof Entities\Item) {
$collection = $item->get_collection();
if($collection->get_comment_status() !== 'open' ) return false;
if( $collection->get_allow_comments() !== 'open' ) return false;
}
return $open_comment;