Merge branch 'danbarretodev-hook' into 1.10.x

1.10.x
Yannick Warnier 10 years ago
commit 9e50a0b5d2
  1. 5
      main/inc/lib/hook/HookEvent.php
  2. 48
      main/inc/lib/hook/HookNotificationContent.php
  3. 49
      main/inc/lib/hook/HookNotificationTitle.php
  4. 18
      main/inc/lib/hook/interfaces/HookNotificationContentEventInterface.php
  5. 18
      main/inc/lib/hook/interfaces/HookNotificationContentObserverInterface.php
  6. 18
      main/inc/lib/hook/interfaces/HookNotificationTitleEventInterface.php
  7. 18
      main/inc/lib/hook/interfaces/HookNotificationTitleObserverInterface.php
  8. 32
      main/inc/lib/notification.lib.php
  9. 2
      vendor/autoload.php
  10. 7
      vendor/composer/autoload_classmap.php
  11. 10
      vendor/composer/autoload_real.php

@ -126,7 +126,10 @@ abstract class HookEvent implements HookEventInterface
*/
public function setEventData(array $data)
{
$this->eventData = $data;
foreach ($data as $key => $value) {
// Assign value for each array item
$this->eventData[$key] = $value;
}
return $this;
}

@ -0,0 +1,48 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This file contains the Hook Event class for Content format of Notifications
* @package chamilo.library.hook
*/
/**
* Class HookNotificationContent
*/
class HookNotificationContent extends HookEvent implements HookNotificationContentEventInterface
{
/**
* Construct
*/
protected function __construct()
{
parent::__construct('HookNotificationContent');
}
/**
* @param int $type
* @return array|null
*/
public function notifyNotificationContent($type)
{
/** @var \HookNotificationContentObserverInterface $observer */
// Check if exists data content
if (isset($this->eventData['content'])) {
// Save data type
$this->eventData['type'] = $type;
// Check for hook all registered observers
foreach ($this->observers as $observer) {
$data = $observer->hookNotificationContent($this);
// Check if isset content
if (isset($data['content'])) {
// Set data from hook observer data
$this->setEventData($data);
}
}
return $this->eventData;
}
return null;
}
}

@ -0,0 +1,49 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This file contains the Hook Event class for Title of Notifications
* @package chamilo.library.hook
*/
/**
* Class HookNotificationTitle
*/
class HookNotificationTitle extends HookEvent implements HookNotificationTitleEventInterface
{
/**
* Construct
*/
protected function __construct()
{
parent::__construct('HookNotificationTitle');
}
/**
* @param int $type
* @return array|null
*/
public function notifyNotificationTitle($type)
{
/** @var \HookNotificationTitleObserverInterface $observer */
// Check if exists data title
if (isset($this->eventData['title'])) {
// Save data type
$this->eventData['type'] = $type;
// Check for hook all registered observers
foreach ($this->observers as $observer) {
// Get data from hook observer
$data = $observer->hookNotificationTitle($this);
// Check if isset data title
if (isset($data['title'])) {
// Set data from hook observer data
$this->setEventData($data);
}
}
return $this->eventData;
}
return null;
}
}

@ -0,0 +1,18 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This file contains Hook event interface for notification content
* @package chamilo.library.hook
*/
/**
* Interface HookNotificationContentEventInterface
*/
interface HookNotificationContentEventInterface extends HookEventInterface
{
/**
* @param int $type
* @return array
*/
public function notifyNotificationContent($type);
}

@ -0,0 +1,18 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This file contains Hook observer interface for notification content
* @package chamilo.library.hook
*/
/**
* Interface HookNotificationContentObserverInterface
*/
interface HookNotificationContentObserverInterface extends HookObserverInterface
{
/**
* @param HookNotificationContentEventInterface $hook
* @return array
*/
public function hookNotificationContent(HookNotificationContentEventInterface $hook);
}

@ -0,0 +1,18 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This file contains Hook event interface for notification title
* @package chamilo.library.hook
*/
/**
* Interface HookNotificationTitleEventInterface
*/
interface HookNotificationTitleEventInterface extends HookEventInterface
{
/**
* @param int $type
* @return array
*/
public function notifyNotificationTitle($type);
}

@ -0,0 +1,18 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This file contains Hook observer interface for notification title
* @package chamilo.library.hook
*/
/**
* Interface HookNotificationTitleObserverInterface
*/
interface HookNotificationTitleObserverInterface extends HookObserverInterface
{
/**
* @param HookNotificationTitleEventInterface $hook
* @return array
*/
public function hookNotificationTitle(HookNotificationTitleEventInterface $hook);
}

@ -144,6 +144,14 @@ class Notification extends Model
*/
public function formatTitle($title, $senderInfo)
{
$hook = HookNotificationTitle::create();
if (!empty($hook)) {
$hook->setEventData(array('title' => $title));
$data = $hook->notifyNotificationTitle(HOOK_TYPE_PRE);
if (isset($data['title'])) {
$title = $data['title'];
}
}
$newTitle = $this->getTitlePrefix();
switch ($this->type) {
@ -184,6 +192,14 @@ class Notification extends Model
break;
}
if (!empty($hook)) {
$hook->setEventData(array('title' => $newTitle));
$data = $hook->notifyNotificationTitle(HOOK_TYPE_POST);
if (isset($data['title'])) {
$newTitle = $data['title'];
}
}
return $newTitle;
}
@ -309,6 +325,14 @@ class Notification extends Model
* */
public function formatContent($content, $sender_info)
{
$hook = HookNotificationContent::create();
if (!empty($hook)) {
$hook->setEventData(array('content' => $content));
$data = $hook->notifyNotificationContent(HOOK_TYPE_PRE);
if (isset($data['content'])) {
$content = $data['content'];
}
}
$new_message_text = $link_to_new_message = '';
switch ($this->type) {
@ -382,6 +406,14 @@ class Notification extends Model
Display::url($preference_url, $preference_url)
).'</i>';
if (!empty($hook)) {
$hook->setEventData(array('content' => $content));
$data = $hook->notifyNotificationContent(HOOK_TYPE_POST);
if (isset($data['content'])) {
$content = $data['content'];
}
}
return $content;
}
}

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInita9b0f303a257c742005e4211979b1a3b::getLoader();
return ComposerAutoloaderInit2a4794162b3ce734639136efd77d5c25::getLoader();

@ -821,6 +821,12 @@ return array(
'HookEventInterface' => $baseDir . '/main/inc/lib/hook/interfaces/base/HookEventInterface.php',
'HookManagement' => $baseDir . '/main/inc/lib/hook/HookManagement.php',
'HookManagementInterface' => $baseDir . '/main/inc/lib/hook/interfaces/base/HookManagementInterface.php',
'HookNotificationContent' => $baseDir . '/main/inc/lib/hook/HookNotificationContent.php',
'HookNotificationContentEventInterface' => $baseDir . '/main/inc/lib/hook/interfaces/HookNotificationContentEventInterface.php',
'HookNotificationContentObserverInterface' => $baseDir . '/main/inc/lib/hook/interfaces/HookNotificationContentObserverInterface.php',
'HookNotificationTitle' => $baseDir . '/main/inc/lib/hook/HookNotificationTitle.php',
'HookNotificationTitleEventInterface' => $baseDir . '/main/inc/lib/hook/interfaces/HookNotificationTitleEventInterface.php',
'HookNotificationTitleObserverInterface' => $baseDir . '/main/inc/lib/hook/interfaces/HookNotificationTitleObserverInterface.php',
'HookObserver' => $baseDir . '/main/inc/lib/hook/HookObserver.php',
'HookObserverInterface' => $baseDir . '/main/inc/lib/hook/interfaces/base/HookObserverInterface.php',
'HookPluginInterface' => $baseDir . '/main/inc/lib/hook/interfaces/base/HookPluginInterface.php',
@ -858,7 +864,6 @@ return array(
'ImsAnswerHotspot' => $baseDir . '/main/exercice/export/qti2/qti2_classes.php',
'ImsAnswerMatching' => $baseDir . '/main/exercice/export/qti2/qti2_classes.php',
'ImsAnswerMultipleChoice' => $baseDir . '/main/exercice/export/qti2/qti2_classes.php',
'ImsAnswerTrueFalse' => $baseDir . '/main/exercice/export/qti/qti_classes.php',
'ImsAssessmentItem' => $baseDir . '/main/exercice/export/qti2/qti2_export.php',
'ImsItem' => $baseDir . '/main/exercice/export/qti2/qti2_export.php',
'ImsSection' => $baseDir . '/main/exercice/export/qti2/qti2_export.php',

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInita9b0f303a257c742005e4211979b1a3b
class ComposerAutoloaderInit2a4794162b3ce734639136efd77d5c25
{
private static $loader;
@ -19,9 +19,9 @@ class ComposerAutoloaderInita9b0f303a257c742005e4211979b1a3b
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInita9b0f303a257c742005e4211979b1a3b', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit2a4794162b3ce734639136efd77d5c25', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInita9b0f303a257c742005e4211979b1a3b', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit2a4794162b3ce734639136efd77d5c25', 'loadClassLoader'));
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
@ -42,14 +42,14 @@ class ComposerAutoloaderInita9b0f303a257c742005e4211979b1a3b
$includeFiles = require __DIR__ . '/autoload_files.php';
foreach ($includeFiles as $file) {
composerRequirea9b0f303a257c742005e4211979b1a3b($file);
composerRequire2a4794162b3ce734639136efd77d5c25($file);
}
return $loader;
}
}
function composerRequirea9b0f303a257c742005e4211979b1a3b($file)
function composerRequire2a4794162b3ce734639136efd77d5c25($file)
{
require $file;
}

Loading…
Cancel
Save