Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

+121 -17
View File
@@ -2,9 +2,9 @@
/**
* @brief Content Review Model
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @since 4 Nov 2013
* @version SVN_VERSION_NUMBER
*/
@@ -31,24 +31,26 @@ abstract class _Review extends \IPS\Content\Comment
/**
* Create first comment (created with content item)
*
* @param \IPS\Content\Item $item The content item just created
* @param string $comment The comment
* @param bool $first Is the first comment?
* @param int $rating The rating (1-5)
* @param string $guestName If author is a guest, the name to use
* @param \IPS\Member|NULL $member The author of this comment. If NULL, uses currently logged in member.
* @param \IPS\DateTime|NULL $time The time
* @param \IPS\Content\Item $item The content item just created
* @param string $comment The comment
* @param bool $first Is the first comment?
* @param int $rating The rating (1-5)
* @param string $guestName If author is a guest, the name to use
* @param \IPS\Member|NULL $member The author of this comment. If NULL, uses currently logged in member.
* @param \IPS\DateTime|NULL $time The time
* @param string|NULL $ipAddress The IP address or NULL to detect automatically
* @param int|NULL $hiddenStatus NULL to set automatically or override: 0 = unhidden; 1 = hidden, pending moderator approval; -1 = hidden (as if hidden by a moderator)
* @return static
* @throws \InvalidArgumentException
*/
public static function create( $item, $comment, $first=FALSE, $rating=NULL, $guestName=NULL, $member=NULL, \IPS\DateTime $time=NULL )
public static function create( $item, $comment, $first=FALSE, $rating=NULL, $guestName=NULL, $member=NULL, \IPS\DateTime $time=NULL, $ipAddress=NULL, $hiddenStatus=NULL )
{
if ( !is_int( $rating ) or $rating < 1 or $rating > intval( \IPS\Settings::i()->reviews_rating_out_of ) )
{
throw new \InvalidArgumentException;
}
$obj = parent::create( $item, $comment, $first, $guestName, $member, $time );
$obj = parent::create( $item, $comment, $first, $guestName, NULL, $member, $time, $ipAddress );
foreach ( array( 'rating', 'votes_data' ) as $k )
{
@@ -81,12 +83,22 @@ abstract class _Review extends \IPS\Content\Comment
$obj->save();
/* Have to do this AFTER rating is set */
/* Have to do these AFTER rating is set */
$itemClass = static::$itemClass;
$ratingField = $itemClass::$databaseColumnMap['rating'];
$obj->item()->$ratingField = $obj->item()->averageReviewRating() ?: 0;
$obj->item()->save();
/* Send notifications */
if ( !$obj->hidden() and ( !$first or !$item::$firstCommentRequired ) )
{
$obj->sendNotifications();
}
else if( $obj->hidden() === 1 )
{
$obj->sendUnapprovedNotification();
}
return $obj;
}
@@ -121,6 +133,11 @@ abstract class _Review extends \IPS\Content\Comment
$lastReviewByField = $item::$databaseColumnMap['last_review_by'];
$item->$lastReviewByField = $this->author()->member_id;
}
if ( isset( $item::$databaseColumnMap['last_review_name'] ) )
{
$lastReviewNameField = $item::$databaseColumnMap['last_review_name'];
$item->$lastReviewNameField = $this->author()->name;
}
if ( isset( $item::$databaseColumnMap['num_reviews'] ) )
{
$numReviewsField = $item::$databaseColumnMap['num_reviews'];
@@ -180,7 +197,26 @@ abstract class _Review extends \IPS\Content\Comment
}
else
{
$commentPosition = \IPS\Db::i()->select( 'COUNT(*) AS position', static::$databaseTable, array( static::$databasePrefix . static::$databaseColumnMap['item'] . '=? AND ' . static::$databasePrefix . static::$databaseColumnId . '<=?', $this->$itemField, $this->$idColumn ), static::$databasePrefix . static::$databaseColumnMap['date'] . ' asc' )->first();
$where = array( array( static::$databasePrefix . static::$databaseColumnMap['item'] . '=? AND ' . static::$databasePrefix . static::$databaseColumnId . '<=?', $this->$itemField, $this->$idColumn ) );
if ( static::commentWhere() !== NULL )
{
$where[] = static::commentWhere();
}
if ( static::modPermission( 'view_hidden' ) === FALSE )
{
if ( isset( static::$databaseColumnMap['approved'] ) )
{
$where[] = array( static::$databasePrefix . static::$databaseColumnMap['approved'] . '=?', 1 );
}
elseif( isset( static::$databaseColumnMap['hidden'] ) )
{
$where[] = array( static::$databasePrefix . static::$databaseColumnMap['hidden'] . '=?', 0 );
}
}
$commentPosition = \IPS\Db::i()->select( 'COUNT(*) AS position', static::$databaseTable, $where )->first();
$page = ceil( $commentPosition / $itemClass::$reviewsPerPage );
if ( $page != 1 )
{
@@ -207,9 +243,10 @@ abstract class _Review extends \IPS\Content\Comment
/**
* Syncing to run when hiding
*
* @param \IPS\Member|NULL|FALSE $member The member doing the action (NULL for currently logged in member, FALSE for no member)
* @return void
*/
public function onHide()
public function onHide( $member )
{
$item = $this->item();
if ( $item->container()->_reviews !== NULL )
@@ -218,6 +255,12 @@ abstract class _Review extends \IPS\Content\Comment
$item->container()->setLastReview();
$item->container()->save();
}
if ( isset( $item::$databaseColumnMap['hidden_reviews'] ) )
{
$column = $item::$databaseColumnMap['hidden_reviews'];
$item->$column = $item->mapped('hidden_reviews') + 1;
}
if ( isset( $item::$databaseColumnMap['num_reviews'] ) )
{
$column = $item::$databaseColumnMap['num_reviews'];
@@ -234,10 +277,11 @@ abstract class _Review extends \IPS\Content\Comment
/**
* Syncing to run when unhiding
*
* @param bool $approving If true, is being approved for the first time
* @param bool $approving If true, is being approved for the first time
* @param \IPS\Member|NULL|FALSE $member The member doing the action (NULL for currently logged in member, FALSE for no member)
* @return void
*/
public function onUnhide( $approving )
public function onUnhide( $approving, $member )
{
$item = $this->item();
@@ -255,6 +299,11 @@ abstract class _Review extends \IPS\Content\Comment
$item->container()->save();
}
}
else if ( isset( $item::$databaseColumnMap['hidden_reviews'] ) )
{
$column = $item::$databaseColumnMap['hidden_reviews'];
$item->$column = $item->mapped('hidden_reviews') - 1;
}
if ( isset( $item::$databaseColumnMap['num_reviews'] ) )
{
@@ -285,6 +334,27 @@ abstract class _Review extends \IPS\Content\Comment
{
return FALSE;
}
/**
* Can view?
*
* @param \IPS\Member|NULL $member The member to check for or NULL for the currently logged in member
* @return bool
*/
public function canView( $member=NULL )
{
if( $member === NULL )
{
$member = \IPS\Member::loggedIn();
}
if ( $this instanceof \IPS\Content\Hideable and $this->hidden() and !$this->item()->canViewHiddenReviews( $member ) and ( $this->hidden() !== 1 or $this->author() !== $member ) )
{
return FALSE;
}
return $this->item()->canView( $member );
}
/**
* Warning Reference Key
@@ -338,7 +408,41 @@ abstract class _Review extends \IPS\Content\Comment
parent::delete();
$itemClass = static::$itemClass;
$ratingField = $itemClass::$databaseColumnMap['rating'];
$this->item()->$ratingField = $this->item()->averageReviewRating() ?: 0;
$this->item()->$ratingField = $this->item()->averageReviewRating() ?: 0;
$this->item()->save();
}
/**
* Get output for API
*
* @return array
* @apiresponse int id ID number
* @apiresponse int item The ID number of the item this belongs to
* @apiresponse \IPS\Member author Author
* @apiresponse datetime date Date
* @apiresponse int rating The number of stars this review gave
* @apiresponse int votesTotal The number of users that have voted if this review was helpful or unhelpful
* @apiresponse int votesHelpful The number of users that voted helpful
* @apiresponse string content The content
* @apiresponse bool hidden Is hidden?
* @apiresponse string url URL to content
*/
public function apiOutput()
{
$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()
);
}
/* !Embeddable */