Code Duplication    Length = 49-53 lines in 2 locations

src/Chamilo/CourseBundle/Component/CourseCopy/CourseBuilder.php 2 locations

@@ 979-1031 (lines=53) @@
976
     * @param bool $with_base_content Whether to include content from the course without session or not
977
     * @param array $id_list If you want to restrict the structure to only the given IDs
978
     */
979
    public function build_announcements(
980
        $session_id = 0,
981
        $courseId = 0,
982
        $with_base_content = false,
983
        $id_list = array()
984
    ) {
985
        $table = Database:: get_course_table(TABLE_ANNOUNCEMENT);
986
987
        $sessionCondition = api_get_session_condition(
988
            $session_id,
989
            true,
990
            $with_base_content
991
        );
992
993
        $sql = 'SELECT * FROM '.$table.'
994
                WHERE c_id = '.$courseId.' '.$sessionCondition;
995
        $db_result = Database::query($sql);
996
        $table_attachment = Database:: get_course_table(
997
            TABLE_ANNOUNCEMENT_ATTACHMENT
998
        );
999
        while ($obj = Database::fetch_object($db_result)) {
1000
            if (empty($obj->id)) {
1001
                continue;
1002
            }
1003
            $sql = 'SELECT path, comment, filename, size
1004
                    FROM '.$table_attachment.'
1005
                    WHERE c_id = '.$courseId.' AND announcement_id = '.$obj->id.'';
1006
            $result = Database::query($sql);
1007
            $attachment_obj = Database::fetch_object($result);
1008
            $att_path = $att_filename = $att_size = $atth_comment = '';
1009
1010
            if (!empty($attachment_obj)) {
1011
                $att_path = $attachment_obj->path;
1012
                $att_filename = $attachment_obj->filename;
1013
                $att_size = $attachment_obj->size;
1014
                $atth_comment = $attachment_obj->comment;
1015
            }
1016
1017
            $announcement = new Announcement(
1018
                $obj->id,
1019
                $obj->title,
1020
                $obj->content,
1021
                $obj->end_date,
1022
                $obj->display_order,
1023
                $obj->email_sent,
1024
                $att_path,
1025
                $att_filename,
1026
                $att_size,
1027
                $atth_comment
1028
            );
1029
            $this->course->add_resource($announcement);
1030
        }
1031
    }
1032
1033
    /**
1034
     * Build the events
@@ 1040-1088 (lines=49) @@
1037
     * @param bool $with_base_content Whether to include content from the course without session or not
1038
     * @param array $id_list If you want to restrict the structure to only the given IDs
1039
     */
1040
    public function build_events(
1041
        $session_id = 0,
1042
        $courseId = 0,
1043
        $with_base_content = false,
1044
        $id_list = array()
1045
    ) {
1046
        $table = Database:: get_course_table(TABLE_AGENDA);
1047
1048
        $sessionCondition = api_get_session_condition(
1049
            $session_id,
1050
            true,
1051
            $with_base_content
1052
        );
1053
1054
        $sql = 'SELECT * FROM '.$table.'
1055
                WHERE c_id = '.$courseId.' '.$sessionCondition;
1056
        $db_result = Database::query($sql);
1057
        while ($obj = Database::fetch_object($db_result)) {
1058
            $table_attachment = Database:: get_course_table(
1059
                TABLE_AGENDA_ATTACHMENT
1060
            );
1061
            $sql = 'SELECT path, comment, filename, size
1062
                    FROM '.$table_attachment.'
1063
                    WHERE c_id = '.$courseId.' AND agenda_id = '.$obj->id.'';
1064
            $result = Database::query($sql);
1065
1066
            $attachment_obj = Database::fetch_object($result);
1067
            $att_path = $att_filename = $att_size = $atth_comment = '';
1068
            if (!empty($attachment_obj)) {
1069
                $att_path = $attachment_obj->path;
1070
                $att_filename = $attachment_obj->filename;
1071
                $att_size = $attachment_obj->size;
1072
                $atth_comment = $attachment_obj->comment;
1073
            }
1074
            $event = new CalendarEvent(
1075
                $obj->id,
1076
                $obj->title,
1077
                $obj->content,
1078
                $obj->start_date,
1079
                $obj->end_date,
1080
                $att_path,
1081
                $att_filename,
1082
                $att_size,
1083
                $atth_comment,
1084
                $obj->all_day
1085
            );
1086
            $this->course->add_resource($event);
1087
        }
1088
    }
1089
1090
    /**
1091
     * Build the course-descriptions