/** * This function deletes a survey (and also all the question in that survey * * @param int $survey_id id of the survey that has to be deleted * @return true * * @author Patrick Cool <*****@*****.**>, Ghent University * @version January 2007 */ public static function delete_survey($survey_id, $shared = false, $course_id = '') { // Database table definitions if (empty($course_id)) { $course_id = api_get_course_int_id(); } $survey_id = intval($survey_id); if (empty($survey_id)) { return false; } $em = Database::getManager(); $course_info = api_get_course_info_by_id($course_id); $course_id = $course_info['real_id']; $table_survey = Database::get_course_table(TABLE_SURVEY); $table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP); if ($shared) { // Deleting the survey $sharedSurvey = $em->find('ChamiloCoreBundle:SharedSurvey', $survey_id); if ($sharedSurvey) { $em->remove($sharedSurvey); $em->flush(); } } else { $sql = "DELETE FROM {$table_survey}\n WHERE c_id = {$course_id} AND survey_id='" . $survey_id . "'"; Database::query($sql); } // Deleting groups of this survey $sql = "DELETE FROM {$table_survey_question_group}\n WHERE c_id = {$course_id} AND survey_id='" . $survey_id . "'"; Database::query($sql); // Deleting the questions of the survey SurveyManager::delete_all_survey_questions($survey_id, $shared); // Update into item_property (delete) api_item_property_update($course_info, TOOL_SURVEY, $survey_id, 'SurveyDeleted', api_get_user_id()); return true; }