diff --git a/main/inc/lib/hook/HookSkype.php b/main/inc/lib/hook/HookSkype.php new file mode 100644 index 0000000000..ca29f0ddf4 --- /dev/null +++ b/main/inc/lib/hook/HookSkype.php @@ -0,0 +1,33 @@ +<?php +/* For licensing terms, see /license.txt */ + +/** + * Class HookEventSkype + * @var \SplObjectStorage $observers + */ +class HookEventSkype extends HookEvent implements HookSkypeEventInterface +{ + /** + * Constructor + */ + protected function __construct() + { + parent::__construct('HookEventSkype'); + } + + /** + * Update all the observers + * @param int $type + * + * @return int + */ + public function notifySkype($type) + { + /** @var \HookSkypeObserverInterface $observer */ + $this->eventData['type'] = $type; + foreach ($this->observers as $observer) { + $observer->hookEventSkype($this); + } + return 1; + } +} diff --git a/main/inc/lib/hook/interfaces/HookSkypeEventInterface.php b/main/inc/lib/hook/interfaces/HookSkypeEventInterface.php new file mode 100644 index 0000000000..3dae1a9c3b --- /dev/null +++ b/main/inc/lib/hook/interfaces/HookSkypeEventInterface.php @@ -0,0 +1,21 @@ +<?php +/* For licensing terms, see /license.txt */ +/** + * This file contains all Hook interfaces and their relation. + * They are used for Hook classes + * @package chamilo.library.hook + */ + +/** + * Interface HookSkypeEventInterface + */ +interface HookSkypeEventInterface extends HookEventInterface +{ + /** + * Update all the observers + * @param int $type + * + * @return int + */ + public function notifySkype($type); +} diff --git a/main/inc/lib/hook/interfaces/HookSkypeObserverInterface.php b/main/inc/lib/hook/interfaces/HookSkypeObserverInterface.php new file mode 100644 index 0000000000..04ba206ed0 --- /dev/null +++ b/main/inc/lib/hook/interfaces/HookSkypeObserverInterface.php @@ -0,0 +1,20 @@ +<?php +/* For licensing terms, see /license.txt */ +/** + * This file contains all Hook interfaces and their relation. + * They are used for Hook classes + * @package chamilo.library.hook + */ + +/** + * Interface SkypeHookInterface + */ +interface HookSkypeObserverInterface extends HookObserverInterface +{ + /** + * @param HookSkypeObserverInterface $hook + * + * @return int + */ + public function hookEventSkype(HookSkypeEventInterface $hook); +} diff --git a/plugin/skype/README.md b/plugin/skype/README.md new file mode 100644 index 0000000000..52581bb158 --- /dev/null +++ b/plugin/skype/README.md @@ -0,0 +1,4 @@ +Skype Plugin +============== + +Create Skype user field diff --git a/plugin/skype/config.php b/plugin/skype/config.php new file mode 100644 index 0000000000..4fd8b4a6d1 --- /dev/null +++ b/plugin/skype/config.php @@ -0,0 +1,9 @@ +<?php +/* For licensing terms, see /license.txt */ +/** + * Config the plugin + * @author Imanol Losada Oriol <imanol.losada@beeznest.com> + * @package chamilo.plugin.skype + */ + +require_once api_get_path(SYS_PATH) . 'main/inc/global.inc.php'; diff --git a/plugin/skype/index.php b/plugin/skype/index.php new file mode 100644 index 0000000000..a9c71a002f --- /dev/null +++ b/plugin/skype/index.php @@ -0,0 +1,8 @@ +<?php +/* For licensing terms, see /license.txt */ +/** + * Config the plugin + * @author Imanol Losada Oriol <imanol.losada@beeznest.com> + * @package chamilo.plugin.skype + */ +require_once __DIR__ . '/config.php'; diff --git a/plugin/skype/install.php b/plugin/skype/install.php new file mode 100644 index 0000000000..23be3530f3 --- /dev/null +++ b/plugin/skype/install.php @@ -0,0 +1,10 @@ +<?php +/* For licensing terms, see /license.txt */ +/** + * Initialization install + * @author Imanol Losada Oriol <imanol.losada@beeznest.com> + * @package chamilo.plugin.skype + */ +require_once __DIR__ . '/config.php'; + +Skype::create()->install(); diff --git a/plugin/skype/lang/english.php b/plugin/skype/lang/english.php new file mode 100644 index 0000000000..0af54a0d32 --- /dev/null +++ b/plugin/skype/lang/english.php @@ -0,0 +1,9 @@ +<?php +/* For licensing terms, see /license.txt */ +/** + * Strings to english L10n + * @author Imanol Losada Oriol <imanol.losada@beeznest.com> + * @package chamilo.plugin.skype + */ +$strings['plugin_title'] = 'Skype'; +$strings['plugin_comment'] = 'This plugin creates a Skype user field.'; diff --git a/plugin/skype/lang/spanish.php b/plugin/skype/lang/spanish.php new file mode 100644 index 0000000000..01bfdc4407 --- /dev/null +++ b/plugin/skype/lang/spanish.php @@ -0,0 +1,9 @@ +<?php +/* For licensing terms, see /license.txt */ +/** + * Strings to spanish L10n + * @author Imanol Losada Oriol <imanol.losada@beeznest.com> + * @package chamilo.plugin.skype + */ +$strings['plugin_title'] = 'Skype'; +$strings['plugin_comment'] = 'Este plugin crea un campo de usuario Skype.'; diff --git a/plugin/skype/plugin.php b/plugin/skype/plugin.php new file mode 100644 index 0000000000..687ba24e1f --- /dev/null +++ b/plugin/skype/plugin.php @@ -0,0 +1,10 @@ +<?php +/* For licensing terms, see /license.txt */ +/** + * Get the plugin info + * @author Imanol Losada Oriol <imanol.losada@beeznest.com> + * @package chamilo.plugin.skype + */ +require_once __DIR__.'/config.php'; + +$plugin_info = Skype::create()->get_info(); diff --git a/plugin/skype/readme.txt b/plugin/skype/readme.txt new file mode 100644 index 0000000000..6f371bb1df --- /dev/null +++ b/plugin/skype/readme.txt @@ -0,0 +1,2 @@ +<h1>Skype Plugin</h1> +<p>Create Skype user field</p> diff --git a/plugin/skype/src/HookSkype.php b/plugin/skype/src/HookSkype.php new file mode 100644 index 0000000000..f5e9c7b54c --- /dev/null +++ b/plugin/skype/src/HookSkype.php @@ -0,0 +1,34 @@ +<?php +/* For licensing terms, see /license.txt */ + +/** + * Create Skype user field + * + * @author Imanol Losada Oriol <imanol.losada@beeznest.com> + * @package chamilo.plugin.skype + */ +class HookObserverSkype extends HookObserver implements HookSkypeObserverInterface +{ + + /** + * Class constructor + */ + public function __construct() + { + parent::__construct( + 'plugin/skype/src/Skype.php', 'skype' + ); + } + + /** + * Create Skype user field when plugin is enabled + * @param HookSkypeEventInterface $hook The hook + */ + public function hookEventSkype(HookSkypeEventInterface $hook) + { + $data = $hook->getEventData(); + if ($data['type'] === HOOK_EVENT_TYPE_PRE) { + // Code + } + } +} diff --git a/plugin/skype/src/Skype.php b/plugin/skype/src/Skype.php new file mode 100644 index 0000000000..b06d8b557b --- /dev/null +++ b/plugin/skype/src/Skype.php @@ -0,0 +1,88 @@ +<?php +/* For licensing terms, see /license.txt */ + +/** + * Create Skype user field + * + * @author Imanol Losada Oriol <imanol.losada@beeznest.com> + * @package chamilo.plugin.skype + */ +class Skype extends Plugin implements HookPluginInterface +{ + + /** + * Class constructor + */ + protected function __construct() + { + parent::__construct('0.1', 'Imanol Losada Oriol'); + } + + /** + * Instance the plugin + * @staticvar null $result + * @return Skype + */ + static function create() + { + static $result = null; + + return $result ? $result : $result = new self(); + } + + /** + * Install the plugin + */ + public function install() + { + $this->installHook(); + $result = Database::select( + 'field_variable', + Database::get_main_table(TABLE_MAIN_USER_FIELD), + array( + 'where'=> array( + 'field_variable = ?' => array( + 'skype' + ) + ) + ) + ); + if (empty($result)) { + $extraField = new Extrafield('user'); + $extraField->save(array( + 'field_variable' => 'skype', + 'field_display_text' => 'Skype', + 'field_visible' => 1, + 'field_changeable' => 1 + )); + } + } + + /** + * Uninstall the plugin + * @return void + */ + public function uninstall() + { + $this->uninstallHook(); + } + + /** + * Install the Skype hook + */ + public function installHook() + { + $hook = HookObserverSkype::create(); + HookEventSkype::create()->attach($hook); + } + + /** + * Uninstall the Skype hook + */ + public function uninstallHook() + { + $hook = HookObserverSkype::create(); + HookEventSkype::create()->detach($hook); + } + +} diff --git a/plugin/skype/uninstall.php b/plugin/skype/uninstall.php new file mode 100644 index 0000000000..7ca4b44a8e --- /dev/null +++ b/plugin/skype/uninstall.php @@ -0,0 +1,10 @@ +<?php +/* For licensing terms, see /license.txt */ +/** + * Initialization uninstall + * @author Imanol Losada Oriol <imanol.losada@beeznest.com> + * @package chamilo.plugin.skype + */ +require_once __DIR__ . '/config.php'; + +Skype::create()->uninstall();