diff --git a/plugin/createdrupaluser/README.md b/plugin/createdrupaluser/README.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/plugin/createdrupaluser/config.php b/plugin/createdrupaluser/config.php new file mode 100644 index 0000000000..dfb21aaadb --- /dev/null +++ b/plugin/createdrupaluser/config.php @@ -0,0 +1,12 @@ + + * @package chamilo.plugin.createDrupalUser + */ + +require_once api_get_path(SYS_PATH) . 'main/inc/global.inc.php'; +require_once api_get_path(LIBRARY_PATH) . 'plugin.class.php'; +require_once api_get_path(PLUGIN_PATH) . 'createdrupaluser/src/HookCreateDrupalUser.php'; +require_once api_get_path(PLUGIN_PATH) . 'createdrupaluser/src/CreateDrupalUser.php'; diff --git a/plugin/createdrupaluser/index.php b/plugin/createdrupaluser/index.php new file mode 100644 index 0000000000..206504389d --- /dev/null +++ b/plugin/createdrupaluser/index.php @@ -0,0 +1,8 @@ + + * @package chamilo.plugin.createDrupalUser + */ +require_once __DIR__ . '/config.php'; diff --git a/plugin/createdrupaluser/install.php b/plugin/createdrupaluser/install.php new file mode 100644 index 0000000000..8e053a7e0c --- /dev/null +++ b/plugin/createdrupaluser/install.php @@ -0,0 +1,10 @@ + + * @package chamilo.plugin.createDrupalUser + */ +require_once __DIR__ . '/config.php'; + +CreateDrupalUser::create()->install(); diff --git a/plugin/createdrupaluser/lang/english.php b/plugin/createdrupaluser/lang/english.php new file mode 100644 index 0000000000..71bb3d2b6f --- /dev/null +++ b/plugin/createdrupaluser/lang/english.php @@ -0,0 +1,12 @@ + + * @package chamilo.plugin.createDrupalUser + */ +$strings['plugin_title'] = 'Create Drupal user'; +$strings['plugin_comment'] = 'This plugin create a user in Drupal website when a user is registered in Chamilo LMS'; + +$strings['drupal_domain'] = 'Drupal website URL'; +$strings['drupal_domain_help'] = 'The server domain name should be written with a trailing slash and with the protocol, e.g. http://www.example.com/'; diff --git a/plugin/createdrupaluser/lang/spanish.php b/plugin/createdrupaluser/lang/spanish.php new file mode 100644 index 0000000000..306652e864 --- /dev/null +++ b/plugin/createdrupaluser/lang/spanish.php @@ -0,0 +1,12 @@ + + * @package chamilo.plugin.createDrupalUser + */ +$strings['plugin_title'] = 'Crear usuario Drupal'; +$strings['plugin_comment'] = 'Este plugin permite crear un usuario en un sitio web Drupal cuando un usuario es registrado en Chamilo LMS'; + +$strings['drupal_domain'] = 'URL del sitio web Drupal'; +$strings['drupal_domain_help'] = 'La dirección del servidor debe escribirse con el protocolo al comienzo y con la barra al final, por ejemplo http://www.example.com/'; diff --git a/plugin/createdrupaluser/plugin.php b/plugin/createdrupaluser/plugin.php new file mode 100644 index 0000000000..61770c6cb6 --- /dev/null +++ b/plugin/createdrupaluser/plugin.php @@ -0,0 +1,10 @@ + + * @package chamilo.plugin.createDrupalUser + */ +require_once __DIR__.'/config.php'; + +$plugin_info = CreateDrupalUser::create()->get_info(); diff --git a/plugin/createdrupaluser/readme.txt b/plugin/createdrupaluser/readme.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/plugin/createdrupaluser/src/CreateDrupalUser.php b/plugin/createdrupaluser/src/CreateDrupalUser.php new file mode 100644 index 0000000000..0f41abd815 --- /dev/null +++ b/plugin/createdrupaluser/src/CreateDrupalUser.php @@ -0,0 +1,72 @@ + + * @package chamilo.plugin.createDrupalUser + */ +class CreateDrupalUser extends Plugin implements HookPluginInterface +{ + + /** + * Class constructor + */ + protected function __construct() + { + $parameters = array( + 'drupal_domain' => 'text' + ); + + parent::__construct('1.0', 'Angel Fernando Quiroz Campos', $parameters); + } + + /** + * Instance the plugin + * @staticvar null $result + * @return CreateDrupalUser + */ + static function create() + { + static $result = null; + + return $result ? $result : $result = new self(); + } + + /** + * Install the plugin + */ + public function install() + { + $this->installHook(); + } + + /** + * Uninstall the plugin + * @return void + */ + public function uninstall() + { + $this->uninstallHook(); + } + + /** + * Install the Create User hook + */ + public function installHook() + { + $hook = HookCreateDrupalUser::create(); + HookCreateUser::create()->attach($hook); + } + + /** + * Uninstall the Create User hook + */ + public function uninstallHook() + { + $hook = HookCreateDrupalUser::create(); + HookCreateUser::create()->detach($hook); + } + +} diff --git a/plugin/createdrupaluser/src/HookCreateDrupalUser.php b/plugin/createdrupaluser/src/HookCreateDrupalUser.php new file mode 100644 index 0000000000..fd73578783 --- /dev/null +++ b/plugin/createdrupaluser/src/HookCreateDrupalUser.php @@ -0,0 +1,63 @@ + + * @package chamilo.plugin.createDrupalUser + */ +class HookCreateDrupalUser extends HookObserver implements HookCreateUserObserverInterface +{ + + /** + * Class constructor + */ + public function __construct() + { + parent::__construct( + 'plugin/createdrupaluser/src/CreateDrupalUser.php', 'drupaluser' + ); + } + + /** + * Create a Drupal user when the Chamilo user is registered + * @param HookCreateUserEventInterface $hook The hook + */ + public function hookCreateUser(HookCreateUserEventInterface $hook) + { + $data = $hook->getEventData(); + + $drupalDomain = CreateDrupalUser::create()->get('drupal_domain'); + $drupalDomain = rtrim($drupalDomain, '/') . '/'; + + if ($data['type'] === HOOK_EVENT_TYPE_POST) { + $return = $data['return']; + $originalPassword = $data['originalPassword']; + + $userInfo = UserManager::get_user_info_by_id($return); + $fields = array( + 'name' => $userInfo['username'], + 'pass' => $originalPassword, + 'mail' => $userInfo['email'], + 'status' => 1, + 'init' => $userInfo['email'] + ); + $extraFields = array( + 'firstname' => $userInfo['firstname'], + 'lastname' => $userInfo['lastname'] + ); + + var_dump($drupalDomain . 'sites/all/modules/chamilo/soap.php?wsdl'); + + $options = array( + 'location' => $drupalDomain . 'sites/all/modules/chamilo/soap.php?wsdl', + 'uri' => $drupalDomain + ); + + $client = new SoapClient(null, $options); + $client->addUser($fields, $extraFields); + } + } + +} diff --git a/plugin/createdrupaluser/uninstall.php b/plugin/createdrupaluser/uninstall.php new file mode 100644 index 0000000000..fac2ff6868 --- /dev/null +++ b/plugin/createdrupaluser/uninstall.php @@ -0,0 +1,10 @@ + + * @package chamilo.plugin.createDrupalUser + */ +require_once __DIR__ . '/config.php'; + +CreateDrupalUser::create()->uninstall();