Code Duplication    Length = 41-44 lines in 2 locations

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

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