From dd2fc3f2d80566ab0d6db3049f2480888482fe8a Mon Sep 17 00:00:00 2001 From: Daniel Barreto Date: Mon, 9 Feb 2015 16:13:12 -0500 Subject: [PATCH 1/3] Add hook for notification content and notification title formats - refs BT#9092 Conflicts: main/inc/lib/hook/HookEvent.class.php --- main/inc/lib/hook/HookEvent.php | 4 +- main/inc/lib/hook/HookNotificationContent.php | 42 +++++++++++++++++++ main/inc/lib/hook/HookNotificationTitle.php | 42 +++++++++++++++++++ .../HookNotificationContentEventInterface.php | 14 +++++++ ...okNotificationContentObserverInterface.php | 14 +++++++ .../HookNotificationTitleEventInterface.php | 14 +++++++ ...HookNotificationTitleObserverInterface.php | 14 +++++++ main/inc/lib/notification.lib.php | 32 ++++++++++++++ 8 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 main/inc/lib/hook/HookNotificationContent.php create mode 100644 main/inc/lib/hook/HookNotificationTitle.php create mode 100644 main/inc/lib/hook/interfaces/HookNotificationContentEventInterface.php create mode 100644 main/inc/lib/hook/interfaces/HookNotificationContentObserverInterface.php create mode 100644 main/inc/lib/hook/interfaces/HookNotificationTitleEventInterface.php create mode 100644 main/inc/lib/hook/interfaces/HookNotificationTitleObserverInterface.php diff --git a/main/inc/lib/hook/HookEvent.php b/main/inc/lib/hook/HookEvent.php index 759fb35206..c4755f6fb9 100644 --- a/main/inc/lib/hook/HookEvent.php +++ b/main/inc/lib/hook/HookEvent.php @@ -126,7 +126,9 @@ abstract class HookEvent implements HookEventInterface */ public function setEventData(array $data) { - $this->eventData = $data; + foreach ($data as $key => $value) { + $this->eventData[$key] = $value; + } return $this; } diff --git a/main/inc/lib/hook/HookNotificationContent.php b/main/inc/lib/hook/HookNotificationContent.php new file mode 100644 index 0000000000..cbef32b58d --- /dev/null +++ b/main/inc/lib/hook/HookNotificationContent.php @@ -0,0 +1,42 @@ +eventData['content'])) { + $this->eventData['type'] = $type; + foreach ($this->observers as $observer) { + $data = $observer->hookNotificationContent($this); + if (isset($data['content'])) { + $this->setEventData($data); + } + } + + return $this->eventData; + } + + return null; + } +} \ No newline at end of file diff --git a/main/inc/lib/hook/HookNotificationTitle.php b/main/inc/lib/hook/HookNotificationTitle.php new file mode 100644 index 0000000000..8df6fe31cd --- /dev/null +++ b/main/inc/lib/hook/HookNotificationTitle.php @@ -0,0 +1,42 @@ +eventData['title'])) { + $this->eventData['type'] = $type; + foreach ($this->observers as $observer) { + $data = $observer->hookNotificationTitle($this); + if (isset($data['title'])) { + $this->setEventData($data); + } + } + + return $this->eventData; + } + + return null; + } +} \ No newline at end of file diff --git a/main/inc/lib/hook/interfaces/HookNotificationContentEventInterface.php b/main/inc/lib/hook/interfaces/HookNotificationContentEventInterface.php new file mode 100644 index 0000000000..a4b931a151 --- /dev/null +++ b/main/inc/lib/hook/interfaces/HookNotificationContentEventInterface.php @@ -0,0 +1,14 @@ +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) ).''; + if (!empty($hook)) { + $hook->setEventData(array('content' => $content)); + $data = $hook->notifyNotificationContent(HOOK_TYPE_POST); + if (isset($data['content'])) { + $content = $data['content']; + } + } + return $content; } } From 219ef5b7951cc720d72c87927c719935062a4701 Mon Sep 17 00:00:00 2001 From: Daniel Barreto Date: Mon, 9 Feb 2015 16:27:55 -0500 Subject: [PATCH 2/3] Update composer autoload - refs BT#9092 --- vendor/autoload.php | 2 +- vendor/composer/autoload_classmap.php | 7 ++++++- vendor/composer/autoload_real.php | 10 +++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/vendor/autoload.php b/vendor/autoload.php index a253926a39..06bff041cc 100755 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer' . '/autoload_real.php'; -return ComposerAutoloaderInit8dc63da0bae852e2c5fe3026e05ecb41::getLoader(); +return ComposerAutoloaderInit2a4794162b3ce734639136efd77d5c25::getLoader(); diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 4221e356c8..85256a80bd 100755 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -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', diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index ebb17872f5..91153957a1 100755 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit8dc63da0bae852e2c5fe3026e05ecb41 +class ComposerAutoloaderInit2a4794162b3ce734639136efd77d5c25 { private static $loader; @@ -19,9 +19,9 @@ class ComposerAutoloaderInit8dc63da0bae852e2c5fe3026e05ecb41 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit8dc63da0bae852e2c5fe3026e05ecb41', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit2a4794162b3ce734639136efd77d5c25', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); - spl_autoload_unregister(array('ComposerAutoloaderInit8dc63da0bae852e2c5fe3026e05ecb41', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit2a4794162b3ce734639136efd77d5c25', 'loadClassLoader')); $map = require __DIR__ . '/autoload_namespaces.php'; foreach ($map as $namespace => $path) { @@ -42,14 +42,14 @@ class ComposerAutoloaderInit8dc63da0bae852e2c5fe3026e05ecb41 $includeFiles = require __DIR__ . '/autoload_files.php'; foreach ($includeFiles as $file) { - composerRequire8dc63da0bae852e2c5fe3026e05ecb41($file); + composerRequire2a4794162b3ce734639136efd77d5c25($file); } return $loader; } } -function composerRequire8dc63da0bae852e2c5fe3026e05ecb41($file) +function composerRequire2a4794162b3ce734639136efd77d5c25($file) { require $file; } From 58d6654c64d7b5ccad553926e38c636db64bdfa6 Mon Sep 17 00:00:00 2001 From: Daniel Barreto Date: Mon, 9 Feb 2015 16:55:06 -0500 Subject: [PATCH 3/3] Improve comments and documentation - refs BT#9092 --- main/inc/lib/hook/HookEvent.php | 1 + main/inc/lib/hook/HookNotificationContent.php | 10 ++++++++-- main/inc/lib/hook/HookNotificationTitle.php | 9 ++++++++- .../HookNotificationContentEventInterface.php | 6 +++++- .../HookNotificationContentObserverInterface.php | 6 +++++- .../interfaces/HookNotificationTitleEventInterface.php | 6 +++++- .../HookNotificationTitleObserverInterface.php | 6 +++++- 7 files changed, 37 insertions(+), 7 deletions(-) diff --git a/main/inc/lib/hook/HookEvent.php b/main/inc/lib/hook/HookEvent.php index c4755f6fb9..863f92d1b6 100644 --- a/main/inc/lib/hook/HookEvent.php +++ b/main/inc/lib/hook/HookEvent.php @@ -127,6 +127,7 @@ abstract class HookEvent implements HookEventInterface public function setEventData(array $data) { foreach ($data as $key => $value) { + // Assign value for each array item $this->eventData[$key] = $value; } return $this; diff --git a/main/inc/lib/hook/HookNotificationContent.php b/main/inc/lib/hook/HookNotificationContent.php index cbef32b58d..82348f9765 100644 --- a/main/inc/lib/hook/HookNotificationContent.php +++ b/main/inc/lib/hook/HookNotificationContent.php @@ -1,7 +1,8 @@ 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); } } diff --git a/main/inc/lib/hook/HookNotificationTitle.php b/main/inc/lib/hook/HookNotificationTitle.php index 8df6fe31cd..d1758f1b4e 100644 --- a/main/inc/lib/hook/HookNotificationTitle.php +++ b/main/inc/lib/hook/HookNotificationTitle.php @@ -2,6 +2,7 @@ /* For licensing terms, see /license.txt */ /** * This file contains the Hook Event class for Title of Notifications + * @package chamilo.library.hook */ /** @@ -20,16 +21,22 @@ class HookNotificationTitle extends HookEvent implements HookNotificationTitleEv /** * @param int $type - * @return int + * @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); } } diff --git a/main/inc/lib/hook/interfaces/HookNotificationContentEventInterface.php b/main/inc/lib/hook/interfaces/HookNotificationContentEventInterface.php index a4b931a151..ec85d2d7ef 100644 --- a/main/inc/lib/hook/interfaces/HookNotificationContentEventInterface.php +++ b/main/inc/lib/hook/interfaces/HookNotificationContentEventInterface.php @@ -1,5 +1,9 @@