Version 5.0.13

This commit is contained in:
Neo committed 2025-12-19 19:04:57 -08:00
1 parent b89858b2ff
commit 5efe744c5f
1407 files changed
+69690 -30177

No files matched your search

+111
View File
@@ -13,8 +13,11 @@ namespace IPS\Content;
use ArrayObject;
use BadMethodCallException;
use IPS\Content;
use IPS\core\Followed\Follow;
use IPS\Db;
use IPS\Events\Event;
use IPS\IPS;
use IPS\Member;
use IPS\Notification;
use IPS\Application;
use IPS\DateTime;
@@ -22,6 +25,7 @@ use IPS\Node\Model;
use IPS\Db\Select;
use ArrayIterator;
use Iterator;
use OutOfRangeException;
use UnderflowException;
use function defined;
use function header;
@@ -44,6 +48,113 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
trait Followable
{
/**
* Follow an object. Using a static method here
* because Model does not use the Followable trait
*
* @param object $object
* @param string $frequency
* @param bool $public
* @param Member|null $member
* @return void
*/
public static function staticFollow( object $object, string $frequency, bool $public=true, ?Member $member=null ) : void
{
$member = $member ?: Member::loggedIn();
try
{
/* Are we already following this? */
$follow = Follow::loadByObject( $object, $member );
}
catch( OutOfRangeException )
{
$follow = new Follow;
$follow->object = $object;
$follow->member_id = $member->member_id;
}
$follow->is_anon = !$public;
$follow->notify_do = ( $frequency == 'none' ? 0 : 1 );
$follow->notify_freq = $frequency;
$follow->save();
$followParams = Follow::getFollowParameters( $object );
$idCol = $object::$databaseColumnId;
$member->clearFollowingCache( $followParams['app'], $followParams['area'], $object->$idCol );
/* Fire the event */
Event::fire( 'onFollow', $member, [ $object, $public ] );
}
/**
* Follow this object
*
* @param string $frequency ( 'none', 'immediate', 'daily', 'weekly' )
* @param bool $public
* @param Member|null $member
* @return void
*/
public function follow( string $frequency, bool $public=true, ?Member $member=null ) : void
{
static::staticFollow( $this, $frequency, $public, $member );
/* If this is an item, handle achievements */
if( $this instanceof Item )
{
Member::loggedIn()->achievementAction( 'core', 'FollowContentItem', [
'item' => $this,
'author' => $this->author()
] );
}
}
/**
* Nodes don't use followable, so we have a static method on the item level
*
* @param Model $container
* @param Member|null $member
* @return void
*/
public static function containerUnfollow( Model $container, ?Member $member=null ) : void
{
try
{
$member = $member ?: Member::loggedIn();
Follow::loadByObject( $container, $member )->delete();
}
catch( OutOfRangeException ){}
}
/**
* Unfollow this object
*
* @param Member|null $member
* @param string|null $followId
* @return void
*/
public function unfollow( ?Member $member=null, ?string $followId=null ) : void
{
$member = $member ?: Member::loggedIn();
try
{
/* We might already have the follow ID (like in the notifications controller) */
if( $followId === null )
{
Follow::loadByObject( $this, $member )->delete();
$followParams = Follow::getFollowParameters( $this );
$idCol = $this::$databaseColumnId;
$member->clearFollowingCache( $followParams['app'], $followParams['area'], $this->$idCol );
}
else
{
Follow::load( $followId )->delete();
}
}
catch( OutOfRangeException ){}
}
/**
* @brief Cache for current follow data, used on "My Followed Content" screen
*/