* @link https://TheTempusProject.com * @license https://opensource.org/licenses/MIT [MIT LICENSE] */ namespace TheTempusProject\Plugins; use TheTempusProject\TheTempusProject as App; use TheTempusProject\Classes\Plugin; use TheTempusProject\Models\Notification; use TheTempusProject\Houdini\Classes\Components; use TheTempusProject\Houdini\Classes\Views; class Notifications extends Plugin { public $pluginName = 'TP Notifications'; public $configName = 'notifications'; public $pluginAuthor = 'JoeyK'; public $pluginWebsite = 'https://TheTempusProject.com'; public $modelVersion = '1.0'; public $pluginVersion = '3.0'; public $pluginDescription = 'A simple plugin which adds a site wide notification system.'; public $permissionMatrix = [ 'sendNotifications' => [ 'pretty' => 'Can send notifications', 'default' => false, ], ]; public $admin_links = [ [ 'text' => ' Notify', 'url' => '{ROOT_URL}admin/notifications', ], ]; private static $loaded = false; public function __construct( $load = false ) { parent::__construct( $load ); if ( $this->checkEnabled() && App::$isLoggedIn ) { $notifications = new Notification; Components::set( 'notificationCount', $notifications->getUnreadCount( App::$activeUser->ID ) ); if ( $notifications->getUnreadCount( App::$activeUser->ID ) > 0 ) { $messageBadge = Views::simpleView( 'notifications.badge' ); } else { $messageBadge = ''; } Components::set( 'NBADGE', $messageBadge ); if ( App::$isLoggedIn ) { Components::set( 'recentNotifications', Views::simpleView( 'notifications.nav.recentNotificationsDropdown', $notifications->getByUser( 10 ) ) ); } else { Components::set( 'recentNotifications', '' ); } if ( ! self::$loaded ) { App::$topNavRight .= '{recentNotifications}'; App::$topNavRightDropdown .= '
  • Notifications {NBADGE}
  • '; self::$loaded = true; } } } }