Version 5.0.13
This commit is contained in:
1 parent
b89858b2ff
commit
5efe744c5f
1407 files changed
+69690
-30177
No files matched your search
@@ -85,6 +85,26 @@ trait Helpful
|
||||
'node_id' => $this->item()->container()->_id
|
||||
) );
|
||||
|
||||
/* If we have a mapping, increment that column */
|
||||
if( isset( static::$databaseColumnMap['num_helpful'] ) )
|
||||
{
|
||||
$helpfulCountColumn = static::$databaseColumnMap['num_helpful'];
|
||||
$this->$helpfulCountColumn++;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/* And if this is a comment, check if item has a mapping */
|
||||
if( $this instanceof Comment )
|
||||
{
|
||||
$item = $this->item();
|
||||
if( isset( $item::$databaseColumnMap['num_helpful'] ) )
|
||||
{
|
||||
$helpfulCountColumn = $item::$databaseColumnMap['num_helpful'];
|
||||
$item->$helpfulCountColumn++;
|
||||
$item->save();
|
||||
}
|
||||
}
|
||||
|
||||
/* Trending */
|
||||
if( Application::appIsEnabled( 'cloud' ) and Bridge::i()->featureIsEnabled( 'trending' ) )
|
||||
{
|
||||
@@ -141,6 +161,26 @@ trait Helpful
|
||||
unset( $this->hasMarkedHelpful[ $member->member_id ] );
|
||||
}
|
||||
|
||||
/* If we have a mapping, decrement that column */
|
||||
if( isset( static::$databaseColumnMap['num_helpful'] ) )
|
||||
{
|
||||
$helpfulCountColumn = static::$databaseColumnMap['num_helpful'];
|
||||
$this->$helpfulCountColumn--;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/* And if this is a comment, check if item has a mapping */
|
||||
if( $this instanceof Comment )
|
||||
{
|
||||
$item = $this->item();
|
||||
if( isset( $item::$databaseColumnMap['num_helpful'] ) )
|
||||
{
|
||||
$helpfulCountColumn = $item::$databaseColumnMap['num_helpful'];
|
||||
$item->$helpfulCountColumn--;
|
||||
$item->save();
|
||||
}
|
||||
}
|
||||
|
||||
if ( IPS::classUsesTrait( $this->item(), 'IPS\Content\Statistics' ) )
|
||||
{
|
||||
$this->item()->clearCachedStatistics();
|
||||
@@ -170,22 +210,36 @@ trait Helpful
|
||||
*/
|
||||
public function helpfulsRepliesCount(): int
|
||||
{
|
||||
if( isset( static::$databaseColumnMap['num_helpful'] ) )
|
||||
{
|
||||
return $this->mapped( 'num_helpful' );
|
||||
}
|
||||
|
||||
if ( $this->_helpfulRepliesCount === NULL )
|
||||
{
|
||||
$idColumn = static::$databaseColumnId;
|
||||
try
|
||||
{
|
||||
$this->_helpfulRepliesCount = (int)Db::i()->select( 'COUNT( DISTINCT(comment_id) )', 'core_solved_index', [["app=? AND item_id=? AND type=? AND hidden=0", static::$application, $this->$idColumn, 'helpful']], null, null, 'item_id' )->first();
|
||||
}
|
||||
catch( Exception )
|
||||
{
|
||||
$this->_helpfulRepliesCount = 0;
|
||||
}
|
||||
$this->_helpfulRepliesCount = (int) Db::i()->select( 'COUNT( DISTINCT(comment_id) )', 'core_solved_index', ["app=? AND item_id=? AND type=? AND hidden=0", static::$application, $this->$idColumn, 'helpful'] )->first();
|
||||
}
|
||||
|
||||
return $this->_helpfulRepliesCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recount the total helpful replies
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function recountHelpfuls() : void
|
||||
{
|
||||
if( isset( static::$databaseColumnMap['num_helpful'] ) )
|
||||
{
|
||||
$idColumn = static::$databaseColumnId;
|
||||
$helpfulColumn = static::$databaseColumnMap['num_helpful'];
|
||||
$this->$helpfulColumn = (int) Db::i()->select( 'COUNT( DISTINCT(comment_id) )', 'core_solved_index', [ 'app=? and item_id=? and type=? and hidden=?', static::$application, $this->$idColumn, 'helpful', 0 ], flags: Db::SELECT_FROM_WRITE_SERVER )->first();
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helpful Count
|
||||
*
|
||||
@@ -280,6 +334,12 @@ trait Helpful
|
||||
*/
|
||||
public function canMarkHelpful( ?Member $member = NULL ): bool
|
||||
{
|
||||
/* Extensions go first */
|
||||
if( $permCheck = Permissions::can( 'helpful', $this, $member ) )
|
||||
{
|
||||
return ( $permCheck === Permissions::PERM_ALLOW );
|
||||
}
|
||||
|
||||
$member = $member ?: Member::loggedIn();
|
||||
|
||||
/* It's a no for guests */
|
||||
@@ -320,7 +380,7 @@ trait Helpful
|
||||
public function authorIsAnExpert() : bool
|
||||
{
|
||||
/* Do they have it disabled? */
|
||||
if( !Bridge::i()->featureIsEnabled( 'experts' ) or $this->author()->members_bitoptions['expert_user_disabled'] or $this->author()->members_bitoptions['expert_user_blocked'] )
|
||||
if( !Bridge::i()->featureIsEnabled( 'experts' ) or $this->author()->members_bitoptions['expert_user_disabled'] or !$this->author()->isExpert() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -350,6 +410,11 @@ trait Helpful
|
||||
*/
|
||||
public static function itemHasHelpful( Item $item ): bool
|
||||
{
|
||||
if( isset( $item::$databaseColumnMap['num_helpful'] ) )
|
||||
{
|
||||
return (bool) $item->mapped( 'num_helpful' );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return (bool) $item->helpfulPosts(1);
|
||||
|
||||
Reference in new issue
Block a user