static function check_system() { $mainframe = JFactory::getApplication(); $comp_params = JComponentHelper::getParams('com_joomdle'); // If profiles types enabled, check at least 1 is defined to be created in moodle $use_profiletypes = $comp_params->get('use_profiletypes'); if ($use_profiletypes) { $profiles = JoomdleHelperProfiletypes::get_profiletypes_to_create(); if (count($profiles) < 1) { $msg = JText::_('COM_JOOMDLE_NO_PROFILES_TO_CREATE_IN_MOODLE'); $mainframe->enqueueMessage($msg); } } }
function onUserAfterSave ($user, $isnew, $success, $msg) { $mainframe = JFactory::getApplication('site'); $last_visit = $user['lastvisitDate']; if ($last_visit == 0) $isnew = 1; else $isnew = 0; $comp_params = JComponentHelper::getParams( 'com_joomdle' ); /* Don't create user if not configured to do so */ if (($isnew) && (!$comp_params->get( 'auto_create_users' ))) return; $username = $user['username']; $str = $user['name']; $moodle_user = JoomdleHelperContent::call_method ("user_id", $username); /* If user don't exist, and it is configured to not autocreate return */ if ((!$moodle_user) && (!$comp_params->get( 'auto_create_users' ))) return; $is_child = false; if (strstr ($user['params'], '_parent_id')) $is_child = true; /* Check Profile Types */ $use_profiletypes = $comp_params->get( 'use_profiletypes' ); if ((!$moodle_user) && ($use_profiletypes) && (!$is_child)) { /* Only create Moodle user if Profile Type in selected ones */ if ($use_profiletypes == 'xipt') { $db = JFactory::getDBO(); $query = "select id from #__community_fields where fieldcode = 'XIPT_PROFILETYPE'"; $db->setQuery($query); $field_id = $db->loadResult(); $field = 'field'.$field_id; /* If editing anyhting else in the profile, not intereseting */ if (!array_key_exists ($field, $_POST)) return; $profile_type = $_POST[$field]; } else if ($use_profiletypes == 'jomsocial') { $profile_type = JRequest::getVar( 'profileType' ); } $profile_type_ids = JoomdleHelperProfiletypes::get_profiletypes_to_create (); $profile_ok = in_array ($profile_type, $profile_type_ids); if ((!$profile_ok) && (!$moodle_user) ) return; } /* If we reach here, user HAS to be created */ $reply = JoomdleHelperContent::call_method ("create_joomdle_user", $username); /* Auto login user */ if (($isnew) && ($comp_params->get( 'auto_login_users' )) && (!$mainframe->isAdmin())) { $credentials = array ( 'username' => $user['username'], 'password' => $user['password_clear']); $options = array (); // $link = JRequest::getVar( 'link' ); // $options = array ( 'url' => $link); $mainframe->login( $credentials, $options ); } }
public static function sync_user($user, $isnew, $success, $msg) { $mainframe = JFactory::getApplication('site'); $last_visit = $user['lastvisitDate']; if ($last_visit == 0) { $isnew = 1; } else { $isnew = 0; } $comp_params = JComponentHelper::getParams('com_joomdle'); /* Don't create user if not configured to do so */ if ($isnew && !$comp_params->get('auto_create_users')) { return; } $username = $user['username']; $moodle_user = JoomdleHelperContent::call_method("user_id", $username); /* If user don't exist, and it is configured to not autocreate return */ if (!$moodle_user && !$comp_params->get('auto_create_users')) { return; } $is_child = false; if (is_string($user['params'])) { // check added because CB passes different info in params if (strstr($user['params'], '_parent_id')) { $is_child = true; } } /* Check Profile Types */ $use_profiletypes = $comp_params->get('use_profiletypes'); if (!$moodle_user && $use_profiletypes && !$is_child) { /* Only create Moodle user if Profile Type in selected ones */ if ($use_profiletypes == 'xipt') { $db = JFactory::getDBO(); $query = "select id from #__community_fields where fieldcode = 'XIPT_PROFILETYPE'"; $db->setQuery($query); $field_id = $db->loadResult(); $field = 'field' . $field_id; /* If editing anyhting else in the profile, not intereseting */ if (!array_key_exists($field, $_POST)) { return; } $profile_type = $_POST[$field]; } else { if ($use_profiletypes == 'jomsocial') { $profile_type = JRequest::getVar('profileType'); } } $profile_type_ids = JoomdleHelperProfiletypes::get_profiletypes_to_create(); $profile_ok = in_array($profile_type, $profile_type_ids); if (!$profile_ok && !$moodle_user) { return; } } /* If we reach here, user HAS to be created */ $reply = JoomdleHelperContent::call_method("create_joomdle_user", $username); }