Merge branch '1.10.x' of github.com:chamilo/chamilo-lms into 1.10.x

1.10.x
Yannick Warnier 10 years ago
commit 5076ee5128
  1. 3
      .gitattributes
  2. 1
      .gitignore
  3. 12
      main/admin/usergroup_export.php
  4. 32
      main/admin/usergroup_import.php
  5. 3
      main/inc/lib/model.lib.php
  6. 61
      main/inc/lib/usergroup.lib.php

3
.gitattributes vendored

@ -2,6 +2,7 @@
.gitignore export-ignore
.travis.yml export-ignore
/tests export-ignore
/vendor/ezyang/htmlpurifier/docs export-ignore
/vendor/ezyang/htmlpurifier/benchmarks export-ignore
/vendor/ezyang/htmlpurifier/tests export-ignore
@ -13,6 +14,6 @@
/vendor/twig/twig/test export-ignore
/vendor/monolog/monolog/tests/ export-ignore
/vendor/neutron/temporary-filesystem/tests export-ignore
/vendor/sabre/vobject/tests export-ignore
/vendor/twig/twig/test export-ignore
/vendor/symfony/console/Symfony/Component/Console/Tests export-ignore

1
.gitignore vendored

@ -35,3 +35,4 @@ searchdb/*
nbproject/*
plugin/bbb/config.vm.php
main/cron/incoming/*

@ -1,11 +1,10 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @package chamilo.admin
*/
/**
* Code
*/
// name of the language file that needs to be included
$language_file = 'admin';
$cidReset = true;
@ -29,14 +28,15 @@ $form->addElement('header', $tool_name);
$form->addElement('style_submit_button', 'submit', get_lang('Export'), 'class="save"');
if ($form->validate()) {
$user_group = new UserGroup;
$header = array(array('id', 'name', 'description'));
$data = $user_group->get_all_for_export();
$userGroup = new UserGroup();
$header = array(array('id', 'name', 'description', 'users'));
$data = $userGroup->getDataToExport();
$data = array_merge($header, $data);
$filename = 'export_classes_'.api_get_local_time();
Export::export_table_csv($data, $filename);
exit;
}
Display :: display_header($tool_name);
$form->display();
Display::display_footer();

@ -1,5 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
/**
* This tool allows platform admins to add classes by uploading a CSV file
* @todo Add some langvars to DLTT
@ -13,7 +14,7 @@ function validate_data($classes) {
$errors = array();
$usergroup = new UserGroup();
foreach ($classes as $index => $class) {
// 1. Check wheter ClassName is available.
// 1. Check of class name is available.
if (!isset($class['name']) || strlen(trim($class['name'])) == 0) {
$class['line'] = $index + 2;
$class['error'] = get_lang('MissingClassName');
@ -41,15 +42,34 @@ function validate_data($classes) {
*/
function save_data($classes)
{
$number_of_added_classes = 0;
$count = 0;
$usergroup = new UserGroup();
foreach ($classes as $index => $class) {
$usersToAdd = isset($class['users']) ? $class['users'] : null;
unset($class['users']);
$id = $usergroup->save($class);
if ($id) {
$number_of_added_classes++;
if (!empty($usersToAdd)) {
$usersToAddList = explode(',', $usersToAdd);
$userIdList = array();
foreach ($usersToAddList as $username) {
$userInfo = api_get_user_info_from_username($username);
$userIdList[] = $userInfo['user_id'];
}
if (!empty($userIdList)) {
$usergroup->subscribe_users_to_usergroup(
$id,
$userIdList,
false
);
}
}
$count++;
}
}
return $number_of_added_classes;
return $count;
}
// Language files that should be included.
@ -113,8 +133,8 @@ $form->display();
<p><?php echo get_lang('CSVMustLookLike') . ' (' . get_lang('MandatoryFields') . ')'; ?> :</p>
<pre>
<b>name;description</b>
"User group 1";"Description"
<b>name;description;</b>users
"User group 1";"Description";admin,username1,username2
</pre>
<?php
// Displaying the footer.

@ -105,9 +105,10 @@ class Model
/**
* @param array $options
*
* @return array
*/
public function get_all_for_export($options = null)
public function getDataToExport($options = array())
{
return Database::select('name, description', $this->table, $options);
}

@ -149,7 +149,7 @@ class UserGroup extends Model
/**
* Gets a list of course ids by user group
* @param int user group id
* @param int $id user group id
* @param array $loadCourseData
* @return array
*/
@ -331,6 +331,7 @@ class UserGroup extends Model
$array[] = $row['usergroup_id'];
}
}
return $array;
}
@ -346,15 +347,17 @@ class UserGroup extends Model
$this->usergroup_rel_course_table,
array('where' => array('course_id = ? AND usergroup_id = ?' => array($course_id, $usergroup_id)))
);
if (empty($results)) {
return false;
}
return true;
}
/**
* Gets a list of session ids by user group
* @param int user group id
* @param int $id user group id
* @return array
*/
public function get_sessions_by_usergroup($id)
@ -371,12 +374,13 @@ class UserGroup extends Model
$array[] = $row['session_id'];
}
}
return $array;
}
/**
* Gets a list of user ids by user group
* @param int user group id
* @param int $id user group id
* @return array with a list of user ids
*/
public function get_users_by_usergroup($id = null)
@ -393,12 +397,13 @@ class UserGroup extends Model
$array[] = $row['user_id'];
}
}
return $array;
}
/**
* Gets the usergroup id list by user id
* @param int user id
* @param int $userId user id
* @return array
*/
public function get_usergroup_by_user($userId)
@ -424,13 +429,14 @@ class UserGroup extends Model
$array[] = $row['usergroup_id'];
}
}
return $array;
}
/**
* Subscribes sessions to a group (also adding the members of the group in the session and course)
* @param int usergroup id
* @param array list of session ids
* @param int $usergroup_id usergroup id
* @param array $list list of session ids
*/
public function subscribe_sessions_to_usergroup($usergroup_id, $list)
{
@ -483,8 +489,8 @@ class UserGroup extends Model
/**
* Subscribes courses to a group (also adding the members of the group in the course)
* @param int usergroup id
* @param array list of course ids (integers)
* @param int $usergroup_id usergroup id
* @param array $list list of course ids (integers)
* @param bool $delete_groups
*/
public function subscribe_courses_to_usergroup($usergroup_id, $list, $delete_groups = true)
@ -544,15 +550,18 @@ class UserGroup extends Model
CourseManager::unsubscribe_user($user_id, $course_info['code']);
}
}
Database::delete($this->usergroup_rel_course_table, array('usergroup_id = ? AND course_id = ?' => array($usergroup_id, $course_id)));
Database::delete(
$this->usergroup_rel_course_table,
array('usergroup_id = ? AND course_id = ?' => array($usergroup_id, $course_id))
);
}
}
}
/**
* Subscribe users to a group
* @param int usergroup id
* @param array list of user ids
* @param int $usergroup_id usergroup id
* @param array $list list of user ids
* @param bool $delete_users_not_present_in_list
*/
public function subscribe_users_to_usergroup($usergroup_id, $list, $delete_users_not_present_in_list = true)
@ -698,16 +707,36 @@ class UserGroup extends Model
* @param array $options
* @return array
*/
public function get_all_for_export($options = null)
public function getDataToExport($options = array())
{
if ($this->useMultipleUrl) {
$urlId = api_get_current_access_url_id();
$from = $this->table." u INNER JOIN {$this->access_url_rel_usergroup} a ON (u.id = a.usergroup_id)";
$from = $this->table." u INNER JOIN {$this->access_url_rel_usergroup} a
ON (u.id = a.usergroup_id)";
$options = array('where' => array('access_url_id = ? ' => $urlId));
return Database::select('a.id, name, description', $from, $options);
$classes = Database::select('a.id, name, description', $from, $options);
} else {
return Database::select('id, name, description', $this->table, $options);
$classes = Database::select('id, name, description', $this->table, $options);
}
$result = array();
if (!empty($classes)) {
foreach ($classes as $data) {
$users = self::getUserListByUserGroup($data['id']);
$userToString = null;
if (!empty($users)) {
$userNameList = array();
foreach ($users as $userData) {
$userNameList[] = $userData['username'];
}
$userToString = implode(',', $userNameList);
}
$data['users'] = $userToString;
$result[] = $data;
}
}
return $result;
}
/**
@ -753,10 +782,12 @@ class UserGroup extends Model
{
$groupExists = $this->usergroup_exists(trim($params['name']));
if ($groupExists == false) {
$id = parent::save($params, $show_query);
if ($this->useMultipleUrl) {
$this->subscribeToUrl($id, api_get_current_access_url_id());
}
return $id;
}

Loading…
Cancel
Save