Plugin: External Notification Connect: Send notification when changing post visibility - refs BT#20443
parent
d32f518ed5
commit
2675965ec5
@ -0,0 +1,22 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
class HookPortfolioItemVisibility extends HookEvent implements HookPortfolioItemVisibilityEventInterface |
||||
{ |
||||
protected function __construct() |
||||
{ |
||||
parent::__construct('HookPortfolioItemVisibility'); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public function notifyItemVisibility() |
||||
{ |
||||
/** @var HookPortfolioItemVisibilityObserverInterface $observer */ |
||||
foreach ($this->observers as $observer) { |
||||
$observer->hookItemVisibility($this); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,11 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
interface HookPortfolioItemVisibilityEventInterface extends HookEventInterface |
||||
{ |
||||
/** |
||||
* @return void |
||||
*/ |
||||
public function notifyItemVisibility(); |
||||
} |
||||
@ -0,0 +1,11 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
interface HookPortfolioItemVisibilityObserverInterface extends HookObserverInterface |
||||
{ |
||||
/** |
||||
* @return void |
||||
*/ |
||||
public function hookItemVisibility(HookPortfolioItemVisibilityEventInterface $event); |
||||
} |
||||
@ -0,0 +1,44 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
use Chamilo\CoreBundle\Entity\Portfolio; |
||||
use Chamilo\PluginBundle\ExternalNotificationConnect\Traits\RequestTrait\RequestTrait; |
||||
|
||||
class ExternalNotificationConnectPortfolioItemVisibilityHookObserver extends ExternalNotificationConnectHookObserver implements HookPortfolioItemVisibilityObserverInterface |
||||
{ |
||||
use RequestTrait; |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
public function hookItemVisibility(HookPortfolioItemVisibilityEventInterface $event) |
||||
{ |
||||
/** @var Portfolio $item */ |
||||
$item = $event->getEventData()['item']; |
||||
$recipients = $event->getEventData()['recipients']; |
||||
|
||||
try { |
||||
$json = $this->doVisibilityRequest( |
||||
[ |
||||
'content_id' => $item->getId(), |
||||
'content_type' => 'eportfolio', |
||||
'visibility' => $item->getVisibility(), |
||||
'user_list' => $recipients, |
||||
] |
||||
); |
||||
} catch (Exception $e) { |
||||
Display::addFlash( |
||||
Display::return_message($e->getMessage(), 'error') |
||||
); |
||||
|
||||
return; |
||||
} |
||||
|
||||
if (empty($json)) { |
||||
return; |
||||
} |
||||
|
||||
error_log('ExtNotifConn: Portfolio item visibility: ID '.$json['data']['notification_id']); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue