Skip to content

Commit

Permalink
Replace calls of GroupPortalManager with UserGroup see BT#4301
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed May 26, 2015
1 parent 6cc7390 commit 0c8ff36
Show file tree
Hide file tree
Showing 42 changed files with 1,185 additions and 1,107 deletions.
12 changes: 6 additions & 6 deletions main/admin/add_users_to_group.php
Expand Up @@ -22,7 +22,7 @@
// Database Table Definitions
$tbl_group = Database::get_main_table(TABLE_MAIN_GROUP);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_group_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
$tbl_group_rel_user = Database::get_main_table(TABLE_USERGROUP_REL_USER);
$tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$needle = null;
$user_anonymous = api_get_anonymous_id();
Expand Down Expand Up @@ -212,11 +212,11 @@ function validate_filter() {
Display::display_header($group_name);

if (isset($_POST['form_sent']) && $_POST['form_sent']) {
$form_sent = $_POST['form_sent'];
$firstLetterUser = isset($_POST['firstLetterUser']) ? $_POST['firstLetterUser'] : null;
$UserList = $_POST['sessionUsersList'];
$group_id = intval($_POST['id']);
$relation_type = intval($_POST['relation']);
$form_sent = $_POST['form_sent'];
$firstLetterUser = isset($_POST['firstLetterUser']) ? $_POST['firstLetterUser'] : null;
$UserList = $_POST['sessionUsersList'];
$group_id = intval($_POST['id']);
$relation_type = intval($_POST['relation']);

if (!is_array($UserList)) {
$UserList = array();
Expand Down
68 changes: 47 additions & 21 deletions main/admin/add_users_to_usergroup.php
@@ -1,8 +1,10 @@
<?php
/* For licensing terms, see /license.txt */

/**
* @package chamilo.admin
*/

// resetting the course id
$cidReset = true;

Expand All @@ -24,13 +26,19 @@
// setting the name of the tool
$tool_name = get_lang('SubscribeUsersToClass');

$add_type = 'multiple';
if (isset($_REQUEST['add_type']) && $_REQUEST['add_type']!='') {
$add_type = Security::remove_XSS($_REQUEST['add_type']);
}
$id = intval($_GET['id']);

$relation = isset($_REQUEST['relation']) ? intval($_REQUEST['relation']) : '';

$htmlHeadXtra[] = '
<script>
$(document).ready( function() {
$("#relation").change(function() {
window.location = "add_users_to_usergroup.php?id='.$id.'" +"&relation=" + $(this).val();
});
});
function add_user_to_session (code, content) {
document.getElementById("user_to_add").value = "";
Expand Down Expand Up @@ -58,12 +66,16 @@ function remove_item(origin) {
}
function validate_filter() {
document.formulaire.add_type.value = \''.$add_type.'\';
document.formulaire.form_sent.value=0;
document.formulaire.submit();
}
function checked_in_no_group(checked) {
$("#relation")
.find("option")
.attr("selected", false);
$("#first_letter_user")
.find("option")
.attr("selected", false);
Expand All @@ -80,7 +92,6 @@ function change_select(val) {
</script>';

$form_sent = 0;
$errorMsg = '';

$extra_field_list = UserManager::get_extra_fields();
$new_field_list = array();
Expand All @@ -97,24 +108,28 @@ function change_select(val) {
}

$usergroup = new UserGroup();
$id = intval($_GET['id']);

if (empty($id)) {
api_not_allowed(true);
}
$first_letter_user = '';

if (isset($_POST['form_sent']) && $_POST['form_sent']) {
$form_sent = $_POST['form_sent'];
$elements_posted = isset($_POST['elements_in_name']) ? $_POST['elements_in_name'] : null;
$first_letter_user = $_POST['firstLetterUser'];
$form_sent = $_POST['form_sent'];
$elements_posted = isset($_POST['elements_in_name']) ? $_POST['elements_in_name'] : null;
$first_letter_user = $_POST['firstLetterUser'];

if (!is_array($elements_posted)) {
$elements_posted=array();
$elements_posted = array();
}
if ($form_sent == 1) {
//added a parameter to send emails when registering a user
$usergroup->subscribe_users_to_usergroup($id, $elements_posted);
$usergroup->subscribe_users_to_usergroup(
$id,
$elements_posted,
true,
$relation
);
header('Location: usergroups.php');
exit;
}
Expand All @@ -138,7 +153,7 @@ function change_select(val) {
}


//Filter by Extra Fields
// Filter by Extra Fields
$use_extra_fields = false;
if (is_array($extra_field_list)) {
if (is_array($new_field_list) && count($new_field_list)>0 ) {
Expand Down Expand Up @@ -195,7 +210,7 @@ function change_select(val) {
}

$data = $usergroup->get($id);
$list_in = $usergroup->get_users_by_usergroup($id);
$list_in = $usergroup->getUsersByUsergroupAndRelation($id, $relation);
$list_all = $usergroup->get_users_by_usergroup();

$order = array('lastname');
Expand Down Expand Up @@ -311,8 +326,6 @@ function change_select(val) {
}
}

$add_type == 'unique' ? true : false;

Display::display_header($tool_name);

echo '<div class="actions">';
Expand All @@ -336,7 +349,7 @@ function change_select(val) {
<?php
echo '<legend>'.$tool_name.': '.$data['name'].'</legend>';

if ($add_type=='multiple') {

if (is_array($extra_field_list)) {
if (is_array($new_field_list) && count($new_field_list)>0) {
echo '<h3>'.get_lang('FilterByUser').'</h3>';
Expand All @@ -361,18 +374,31 @@ function change_select(val) {
echo '<br /><br />';
}
}
}

echo Display::input('hidden', 'id', $id);
echo Display::input('hidden', 'form_sent', '1');
echo Display::input('hidden', 'add_type', null);

if (!empty($errorMsg)) {
Display::display_normal_message($errorMsg);
}
?>

<div class="row">
<div class="col-md-5">
<?php if ($data['group_type'] == UserGroup::SOCIAL_CLASS) { ?>
<select name="relation" id="relation">
<option value=""><?php echo get_lang('SelectARelationType')?></option>
<option value="<?php echo GROUP_USER_PERMISSION_ADMIN ?>" <?php echo ((isset($relation) && $relation == GROUP_USER_PERMISSION_ADMIN)?'selected=selected':'') ?> >
<?php echo get_lang('Admin') ?></option>
<option value="<?php echo GROUP_USER_PERMISSION_READER ?>" <?php echo ((isset($relation) && $relation == GROUP_USER_PERMISSION_READER)?'selected=selected':'') ?> >
<?php echo get_lang('Reader') ?></option>
<option value="<?php echo GROUP_USER_PERMISSION_PENDING_INVITATION ?>" <?php echo ((isset($relation) && $relation == GROUP_USER_PERMISSION_PENDING_INVITATION)?'selected=selected':'') ?> >
<?php echo get_lang('PendingInvitation') ?></option>
<option value="<?php echo GROUP_USER_PERMISSION_MODERATOR ?>" <?php echo ((isset($relation) && $relation == GROUP_USER_PERMISSION_MODERATOR)?'selected=selected':'') ?> >
<?php echo get_lang('Moderator') ?></option>
<option value="<?php echo GROUP_USER_PERMISSION_HRM ?>" <?php echo ((isset($relation) && $relation == GROUP_USER_PERMISSION_HRM)?'selected=selected':'') ?> >
<?php echo get_lang('Drh') ?></option>
</select>
<?php } ?>

<div class="multiple_select_header">
<b><?php echo get_lang('UsersInPlatform') ?> :</b>
<?php echo get_lang('FirstLetterUser'); ?> :
Expand Down
4 changes: 2 additions & 2 deletions main/admin/index.php
Expand Up @@ -107,8 +107,8 @@
array('url' => 'user_import.php', 'label' => get_lang('ImportUserListXMLCSV')),
array('url' => 'user_update_import.php', 'label' => get_lang('EditUserListCSV')),
);
$items[] = array('url' => 'group_add.php', 'label' => get_lang('AddGroups'));
$items[] = array('url' => 'group_list.php', 'label' => get_lang('GroupList'));
//$items[] = array('url' => 'group_add.php', 'label' => get_lang('AddGroups'));
//$items[] = array('url' => 'group_list.php', 'label' => get_lang('GroupList'));

if (isset($extAuthSource) && isset($extAuthSource['extldap']) && count($extAuthSource['extldap']) > 0) {
$items[] = array('url' => 'ldap_users_list.php', 'label' => get_lang('ImportLDAPUsersIntoPlatform'));
Expand Down
83 changes: 52 additions & 31 deletions main/admin/system_announcements.php
Expand Up @@ -64,7 +64,7 @@
$action_todo = true;
}

//Actions
// Actions
switch($action) {
case 'make_visible':
case 'make_invisible':
Expand All @@ -79,7 +79,6 @@
SystemAnnouncementManager :: delete_announcement($_GET['id']);
Display :: display_confirmation_message(get_lang('AnnouncementDeleted'));
break;

case 'delete_selected':
foreach($_POST['id'] as $index => $id) {
SystemAnnouncementManager :: delete_announcement($id);
Expand All @@ -101,46 +100,58 @@
break;
case 'edit':
// Edit an announcement.
$announcement = SystemAnnouncementManager :: get_announcement($_GET['id']);
$values['id'] = $announcement->id;
$values['title'] = $announcement->title;
$values['content'] = $announcement->content;
$values['start'] = api_get_local_time($announcement->date_start);
$values['end'] = api_get_local_time($announcement->date_end);
$announcement = SystemAnnouncementManager:: get_announcement($_GET['id']);
$values['id'] = $announcement->id;
$values['title'] = $announcement->title;
$values['content'] = $announcement->content;
$values['start'] = api_get_local_time($announcement->date_start);
$values['end'] = api_get_local_time($announcement->date_end);

$values['range'] =
substr(api_get_local_time($announcement->date_start), 0, 16).' / '.
substr(api_get_local_time($announcement->date_end), 0, 16);

$values['visible_teacher'] = $announcement->visible_teacher;
$values['visible_student'] = $announcement->visible_student ;
$values['visible_guest'] = $announcement->visible_guest ;
$values['lang'] = $announcement->lang;
$values['action'] = 'edit';
$groups = SystemAnnouncementManager :: get_announcement_groups($announcement->id);
$values['group'] = isset($groups[0]['group_id']) ? $groups[0]['group_id'] : 0;
$values['visible_teacher'] = $announcement->visible_teacher;
$values['visible_student'] = $announcement->visible_student;
$values['visible_guest'] = $announcement->visible_guest;
$values['lang'] = $announcement->lang;
$values['action'] = 'edit';
$groups = SystemAnnouncementManager::get_announcement_groups($announcement->id);
$values['group'] = isset($groups['group_id']) ? $groups['group_id'] : 0;
$action_todo = true;
break;
}

if ($action_todo) {
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'add') {
$form_title = get_lang('AddNews');
$url = api_get_self();
} elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit') {
$form_title = get_lang('EditNews');
$url = api_get_self().'?id='.intval($_GET['id']);
}
$form = new FormValidator('system_announcement');
$form = new FormValidator('system_announcement', 'post', $url);
$form->addElement('header', '', $form_title);
$form->addText('title', get_lang('Title'), true, array('class'=>'span4'));
$form->addText('title', get_lang('Title'), true);
$language_list = api_get_languages();
$language_list_with_keys = array();
$language_list_with_keys['all'] = get_lang('All');
for($i=0; $i<count($language_list['name']) ; $i++) {
for ($i=0; $i<count($language_list['name']) ; $i++) {
$language_list_with_keys[$language_list['folder'][$i]] = $language_list['name'][$i];
}

$form->addElement('select', 'lang',get_lang('Language'), $language_list_with_keys);
$form->addHtmlEditor('content', get_lang('Content'), true, false, array('ToolbarSet' => 'PortalNews', 'Width' => '100%', 'Height' => '300'));
$form->addHtmlEditor(
'content',
get_lang('Content'),
true,
false,
array(
'ToolbarSet' => 'PortalNews',
'Width' => '100%',
'Height' => '300',
)
);
$form->addDateRangePicker('range', get_lang('StartTimeWindow'), true, array('id' => 'date_range'));

$group = array();
Expand All @@ -152,15 +163,20 @@
$form->addGroup($group, null, get_lang('Visible'), '');

$form->addElement('hidden', 'id');
$userGroup = new UserGroup();
$group_list = $userGroup->get_all();

if (!empty($group_list)) {
$group_list = array_column($group_list, 'name', 'id');
$group_list[0] = get_lang('All');
$form->addElement(
'select',
'group',
get_lang('AnnouncementForGroup'),
$group_list
);
}

$group_list = GroupPortalManager::get_groups_list();
$group_list[0] = get_lang('All');
$form->addElement(
'select',
'group',
get_lang('AnnouncementForGroup'),
$group_list
);
$values['group'] = isset($values['group']) ? $values['group'] : '0';

$form->addElement('checkbox', 'send_mail', null, get_lang('SendMail'));
Expand Down Expand Up @@ -209,8 +225,8 @@
$values['visible_guest'],
$values['lang'],
$sendMail,
empty($values['add_to_calendar'])?false:true,
empty($values['send_email_test'])?false:true
empty($values['add_to_calendar']) ? false : true,
empty($values['send_email_test']) ? false : true
);

if ($announcement_id !== false) {
Expand All @@ -222,6 +238,8 @@
}
break;
case 'edit':
$sendMailTest = isset($values['send_email_test']) ? $values['send_email_test'] : null;

if (SystemAnnouncementManager::update_announcement(
$values['id'],
$values['title'],
Expand All @@ -233,10 +251,13 @@
$values['visible_guest'],
$values['lang'],
$sendMail,
$values['send_email_test']
$sendMailTest
)
) {
SystemAnnouncementManager::announcement_for_groups($values['id'], array($values['group']));
SystemAnnouncementManager::announcement_for_groups(
$values['id'],
array($values['group'])
);
Display :: display_confirmation_message(get_lang('AnnouncementUpdated'));
} else {
$show_announcement_list = false;
Expand Down
5 changes: 3 additions & 2 deletions main/gradebook/certificate_report.php
Expand Up @@ -5,7 +5,7 @@
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.gradebook
*/
use \ChamiloSession as Session;
use ChamiloSession as Session;

$cidReset = true;

Expand All @@ -31,7 +31,8 @@
$sessions = $courses = $months = $students = [0 => get_lang('Select')];

if (api_is_student_boss()) {
$userList = GroupPortalManager::getGroupUsersByUser($userId);
$userGroup = new UserGroup();
$userList = $userGroup->getGroupUsersByUser($userId);
$sessionsList = SessionManager::getSessionsFollowedForGroupAdmin($userId);
} else {
$sessionsList = SessionManager::getSessionsCoachedByUser($userId, false, api_is_platform_admin());
Expand Down
3 changes: 2 additions & 1 deletion main/gradebook/gradebook_display_certificate.php
Expand Up @@ -39,7 +39,8 @@ function confirmation() {
switch ($action) {
case 'export_all_certificates':
if (api_is_student_boss()) {
$userList = GroupPortalManager::getGroupUsersByUser(api_get_user_id());
$userGroup = new UserGroup();
$userList = $userGroup->getGroupUsersByUser(api_get_user_id());
} else {
$userList = array();
if (!empty($filterOfficialCodeGet)) {
Expand Down

0 comments on commit 0c8ff36

Please sign in to comment.