Code Duplication    Length = 41-44 lines in 2 locations

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

@@ 4862-4902 (lines=41) @@
4859
     *
4860
     * @return bool
4861
     */
4862
    public static function folderExists(
4863
        $folder,
4864
        $courseInfo,
4865
        $sessionId,
4866
        $groupId
4867
    ) {
4868
        $courseId = $courseInfo['real_id'];
4869
4870
        if (empty($courseId)) {
4871
            return false;
4872
        }
4873
4874
        $sessionId = intval($sessionId);
4875
        $folderWithSuffix = self::fixDocumentName(
4876
            $folder,
4877
            'folder',
4878
            $courseInfo,
4879
            $sessionId,
4880
            $groupId
4881
        );
4882
4883
        $folder = Database::escape_string($folder);
4884
        $folderWithSuffix = Database::escape_string($folderWithSuffix);
4885
4886
        // Check if pathname already exists inside document table
4887
        $tbl_document = Database::get_course_table(TABLE_DOCUMENT);
4888
        $sql = "SELECT id, path FROM $tbl_document
4889
                WHERE
4890
                    filetype = 'folder' AND
4891
                    c_id = $courseId AND
4892
                    (path = '$folder' OR path = '$folderWithSuffix') AND
4893
                    (session_id = 0 OR session_id = $sessionId)
4894
        ";
4895
4896
        $rs = Database::query($sql);
4897
        if (Database::num_rows($rs)) {
4898
            return true;
4899
        }
4900
4901
        return false;
4902
    }
4903
4904
    /**
4905
     * Check if file exist in the course base or in the session course
@@ 4913-4956 (lines=44) @@
4910
     *
4911
     * @return bool
4912
     */
4913
    public static function documentExists(
4914
        $fileName,
4915
        $courseInfo,
4916
        $sessionId,
4917
        $groupId
4918
    ) {
4919
        $courseId = $courseInfo['real_id'];
4920
4921
        if (empty($courseId)) {
4922
            return false;
4923
        }
4924
4925
        $sessionId = intval($sessionId);
4926
        $fileNameEscape = Database::escape_string($fileName);
4927
4928
        $fileNameWithSuffix = self::fixDocumentName(
4929
            $fileName,
4930
            'file',
4931
            $courseInfo,
4932
            $sessionId,
4933
            $groupId
4934
        );
4935
4936
        $fileNameWithSuffix = Database::escape_string($fileNameWithSuffix);
4937
4938
        // Check if pathname already exists inside document table
4939
        $table = Database::get_course_table(TABLE_DOCUMENT);
4940
        $sql = "SELECT id, path FROM $table
4941
                WHERE
4942
                    filetype = 'file' AND
4943
                    c_id = $courseId AND
4944
                    (
4945
                        path = '".$fileNameEscape."' OR
4946
                        path = '$fileNameWithSuffix'
4947
                    ) AND
4948
                    (session_id = 0 OR session_id = $sessionId)
4949
        ";
4950
        $rs = Database::query($sql);
4951
        if (Database::num_rows($rs)) {
4952
            return true;
4953
        }
4954
4955
        return false;
4956
    }
4957
4958
    /**
4959
     * Undo the suffix applied to a file example: