Example #1
0
/**
 * Used to delete a link or a category
 * @author Patrick Cool <*****@*****.**>, Ghent University
 * @param int $id
 * @param string    $type   The type of item to delete
 * @return bool
 */
function deletelinkcategory($id, $type)
{
    $courseInfo = api_get_course_info();
    $tbl_link = Database::get_course_table(TABLE_LINK);
    $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
    $course_id = api_get_course_int_id();
    $id = intval($id);
    if (empty($id)) {
        return false;
    }
    $result = false;
    switch ($type) {
        case 'link':
            // -> Items are no longer physically deleted,
            // but the visibility is set to 2 (in item_property).
            // This will make a restore function possible for the platform administrator.
            $sql = "UPDATE {$tbl_link} SET on_homepage='0'\n                    WHERE c_id = {$course_id} AND id='" . $id . "'";
            Database::query($sql);
            api_item_property_update($courseInfo, TOOL_LINK, $id, 'delete', api_get_user_id());
            delete_link_from_search_engine(api_get_course_id(), $id);
            Display::display_confirmation_message(get_lang('LinkDeleted'));
            $result = true;
            break;
        case 'category':
            // First we delete the category itself and afterwards all the links of this category.
            $sql = "DELETE FROM " . $tbl_categories . "\n                    WHERE c_id = {$course_id} AND id='" . $id . "'";
            Database::query($sql);
            $sql = "DELETE FROM " . $tbl_link . "\n                    WHERE c_id = {$course_id} AND category_id='" . $id . "'";
            Database::query($sql);
            api_item_property_update($courseInfo, TOOL_LINK_CATEGORY, $id, 'delete', api_get_user_id());
            Display::display_confirmation_message(get_lang('CategoryDeleted'));
            $result = true;
            break;
    }
    return $result;
}
Example #2
0
/**
 * Used to delete a link or a category
 * @author Patrick Cool <*****@*****.**>, Ghent University
 */
function deletelinkcategory($id, $type)
{
    global $catlinkstatus;
    $_course = api_get_course_info();
    $course_id = api_get_course_int_id();
    $tbl_link = Database::get_course_table(TABLE_LINK);
    $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
    $id = intval($id);
    if ($type == 'link') {
        // -> Items are no longer fysically deleted, but the visibility is set to 2 (in item_property).
        // This will make a restore function possible for the platform administrator.
        $sql = "UPDATE {$tbl_link} SET on_homepage='0' WHERE c_id = {$course_id} AND id='" . $id . "'";
        Database::query($sql);
        api_item_property_update($_course, TOOL_LINK, $id, 'delete', api_get_user_id());
        delete_link_from_search_engine(api_get_course_id(), $id);
        $catlinkstatus = get_lang('LinkDeleted');
        Display::display_confirmation_message(get_lang('LinkDeleted'));
    }
    if ($type == 'category') {
        // First we delete the category itself and afterwards all the links of this category.
        $sql = "DELETE FROM " . $tbl_categories . " WHERE c_id = {$course_id} AND id='" . $id . "'";
        Database::query($sql);
        $sql = "DELETE FROM " . $tbl_link . " WHERE c_id = {$course_id} AND category_id='" . $id . "'";
        $catlinkstatus = get_lang('CategoryDeleted');
        Database::query($sql);
        Display::display_confirmation_message(get_lang('CategoryDeleted'));
    }
}