Merge 1.10.x

remotes/angel/1.11.x
Julio 9 years ago
commit 7e3fb7badc
  1. 30
      main/admin/dashboard_add_users_to_user.php
  2. 23
      main/admin/user_edit.php
  3. 78
      main/admin/user_information.php
  4. 18
      main/exercice/exercise.class.php
  5. 16
      main/exercice/exercise_submit.php
  6. 27
      main/exercice/overview.php
  7. 4
      main/exercice/result.php
  8. 1
      main/inc/lib/api.lib.php
  9. 27
      main/inc/lib/exercise.lib.php
  10. 1
      main/inc/lib/export.lib.inc.php
  11. 2
      main/inc/lib/template.lib.php
  12. 122
      main/inc/lib/usermanager.lib.php
  13. 4
      plugin/advanced_subscription/ajax/advanced_subscription.ajax.php
  14. 2
      plugin/advanced_subscription/test/mails.php

@ -5,6 +5,7 @@
* Interface for assigning users to Human Resources Manager
* @package chamilo.admin
*/
// resetting the course id
$cidReset = true;
@ -293,7 +294,7 @@ if (isset($_POST['formSent']) && intval($_POST['formSent']) == 1) {
$affected_rows = UserManager::suscribe_users_to_hr_manager($user_id, $user_list);
break;
case STUDENT_BOSS:
$affected_rows = UserManager::subscribeUsersToBoss($user_id, $user_list);
$affected_rows = UserManager::subscribeBossToUsers($user_id, $user_list);
break;
default:
$affected_rows = 0;
@ -308,20 +309,26 @@ if (isset($_POST['formSent']) && intval($_POST['formSent']) == 1) {
Display::display_header($tool_name);
// actions
$actionsLeft = '';
if ($userStatus != STUDENT_BOSS) {
$actionsLeft = Display::url(
Display::return_icon('course-add.png', get_lang('AssignCourses'), null, ICON_SIZE_MEDIUM ), "dashboard_add_courses_to_user.php?user=$user_id"
Display::return_icon('course-add.png', get_lang('AssignCourses'), null, ICON_SIZE_MEDIUM ),
"dashboard_add_courses_to_user.php?user=$user_id"
);
$actionsLeft .= Display::url(
Display::return_icon('session-add.png', get_lang('AssignSessions'), null, ICON_SIZE_MEDIUM ) , "dashboard_add_sessions_to_user.php?user=$user_id"
Display::return_icon('session-add.png', get_lang('AssignSessions'), null, ICON_SIZE_MEDIUM ) ,
"dashboard_add_sessions_to_user.php?user=$user_id"
);
}
$actionsRight = Display::url('<em class="fa fa-search"></em> ' . get_lang('AdvancedSearch'), '#', array('class' => 'btn btn-default advanced_options', 'id' => 'advanced_search'));
$actionsRight = Display::url(
'<em class="fa fa-search"></em> ' . get_lang('AdvancedSearch'),
'#',
array('class' => 'btn btn-default advanced_options', 'id' => 'advanced_search')
);
$toolbar = Display::toolbarAction('toolbar-dashboard', $content = array( 0 => $actionsLeft, 1 => $actionsRight ));
$toolbar = Display::toolbarAction('toolbar-dashboard', [$actionsLeft, $actionsRight]);
echo $toolbar;
echo '<div id="advanced_search_options" style="display:none">';
@ -329,8 +336,12 @@ $searchForm->display();
echo '</div>';
echo Display::page_header(
sprintf(get_lang('AssignUsersToX'), api_get_person_name($user_info['firstname'], $user_info['lastname'])),
null, $size = 'h3'
sprintf(
get_lang('AssignUsersToX'),
api_get_person_name($user_info['firstname'], $user_info['lastname'])
),
null,
'h3'
);
$assigned_users_to_hrm = array();
@ -492,11 +503,8 @@ if(!empty($msg)) {
</select>
</div>
</div>
</div>
</div>
</form>
<?php
Display::display_footer();

@ -345,6 +345,25 @@ if (!$user_data['platform_admin']) {
$form->addElement('radio', 'active', get_lang('ActiveAccount'), get_lang('Active'), 1);
$form->addElement('radio', 'active', '', get_lang('Inactive'), 0);
}
$studentBossList = UserManager::getStudentBossList($user_data['user_id']);
$conditions = ['status' => STUDENT_BOSS];
$studentBoss = UserManager::get_user_list($conditions);
$studentBossToSelect = [];
if ($studentBoss) {
foreach ($studentBoss as $bossId => $userData) {
$bossInfo = api_get_user_info($userData['user_id']);
$studentBossToSelect[$bossInfo['user_id']] = $bossInfo['complete_name_with_username'];
}
}
if ($studentBossList) {
$studentBossList = array_column($studentBossList, 'boss_id');
}
$user_data['student_boss'] = array_values($studentBossList);
$form->addElement('advmultiselect', 'student_boss', get_lang('StudentBoss'), $studentBossToSelect);
// EXTRA FIELDS
$extraField = new ExtraField('user');
@ -461,6 +480,10 @@ if ($form->validate()) {
$reset_password
);
if (isset($user['student_boss'])) {
UserManager::subscribeUserToBossList($user_id, $user['student_boss']);
}
if (api_get_setting('openid_authentication') == 'true' && !empty($user['openid'])) {
$up = UserManager::update_openid($user_id, $user['openid']);
}

@ -21,6 +21,7 @@ if (!isset($_GET['user_id'])) {
api_not_allowed();
}
$user = api_get_user_info($_GET['user_id'], true);
$userId = $user['user_id'];
$tool_name = $user['complete_name'].(empty($user['official_code'])?'':' ('.$user['official_code'].')');
$table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
@ -31,7 +32,7 @@ $editUser = null;
if (api_is_platform_admin()) {
$login_as_icon =
'<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_list.php'
.'?action=login_as&user_id='.$user['user_id'].'&'
.'?action=login_as&user_id='.$userId.'&'
.'sec_token='.$_SESSION['sec_token'].'">'
.Display::return_icon('login_as.png', get_lang('LoginAs'),
array(), ICON_SIZE_MEDIUM).'</a>';
@ -42,20 +43,20 @@ if (api_is_platform_admin()) {
array(),
ICON_SIZE_MEDIUM
),
api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$user['user_id']
api_get_path(WEB_CODE_PATH).'admin/user_edit.php?user_id='.$userId
);
$exportLink = Display::url(
Display::return_icon(
'export_csv.png', get_lang('ExportAsCSV'),'', ICON_SIZE_MEDIUM
),
api_get_self().'?user_id='.$user['user_id'].'&action=export'
api_get_self().'?user_id='.$userId.'&action=export'
);
$vCardExportLink = Display::url(
Display::return_icon(
'vcard.png', get_lang('UserInfo'),'', ICON_SIZE_MEDIUM
),
api_get_path(WEB_PATH).'main/social/vcard_export.php?userId='.$user['user_id']
api_get_path(WEB_PATH).'main/social/vcard_export.php?userId='.$userId
);
}
@ -65,11 +66,10 @@ $creatorId = $user['creator_id'];
$creatorInfo = api_get_user_info($creatorId);
$registrationDate = $user['registration_date'];
$csvContent = array();
$table = new HTML_Table(array('class' => 'data_table'));
$table->setHeaderContents(0, 0, get_lang('Information'));
$csvContent[] = get_lang('Information');
$csvContent[] = [get_lang('Information')];
$data = array(
get_lang('Name') => $user['complete_name'],
get_lang('Email') => $user['email'],
@ -104,10 +104,10 @@ $userInformation = $table->toHtml();
$table = new HTML_Table(array('class' => 'data_table'));
$table->setHeaderContents(0, 0, get_lang('Tracking'));
$csvContent[] = get_lang('Tracking');
$csvContent[] = [get_lang('Tracking')];
$data = array(
get_lang('FirstLogin') => Tracking :: get_first_connection_date($user['user_id']),
get_lang('LatestLogin') => Tracking :: get_last_connection_date($user['user_id'], true)
get_lang('FirstLogin') => Tracking :: get_first_connection_date($userId),
get_lang('LatestLogin') => Tracking :: get_last_connection_date($userId, true)
);
$row = 1;
foreach ($data as $label => $item) {
@ -126,8 +126,7 @@ $tbl_session = Database:: get_main_table(TABLE_MAIN_SESSION);
$tbl_course = Database:: get_main_table(TABLE_MAIN_COURSE);
$tbl_user = Database:: get_main_table(TABLE_MAIN_USER);
$user_id = $user['user_id'];
$sessions = SessionManager::get_sessions_by_user($user_id, true);
$sessions = SessionManager::get_sessions_by_user($userId, true);
$personal_course_list = array();
$courseToolInformationTotal = null;
if (count($sessions) > 0) {
@ -159,7 +158,7 @@ if (count($sessions) > 0) {
foreach ($session_item['courses'] as $my_course) {
$courseInfo = api_get_course_info_by_id($my_course['real_id']);
$sessionStatus = SessionManager::get_user_status_in_session(
$user['user_id'],
$userId,
$courseInfo['real_id'],
$id_session
);
@ -179,20 +178,20 @@ if (count($sessions) > 0) {
Display::return_icon('course_home.gif', get_lang('CourseHomepage')).'</a>';
if ($my_course['status'] == STUDENT) {
$tools .= '<a href="user_information.php?action=unsubscribeSessionCourse&course_code='.$courseInfo['code'].'&user_id='.$user['user_id'].'&id_session='.$id_session.'">'.
$tools .= '<a href="user_information.php?action=unsubscribeSessionCourse&course_code='.$courseInfo['code'].'&user_id='.$userId.'&id_session='.$id_session.'">'.
Display::return_icon('delete.png', get_lang('Delete')).'</a>';
}
$timeSpent = api_time_to_hms(
Tracking :: get_time_spent_on_the_course(
$user['user_id'],
$userId,
$courseInfo['real_id'],
$id_session
)
);
$totalForumMessages = CourseManager::getCountPostInForumPerUser(
$user['user_id'],
$userId,
$courseInfo['real_id'],
$id_session
);
@ -213,7 +212,7 @@ if (count($sessions) > 0) {
$data[] = $row;
$result = TrackingUserLogCSV::getToolInformation(
$user['user_id'],
$userId,
$courseInfo,
$id_session
);
@ -261,7 +260,7 @@ $courseToolInformationTotal = null;
*/
$sql = 'SELECT * FROM '.$table_course_user.' cu, '.$table_course.' c
WHERE
cu.user_id = '.$user['user_id'].' AND
cu.user_id = '.$userId.' AND
cu.c_id = c.id AND
cu.relation_type <> '.COURSE_RELATION_TYPE_RRHH.' ';
$res = Database::query($sql);
@ -297,20 +296,20 @@ if (Database::num_rows($res) > 0) {
'<a href="course_edit.php?id='.$course->c_id.'">'.
Display::return_icon('edit.gif', get_lang('Edit')).'</a>';
if ($course->status == STUDENT) {
$tools .= '<a href="user_information.php?action=unsubscribe&course_code='.$courseCode.'&user_id='.$user['user_id'].'">'.
$tools .= '<a href="user_information.php?action=unsubscribe&course_code='.$courseCode.'&user_id='.$userId.'">'.
Display::return_icon('delete.png', get_lang('Delete')).'</a>';
}
$timeSpent = api_time_to_hms(
Tracking :: get_time_spent_on_the_course(
$user['user_id'],
$userId,
$courseInfo['real_id'],
0
)
);
$totalForumMessages = CourseManager::getCountPostInForumPerUser(
$user['user_id'],
$userId,
$course->id,
0
);
@ -328,7 +327,7 @@ if (Database::num_rows($res) > 0) {
$data[] = $row;
$result = TrackingUserLogCSV::getToolInformation(
$user['user_id'],
$userId,
$courseInfo,
0
);
@ -352,9 +351,9 @@ if (Database::num_rows($res) > 0) {
/**
* Show the URL in which this user is subscribed
*/
$urlInformation = null;
$urlInformation = '';
if (api_is_multiple_url_enabled()) {
$urlList = UrlManager::get_access_url_from_user($user['user_id']);
$urlList = UrlManager::get_access_url_from_user($userId);
if (count($urlList) > 0) {
$header = array();
$header[] = array('URL', true);
@ -381,6 +380,25 @@ if (api_is_multiple_url_enabled()) {
$urlInformation = '<p>'.get_lang('NoUrlForThisUser').'</p>';
}
}
$studentBossList = UserManager::getStudentBossList($userId);
$studentBossListToString = '';
if ($studentBossList) {
$table = new HTML_Table(array('class' => 'data_table'));
$table->setHeaderContents(0, 0, get_lang('User'));
$csvContent[] = [get_lang('StudentBoss')];
$row = 1;
foreach ($studentBossList as $studentBossId) {
$studentBoss = api_get_user_info($studentBossId);
$table->setCellContents($row, 0, $studentBoss['complete_name_with_username']);
$csvContent[] = array($studentBoss['complete_name_with_username']);
$row++;
}
$studentBossListToString = $table->toHtml();
}
$message = null;
if (isset($_GET['action'])) {
@ -425,14 +443,13 @@ echo '<div class="actions">
echo Display::page_header($tool_name);
$fullUrlBig = UserManager::getUserPicture(
$user['user_id'],
$userId,
USER_IMAGE_SIZE_BIG
);
$fullUrl = UserManager::getUserPicture(
$user['user_id'],
$userId,
USER_IMAGE_SIZE_ORIGINAL
);
@ -453,8 +470,15 @@ echo $trackingInformation;
echo '</div>';
echo '</div>';
if ($studentBossList) {
echo Display::page_subheader(get_lang('StudentBossList'));
echo $studentBossListToString;
}
echo Display::page_subheader(get_lang('SessionList'));
echo $sessionInformation;
echo Display::page_subheader(get_lang('CourseList'));
echo $courseInformation;
echo $urlInformation;

@ -1928,6 +1928,16 @@ class Exercise
array('id' => 'result_disabled_2')
);
$radios_results_disabled[] = $form->createElement(
'radio',
'results_disabled',
null,
get_lang('ShowScoreEveryAttemptShowAnswersLastAttempt'),
'4',
array('id' => 'result_disabled_4')
);
$form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), '');
// Type of questions disposition on page
@ -7705,7 +7715,13 @@ class Exercise
$show_results = true;
}
if (in_array($this->results_disabled, array(RESULT_DISABLE_SHOW_SCORE_ONLY, RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES))) {
$showScoreOptions = [
RESULT_DISABLE_SHOW_SCORE_ONLY,
RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES,
RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT
];
if (in_array($this->results_disabled, $showScoreOptions)) {
$show_only_score = true;
}

@ -111,10 +111,10 @@ if (api_is_allowed_to_edit(null, true) && isset($_GET['preview']) && $_GET['prev
/** @var \Exercise $exerciseInSession */
$exerciseInSession = Session::read('objExercise');
if (!isset($exerciseInSession) || isset($exerciseInSession) && ($exerciseInSession->id != $_GET['exerciseId'])) {
// Construction of Exercise
$objExercise = new Exercise();
Session::write('firstTime', true);
if ($debug) {error_log('1. Setting the $objExercise variable'); };
Session::erase('questionList');
@ -134,7 +134,6 @@ if (!isset($exerciseInSession) || isset($exerciseInSession) && ($exerciseInSessi
} else {
Session::write('firstTime', false);
}
//2. Checking if $objExercise is set
if (!isset($objExercise) && isset($exerciseInSession)) {
if ($debug) { error_log('2. Loading $objExercise from session'); };
@ -245,12 +244,14 @@ if ($objExercise->selectAttempts() > 0) {
if ($origin == 'learnpath') {
Display :: display_reduced_header();
} else {
Display :: display_header($nameTools,'Exercises');
Display :: display_header(get_lang('Exercises'));
}
echo $attempt_html;
if ($origin != 'learnpath')
Display :: display_footer();
if ($origin != 'learnpath') {
Display:: display_footer();
}
exit;
}
}
@ -460,9 +461,8 @@ if ($time_control) { //Sends the exercise form when the expired time is finished
}
// if the user has submitted the form
$exercise_title = $objExercise->selectTitle();
$exercise_sound = $objExercise->selectSound();
$exercise_title = $objExercise->selectTitle();
$exercise_sound = $objExercise->selectSound();
//in LP's is enabled the "remember question" feature?

@ -169,6 +169,13 @@ if ($current_browser == 'Internet Explorer') {
$btn_class = '';
}
$blockShowAnswers = false;
if ($objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) {
if (count($attempts) < $objExercise->attempts ) {
$blockShowAnswers = true;
}
}
if (!empty($attempts)) {
$i = $counter;
foreach ($attempts as $attempt_result) {
@ -213,7 +220,8 @@ if (!empty($attempts)) {
array(
RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS,
RESULT_DISABLE_SHOW_SCORE_ONLY,
RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES
RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES,
RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT
)
)) {
$row['result'] = $score;
@ -223,23 +231,36 @@ if (!empty($attempts)) {
$objExercise->results_disabled,
array(
RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS,
RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES
RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES,
RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT
)
)
|| (
$objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_ONLY &&
$objExercise->feedback_type == EXERCISE_FEEDBACK_TYPE_END)
) {
if ($blockShowAnswers) {
$attempt_link = '';
}
$row['attempt_link'] = $attempt_link;
}
$my_attempt_array[] = $row;
$i--;
}
$header_names = [];
$table = new HTML_Table(array('class' => 'table table-striped table-hover'));
//Hiding score and answer
// Hiding score and answer
switch ($objExercise->results_disabled) {
case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
if ($blockShowAnswers) {
$header_names = array(get_lang('Attempt'), get_lang('StartDate'), get_lang('IP'), get_lang('Score'));
} else {
$header_names = array(get_lang('Attempt'), get_lang('StartDate'), get_lang('IP'), get_lang('Score'), get_lang('Details'));
}
break;
case RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS:
case RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES:
$header_names = array(get_lang('Attempt'), get_lang('StartDate'), get_lang('IP'), get_lang('Score'), get_lang('Details'));

@ -28,10 +28,10 @@ if (empty($id)) {
$is_allowedToEdit = api_is_allowed_to_edit(null,true) || $is_courseTutor;
//Getting results from the exe_id. This variable also contain all the information about the exercise
// Getting results from the exe_id. This variable also contain all the information about the exercise
$track_exercise_info = ExerciseLib::get_exercise_track_exercise_info($id);
//No track info
// No track info
if (empty($track_exercise_info)) {
api_not_allowed($show_headers);
}

@ -446,6 +446,7 @@ define('RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS', 0); //show score and ex
define('RESULT_DISABLE_NO_SCORE_AND_EXPECTED_ANSWERS', 1); //Do not show score nor answers
define('RESULT_DISABLE_SHOW_SCORE_ONLY', 2); //Show score only
define('RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES', 3); //Show final score only with categories
define('RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT', 4); //Show final score only with categories
define('EXERCISE_MAX_NAME_SIZE', 80);

@ -3488,6 +3488,32 @@ HOTSPOT;
$show_only_score = false;
}
if ($objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) {
$show_only_score = true;
if ($objExercise->attempts > 0) {
$attempts = Event::getExerciseResultsByUser(
api_get_user_id(),
$objExercise->id,
api_get_course_int_id(),
api_get_session_id(),
$exercise_stat_info['orig_lp_id'],
$exercise_stat_info['orig_lp_item_id'],
'desc'
);
if ($attempts) {
$numberAttempts = count($attempts);
if ($save_user_result) {
$numberAttempts++;
}
if ($numberAttempts >= $objExercise->attempts) {
$show_results = true;
$show_only_score = false;
};
}
}
}
if ($show_results || $show_only_score) {
$user_info = api_get_user_info($exercise_stat_info['exe_user_id']);
//Shows exercise header
@ -3502,6 +3528,7 @@ HOTSPOT;
);
}
// Display text when test is finished #4074 and for LP #4227
$end_of_message = $objExercise->selectTextWhenFinished();
if (!empty($end_of_message)) {

@ -41,6 +41,7 @@ class Export
public static function arrayToCsv($data, $filename = 'export')
{
if (empty($data)) {
return false;
}

@ -694,7 +694,7 @@ class Template
'bootstrap/dist/js/bootstrap.min.js',
'jquery-ui/jquery-ui.min.js',
'moment/min/moment-with-locales.min.js',
'ckeditor/ckeditor.js',
api_is_anonymous() ? '' : 'ckeditor/ckeditor.js',
'bootstrap-daterangepicker/daterangepicker.js',
'jquery-timeago/jquery.timeago.js',
'mediaelement/build/mediaelement-and-player.min.js',

@ -4137,7 +4137,7 @@ class UserManager
* @param array $subscribedUsersId The id of suscribed users
* @param action $relationType The relation type
*/
public static function subscribeUsersToUser($userId, $subscribedUsersId, $relationType)
public static function subscribeUsersToUser($userId, $subscribedUsersId, $relationType, $deleteUsersBeforeInsert = false)
{
$userRelUserTable = Database::get_main_table(TABLE_MAIN_USER_REL_USER);
$userRelAccessUrlTable = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
@ -4147,40 +4147,48 @@ class UserManager
$affectedRows = 0;
if (api_get_multiple_access_url()) {
//Deleting assigned users to hrm_id
$sql = "SELECT s.user_id FROM $userRelUserTable s "
. "INNER JOIN $userRelAccessUrlTable a ON (a.user_id = s.user_id) "
. "WHERE friend_user_id = $userId "
. "AND relation_type = $relationType "
. "AND access_url_id = " . api_get_current_access_url_id() . "";
// Deleting assigned users to hrm_id
$sql = "SELECT s.user_id FROM $userRelUserTable s
INNER JOIN $userRelAccessUrlTable a ON (a.user_id = s.user_id)
WHERE
friend_user_id = $userId AND
relation_type = $relationType AND
access_url_id = " . api_get_current_access_url_id();
} else {
$sql = "SELECT user_id FROM $userRelUserTable "
. "WHERE friend_user_id = $userId "
. "AND relation_type = $relationType";
$sql = "SELECT user_id FROM $userRelUserTable
WHERE friend_user_id = $userId
AND relation_type = $relationType";
}
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
while ($row = Database::fetch_array($result)) {
$sql = "DELETE FROM $userRelUserTable "
. "WHERE user_id = {$row['user_id']} "
. "AND friend_user_id = $userId "
. "AND relation_type = $relationType";
$sql = "DELETE FROM $userRelUserTable
WHERE
user_id = {$row['user_id']} AND
friend_user_id = $userId AND
relation_type = $relationType";
Database::query($sql);
}
}
if ($deleteUsersBeforeInsert) {
$sql = "DELETE FROM $userRelUserTable
WHERE
user_id = $userId AND
relation_type = $relationType";
Database::query($sql);
}
// Inserting new user list
if (is_array($subscribedUsersId)) {
foreach ($subscribedUsersId as $subscribedUserId) {
$subscribedUserId = intval($subscribedUserId);
$sql = "INSERT IGNORE INTO $userRelUserTable(user_id, friend_user_id, relation_type) "
. "VALUES ($subscribedUserId, $userId, $relationType)";
$sql = "INSERT IGNORE INTO $userRelUserTable (user_id, friend_user_id, relation_type)
VALUES ($subscribedUserId, $userId, $relationType)";
$result = Database::query($sql);
$affectedRows = Database::affected_rows($result);
}
}
@ -4822,16 +4830,44 @@ EOF;
}
/**
* Subscribe users to student boss
* Subscribe boss to students
*
* @param int $bossId The boss id
* @param array $usersId The users array
* @return int Affected rows
*/
public static function subscribeUsersToBoss($bossId, $usersId)
public static function subscribeBossToUsers($bossId, $usersId)
{
return self::subscribeUsersToUser($bossId, $usersId, USER_RELATION_TYPE_BOSS);
}
/**
* Subscribe boss to students
*
* @param int $studentId
* @param array $bossList
* @return int Affected rows
*/
public static function subscribeUserToBossList($studentId, $bossList)
{
$count = 1;
if ($bossList) {
$studentId = (int) $studentId;
$userRelUserTable = Database::get_main_table(TABLE_MAIN_USER_REL_USER);
$userRelAccessUrlTable = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$sql = "DELETE FROM $userRelUserTable
WHERE user_id = $studentId AND relation_type = ".USER_RELATION_TYPE_BOSS;
Database::query($sql);
foreach ($bossList as $bossId) {
$sql = "INSERT IGNORE INTO $userRelUserTable (user_id, friend_user_id, relation_type)
VALUES ($studentId, $bossId, ".USER_RELATION_TYPE_BOSS.")";
Database::query($sql);
}
}
}
/**
* Get users followed by student boss
* @param int $userId
@ -4861,8 +4897,18 @@ EOF;
$lastConnectionDate = null
){
return self::getUsersFollowedByUser(
$userId, $userStatus, $getOnlyUserId, $getSql, $getCount, $from, $numberItems, $column, $direction,
$active, $lastConnectionDate, STUDENT_BOSS
$userId,
$userStatus,
$getOnlyUserId,
$getSql,
$getCount,
$from,
$numberItems,
$column,
$direction,
$active,
$lastConnectionDate,
STUDENT_BOSS
);
}
@ -4976,7 +5022,7 @@ EOF;
* @param $userId
* @return bool
*/
public static function getStudentBoss($userId)
public static function getFirstStudentBoss($userId)
{
$userId = intval($userId);
if ($userId > 0) {
@ -5002,6 +5048,36 @@ EOF;
return false;
}
/**
* Get the boss user ID from a followed user id
* @param $userId
* @return bool
*/
public static function getStudentBossList($userId)
{
$userId = intval($userId);
if ($userId > 0) {
$userRelTable = Database::get_main_table(TABLE_MAIN_USER_REL_USER);
$result = Database::select(
'DISTINCT friend_user_id AS boss_id',
$userRelTable,
array(
'where' => array(
'user_id = ? AND relation_type = ? ' => array(
$userId,
USER_RELATION_TYPE_BOSS,
)
)
),
'all'
);
return $result;
}
return false;
}
/**
* Get either a Gravatar URL or complete image tag for a specified email address.
*

@ -109,7 +109,7 @@ if ($verified) {
$studentArray['picture'] = $studentArray['avatar'];
// Get superior data if exist
$superiorId = UserManager::getStudentBoss($data['studentUserId']);
$superiorId = UserManager::getFirstStudentBoss($data['studentUserId']);
if (!empty($superiorId)) {
$superiorArray = api_get_user_info($superiorId);
} else {
@ -265,7 +265,7 @@ if ($verified) {
$studentArray = api_get_user_info($data['studentUserId']);
$studentArray['picture'] = $studentArray['avatar'];
// Prepare superior data
$superiorId = UserManager::getStudentBoss($data['studentUserId']);
$superiorId = UserManager::getFirstStudentBoss($data['studentUserId']);
if (!empty($superiorId)) {
$superiorArray = api_get_user_info($superiorId);
} else {

@ -67,7 +67,7 @@ $studentArray = api_get_user_info($data['studentUserId']);
$studentArray['picture'] = $studentArray['avatar'];
// Get superior data if exist
$superiorId = UserManager::getStudentBoss($data['studentUserId']);
$superiorId = UserManager::getFirstStudentBoss($data['studentUserId']);
if (!empty($superiorId)) {
$superiorArray = api_get_user_info($superiorId);
} else {

Loading…
Cancel
Save