Пример #1
0
 /**
  * This function deletes a survey (and also all the question in that survey
  *
  * @param $survey_id the 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;
     }
     $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) {
         $table_survey = Database::get_main_table(TABLE_MAIN_SHARED_SURVEY);
         // Deleting the survey
         $sql = "DELETE FROM {$table_survey} WHERE survey_id='" . $survey_id . "'";
         Database::query($sql);
     } else {
         $sql = "DELETE FROM {$table_survey} 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} WHERE c_id = {$course_id} AND survey_id='" . $survey_id . "'";
     Database::query($sql);
     // Deleting the questions of the survey
     survey_manager::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;
 }