Code Duplication    Length = 25-25 lines in 2 locations

main/webservices/cm_webservice_course.php 1 location

@@ 417-441 (lines=25) @@
414
     * @param int Status (STUDENT or TEACHER) Used for subscription only
415
     * @return mixed True if subscription or unsubscription was successful, false otherwise
416
     */
417
    protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) {
418
        $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
419
        if ($course_id instanceof WSError) {
420
            return $course_id;
421
        } else {
422
            $user_id = $this->getUserId($user_id_field_name, $user_id_value);
423
            if ($user_id instanceof WSError) {
424
                return $user_id;
425
            } else {
426
                $course_code = CourseManager::get_course_code_from_course_id($course_id);
427
                if ($state == 0) {
428
                    // Unsubscribe user
429
                    CourseManager::unsubscribe_user($user_id, $course_code);
430
                    return true;
431
                } else {
432
                    // Subscribe user
433
                    if (CourseManager::subscribe_user($user_id, $course_code, $status)) {
434
                        return true;
435
                    } else {
436
                        return new WSError(203, 'An error occured subscribing to this course');
437
                    }
438
                }
439
            }
440
        }
441
    }
442
443
    /**
444
     * Subscribe user to a course

main/webservices/webservice_course.php 1 location

@@ 506-530 (lines=25) @@
503
     * @param int Status (STUDENT or TEACHER) Used for subscription only
504
     * @return mixed True if subscription or unsubscription was successful, false otherwise
505
     */
506
    protected function changeUserSubscription(
507
        $course_id_field_name,
508
        $course_id_value,
509
        $user_id_field_name,
510
        $user_id_value,
511
        $state,
512
        $status = STUDENT
513
    ) {
514
        $course_id = $this->getCourseId(
515
            $course_id_field_name,
516
            $course_id_value
517
        );
518
        if ($course_id instanceof WSError) {
519
            return $course_id;
520
        } else {
521
            $user_id = $this->getUserId($user_id_field_name, $user_id_value);
522
            if ($user_id instanceof WSError) {
523
                return $user_id;
524
            } else {
525
                $course_code = CourseManager::get_course_code_from_course_id(
526
                    $course_id
527
                );
528
                if ($state == 0) {
529
                    // Unsubscribe user
530
                    CourseManager::unsubscribe_user($user_id, $course_code);
531
532
                    return true;
533
                } else {