protected function addToolbar() { JToolbarHelper::title(JText::_('COM_JOOMDLE_VIEW_PROFILETYPES_TITLE'), 'customprofiletypes'); JToolBarHelper::custom('create_profiletype_on_moodle', 'publish', 'publish', 'COM_JOOMDLE_CREATE_ON_MOODLE', true, false); JToolBarHelper::custom('dont_create_profiletype_on_moodle', 'unpublish', 'unpublish', 'COM_JOOMDLE_NOT_CREATE_ON_MOODLE', true, false); JHtmlSidebar::setAction('index.php?option=com_joomdle&view=customprofiletypes'); JHtmlSidebar::addFilter(JText::_('COM_JOOMDLE_SELECT_STATE'), 'filter_state', JHtml::_('select.options', JoomdleHelperProfiletypes::getStateOptions(), 'value', 'text', $this->state->get('filter.state'))); }
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); } } }
/** * Method to get the field options. * * @return array The field option objects. * @since 1.6 */ protected function getOptions() { $options = array(); $pts = JoomdleHelperProfiletypes::getProfiletypes('', 0, 1000, 'name', '', ''); $option['value'] = 0; $option['text'] = JText::_('COM_JOOMDLE_NONE'); $options[] = $option; if (is_array($pts)) { foreach ($pts as $pt) { $option['value'] = $pt->id; $option['text'] = $pt->name; $options[] = $option; } } return $options; }
static function getProfiletypes($filter_type, $limitstart, $limit, $filter_order, $filter_order_Dir, $search) { // Check that JS is installed $jcheck = JPATH_BASE . '/components/com_community/libraries/core.php'; if (!file_exists($jcheck)) { return array(); } $db = JFactory::getDBO(); $wheres = array(); if ($filter_type) { /* kludge to use 0 as a value */ if ($filter_type == -1) { $filter_type = 0; } $wheres[] = "create_on_moodle = " . $db->Quote($filter_type); } if ($search) { $wheres_search[] = "joomla_field = " . $db->Quote($search); $wheres_search[] = "moodle_field = " . $db->Quote($search); $wheres[] = "(name LIKE " . $search . ")"; } if ($filter_type == 2) { $query = "SELECT p.id, p.name from #__community_profiles as p " . "LEFT JOIN #__joomdle_profiletypes AS pt ON p.id = pt.profiletype_id " . " WHERE create_on_moodle = '0' OR create_on_moodle IS NULL "; } else { if ($filter_type == 1) { $query = "SELECT p.id, p.name from #__community_profiles as p " . "LEFT JOIN #__joomdle_profiletypes AS pt ON p.id = pt.profiletype_id " . " WHERE create_on_moodle = '1'"; } else { $query = "SELECT p.id, p.name, pt.id as profiletype_id from #__community_profiles as p " . "LEFT JOIN #__joomdle_profiletypes AS pt ON p.id = pt.profiletype_id "; } } $query .= " ORDER BY " . $filter_order . " " . $filter_order_Dir; if (!empty($limit)) { $query .= " LIMIT {$limitstart}, {$limit}"; } $db->setQuery($query); $profiletypes = $db->loadObjectList(); if (!$profiletypes) { return NULL; } $m = array(); foreach ($profiletypes as $profiletype) { $profiletype->published = JoomdleHelperProfiletypes::create_this_type($profiletype->id); $profiletype->create_on_moodle = $profiletype->published; $m[] = $profiletype; } return $m; }
static function getProfiletypes($filter_type, $limitstart, $limit, $filter_order, $filter_order_Dir, $search) { $db = JFactory::getDBO(); $wheres = array(); if ($filter_type) { /* kludge to use 0 as a value */ if ($filter_type == -1) { $filter_type = 0; } $wheres[] = "create_on_moodle = " . $db->Quote($filter_type); } if ($search) { $wheres_search[] = "joomla_field = " . $db->Quote($search); $wheres_search[] = "moodle_field = " . $db->Quote($search); $wheres[] = "(name LIKE " . $search . ")"; } $query = "SELECT * from #__xipt_profiletypes"; // $query = 'SELECT j.id, name, create_on_moodle // FROM #__xipt_profiletypes as x, #__joomdle_profiletypes as j // where x.id = j.profiletype_id'; if (!empty($wheres)) { $query .= " AND " . implode(' AND ', $wheres); } $query .= " ORDER BY " . $filter_order . " " . $filter_order_Dir; if (!empty($limit)) { $query .= " LIMIT {$limitstart}, {$limit}"; } $db->setQuery($query); $profiletypes = $db->loadObjectList(); if (!$profiletypes) { return NULL; } foreach ($profiletypes as $profiletype) { $profiletype->published = JoomdleHelperProfiletypes::create_this_type($profiletype->id); $profiletype->create_on_moodle = $profiletype->published; $m[] = $profiletype; } return $m; }
/** * Method to get a single record. * * @param integer The id of the primary key. * * @return mixed Object on success, false on failure. * @since 1.6 */ public function getItem($pk = null) { /* // Get info by profiletype_id $pk = (!empty($pk)) ? $pk : (int) $this->getState($this->getName() . '.id'); echo $pk; echo "XXXX"; $item = JoomdleHelperProfiletypes::get_profiletype_data ($pk); // $item->profiletype = $item->name; print_r ($item); return $item; */ if ($item = parent::getItem($pk)) { // Get profile name $profile_info = JoomdleHelperProfiletypes::get_profiletype_data($item->profiletype_id); $item->name = $profile_info->name; } return $item; }
/** * Gets the list of users * * @return mixed An array of data items on success, false on failure. * @since 1.6 */ public function getItems() { $db = JFactory::getDBO(); $search = $this->getState('filter.search'); if ($search) { $searchEscaped = $db->Quote('%' . $db->getEscaped($search, true) . '%', false); } else { $searchEscaped = ""; } $pagination = $this->getPagination(); $limitstart = $pagination->limitstart; $limit = $pagination->limit; $listOrder = $this->state->get('list.ordering'); $listDirn = $this->state->get('list.direction'); $filter_order = $listOrder; $filter_order_Dir = $listDirn; $filter_type = $this->getState('filter.state'); if ($filter_type == '*') { $filter_type = 0; } $items = JoomdleHelperProfiletypes::getProfiletypes($filter_type, $limitstart, $limit, $filter_order, $filter_order_Dir, $searchEscaped); return $items; }
function register_save() { $otherlanguage = JFactory::getLanguage(); $otherlanguage->load('com_user', JPATH_SITE); $usersConfig = JComponentHelper::getParams('com_users'); if ($usersConfig->get('allowUserRegistration') == '0') { JError::raiseError(403, JText::_('Access Forbidden')); return; } $authorize = JFactory::getACL(); $user = new JUser(); $system = 2; // ID of Registered $user->groups = array(); $user->groups[] = $system; // Bind the post array to the user object $post = JRequest::get('post'); if (!$user->bind($post, 'usertype')) { JError::raiseError(500, $user->getError()); } // Set some initial user values $user->set('id', 0); $date = JFactory::getDate(); $user->set('registerDate', $date->toSql()); $parent = JFactory::getUser(); $user->setParam('u' . $parent->id . '_parent_id', $parent->id); // If user activation is turned on, we need to set the activation information $useractivation = $usersConfig->get('useractivation'); if ($useractivation == 1 || $useractivation == 2) { jimport('joomla.user.helper'); $user->set('activation', JApplication::getHash(JUserHelper::genRandomPassword())); $user->set('block', '1'); } // If there was an error with registration, set the message and display form if (!$user->save()) { JError::raiseWarning('', JText::_($user->getError())); $this->setRedirect('index.php?option=com_joomdle&view=register'); return false; } // Add to profile type if needed $params = JComponentHelper::getParams('com_joomdle'); $children_pt = $params->get('children_profiletype'); if ($children_pt) { JoomdleHelperProfiletypes::add_user_to_profile($user->id, $children_pt); } // Send registration confirmation mail $password = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW); $password = preg_replace('/[\\x00-\\x1F\\x7F]/', '', $password); //Disallow control chars in the email // UserController::_sendMail($user, $password); JoomdleHelperSystem::send_registration_email($user->username, $password); $parent_user = JFactory::getUser(); // Set parent role in Moodle JoomdleHelperContent::call_method("add_parent_role", $user->username, $parent_user->username); $message = JText::_('COM_JOOMDLE_USER_CREATED'); $this->setRedirect('index.php?option=com_joomdle&view=register', $message); //XXX poenr un get current uri }
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); }
static function enrolUser($username, $id) { $params = JComponentHelper::getParams('com_joomdle'); if ($params->get('use_profiletypes')) { $moodle_role = JoomdleHelperProfiletypes::get_user_profile_role($username); if (!$moodle_role) { $moodle_role = 5; } $return = JoomdleHelperContent::call_method('enrol_user', $username, (int) $id, (int) $moodle_role); } else { $return = JoomdleHelperContent::call_method('enrol_user', $username, (int) $id, 5); } //5 = student return $return; }
function save_profiletype() { $id = JRequest::getVar('profiletype_id', array(), 'post', 'int'); $create_on_moodle = JRequest::getVar('create_on_moodle', '', 'post', 'string'); $moodle_role = JRequest::getVar('roles', array(), 'post', 'int'); $data->id = $id; if ($create_on_moodle == 'on') { $data->create_on_moodle = 1; } else { $data->create_on_moodle = 0; } $data->moodle_role = $moodle_role; JoomdleHelperProfiletypes::save_profiletype($data); // $this->setRedirect( 'index.php?option=com_joomdle&view=customprofiletypes&task=edit&profiletype_id='.$id ); $this->setRedirect('index.php?option=com_joomdle&view=customprofiletypes'); }