Code Duplication    Length = 36-40 lines in 2 locations

main/work/work.lib.php 2 locations

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