public function submit($song_id = null)
 {
     $this->require_login();
     if (!$song_id) {
         $this->content_view = "scores/submit";
         $this->data['songs'] = Ranked_file::get_all_charts();
         $this->data['packs'] = Pack::all(array('order' => 'name asc'));
     } else {
         if (Ranked_file::count(array('conditions' => array('id = ?', $song_id))) != 1) {
             redirect('scores/submit');
         } else {
             if ($_POST) {
                 $song = Ranked_file::find($song_id);
                 $this->data['song'] = $song;
                 $total_notes = $this->input->post('marvelous_count') + $this->input->post('perfect_count') + $this->input->post('great_count') + $this->input->post('good_count') + $this->input->post('boo_count') + $this->input->post('miss_count');
                 $total_holds = $this->input->post('ok_count');
                 if ($total_notes > $song->taps || $total_holds > $song->holds) {
                     $this->content_view = "scores/confirm";
                     $this->data['error_nc'] = true;
                 } elseif ($this->form_validation->run('submit_score') == FALSE) {
                     $this->content_view = "scores/confirm";
                     $this->data['error'] = true;
                 } else {
                     $attributes = array('user_id' => $this->session->userdata('user_id'), 'file_id' => $song_id, 'date_achieved' => $this->input->post('score_achieved'), 'marvelous_count' => $this->input->post('marvelous_count'), 'perfect_count' => $this->input->post('perfect_count'), 'great_count' => $this->input->post('great_count'), 'good_count' => $this->input->post('good_count'), 'boo_count' => $this->input->post('boo_count'), 'miss_count' => $this->input->post('miss_count'), 'ok_count' => $this->input->post('ok_count'), 'mines_hit' => $this->input->post('mines_hit'), 'screenshot_url' => $this->input->post('screenshot_url'));
                     $new_score = new User_score($attributes);
                     $new_score->save();
                     // Check if score is below AA
                     $max_dp_max = $song->dance_points;
                     $max_dp_achieved = $new_score->marvelous_count * 2 + $new_score->perfect_count * 2 + $new_score->great_count * 1 + $new_score->boo_count * -4 + $new_score->miss_count * -8 + $new_score->ok_count * 6 + $new_score->mines_hit * -8;
                     $max_dp_percent = $max_dp_achieved / $max_dp_max * 100;
                     if ($max_dp_percent < 93) {
                         $new_score->status = "below_aa";
                         $new_score->save();
                     }
                     // Check if score is in top 10% of all scores
                     $this->data['score_pending'] = false;
                     $percentile = User_score::get_top_10_percentile();
                     if ($song->difficulty_score > $percentile) {
                         $new_score->status = "pending";
                         $new_score->was_pending = 1;
                         $new_score->save();
                         $this->data['score_pending'] = true;
                     }
                     $this->content_view = "scores/success";
                 }
             } else {
                 $this->data['song'] = Ranked_file::find($song_id);
                 $this->content_view = "scores/confirm";
                 $this->data['error'] = false;
             }
         }
     }
 }
Exemplo n.º 2
0
 public static function get_recent_packs()
 {
     return Pack::all(array("select" => "`packs`.*, (SELECT COUNT(*) FROM `ranked_files` WHERE `ranked_files`.`pack_id` = `packs`.`id`) AS file_count, (SELECT AVG(difficulty_score) FROM `ranked_files` WHERE `ranked_files`.`pack_id` = `packs`.`id` AND `ranked_files`.`rate` = 1) as average", 'order' => '`packs`.id DESC', 'limit' => 10));
 }
Exemplo n.º 3
0
 function edit_chart($id)
 {
     $this->data['subtitle'] = "Edit Ranked Chart";
     $this->data['chart'] = Ranked_file::find($id);
     if (intval($this->input->post('step')) == 2) {
         if ($this->form_validation->run('rank_chart') == FALSE) {
             $this->data['packs'] = Pack::all(array('order' => 'name asc'));
             $this->data['error'] = true;
             $this->content_view = "mod/edit_chart";
         } else {
             // Validation good, save the file!
             $this->data['chart']->pack_id = $this->input->post('pack_id');
             $this->data['chart']->stamina_file = $this->input->post('stamina_file');
             $this->data['chart']->file_type = $this->input->post('file_type');
             $this->data['chart']->date_ranked = $this->input->post('date_ranked');
             $this->data['chart']->rate = $this->input->post('rate');
             $this->data['chart']->title = $this->input->post('title');
             $this->data['chart']->subtitle = $this->input->post('subtitle');
             $this->data['chart']->artist = $this->input->post('artist');
             $this->data['chart']->length = $this->input->post('length');
             $this->data['chart']->dance_points = $this->input->post('dance_points');
             $this->data['chart']->notes = $this->input->post('notes');
             $this->data['chart']->taps = $this->input->post('taps');
             $this->data['chart']->jumps = $this->input->post('jumps');
             $this->data['chart']->hands = $this->input->post('hands');
             $this->data['chart']->quads = $this->input->post('quads');
             $this->data['chart']->holds = $this->input->post('holds');
             $this->data['chart']->mines = $this->input->post('mines');
             $this->data['chart']->peak_nps = $this->input->post('peak_nps');
             $this->data['chart']->avg_nps = $this->input->post('avg_nps');
             $this->data['chart']->avg_weighted_nps = $this->input->post('avg_weighted_nps');
             $this->data['chart']->difficulty_score = $this->input->post('difficulty_score');
             $this->data['chart']->raw_file = $this->input->post('raw_file');
             $this->data['chart']->save();
             $rate = $this->input->post('rate');
             $log_string = $this->session->userdata('username') . " (" . $this->session->userdata('display_name') . ") edited ranked chart: " . $this->input->post('title') . " " . number_format($rate, 1) . "x " . " - " . $this->input->post('difficulty_score');
             write_to_mod_log($log_string);
             $this->data['rank_success'] = true;
             $this->content_view = "mod/edit_chart";
         }
     } else {
         $this->data['packs'] = Pack::all(array('order' => 'name asc'));
         $this->content_view = "mod/edit_chart";
     }
 }