Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -11,33 +11,45 @@
|
||||
namespace IPS\Notification;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Application;
|
||||
use IPS\DateTime;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Patterns\ActiveRecord;
|
||||
use LogicException;
|
||||
use OutOfRangeException;
|
||||
use RuntimeException;
|
||||
use function defined;
|
||||
use function get_class;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inline Notification Model
|
||||
*/
|
||||
class _Inline extends \IPS\Patterns\ActiveRecord
|
||||
class Inline extends ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_notifications';
|
||||
public static ?string $databaseTable = 'core_notifications';
|
||||
|
||||
/**
|
||||
* Set Default Values
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultValues()
|
||||
public function setDefaultValues() : void
|
||||
{
|
||||
$this->sent_time = time();
|
||||
$this->updated_time = time();
|
||||
@@ -46,40 +58,40 @@ class _Inline extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get sent time
|
||||
*
|
||||
* @return \IPS\DateTime
|
||||
* @return DateTime
|
||||
*/
|
||||
public function get_sent_time()
|
||||
public function get_sent_time(): DateTime
|
||||
{
|
||||
return \IPS\DateTime::ts( $this->_data['sent_time'] );
|
||||
return DateTime::ts( $this->_data['sent_time'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get updated time
|
||||
*
|
||||
* @return \IPS\DateTime
|
||||
* @return DateTime
|
||||
*/
|
||||
public function get_updated_time()
|
||||
public function get_updated_time(): DateTime
|
||||
{
|
||||
return \IPS\DateTime::ts( $this->_data['updated_time'] );
|
||||
return DateTime::ts( $this->_data['updated_time'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get member
|
||||
*
|
||||
* @return \IPS\Member
|
||||
* @return Member
|
||||
*/
|
||||
public function get_member()
|
||||
public function get_member(): Member
|
||||
{
|
||||
return \IPS\Member::load( $this->_data['member'] );
|
||||
return Member::load( $this->_data['member'] );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set member
|
||||
*
|
||||
* @param |IPS\Member $member The member
|
||||
* @return void
|
||||
* @param Member $member
|
||||
* @return void
|
||||
*/
|
||||
public function set_member( \IPS\Member $member )
|
||||
public function set_member( Member $member ) : void
|
||||
{
|
||||
$this->_data['member'] = $member->member_id;
|
||||
}
|
||||
@@ -89,7 +101,7 @@ class _Inline extends \IPS\Patterns\ActiveRecord
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_member_data()
|
||||
public function get_member_data(): array
|
||||
{
|
||||
return json_decode( $this->_data['member_data'], TRUE );
|
||||
}
|
||||
@@ -100,7 +112,7 @@ class _Inline extends \IPS\Patterns\ActiveRecord
|
||||
* @param mixed $data Member data
|
||||
* @return void
|
||||
*/
|
||||
public function set_member_data( $data )
|
||||
public function set_member_data( mixed $data ) : void
|
||||
{
|
||||
$this->_data['member_data'] = $data ? json_encode( $data ) : NULL;
|
||||
}
|
||||
@@ -110,7 +122,7 @@ class _Inline extends \IPS\Patterns\ActiveRecord
|
||||
*
|
||||
* @return object|NULL
|
||||
*/
|
||||
public function get_item()
|
||||
public function get_item(): ?object
|
||||
{
|
||||
if ( $this->_data['item_class'] and $this->_data['item_id'] )
|
||||
{
|
||||
@@ -122,7 +134,7 @@ class _Inline extends \IPS\Patterns\ActiveRecord
|
||||
return $class::load( $this->_data['item_id'] );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -133,13 +145,13 @@ class _Inline extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Set item
|
||||
*
|
||||
* @param object $item The item
|
||||
* @param object $item The item
|
||||
* @return void
|
||||
*/
|
||||
public function set_item( $item )
|
||||
public function set_item( object $item ) : void
|
||||
{
|
||||
$idColumn = $item::$databaseColumnId;
|
||||
$this->_data['item_class'] = \get_class( $item );
|
||||
$this->_data['item_class'] = get_class( $item );
|
||||
$this->_data['item_id'] = $item->$idColumn;
|
||||
}
|
||||
|
||||
@@ -148,7 +160,7 @@ class _Inline extends \IPS\Patterns\ActiveRecord
|
||||
*
|
||||
* @return object|NULL
|
||||
*/
|
||||
public function get_item_sub()
|
||||
public function get_item_sub(): ?object
|
||||
{
|
||||
if ( $this->_data['item_sub_class'] and $this->_data['item_sub_id'] )
|
||||
{
|
||||
@@ -160,7 +172,7 @@ class _Inline extends \IPS\Patterns\ActiveRecord
|
||||
return $class::load( $this->_data['item_sub_id'] );
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -171,20 +183,20 @@ class _Inline extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get application
|
||||
*
|
||||
* @return \IPS\Application
|
||||
* @return Application
|
||||
*/
|
||||
public function get_notification_app()
|
||||
public function get_notification_app(): Application
|
||||
{
|
||||
return \IPS\Application::load( $this->_data['notification_app'] );
|
||||
return Application::load( $this->_data['notification_app'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set application
|
||||
*
|
||||
* @param mixed $data Member data
|
||||
* @param Application $app
|
||||
* @return void
|
||||
*/
|
||||
public function set_notification_app( \IPS\Application $app )
|
||||
public function set_notification_app( Application $app ) : void
|
||||
{
|
||||
$this->_data['notification_app'] = $app->directory;
|
||||
}
|
||||
@@ -194,7 +206,7 @@ class _Inline extends \IPS\Patterns\ActiveRecord
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_extra()
|
||||
public function get_extra(): array
|
||||
{
|
||||
return $this->_data['extra'] ? json_decode( $this->_data['extra'], TRUE ) : array();
|
||||
}
|
||||
@@ -205,7 +217,7 @@ class _Inline extends \IPS\Patterns\ActiveRecord
|
||||
* @param mixed $data Member data
|
||||
* @return void
|
||||
*/
|
||||
public function set_extra( $data )
|
||||
public function set_extra( mixed $data ) : void
|
||||
{
|
||||
$this->_data['extra'] = $data ? json_encode( $data ) : NULL;
|
||||
}
|
||||
@@ -213,9 +225,9 @@ class _Inline extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Save Changed Columns
|
||||
*
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
public function save(): void
|
||||
{
|
||||
parent::save();
|
||||
$this->member->recountNotifications();
|
||||
@@ -224,11 +236,11 @@ class _Inline extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get data from extension
|
||||
*
|
||||
* @param bool $htmlEscape TRUE to escape HTML
|
||||
* @param bool $htmlEscape TRUE to escape HTML
|
||||
* @return array
|
||||
* @throws \RuntimeException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function getData( $htmlEscape = TRUE )
|
||||
public function getData( bool $htmlEscape = TRUE ): array
|
||||
{
|
||||
$method = "parse_{$this->notification_key}";
|
||||
|
||||
@@ -246,13 +258,13 @@ class _Inline extends \IPS\Patterns\ActiveRecord
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
throw new \RuntimeException;
|
||||
throw new RuntimeException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @param Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @return array
|
||||
* @apiresponse string notificationType The type (key) of notification sent
|
||||
* @apiresponse string notificationApp The app that processes this type of notification
|
||||
@@ -267,13 +279,13 @@ class _Inline extends \IPS\Patterns\ActiveRecord
|
||||
* @apiresponse datetime|null readDate Date and time the notification was read by the user
|
||||
* @apiresponse array notificationData Array of additional data relevant to this specific notification
|
||||
*/
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL )
|
||||
public function apiOutput( Member $authorizedMember = NULL ): array
|
||||
{
|
||||
try
|
||||
{
|
||||
$ourData = $this->getData();
|
||||
}
|
||||
catch( \LogicException | \RuntimeException $e )
|
||||
catch( LogicException | RuntimeException $e )
|
||||
{
|
||||
$ourData = array();
|
||||
}
|
||||
@@ -289,17 +301,17 @@ class _Inline extends \IPS\Patterns\ActiveRecord
|
||||
'itemSub' => ( $this->item_sub AND method_exists( $this->item_sub, 'apiOutput' ) ) ? $this->item_sub->apiOutput( $authorizedMember ) : NULL,
|
||||
'sentDate' => $this->sent_time->rfc3339(),
|
||||
'updatedDate' => $this->updated_time->rfc3339(),
|
||||
'readDate' => $this->read_time ? \IPS\DateTime::ts( $this->read_time )->rfc3339() : NULL,
|
||||
'readDate' => $this->read_time ? DateTime::ts( $this->read_time )->rfc3339() : NULL,
|
||||
'notificationData' => array_map( function( $val ) {
|
||||
if( $val instanceof \IPS\Http\Url )
|
||||
if( $val instanceof Url )
|
||||
{
|
||||
return (string) $val;
|
||||
}
|
||||
elseif( $val instanceof \IPS\Member )
|
||||
elseif( $val instanceof Member )
|
||||
{
|
||||
return $val->apiOutput();
|
||||
}
|
||||
elseif( $val instanceof \IPS\DateTime )
|
||||
elseif( $val instanceof DateTime )
|
||||
{
|
||||
return $val->rfc3339();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user