Code Duplication    Length = 41-44 lines in 2 locations

main/inc/lib/document.lib.php 2 locations

@@ 4887-4927 (lines=41) @@
4884
     *
4885
     * @return bool
4886
     */
4887
    public static function folderExists(
4888
        $folder,
4889
        $courseInfo,
4890
        $sessionId,
4891
        $groupId
4892
    ) {
4893
        $courseId = $courseInfo['real_id'];
4894
4895
        if (empty($courseId)) {
4896
            return false;
4897
        }
4898
4899
        $sessionId = intval($sessionId);
4900
        $folderWithSuffix = self::fixDocumentName(
4901
            $folder,
4902
            'folder',
4903
            $courseInfo,
4904
            $sessionId,
4905
            $groupId
4906
        );
4907
4908
        $folder = Database::escape_string($folder);
4909
        $folderWithSuffix = Database::escape_string($folderWithSuffix);
4910
4911
        // Check if pathname already exists inside document table
4912
        $tbl_document = Database::get_course_table(TABLE_DOCUMENT);
4913
        $sql = "SELECT id, path FROM $tbl_document
4914
                WHERE
4915
                    filetype = 'folder' AND
4916
                    c_id = $courseId AND
4917
                    (path = '$folder' OR path = '$folderWithSuffix') AND
4918
                    (session_id = 0 OR session_id = $sessionId)
4919
        ";
4920
4921
        $rs = Database::query($sql);
4922
        if (Database::num_rows($rs)) {
4923
            return true;
4924
        }
4925
4926
        return false;
4927
    }
4928
4929
    /**
4930
     * Check if file exist in the course base or in the session course
@@ 4938-4981 (lines=44) @@
4935
     *
4936
     * @return bool
4937
     */
4938
    public static function documentExists(
4939
        $fileName,
4940
        $courseInfo,
4941
        $sessionId,
4942
        $groupId
4943
    ) {
4944
        $courseId = $courseInfo['real_id'];
4945
4946
        if (empty($courseId)) {
4947
            return false;
4948
        }
4949
4950
        $sessionId = intval($sessionId);
4951
        $fileNameEscape = Database::escape_string($fileName);
4952
4953
        $fileNameWithSuffix = self::fixDocumentName(
4954
            $fileName,
4955
            'file',
4956
            $courseInfo,
4957
            $sessionId,
4958
            $groupId
4959
        );
4960
4961
        $fileNameWithSuffix = Database::escape_string($fileNameWithSuffix);
4962
4963
        // Check if pathname already exists inside document table
4964
        $table = Database::get_course_table(TABLE_DOCUMENT);
4965
        $sql = "SELECT id, path FROM $table
4966
                WHERE
4967
                    filetype = 'file' AND
4968
                    c_id = $courseId AND
4969
                    (
4970
                        path = '".$fileNameEscape."' OR
4971
                        path = '$fileNameWithSuffix'
4972
                    ) AND
4973
                    (session_id = 0 OR session_id = $sessionId)
4974
        ";
4975
        $rs = Database::query($sql);
4976
        if (Database::num_rows($rs)) {
4977
            return true;
4978
        }
4979
4980
        return false;
4981
    }
4982
4983
    /**
4984
     * Undo the suffix applied to a file example: