Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

@@ -11,77 +11,92 @@
namespace IPS\core\Achievements;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use BadMethodCallException;
use Exception;
use IPS\Application;
use IPS\Content;
use IPS\Db;
use IPS\Member;
use IPS\Notification;
use IPS\Patterns\ActiveRecord;
use OutOfRangeException;
use function defined;
use function get_class;
use function intval;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Recognize
*/
class _Recognize extends \IPS\Patterns\ActiveRecord
class Recognize extends ActiveRecord
{
/**
* @brief Database Table
*/
public static $databaseTable = 'core_member_recognize';
public static ?string $databaseTable = 'core_member_recognize';
/**
* @brief [ActiveRecord] Database Prefix
*/
public static $databasePrefix = 'r_';
public static string $databasePrefix = 'r_';
/**
* @brief Multiton Store
*/
protected static $multitons = array();
protected static array $multitons = array();
/**
* Get member object
*
* @return \IPS\Member
* @return Member
*/
public function get__given_by(): \IPS\Member
public function get__given_by(): Member
{
return \IPS\Member::load( $this->given_by );
return Member::load( $this->given_by );
}
/**
* Load a recognize row from the content item
*
* @param \IPS\Content $content Content item that has been rewarded
* @return \IPS\core\Achievements\Recognize
* @param Content $content Content item that has been rewarded
* @return ActiveRecord
*/
public static function loadFromContent( $content ): \IPS\core\Achievements\Recognize
public static function loadFromContent( Content $content ): ActiveRecord
{
$idField = $content::$databaseColumnId;
/* Let any exceptions bubble up */
return static::constructFromData(
\IPS\Db::i()->select( '*', 'core_member_recognize', [ 'r_content_class=? and r_content_id=?', \get_class( $content ), $content->$idField ] )->first()
Db::i()->select( '*', 'core_member_recognize', [ 'r_content_class=? and r_content_id=?', get_class( $content ), $content->$idField ] )->first()
);
}
/**
* Add a new recognize entry
*
* @param \IPS\Content $content Content item that is being rewarded
* @param \IPS\Member $member Member to award
* @param Content $content Content item that is being rewarded
* @param Member $member Member to award
* @param int $points Number of points to add
* @param \IPS\core\Achievements\Badge|NULL $badge Badge to assign (if any)
* @param Badge|NULL $badge Badge to assign (if any)
* @param string $message Custom message (if any)
* @param \IPS\Member $awardedBy Awarded by
* @param Member $awardedBy Awarded by
* @param bool $showPublicly Show this message to everyone
* @return void
*/
public static function add( $content, \IPS\Member $member, $points, $badge, $message, \IPS\Member $awardedBy, $showPublicly=FALSE )
public static function add( Content $content, Member $member, int $points, ?Badge $badge, string $message, Member $awardedBy, bool $showPublicly=FALSE ) : void
{
$idField = $content::$databaseColumnId;
/* Add to database */
$recognize = new static;
$recognize->member_id = $member->member_id;
$recognize->content_class = \get_class( $content );
$recognize->content_class = get_class( $content );
$recognize->content_id = $content->$idField;
$recognize->added = time();
$recognize->points = $points;
@@ -102,7 +117,7 @@ class _Recognize extends \IPS\Patterns\ActiveRecord
$member->awardPoints( $points, 0, [], ['subject'], $recognize->id );
}
$notification = new \IPS\Notification( \IPS\Application::load( 'core' ), 'new_recognize', $member, [ $member, $recognize ], [ $recognize->id ] );
$notification = new Notification( Application::load( 'core' ), 'new_recognize', $member, [ $member, $recognize ], [ $recognize->id ] );
$notification->recipients->attach( $member );
$notification->send();
}
@@ -110,9 +125,9 @@ class _Recognize extends \IPS\Patterns\ActiveRecord
/**
* Return the content object
*
* @return \IPS\Content
* @return Content
*/
public function content()
public function content(): Content
{
$class = $this->content_class;
return $class::loadAndCheckPerms( $this->content_id );
@@ -121,35 +136,32 @@ class _Recognize extends \IPS\Patterns\ActiveRecord
/**
* Wrapper to get content.
*
* @return \IPS\Content\Item|NULL
* @return Content|NULL
* @note This simply wraps content()
*/
public function contentWrapper()
public function contentWrapper() : Content|null
{
/* Get container, if valid */
$content = NULL;
try
{
$content = $this->content();
return $this->content();
}
catch( \BadMethodCallException | \OutOfRangeException $e ) { }
catch( BadMethodCallException | OutOfRangeException ) { }
return $content;
return null;
}
/**
* Return a badge, or null
*
* @return NULL|\IPS\core\Achievements\Badge
* @return NULL|Badge
*/
public function badge()
public function badge() : Badge|null
{
try
{
return \IPS\core\Achievements\Badge::load( $this->badge );
return Badge::load( $this->badge );
}
catch( \Exception $e ) { }
catch( OutOfRangeException ) { }
return NULL;
}
@@ -157,15 +169,15 @@ class _Recognize extends \IPS\Patterns\ActiveRecord
/**
* Return a member or NULL if the member no longer exists
*
* @return NULL|\IPS\Member
* @return NULL|Member
*/
public function awardedBy()
public function awardedBy() : Member|null
{
try
{
return \IPS\Member::load( $this->given_by );
return Member::load( $this->given_by );
}
catch( \Exception $e ) { }
catch( OutOfRangeException ) { }
return NULL;
}
@@ -175,28 +187,26 @@ class _Recognize extends \IPS\Patterns\ActiveRecord
*
* @return void
*/
public function delete()
public function delete(): void
{
try
{
$author = \IPS\Member::load( $this->member_id );
if ( $this->points )
{
/* Wade does it this way so I guess there's a reason. And let the reason be love */
\IPS\Db::i()->update( 'core_members', "achievements_points = achievements_points - " . \intval( $this->points ), [ 'member_id=?', $this->member_id ] );
\IPS\Db::i()->delete( 'core_points_log', [ 'recognize=?', $this->id ] );
Db::i()->update( 'core_members', "achievements_points = achievements_points - " . intval( $this->points ), [ 'member_id=?', $this->member_id ] );
Db::i()->delete( 'core_points_log', [ 'recognize=?', $this->id ] );
}
if ( $this->badge )
{
\IPS\Db::i()->delete( 'core_member_badges', [ 'member=? and recognize=?', $this->member_id, $this->id ] );
Db::i()->delete( 'core_member_badges', [ 'member=? and recognize=?', $this->member_id, $this->id ] );
}
/* Remove notifications */
\IPS\Db::i()->delete( 'core_notifications', array( 'item_class=? and notification_key=? and item_id=? and extra=?', 'IPS\Member', 'new_recognize', $this->member_id, '[' . $this->id . ']' ) );
Db::i()->delete( 'core_notifications', array( 'item_class=? and notification_key=? and item_id=? and extra=?', 'IPS\Member', 'new_recognize', $this->member_id, '[' . $this->id . ']' ) );
}
catch( \Exception $e ) {}
catch( Exception ) {}
parent::delete();
}