Exemplo n.º 1
0
 function save_results($quiz_id, $result_arr)
 {
     if (!$quiz_id) {
         return false;
     }
     $result_ids = array();
     $new_uploads = new se_upload();
     foreach ($result_arr as $result) {
         $result_id = $result['id'];
         if ($result_id) {
             he_quiz::update_result($result_id, $result['title'], $result['description']);
         } else {
             $result_id = he_quiz::create_result($quiz_id, $result['title'], $result['description']);
         }
         $photo = $result['filename'];
         if (isset($_FILES[$photo]['error']) && $_FILES[$photo]['error'] == 0) {
             $tmp_file = $_FILES[$photo];
             he_quiz::save_photo($result_id, $tmp_file, 'result', $photo, 200);
         }
         $result_ids[] = $result_id;
     }
     //delete removed results
     $result_str = implode(', ', $result_ids);
     $query = he_database::placeholder("SELECT `id` FROM `se_he_quiz_result`\r\n            WHERE `quiz_id`=? AND `id` NOT IN({$result_str}) ORDER BY `id`", $quiz_id);
     $removed_ids = he_database::fetch_column($query);
     he_quiz::delete_results($removed_ids);
 }