Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
+150
-13
@@ -23,10 +23,15 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
abstract class _Review extends \IPS\Content\Comment
|
||||
{
|
||||
/**
|
||||
* @brief [Content\Comment] Comment Template
|
||||
* @brief [Content\Comment] Form Template
|
||||
*/
|
||||
public static $formTemplate = array( array( 'forms', 'core', 'front' ), 'reviewTemplate' );
|
||||
|
||||
/**
|
||||
* @brief [Content\Comment] Reviews Template
|
||||
*/
|
||||
public static $commentTemplate = array( array( 'global', 'core', 'front' ), 'reviewContainer' );
|
||||
|
||||
|
||||
/**
|
||||
* Create first comment (created with content item)
|
||||
*
|
||||
@@ -239,6 +244,28 @@ abstract class _Review extends \IPS\Content\Comment
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'core', 'front' )->reviewHelpful( $this->mapped('votes_helpful'), $this->mapped('votes_total') );
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit and existing rating
|
||||
*
|
||||
* @param int $rating The new rating
|
||||
* @return void
|
||||
*/
|
||||
public function editRating( $rating )
|
||||
{
|
||||
/* Review */
|
||||
$ratingField = static::$databaseColumnMap['rating'];
|
||||
$this->$ratingField = $rating;
|
||||
$this->save();
|
||||
|
||||
/* Item */
|
||||
$item = $this->item();
|
||||
$ratingField = $item::$databaseColumnMap['rating'];
|
||||
$item->$ratingField = $item->averageReviewRating() ?: 0;
|
||||
|
||||
$item->resyncLastReview();
|
||||
$item->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncing to run when hiding
|
||||
*
|
||||
@@ -414,6 +441,7 @@ abstract class _Review extends \IPS\Content\Comment
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @return array
|
||||
* @apiresponse int id ID number
|
||||
* @apiresponse int item The ID number of the item this belongs to
|
||||
@@ -425,22 +453,24 @@ abstract class _Review extends \IPS\Content\Comment
|
||||
* @apiresponse string content The content
|
||||
* @apiresponse bool hidden Is hidden?
|
||||
* @apiresponse string url URL to content
|
||||
* @apiresponse string|NULL authorResponse The content item's author's response to the review, if any
|
||||
*/
|
||||
public function apiOutput()
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL )
|
||||
{
|
||||
$idColumn = static::$databaseColumnId;
|
||||
$itemColumn = static::$databaseColumnMap['item'];
|
||||
return array(
|
||||
'id' => $this->$idColumn,
|
||||
'item_id' => $this->$itemColumn,
|
||||
'author' => $this->author()->apiOutput(),
|
||||
'date' => \IPS\DateTime::ts( $this->mapped('date') )->rfc3339(),
|
||||
'rating' => $this->mapped('rating'),
|
||||
'votesTotal' => $this->mapped('votes_total'),
|
||||
'votesHelpful' => $this->mapped('votes_helpful'),
|
||||
'content' => $this->content(),
|
||||
'hidden' => (bool) $this->hidden(),
|
||||
'url' => (string) $this->url()
|
||||
'id' => $this->$idColumn,
|
||||
'item_id' => $this->$itemColumn,
|
||||
'author' => $this->author()->apiOutput( $authorizedMember ),
|
||||
'date' => \IPS\DateTime::ts( $this->mapped('date') )->rfc3339(),
|
||||
'rating' => $this->mapped('rating'),
|
||||
'votesTotal' => $this->mapped('votes_total'),
|
||||
'votesHelpful' => $this->mapped('votes_helpful'),
|
||||
'content' => $this->content(),
|
||||
'hidden' => (bool) $this->hidden(),
|
||||
'url' => (string) $this->url(),
|
||||
'authorResponse' => $this->mapped('author_response')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -456,4 +486,111 @@ abstract class _Review extends \IPS\Content\Comment
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'core' )->embedReview( $this->item(), $this, $this->url()->setQueryString( $params ), $this->item()->embedImage() );
|
||||
}
|
||||
|
||||
/* !Author responses */
|
||||
|
||||
/**
|
||||
* Has the author responded to this review?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasAuthorResponse()
|
||||
{
|
||||
return !is_null( $this->mapped('author_response') );
|
||||
}
|
||||
|
||||
/**
|
||||
* Can the specified user respond to the review?
|
||||
*
|
||||
* @note Only the author of the content item can respond by default, but this is abstracted so third parties can override
|
||||
* @param \IPS\Member|NULL $member Member to check or NULL for currently logged in member
|
||||
* @return bool
|
||||
*/
|
||||
public function canRespond( $member=NULL )
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
/* If we have not responded... */
|
||||
if( !$this->hasAuthorResponse() )
|
||||
{
|
||||
/* ...and we are the author of the content item... */
|
||||
if( $member->member_id == $this->item()->author()->member_id )
|
||||
{
|
||||
/* ...then we can respond to this review. */
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can the specified user edit the response to this review?
|
||||
*
|
||||
* @param \IPS\Member|NULL $member Member to check or NULL for currently logged in member
|
||||
* @return bool
|
||||
*/
|
||||
public function canEditResponse( $member=NULL )
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
/* If there is an author response... */
|
||||
if( $this->hasAuthorResponse() )
|
||||
{
|
||||
$item = $this->item();
|
||||
|
||||
/* Moderators who can edit content can edit responses */
|
||||
if ( static::modPermission( 'edit', $member, $item->containerWrapper() ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Or maybe the member can edit their own content? */
|
||||
if ( $member->member_id == $item->author()->member_id and ( $member->group['g_edit_posts'] == '1' or in_array( get_class( $item ), explode( ',', $member->group['g_edit_posts'] ) ) ) and ( !( $item instanceof \IPS\Content\Lockable ) or !$item->locked() ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Nope, we cannot edit */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can the specified user delete the response to this review?
|
||||
*
|
||||
* @param \IPS\Member|NULL $member Member to check or NULL for currently logged in member
|
||||
* @return bool
|
||||
*/
|
||||
public function canDeleteResponse( $member=NULL )
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
/* If there is an author response... */
|
||||
if( $this->hasAuthorResponse() )
|
||||
{
|
||||
$container = NULL;
|
||||
|
||||
try
|
||||
{
|
||||
$container = $this->item()->container();
|
||||
}
|
||||
catch ( \BadMethodCallException $e ) { }
|
||||
|
||||
/* Moderators who can delete content can delete responses */
|
||||
if( static::modPermission( 'delete', $member, $container ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Or maybe the author can delete their own content? */
|
||||
if( $member->member_id and $member->member_id == $this->item()->author()->member_id and ( $member->group['g_delete_own_posts'] == '1' or in_array( get_class( $this->item() ), explode( ',', $member->group['g_delete_own_posts'] ) ) ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Nope, we cannot delete */
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user