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
@@ -12,57 +12,86 @@
|
||||
namespace IPS\core\Alerts;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateInterval;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use IPS\Application;
|
||||
use IPS\Application\Module;
|
||||
use IPS\Content\Item;
|
||||
use IPS\Data\Store;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\File;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\CheckboxSet;
|
||||
use IPS\Helpers\Form\Date;
|
||||
use IPS\Helpers\Form\Editor;
|
||||
use IPS\Helpers\Form\Member as FormMember;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Form\Text;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Http\Url\Friendly;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Group;
|
||||
use IPS\Request;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use function is_object;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alerts Model
|
||||
*/
|
||||
class _Alert extends \IPS\Content\Item
|
||||
class Alert extends Item
|
||||
{
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_alerts';
|
||||
public static ?string $databaseTable = 'core_alerts';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Caches
|
||||
* @note Defined cache keys will be cleared automatically as needed
|
||||
*/
|
||||
protected $caches = array( 'alerts' );
|
||||
protected array $caches = array( 'alerts' );
|
||||
|
||||
/**
|
||||
* @brief Application
|
||||
*/
|
||||
public static $application = 'core';
|
||||
public static string $application = 'core';
|
||||
|
||||
/**
|
||||
* @brief Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'alert_';
|
||||
public static string $databasePrefix = 'alert_';
|
||||
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Map
|
||||
*/
|
||||
protected static $multitonMap = array();
|
||||
protected static array $multitonMap = array();
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'id';
|
||||
public static string $databaseColumnId = 'id';
|
||||
|
||||
/**
|
||||
* @brief Database Column Map
|
||||
*/
|
||||
public static $databaseColumnMap = array(
|
||||
public static array $databaseColumnMap = array(
|
||||
'title' => 'title',
|
||||
'date' => 'start',
|
||||
'author' => 'member_id',
|
||||
@@ -73,72 +102,60 @@ class _Alert extends \IPS\Content\Item
|
||||
/**
|
||||
* @brief Title
|
||||
*/
|
||||
public static $title = 'alert';
|
||||
public static string $title = 'alert';
|
||||
|
||||
/**
|
||||
* @brief Title
|
||||
*/
|
||||
public static $icon = 'bullhorn';
|
||||
public static string $icon = 'bullhorn';
|
||||
|
||||
|
||||
CONST REPLY_NOT_REQUIRED = 0;
|
||||
CONST REPLY_OPTIONAL = 1;
|
||||
CONST REPLY_REQUIRED = 2;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get SEO name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_seo_title()
|
||||
public function get_seo_title() : string
|
||||
{
|
||||
if( !$this->_data['seo_title'] )
|
||||
{
|
||||
$this->seo_title = \IPS\Http\Url\Friendly::seoTitle( $this->title );
|
||||
$this->seo_title = Friendly::seoTitle( $this->title );
|
||||
$this->save();
|
||||
}
|
||||
|
||||
return $this->_data['seo_title'] ?: \IPS\Http\Url\Friendly::seoTitle( $this->title );
|
||||
return $this->_data['seo_title'] ?: Friendly::seoTitle( $this->title );
|
||||
}
|
||||
|
||||
/**
|
||||
* Display Form
|
||||
*
|
||||
* @param static|NULL $alert Existing alert (for edits)
|
||||
* @return \IPS\Helpers\Form
|
||||
* @return Form
|
||||
*/
|
||||
public static function form( $alert )
|
||||
public static function form( ?Alert $alert ) : Form
|
||||
{
|
||||
/* Build the form */
|
||||
$form = new \IPS\Helpers\Form( NULL, 'save' );
|
||||
$form->class = 'ipsForm_vertical';
|
||||
$form = new Form( NULL, 'save' );
|
||||
$form->class = 'ipsForm--vertical ipsForm--edit-alert';
|
||||
|
||||
if ( ! \IPS\Member::loggedIn()->canUseMessenger() )
|
||||
if ( ! Member::loggedIn()->canUseMessenger() )
|
||||
{
|
||||
$form->addMessage( 'alert_you_cannot_receive_messages', 'ipsMessage ipsMessage_info' );
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'alert_title', ( $alert ) ? $alert->title : NULL, TRUE, array( 'maxLength' => 255 ) ) );
|
||||
$form->add( new Text( 'alert_title', ( $alert ) ? $alert->title : NULL, TRUE, array( 'maxLength' => 255 ) ) );
|
||||
|
||||
$today = new \IPS\DateTime;
|
||||
$form->add( new \IPS\Helpers\Form\Date( 'alert_start', ( $alert ) ? \IPS\DateTime::ts( $alert->start ) : new \IPS\DateTime, TRUE, array( 'time' => TRUE ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Date( 'alert_end', ( $alert AND $alert->end ) ? \IPS\DateTime::ts( $alert->end ) : 0, FALSE, array( 'min' => $today->setTime( 0, 0, 1 )->add( new \DateInterval( 'P1D' ) ), 'unlimited' => 0, 'unlimitedLang' => 'none' ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Editor( 'alert_content', ( $alert ) ? $alert->content : NULL, TRUE, array( 'app' => 'core', 'key' => 'Alert', 'autoSaveKey' => ( $alert ? 'editAlert__' . $alert->id : 'createAlert' ), 'attachIds' => $alert ? array( $alert->id, NULL, 'alert' ) : NULL ), NULL, NULL, NULL, 'alert_content' ) );
|
||||
$today = new DateTime;
|
||||
$form->add( new Date( 'alert_start', ( $alert ) ? DateTime::ts( $alert->start ) : new DateTime, TRUE, array( 'time' => TRUE ) ) );
|
||||
$form->add( new Date( 'alert_end', ( $alert AND $alert->end ) ? DateTime::ts( $alert->end ) : 0, FALSE, array( 'min' => $today->setTime( 0, 0, 1 )->add( new DateInterval( 'P1D' ) ), 'unlimited' => 0, 'unlimitedLang' => 'none' ) ) );
|
||||
$form->add( new Editor( 'alert_content', ( $alert ) ? $alert->content : NULL, TRUE, array( 'app' => 'core', 'key' => 'Alert', 'autoSaveKey' => ( $alert ? 'editAlert__' . $alert->id : 'createAlert' ), 'attachIds' => $alert ? array( $alert->id, NULL, 'alert' ) : NULL ), NULL, NULL, NULL, 'alert_content' ) );
|
||||
|
||||
$options = array( 'user' => 'alert_type_user', 'group' => 'alert_type_group' );
|
||||
$toggles = array( 'user' => array( 'alert_recipient_user' ), 'group' => array( 'alert_recipient_group', 'alert_show_to' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'alert_recipient_type', ( $alert ) ? $alert->recipient_type : NULL, TRUE, array( 'options' => $options, 'toggles' => $toggles ) ) );
|
||||
|
||||
$formFields = array();
|
||||
|
||||
foreach( $formFields as $field )
|
||||
{
|
||||
$form->add( $field );
|
||||
}
|
||||
$form->add( new Radio( 'alert_recipient_type', ( $alert ) ? $alert->recipient_type : NULL, TRUE, array( 'options' => $options, 'toggles' => $toggles ) ) );
|
||||
|
||||
$groups = array();
|
||||
foreach ( \IPS\Member\Group::groups( TRUE, FALSE ) as $group )
|
||||
foreach ( Group::groups( TRUE, FALSE ) as $group )
|
||||
{
|
||||
$groups[ $group->g_id ] = $group->name;
|
||||
}
|
||||
@@ -155,59 +172,59 @@ class _Alert extends \IPS\Content\Item
|
||||
'minimized' => FALSE
|
||||
];
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Member( 'alert_recipient_user', ( $alert and $alert->recipient_user ) ? \IPS\Member::load( $alert->recipient_user ) : ( isset( \IPS\Request::i()->user ) ? \IPS\Member::load( \IPS\Request::i()->user ) : NULL ), FALSE, array( 'multiple' => 1, 'autocomplete' => $autocomplete ), function( $member ) use ( $form )
|
||||
$form->add( new FormMember( 'alert_recipient_user', ( $alert and $alert->recipient_user ) ? Member::load( $alert->recipient_user ) : ( isset( Request::i()->user ) ? Member::load( Request::i()->user ) : NULL ), FALSE, array( 'multiple' => 1, 'autocomplete' => $autocomplete ), function( $member ) use ( $form )
|
||||
{
|
||||
if ( \IPS\Request::i()->alert_recipient_type === 'user' )
|
||||
if ( Request::i()->alert_recipient_type === 'user' )
|
||||
{
|
||||
if( !\is_object( $member ) or !$member->member_id )
|
||||
if( !is_object( $member ) or !$member->member_id )
|
||||
{
|
||||
throw new \InvalidArgumentException( 'alert_no_recipient_selected' );
|
||||
throw new InvalidArgumentException( 'alert_no_recipient_selected' );
|
||||
}
|
||||
|
||||
if ( ! $member->canUseMessenger() and \IPS\Request::i()->alert_reply == static::REPLY_REQUIRED )
|
||||
if ( ! $member->canUseMessenger() and Request::i()->alert_reply == 2 )
|
||||
{
|
||||
throw new \InvalidArgumentException( \IPS\Member::loggedIn()->language()->addToStack( 'alert_member_pm_disabled', NULL, [ 'sprintf' => $member->name ] ) );
|
||||
throw new InvalidArgumentException( Member::loggedIn()->language()->addToStack( 'alert_member_pm_disabled', NULL, [ 'sprintf' => $member->name ] ) );
|
||||
}
|
||||
}
|
||||
},
|
||||
NULL, NULL, 'alert_recipient_user' ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'alert_recipient_group', ( $alert and $alert->recipient_group ) ? explode( ',', $alert->recipient_group ) : array(), FALSE, array( 'options' => $groups, 'multiple' => TRUE ), function( $groups )
|
||||
$form->add( new CheckboxSet( 'alert_recipient_group', ( $alert and $alert->recipient_group ) ? explode( ',', $alert->recipient_group ) : array(), FALSE, array( 'options' => $groups, 'multiple' => TRUE ), function( $groups )
|
||||
{
|
||||
if ( \IPS\Request::i()->alert_reply == static::REPLY_REQUIRED )
|
||||
if ( Request::i()->alert_reply == 2 )
|
||||
{
|
||||
$module = \IPS\Application\Module::get( 'core', 'messaging' );
|
||||
$module = Module::get( 'core', 'messaging' );
|
||||
$names = [];
|
||||
foreach( $groups as $group )
|
||||
{
|
||||
$group = \IPS\Member\Group::load( $group );
|
||||
if ( ! ( \IPS\Application::load( $module->application )->canAccess( $group ) and ( $module->protected or $module->can( 'view', $group ) ) ) )
|
||||
$group = Group::load( $group );
|
||||
if ( ! ( Application::load( $module->application )->canAccess( $group ) and ( $module->protected or $module->can( 'view', $group ) ) ) )
|
||||
{
|
||||
$names[] = $group->name;
|
||||
}
|
||||
}
|
||||
|
||||
if ( \count( $names ) )
|
||||
if ( count( $names ) )
|
||||
{
|
||||
throw new \InvalidArgumentException( \IPS\Member::loggedIn()->language()->addToStack( 'alert_member_group_pm_disabled', NULL, [ 'htmlsprintf' => \IPS\Member::loggedIn()->language()->formatList( $names ) ] ) );
|
||||
throw new InvalidArgumentException( Member::loggedIn()->language()->addToStack( 'alert_member_group_pm_disabled', NULL, [ 'htmlsprintf' => Member::loggedIn()->language()->formatList( $names ) ] ) );
|
||||
}
|
||||
}
|
||||
},
|
||||
NULL, NULL, 'alert_recipient_group' ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'alert_show_to', ( $alert and $alert->show_to ) ? $alert->show_to : 'all', FALSE, [
|
||||
$form->add( new Radio( 'alert_show_to', ( $alert and $alert->show_to ) ? $alert->show_to : 'all', FALSE, [
|
||||
'options' => [
|
||||
'all' => 'alert_show_to_all',
|
||||
'new' => 'alert_show_to_new'
|
||||
]
|
||||
], NULL, NULL, NULL, 'alert_show_to' ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'alert_anonymous', ( $alert and $alert->anonymous ) ? TRUE : FALSE, TRUE, array( 'togglesOff' => array( 'alert_reply') ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'alert_reply', $alert ? $alert->reply : 0, TRUE, array( 'disabled' => (bool) \IPS\Member::loggedIn()->members_disable_pm, 'options' => array( '0' => 'alert_no_reply', '1' => 'alert_can_reply', '2' => 'alert_must_reply' ) ), NULL, NULL, NULL, 'alert_reply' ) );
|
||||
$form->add( new YesNo( 'alert_anonymous', $alert and $alert->anonymous, TRUE, array( 'togglesOff' => array( 'alert_reply') ) ) );
|
||||
$form->add( new Radio( 'alert_reply', $alert ? $alert->reply : 0, TRUE, array( 'disabled' => (bool) Member::loggedIn()->members_disable_pm, 'options' => array( '0' => 'alert_no_reply', '1' => 'alert_can_reply', '2' => 'alert_must_reply' ) ), NULL, NULL, NULL, 'alert_reply' ) );
|
||||
|
||||
if ( \IPS\Member::loggedIn()->members_disable_pm )
|
||||
if ( Member::loggedIn()->members_disable_pm )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['alert_reply_desc'] = \IPS\Member::loggedIn()->language()->get('alert_reply__nopm_desc');
|
||||
Member::loggedIn()->language()->words['alert_reply_desc'] = Member::loggedIn()->language()->get('alert_reply__nopm_desc');
|
||||
}
|
||||
|
||||
return $form;
|
||||
@@ -218,28 +235,28 @@ class _Alert extends \IPS\Content\Item
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getStore()
|
||||
public static function getStore(): array
|
||||
{
|
||||
if ( !isset( \IPS\Data\Store::i()->alerts ) )
|
||||
if ( !isset( Store::i()->alerts ) )
|
||||
{
|
||||
\IPS\Data\Store::i()->alerts = iterator_to_array( \IPS\Db::i()->select( '*', static::$databaseTable, [
|
||||
Store::i()->alerts = iterator_to_array( Db::i()->select( '*', static::$databaseTable, [
|
||||
[ 'alert_enabled=?', 1 ],
|
||||
[ 'alert_start < ?', time() ],
|
||||
[ '( alert_end = 0 or alert_end > ? )', time() ]
|
||||
], "alert_start ASC" )->setKeyField( 'alert_id' ) );
|
||||
}
|
||||
|
||||
return \IPS\Data\Store::i()->alerts;
|
||||
return Store::i()->alerts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create from form
|
||||
*
|
||||
* @param array $values Values from form
|
||||
* @param \IPS\core\Alerts\Alert|NULL $current Current alert
|
||||
* @return \IPS\core\Alerts\Alert
|
||||
* @param Alert|null $current Current alert
|
||||
* @return Alert
|
||||
*/
|
||||
public static function _createFromForm( $values, $current )
|
||||
public static function _createFromForm( array $values, ?Alert $current ) : static
|
||||
{
|
||||
if( $current )
|
||||
{
|
||||
@@ -248,11 +265,11 @@ class _Alert extends \IPS\Content\Item
|
||||
else
|
||||
{
|
||||
$obj = new static;
|
||||
$obj->member_id = \IPS\Member::loggedIn()->member_id;
|
||||
$obj->member_id = Member::loggedIn()->member_id;
|
||||
}
|
||||
|
||||
$obj->title = $values['alert_title'];
|
||||
$obj->seo_title = \IPS\Http\Url\Friendly::seoTitle( $values['alert_title'] );
|
||||
$obj->seo_title = Friendly::seoTitle( $values['alert_title'] );
|
||||
$obj->content = $values['alert_content'];
|
||||
$obj->start = !empty( $values['alert_start'] ) ? ( $values['alert_start']->getTimestamp() < time() ) ? time() : $values['alert_start']->getTimestamp() : time();
|
||||
$obj->end = !empty ($values['alert_end'] ) ? $values['alert_end']->getTimestamp() : 0;
|
||||
@@ -261,7 +278,7 @@ class _Alert extends \IPS\Content\Item
|
||||
|
||||
if( $obj->recipient_type == 'user' )
|
||||
{
|
||||
if( \is_object( $values['alert_recipient_user'] ) )
|
||||
if( is_object( $values['alert_recipient_user'] ) )
|
||||
{
|
||||
$values['alert_recipient_user'] = $values['alert_recipient_user']->member_id;
|
||||
}
|
||||
@@ -276,13 +293,13 @@ class _Alert extends \IPS\Content\Item
|
||||
}
|
||||
|
||||
$obj->anonymous = $values['alert_anonymous'];
|
||||
$obj->reply = ( ! \IPS\Member::loggedIn()->canUseMessenger() ) ? 0 : $values['alert_reply'];
|
||||
$obj->reply = ( ! Member::loggedIn()->canUseMessenger() ) ? 0 : $values['alert_reply'];
|
||||
|
||||
$obj->save();
|
||||
|
||||
if( !$current )
|
||||
{
|
||||
\IPS\File::claimAttachments( 'createAlert', $obj->id, NULL, 'alert' );
|
||||
File::claimAttachments( 'createAlert', $obj->id, NULL, 'alert' );
|
||||
}
|
||||
|
||||
return $obj;
|
||||
@@ -291,21 +308,21 @@ class _Alert extends \IPS\Content\Item
|
||||
/**
|
||||
* @brief Cached URLs
|
||||
*/
|
||||
protected $_url = array();
|
||||
protected mixed $_url = array();
|
||||
|
||||
/**
|
||||
* Get URL
|
||||
*
|
||||
* @param string|NULL $action Action
|
||||
* @return \IPS\Http\Url
|
||||
* @return Url
|
||||
*/
|
||||
public function url( $action=NULL )
|
||||
public function url( string|null $action=NULL ): Url
|
||||
{
|
||||
$_key = md5( $action );
|
||||
$_key = $action ? md5( $action ) : NULL;
|
||||
|
||||
if( !isset( $this->_url[ $_key ] ) )
|
||||
{
|
||||
$this->_url[ $_key ] = \IPS\Http\Url::internal( "app=core&module=modcp&controller=modcp&tab=alerts&id={$this->id}", 'front', 'modcp_alerts' );
|
||||
$this->_url[ $_key ] = Url::internal( "app=core&module=modcp&controller=modcp&tab=alerts&id={$this->id}", 'front', 'modcp_alerts' );
|
||||
$this->_url[ $_key ] = $this->_url[ $_key ]->setQueryString( 'action', $action );
|
||||
}
|
||||
|
||||
@@ -315,11 +332,11 @@ class _Alert extends \IPS\Content\Item
|
||||
/**
|
||||
* Get owner
|
||||
*
|
||||
* @return \IPS\Member
|
||||
* @return Member
|
||||
*/
|
||||
public function owner()
|
||||
public function owner() : Member
|
||||
{
|
||||
return \IPS\Member::load( $this->member_id );
|
||||
return Member::load( $this->member_id );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -327,9 +344,9 @@ class _Alert extends \IPS\Content\Item
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function unclaimAttachments()
|
||||
protected function unclaimAttachments(): void
|
||||
{
|
||||
\IPS\File::unclaimAttachments( 'core_Alert', $this->id, NULL, 'alert' );
|
||||
File::unclaimAttachments( 'core_Alert', $this->id, NULL, 'alert' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -337,7 +354,7 @@ class _Alert extends \IPS\Content\Item
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getTableFilters()
|
||||
public static function getTableFilters(): array
|
||||
{
|
||||
return array(
|
||||
'active', 'inactive'
|
||||
@@ -345,26 +362,26 @@ class _Alert extends \IPS\Content\Item
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \IPS\Member $member
|
||||
* @param Member $member
|
||||
*
|
||||
* @return \IPS\core\Alerts\Alert|NULL
|
||||
* @return Alert|NULL
|
||||
*/
|
||||
public static function getNextAlertForMember( \IPS\Member $member ): ?Alert
|
||||
public static function getNextAlertForMember( Member $member ): ?Alert
|
||||
{
|
||||
$alerts = static::getStore();
|
||||
|
||||
if ( ! \count( $alerts ) )
|
||||
if ( ! count( $alerts ) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Get possible alerts for this member (group alerts are checked in PHP) */
|
||||
$query = \IPS\Db::i()->select( '*', 'core_alerts', [
|
||||
$query = Db::i()->select( '*', 'core_alerts', [
|
||||
[ 'alert_enabled=?', 1 ],
|
||||
[ 'alert_start < ?', time() ],
|
||||
[ '( alert_end = 0 or alert_end > ? )', time() ],
|
||||
[ '( alert_recipient_type=? OR ( alert_recipient_type=? AND alert_recipient_user=? ) )', 'group', 'user', $member->member_id ],
|
||||
[ 'alert_id NOT IN (?)', \IPS\Db::i()->select( 'seen_alert_id', 'core_alerts_seen', [ 'seen_member_id=?', $member->member_id ] ) ]
|
||||
[ 'alert_id NOT IN (?)', Db::i()->select( 'seen_alert_id', 'core_alerts_seen', [ 'seen_member_id=?', $member->member_id ] ) ]
|
||||
], 'alert_start ASC' );
|
||||
|
||||
foreach( $query as $data )
|
||||
@@ -382,9 +399,10 @@ class _Alert extends \IPS\Content\Item
|
||||
/**
|
||||
* Is this alert valid for the member?
|
||||
*
|
||||
* @param Member $member
|
||||
* @return Bool
|
||||
*/
|
||||
public function forMember( $member )
|
||||
public function forMember( Member $member ) : bool
|
||||
{
|
||||
/* Is it disabled? */
|
||||
if ( ! $this->enabled )
|
||||
@@ -393,7 +411,7 @@ class _Alert extends \IPS\Content\Item
|
||||
}
|
||||
|
||||
/* Are we the alert author? */
|
||||
if ( $this->member_id == \IPS\Member::loggedIn()->member_id )
|
||||
if ( $this->member_id == Member::loggedIn()->member_id )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@@ -423,7 +441,7 @@ class _Alert extends \IPS\Content\Item
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( $this->show_to == 'new' and ( \IPS\Member::loggedIn()->joined->getTimestamp() < $this->start ) )
|
||||
if ( $this->show_to == 'new' and ( Member::loggedIn()->joined->getTimestamp() < $this->start ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@@ -446,9 +464,9 @@ class _Alert extends \IPS\Content\Item
|
||||
{
|
||||
$groups = explode( ',', $this->recipient_group );
|
||||
|
||||
foreach ( \IPS\Member\Group::groups() as $group )
|
||||
foreach ( Group::groups() as $group )
|
||||
{
|
||||
if ( \in_array( $group->g_id, $groups ) )
|
||||
if ( in_array( $group->g_id, $groups ) )
|
||||
{
|
||||
$names[] = $group->name;
|
||||
}
|
||||
@@ -466,18 +484,18 @@ class _Alert extends \IPS\Content\Item
|
||||
*/
|
||||
public function memberName(): string
|
||||
{
|
||||
$member = \IPS\Member::load( $this->recipient_user );
|
||||
return ( $member->member_id ) ? $member->name :\IPS\Member::loggedIn()->language()->addToStack( 'deleted_member' );
|
||||
$member = Member::load( $this->recipient_user );
|
||||
return ( $member->member_id ) ? $member->name : Member::loggedIn()->language()->addToStack( 'deleted_member' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark this alert as viewed
|
||||
*
|
||||
* @param \IPS\Member|null $member Member who viewed
|
||||
* @param Member|null $member Member who viewed
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function viewed( \IPS\Member $member=NULL )
|
||||
public function viewed( ?Member $member=NULL ) : void
|
||||
{
|
||||
$this->viewed++;
|
||||
$this->save();
|
||||
@@ -486,20 +504,20 @@ class _Alert extends \IPS\Content\Item
|
||||
/**
|
||||
* Dismiss alert
|
||||
*
|
||||
* @param \IPS\Member|null $member Member who viewed
|
||||
* @param Member|null $member Member who viewed
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dismiss( \IPS\Member $member=NULL )
|
||||
public function dismiss( ?Member $member=NULL ) : void
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
$member = $member ?: Member::loggedIn();
|
||||
|
||||
if( !$this->forMember( $member ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
\IPS\Db::i()->insert( 'core_alerts_seen', [
|
||||
Db::i()->insert( 'core_alerts_seen', [
|
||||
'seen_alert_id' => $this->id,
|
||||
'seen_member_id' => $member->member_id,
|
||||
'seen_date' => time()
|
||||
@@ -512,13 +530,13 @@ class _Alert extends \IPS\Content\Item
|
||||
/**
|
||||
* [ActiveRecord] Delete Record
|
||||
*
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
parent::delete();
|
||||
|
||||
\IPS\Db::i()->delete( 'core_alerts_seen', [ 'seen_alert_id=?', $this->id ] );
|
||||
Db::i()->delete( 'core_alerts_seen', [ 'seen_alert_id=?', $this->id ] );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -528,18 +546,18 @@ class _Alert extends \IPS\Content\Item
|
||||
*/
|
||||
public function membersRepliedCount(): int
|
||||
{
|
||||
return (int) \IPS\Db::i()->select( 'COUNT(*)', 'core_message_topics', [ 'mt_alert=?', $this->id ] )->first();
|
||||
return (int) Db::i()->select( 'COUNT(*)', 'core_message_topics', [ 'mt_alert=?', $this->id ] )->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current alert that messenger is being filtered by
|
||||
*
|
||||
* @param \IPS\Member|null $member
|
||||
* @param Member|null $member
|
||||
* @return Alert|null
|
||||
*/
|
||||
public static function getAlertCurrentlyFilteringMessages( ?\IPS\Member $member = NULL ): ?\IPS\core\Alerts\Alert
|
||||
public static function getAlertCurrentlyFilteringMessages( ?Member $member = NULL ): ?Alert
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
$member = $member ?: Member::loggedIn();
|
||||
|
||||
if ( isset( $_SESSION['mt_alert'] ) )
|
||||
{
|
||||
@@ -555,7 +573,7 @@ class _Alert extends \IPS\Content\Item
|
||||
|
||||
return $alert;
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
catch( Exception $e ) { }
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -567,7 +585,7 @@ class _Alert extends \IPS\Content\Item
|
||||
* @param Alert $alert
|
||||
* @return void
|
||||
*/
|
||||
public static function setAlertCurrentlyFilteringMessages( \IPS\core\Alerts\Alert $alert )
|
||||
public static function setAlertCurrentlyFilteringMessages( Alert $alert ) : void
|
||||
{
|
||||
$_SESSION['mt_alert'] = $alert->id;
|
||||
}
|
||||
@@ -577,8 +595,34 @@ class _Alert extends \IPS\Content\Item
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function clearMessengerFilters()
|
||||
public static function clearMessengerFilters() : void
|
||||
{
|
||||
unset( $_SESSION['mt_alert'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the form to create a conversation based from an alert
|
||||
*
|
||||
* @param Member|null $member
|
||||
* @return Form|null
|
||||
*/
|
||||
public function getNewConversationForm( ?Member $member = null ) : Form|null
|
||||
{
|
||||
$member = $member?: Member::loggedIn();
|
||||
if ( !$this->anonymous and $this->reply and $this->author()->member_id and $member->canUseMessenger())
|
||||
{
|
||||
$form = \IPS\core\Messenger\Conversation::create();
|
||||
$form->class = 'ipsForm ipsForm--fullWidth';
|
||||
$form->elements['']['messenger_content']->defaultValue = '<blockquote class="ipsQuote">' . $this->content . "</blockquote><br>";
|
||||
$form->elements['']['messenger_content']->setValue(TRUE , FALSE );
|
||||
$form->elements['']['messenger_to']->defaultValue = $form->elements['']['messenger_to']->value = $this->author();
|
||||
$form->elements['']['messenger_title']->defaultValue = $form->elements['']['messenger_title']->value = \IPS\Member::loggedIn()->language()->get( "alert_response_prefix" ) . $this->title;
|
||||
$form->hiddenValues['alert'] = $this->id;
|
||||
$form->hiddenValues['messenger_title'] = $this->title;
|
||||
\IPS\Member::loggedIn()->language()->words['messenger_content'] = \IPS\Member::loggedIn()->language()->addToStack( 'reply' );
|
||||
return $form;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user