Version 5.0.6

This commit is contained in:
Neo committed 2025-12-19 18:55:49 -08:00
1 parent a3a4a9ccbd
commit b89858b2ff
1214 files changed
+92828 -14859

No files matched your search

@@ -17,6 +17,8 @@ namespace IPS\core\Assignments;
use IPS\Content;
use IPS\Content\Comment;
use IPS\Content\Item;
use IPS\core\modules\admin\stats\points;
use IPS\Data\Store;
use IPS\DateTime;
use IPS\Db;
use IPS\Member;
@@ -60,14 +62,26 @@ class Assignment extends ActiveRecord
protected static array $multitonMap = [];
/**
* @return Item
* @throws OutOfRangeException
* @brief [ActiveRecord] Caches
* @note Defined cache keys will be cleared automatically as needed
*/
public function get_item() : Item
protected array $caches = array( 'openAssignments' );
/**
* @return Item|null
*/
public function get_item() : ?Item
{
/* @var Item $class */
$class = $this->item_class;
return $class::load( $this->item_id );
try
{
$class = $this->item_class;
return $class::load( $this->item_id );
}
catch(OutOfRangeException $e)
{
return null;
}
}
/**
@@ -269,6 +283,71 @@ class Assignment extends ActiveRecord
return DateTime::ts( $this->reply_time )->roundedDiff( DateTime::ts( $this->date ) );
}
/**
* Exactly what you think it does.
*
* @return int
*/
public static function totalOpenAssignments() : int
{
try
{
$cache = Store::i()->openAssignments;
}
catch( OutOfRangeException )
{
$cache = [
'members' => iterator_to_array(
Db::i()->select( 'assign_to, count(assign_id) as total', static::$databaseTable, [ 'assign_type=? and assign_closed=?', static::ASSIGNMENT_MEMBER, 0 ], null, null, 'assign_to' )
->setKeyField( 'assign_to' )
->setValueField( 'total' )
),
'teams' => iterator_to_array(
Db::i()->select( 'assign_to, count(assign_id) as total', static::$databaseTable, [ 'assign_type=? and assign_closed=?', static::ASSIGNMENT_TEAM, 0 ], null, null, 'assign_to' )
->setKeyField( 'assign_to' )
->setValueField( 'total' )
)
];
Store::i()->openAssignments = $cache;
}
$totalOpenForMember = $cache['members'][ Member::loggedIn()->member_id ] ?? 0;
/* Do we have teams? */
if( $teams = Member::loggedIn()->teams() )
{
foreach( $teams as $teamId => $team )
{
$totalOpenForMember += $cache['teams'][ $teamId ] ?? 0;
}
}
return $totalOpenForMember;
}
/**
* Determines if the member can access the assignments list
*
* @param Member|null $member
* @return bool
*/
public static function canAccessAssignments( ?Member $member=null ) : bool
{
if( !Bridge::i()->featureIsEnabled( 'assignments' ) )
{
return false;
}
$member = $member ?? Member::loggedIn();
if( static::canAssignOnAny( $member ) )
{
return true;
}
/* If the member is on any team OR they have an assignment, let it through */
return ( $teams = $member->teams() or $member->totalAssignments() );
}
/**
* Get all assignments for this member or team
*