| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
#[AllowDynamicProperties] |
| 3 |
class SH4_Notifications_Html_Admin_View_TurnOnOff |
| 4 |
{ |
| 5 |
public function __construct( |
| 6 |
HC3_Hooks $hooks, |
| 7 |
HC3_Ui $ui, |
| 8 |
HC3_Enqueuer $enqueuer, |
| 9 |
HC3_Notificator $notificator, |
| 10 |
|
| 11 |
HC3_Auth $auth, |
| 12 |
HC3_IPermission $permission |
| 13 |
) |
| 14 |
{ |
| 15 |
$this->self = $hooks->wrap( $this ); |
| 16 |
$this->ui = $hooks->wrap( $ui ); |
| 17 |
|
| 18 |
$this->auth = $hooks->wrap( $auth ); |
| 19 |
$this->permission = $hooks->wrap($permission); |
| 20 |
$this->notificator = $hooks->wrap($notificator); |
| 21 |
$this->enqueuer = $enqueuer; |
| 22 |
} |
| 23 |
|
| 24 |
public function render( $return ) |
| 25 |
{ |
| 26 |
$out = array(); |
| 27 |
$out[] = $this->self->renderInput(); |
| 28 |
$out = $this->ui->makeListInline( $out )->gutter(1); |
| 29 |
|
| 30 |
$to = 'admin/notifications/turnonoff'; |
| 31 |
$out = $this->ui->makeForm( $to, $out ); |
| 32 |
|
| 33 |
$out = $this->ui->makeBlock( $out ) |
| 34 |
->addAttr('class', 'sh4-skip-notifications') |
| 35 |
; |
| 36 |
|
| 37 |
if( isset($return[3]) ){ |
| 38 |
$return[3] = $this->ui->makeList( array($return[3], $out) ); |
| 39 |
} |
| 40 |
else { |
| 41 |
$return[3] = $out; |
| 42 |
} |
| 43 |
|
| 44 |
return $return; |
| 45 |
} |
| 46 |
|
| 47 |
public function renderInput() |
| 48 |
{ |
| 49 |
$return = NULL; |
| 50 |
|
| 51 |
$currentUser = $this->auth->getCurrentUser(); |
| 52 |
$isAdmin = $this->permission->isAdmin( $currentUser ); |
| 53 |
|
| 54 |
if( ! $isAdmin ){ |
| 55 |
return $return; |
| 56 |
} |
| 57 |
|
| 58 |
$this->enqueuer->addScript('notifications', 'sh4/notifications/assets/js/skip-notifications.js?hcver=' . SH4_VERSION); |
| 59 |
|
| 60 |
$isOff = $this->notificator->isOff(); |
| 61 |
$return = $this->ui->makeInputCheckbox( 'notifications_turnoff', '__Skip Notifications__', 1, $isOff ); |
| 62 |
|
| 63 |
return $return; |
| 64 |
} |
| 65 |
} |