Create plugin to crete a Drupal user - refs BT#9083

1.10.x
Angel Fernando Quiroz Campos 11 years ago
parent 2a6d7ae991
commit 40f012b0fa
  1. 0
      plugin/createdrupaluser/README.md
  2. 12
      plugin/createdrupaluser/config.php
  3. 8
      plugin/createdrupaluser/index.php
  4. 10
      plugin/createdrupaluser/install.php
  5. 12
      plugin/createdrupaluser/lang/english.php
  6. 12
      plugin/createdrupaluser/lang/spanish.php
  7. 10
      plugin/createdrupaluser/plugin.php
  8. 0
      plugin/createdrupaluser/readme.txt
  9. 72
      plugin/createdrupaluser/src/CreateDrupalUser.php
  10. 63
      plugin/createdrupaluser/src/HookCreateDrupalUser.php
  11. 10
      plugin/createdrupaluser/uninstall.php

@ -0,0 +1,12 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Config the plugin
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @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';

@ -0,0 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Config the plugin
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.plugin.createDrupalUser
*/
require_once __DIR__ . '/config.php';

@ -0,0 +1,10 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Initialization install
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.plugin.createDrupalUser
*/
require_once __DIR__ . '/config.php';
CreateDrupalUser::create()->install();

@ -0,0 +1,12 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Strings to english L10n
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @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/';

@ -0,0 +1,12 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Strings to spanish L10n
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @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/';

@ -0,0 +1,10 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Get the plugin info
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.plugin.createDrupalUser
*/
require_once __DIR__.'/config.php';
$plugin_info = CreateDrupalUser::create()->get_info();

@ -0,0 +1,72 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Create a user in Drupal website when a user is registered in Chamilo LMS
*
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @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);
}
}

@ -0,0 +1,63 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Hook to create an user in Drupal website
*
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @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);
}
}
}

@ -0,0 +1,10 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Initialization uninstall
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.plugin.createDrupalUser
*/
require_once __DIR__ . '/config.php';
CreateDrupalUser::create()->uninstall();
Loading…
Cancel
Save