/**
  * Unsubscribe a user from a class. If the class is also subscribed in a
  * course, the user will be unsubscribed from that course
  * @param int $user_id The user id
  * @param int $class_id The class id
  */
 public static function unsubscribe_user($user_id, $class_id)
 {
     $class_id = intval($class_id);
     $user_id = intval($user_id);
     $table_class_user = Database::get_main_table(TABLE_MAIN_CLASS_USER);
     $table_course_class = Database::get_main_table(TABLE_MAIN_COURSE_CLASS);
     $courses = ClassManager::get_courses($class_id);
     if (count($courses) != 0) {
         $course_codes = array();
         foreach ($courses as $index => $course) {
             $course_codes[] = $course['course_code'];
             $sql = "SELECT DISTINCT user_id FROM {$table_class_user} t1, {$table_course_class} t2 WHERE t1.class_id=t2.class_id AND course_code = '" . $course['course_code'] . "' AND user_id = {$user_id} AND t2.class_id<>'{$class_id}'";
             $res = Database::query($sql);
             if (Database::num_rows($res) == 0 && CourseManager::get_user_in_course_status($user_id, $course['course_code']) == STUDENT) {
                 CourseManager::unsubscribe_user($user_id, $course['course_code']);
             }
         }
     }
     $sql = "DELETE FROM {$table_class_user} WHERE user_id='" . $user_id . "' AND class_id = '" . $class_id . "'";
     Database::query($sql);
 }
示例#2
0
            $row[] = "<span title='{$username}'>" . $user['lastname'] . "</span>";
            $row[] = $user['firstname'];
        }
        $row[] = Display::encrypted_mailto_link($user['email'], $user['email']);
        $row[] = $user['status'] == 5 ? get_lang('Student') : get_lang('Teacher');
        $row[] = '<a href="user_information.php?user_id=' . $user['user_id'] . '">' . Display::return_icon('synthese_view.gif', get_lang('Info')) . '</a>';
        $data[] = $row;
    }
    Display::display_sortable_table($table_header, $data, array(), array(), array('id' => $_GET['id']));
} else {
    echo get_lang('NoUsersInClass');
}
/**
 * Show all courses in which this class is subscribed.
 */
$courses = ClassManager::get_courses($class_id);
if (count($courses) > 0) {
    $header[] = array(get_lang('Code'), true);
    $header[] = array(get_lang('Title'), true);
    $header[] = array('', false);
    $data = array();
    foreach ($courses as $index => $course) {
        $row = array();
        $row[] = $course['visual_code'];
        $row[] = $course['title'];
        $row[] = '<a href="course_information.php?code=' . $course['code'] . '">' . Display::return_icon('info_small.gif', get_lang('Delete')) . '</a>' . '<a href="' . api_get_path(WEB_COURSE_PATH) . $course['directory'] . '">' . Display::return_icon('course_home.gif', get_lang('CourseHome')) . '</a>' . '<a href="course_edit.php?course_code=' . $course['code'] . '">' . Display::return_icon('edit.gif', get_lang('Edit')) . '</a>';
        $data[] = $row;
    }
    echo '<p><b>' . get_lang('Courses') . '</b></p>';
    echo '<blockquote>';
    Display::display_sortable_table($header, $data, array(), array(), array('id' => $_GET['id']));
 /**
  * Unsubscribe a user from a class. If the class is also subscribed in a
  * course, the user will be unsubscribed from that course
  * @param int $user_id The user id
  * @param int $class_id The class id
  */
 public static function unsubscribe_user($user_id, $class_id)
 {
     $class_id = intval($class_id);
     $user_id = intval($user_id);
     $em = Database::getManager();
     $table_class_user = Database::get_main_table(TABLE_MAIN_CLASS_USER);
     $courses = ClassManager::get_courses($class_id);
     if (count($courses) != 0) {
         $course_codes = array();
         foreach ($courses as $index => $course) {
             $course_codes[] = $course['course_code'];
             $dql = '
                 SELECT DISTICT cu.userId
                 FROM ChamiloCoreBundle:ClassUser cu, ChamiloCoreBundle:CourseRelClass cc
                 WHERE
                     cu.classId = cc.classId AND
                     cc.courseId = :course AND
                     cu.userId = :user AND 
                     cc.classId != :class
             ';
             $res = $em->createQuery($dql)->setParameters(['course' => $course['id'], 'user' => $user_id, 'class' => $class_id])->getResult();
             if (count($res) === 0 && CourseManager::get_user_in_course_status($user_id, $course['course_code']) == STUDENT) {
                 CourseManager::unsubscribe_user($user_id, $course['course_code']);
             }
         }
     }
     $sql = "DELETE FROM {$table_class_user} WHERE user_id='" . $user_id . "' AND class_id = '" . $class_id . "'";
     Database::query($sql);
 }