Code Duplication    Length = 36-40 lines in 2 locations

main/work/work.lib.php 2 locations

@@ 3146-3181 (lines=36) @@
3143
 * @param int $sessionId
3144
 * @return int
3145
 */
3146
function getWorkCommentCountFromParent(
3147
    $parentId,
3148
    $courseInfo = array(),
3149
    $sessionId = 0
3150
) {
3151
    if (empty($courseInfo)) {
3152
        $courseInfo = api_get_course_info();
3153
    }
3154
3155
    if (empty($sessionId)) {
3156
        $sessionId = api_get_session_id();
3157
    } else {
3158
        $sessionId = intval($sessionId);
3159
    }
3160
3161
    $work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
3162
    $commentTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT_COMMENT);
3163
    $parentId = intval($parentId);
3164
    $sessionCondition = api_get_session_condition($sessionId, false, false, 'w.session_id');
3165
3166
    $sql = "SELECT count(*) as count
3167
            FROM $commentTable c INNER JOIN $work w
3168
            ON c.c_id = w.c_id AND w.id = c.work_id
3169
            WHERE
3170
                $sessionCondition AND
3171
                parent_id = $parentId AND
3172
                w.c_id = ".$courseInfo['real_id'];
3173
3174
    $result = Database::query($sql);
3175
    if (Database::num_rows($result)) {
3176
        $comment = Database::fetch_array($result);
3177
        return $comment['count'];
3178
    }
3179
3180
    return 0;
3181
}
3182
3183
/**
3184
 * Get last work information from parent
@@ 3190-3229 (lines=40) @@
3187
 * @param int $sessionId
3188
 * @return int
3189
 */
3190
function getLastWorkStudentFromParent(
3191
    $parentId,
3192
    $courseInfo = array(),
3193
    $sessionId = 0
3194
) {
3195
    if (empty($courseInfo)) {
3196
        $courseInfo = api_get_course_info();
3197
    }
3198
3199
    if (empty($sessionId)) {
3200
        $sessionId = api_get_session_id();
3201
    } else {
3202
        $sessionId = intval($sessionId);
3203
    }
3204
3205
    $work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
3206
    $sessionCondition = api_get_session_condition($sessionId, false);
3207
    $commentTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT_COMMENT);
3208
    $parentId = intval($parentId);
3209
3210
    $sql = "SELECT w.*
3211
            FROM $commentTable c INNER JOIN $work w
3212
            ON c.c_id = w.c_id AND w.id = c.work_id
3213
            WHERE
3214
                $sessionCondition AND
3215
                parent_id = $parentId AND
3216
                w.c_id = ".$courseInfo['real_id']."
3217
            ORDER BY w.sent_date
3218
            LIMIT 1
3219
            ";
3220
3221
    $result = Database::query($sql);
3222
    if (Database::num_rows($result)) {
3223
        $comment = Database::fetch_array($result, 'ASSOC');
3224
3225
        return $comment;
3226
    }
3227
3228
    return array();
3229
}
3230
3231
/**
3232
 * Get last work information from parent