Code Duplication    Length = 36-40 lines in 2 locations

main/work/work.lib.php 2 locations

@@ 2991-3026 (lines=36) @@
2988
 * @param int $sessionId
2989
 * @return int
2990
 */
2991
function getWorkCommentCountFromParent(
2992
    $parentId,
2993
    $courseInfo = array(),
2994
    $sessionId = 0
2995
) {
2996
    if (empty($courseInfo)) {
2997
        $courseInfo = api_get_course_info();
2998
    }
2999
3000
    if (empty($sessionId)) {
3001
        $sessionId = api_get_session_id();
3002
    } else {
3003
        $sessionId = intval($sessionId);
3004
    }
3005
3006
    $work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
3007
    $commentTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT_COMMENT);
3008
    $parentId = intval($parentId);
3009
    $sessionCondition = api_get_session_condition($sessionId, false, false, 'w.session_id');
3010
3011
    $sql = "SELECT count(*) as count
3012
            FROM $commentTable c INNER JOIN $work w
3013
            ON c.c_id = w.c_id AND w.id = c.work_id
3014
            WHERE
3015
                $sessionCondition AND
3016
                parent_id = $parentId AND
3017
                w.c_id = ".$courseInfo['real_id'];
3018
3019
    $result = Database::query($sql);
3020
    if (Database::num_rows($result)) {
3021
        $comment = Database::fetch_array($result);
3022
        return $comment['count'];
3023
    }
3024
3025
    return 0;
3026
}
3027
3028
/**
3029
 * Get last work information from parent
@@ 3035-3074 (lines=40) @@
3032
 * @param int $sessionId
3033
 * @return int
3034
 */
3035
function getLastWorkStudentFromParent(
3036
    $parentId,
3037
    $courseInfo = array(),
3038
    $sessionId = 0
3039
) {
3040
    if (empty($courseInfo)) {
3041
        $courseInfo = api_get_course_info();
3042
    }
3043
3044
    if (empty($sessionId)) {
3045
        $sessionId = api_get_session_id();
3046
    } else {
3047
        $sessionId = intval($sessionId);
3048
    }
3049
3050
    $work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
3051
    $sessionCondition = api_get_session_condition($sessionId, false);
3052
    $commentTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT_COMMENT);
3053
    $parentId = intval($parentId);
3054
3055
    $sql = "SELECT w.*
3056
            FROM $commentTable c INNER JOIN $work w
3057
            ON c.c_id = w.c_id AND w.id = c.work_id
3058
            WHERE
3059
                $sessionCondition AND
3060
                parent_id = $parentId AND
3061
                w.c_id = ".$courseInfo['real_id']."
3062
            ORDER BY w.sent_date
3063
            LIMIT 1
3064
            ";
3065
3066
    $result = Database::query($sql);
3067
    if (Database::num_rows($result)) {
3068
        $comment = Database::fetch_array($result, 'ASSOC');
3069
3070
        return $comment;
3071
    }
3072
3073
    return array();
3074
}
3075
3076
/**
3077
 * Get last work information from parent