Code Duplication    Length = 6-21 lines in 3 locations

main/lp/learnpath.class.php 1 location

@@ 872-886 (lines=15) @@
869
870
                $id = Database::insert($tbl_lp, $params);
871
872
                if ($id > 0) {
873
                    $sql = "UPDATE $tbl_lp SET id = iid WHERE iid = $id";
874
                    Database::query($sql);
875
876
                    // Insert into item_property.
877
                    api_item_property_update(
878
                        $courseInfo,
879
                        TOOL_LEARNPATH,
880
                        $id,
881
                        'LearnpathAdded',
882
                        $userId
883
                    );
884
                    api_set_default_visibility($id, TOOL_LEARNPATH, 0, $courseInfo, $session_id, $userId);
885
                    return $id;
886
                }
887
                break;
888
        }
889
    }

main/forum/forumfunction.inc.php 2 locations

@@ 766-786 (lines=21) @@
763
        ];
764
765
        $last_id = Database::insert($table_forums, $params);
766
        if ($last_id > 0) {
767
            $sql = "UPDATE $table_forums SET forum_id = iid WHERE iid = $last_id";
768
            Database::query($sql);
769
770
            api_item_property_update(
771
                $courseInfo,
772
                TOOL_FORUM,
773
                $last_id,
774
                'ForumAdded',
775
                api_get_user_id(),
776
                $group_id
777
            );
778
779
            api_set_default_visibility(
780
                $last_id,
781
                TOOL_FORUM,
782
                $group_id,
783
                $courseInfo
784
            );
785
        }
786
        $return_message = get_lang('ForumAdded');
787
        if ($returnId) {
788
            return $last_id;
789
        }
@@ 4923-4928 (lines=6) @@
4920
            $safe_post_id = (int) $post_id;
4921
            $safe_id_attach = (int) $id_attach;
4922
            // Storing the attachments if any.
4923
            if ($result) {
4924
                $sql = "UPDATE $table_forum_attachment SET filename = '$safe_file_name', comment = '$safe_file_comment', path = '$safe_new_file_name', post_id = '$safe_post_id', size ='".$attachment['size']."'
4925
                       WHERE c_id = $course_id AND id = '$safe_id_attach'";
4926
                Database::query($sql);
4927
                api_item_property_update($_course, TOOL_FORUM_ATTACH, $safe_id_attach, 'ForumAttachmentUpdated', api_get_user_id());
4928
            }
4929
        }
4930
    }
4931
}