| Total Complexity | 41 |
| Total Lines | 393 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like ContestController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ContestController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 18 | class ContestController extends Controller |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * Show the Contest Page. |
||
| 22 | * |
||
| 23 | * @return Response |
||
|
|
|||
| 24 | */ |
||
| 25 | public function index(Request $request) |
||
| 60 | ]); |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Show the Contest Detail Page. |
||
| 66 | * |
||
| 67 | * @return Response |
||
| 68 | */ |
||
| 69 | public function detail($cid) |
||
| 94 | ]); |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Redirect the Contest Board Page. |
||
| 99 | * |
||
| 100 | * @return Response |
||
| 101 | */ |
||
| 102 | public function board($cid) |
||
| 103 | { |
||
| 104 | return Redirect::route('contest.challenge', ['cid' => $cid]); |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Show the Contest Challenge Page. |
||
| 109 | * |
||
| 110 | * @return Response |
||
| 111 | */ |
||
| 112 | public function challenge($cid) |
||
| 113 | { |
||
| 114 | $contestModel=new ContestModel(); |
||
| 115 | $clearance=$contestModel->judgeClearance($cid, Auth::user()->id); |
||
| 116 | if (!$clearance) { |
||
| 117 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
| 118 | } |
||
| 119 | $contest_name=$contestModel->contestName($cid); |
||
| 120 | $contest_rule=$contestModel->contestRule($cid); |
||
| 121 | $problemSet=$contestModel->contestProblems($cid, Auth::user()->id); |
||
| 122 | $remainingTime=$contestModel->remainingTime($cid); |
||
| 123 | $customInfo=$contestModel->getCustomInfo($cid); |
||
| 124 | $clarificationList=$contestModel->getLatestClarification($cid); |
||
| 125 | $basicInfo=$contestModel->basic($cid); |
||
| 126 | if ($remainingTime<=0) { |
||
| 127 | $remainingTime=0; |
||
| 128 | } |
||
| 129 | return view('contest.board.challenge', [ |
||
| 130 | 'page_title'=>"Challenge", |
||
| 131 | 'navigation' => "Contest", |
||
| 132 | 'site_title'=>$contest_name, |
||
| 133 | 'cid'=>$cid, |
||
| 134 | 'contest_name'=>$contest_name, |
||
| 135 | 'contest_rule'=>$contest_rule, |
||
| 136 | 'problem_set'=> $problemSet, |
||
| 137 | 'remaining_time'=>$remainingTime, |
||
| 138 | 'custom_info' => $customInfo, |
||
| 139 | 'clarification_list' => $clarificationList, |
||
| 140 | 'clearance'=> $clearance, |
||
| 141 | 'basic'=>$basicInfo, |
||
| 142 | ]); |
||
| 143 | } |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Show the Contest Editor Page. |
||
| 147 | * |
||
| 148 | * @return Response |
||
| 149 | */ |
||
| 150 | public function editor($cid, $ncode) |
||
| 151 | { |
||
| 152 | $contestModel=new ContestModel(); |
||
| 153 | $problemModel=new ProblemModel(); |
||
| 154 | $compilerModel=new CompilerModel(); |
||
| 155 | $submissionModel=new SubmissionModel(); |
||
| 156 | $accountModel=new AccountModel(); |
||
| 157 | $clearance=$contestModel->judgeClearance($cid, Auth::user()->id); |
||
| 158 | if (!$clearance) { |
||
| 159 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
| 160 | } |
||
| 161 | $contest_name=$contestModel->contestName($cid); |
||
| 162 | $contest_rule=$contestModel->rule($cid); |
||
| 163 | $contest_ended=$contestModel->isContestEnded($cid); |
||
| 164 | $pid=$contestModel->getPid($cid, $ncode); |
||
| 165 | if (empty($pid)) { |
||
| 166 | return Redirect::route('contest.board', ['cid' => $cid]); |
||
| 167 | } |
||
| 168 | $pcode=$problemModel->pcode($pid); |
||
| 169 | |||
| 170 | $prob_detail=$problemModel->detail($pcode, $cid); |
||
| 171 | if ($problemModel->isBlocked($prob_detail["pid"], $cid)) { |
||
| 172 | return abort('403'); |
||
| 173 | } |
||
| 174 | $compiler_list=$compilerModel->list($prob_detail["OJ"], $prob_detail["pid"]); |
||
| 175 | $prob_status=$submissionModel->getProblemStatus($prob_detail["pid"], Auth::user()->id, $cid); |
||
| 176 | $problemSet=$contestModel->contestProblems($cid, Auth::user()->id); |
||
| 177 | $compiler_pref=$compilerModel->pref($compiler_list, $prob_detail["pid"], Auth::user()->id, $cid); |
||
| 178 | $pref=$compiler_pref["pref"]; |
||
| 179 | $submit_code=$compiler_pref["code"]; |
||
| 180 | $oj_detail=$problemModel->ojdetail($prob_detail["OJ"]); |
||
| 181 | |||
| 182 | if (empty($prob_status)) { |
||
| 183 | $prob_status=[ |
||
| 184 | "verdict"=>"NOT SUBMIT", |
||
| 185 | "color"=>"" |
||
| 186 | ]; |
||
| 187 | } |
||
| 188 | |||
| 189 | $editor_left_width = $accountModel->getExtra(Auth::user()->id, 'editor_left_width'); |
||
| 190 | if(empty($editor_left_width)) $editor_left_width='40'; |
||
| 191 | |||
| 192 | return view('contest.board.editor', [ |
||
| 193 | 'page_title'=>"Problem Detail", |
||
| 194 | 'navigation' => "Contest", |
||
| 195 | 'site_title'=>$contest_name, |
||
| 196 | 'contest_name'=>$contest_name, |
||
| 197 | 'cid'=> $cid, |
||
| 198 | 'detail' => $prob_detail, |
||
| 199 | 'compiler_list' => $compiler_list, |
||
| 200 | 'status' => $prob_status, |
||
| 201 | 'pref' => $pref<0 ? 0 : $pref, |
||
| 202 | 'submit_code' => $submit_code, |
||
| 203 | 'contest_mode' => true, |
||
| 204 | 'contest_ended' => $contest_ended, |
||
| 205 | 'ncode' => $ncode, |
||
| 206 | 'contest_rule' => $contest_rule, |
||
| 207 | 'problem_set' => $problemSet, |
||
| 208 | 'clearance' => $clearance, |
||
| 209 | 'oj_detail' => $oj_detail, |
||
| 210 | 'editor_left_width'=>$editor_left_width, |
||
| 211 | ]); |
||
| 212 | } |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Show the Contest Rank Page. |
||
| 216 | * |
||
| 217 | * @return Response |
||
| 218 | */ |
||
| 219 | public function rank($cid) |
||
| 248 | ]); |
||
| 249 | } |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Show the Contest Status Page. |
||
| 253 | * |
||
| 254 | * @return Response |
||
| 255 | */ |
||
| 256 | public function status($cid) |
||
| 281 | ]); |
||
| 282 | } |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Show the Contest Clarification Page. |
||
| 286 | * |
||
| 287 | * @return Response |
||
| 288 | */ |
||
| 289 | public function clarification($cid) |
||
| 290 | { |
||
| 291 | $contestModel=new ContestModel(); |
||
| 292 | $clearance=$contestModel->judgeClearance($cid, Auth::user()->id); |
||
| 293 | if (!$clearance) { |
||
| 294 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
| 295 | } |
||
| 296 | $basicInfo=$contestModel->basic($cid); |
||
| 297 | $contest_name=$contestModel->contestName($cid); |
||
| 298 | $customInfo=$contestModel->getCustomInfo($cid); |
||
| 299 | $clarificationList=$contestModel->getClarificationList($cid); |
||
| 300 | $contest_ended=$contestModel->isContestEnded($cid); |
||
| 301 | return view('contest.board.clarification', [ |
||
| 302 | 'page_title'=>"Clarification", |
||
| 303 | 'navigation' => "Contest", |
||
| 304 | 'site_title'=>$contest_name, |
||
| 305 | 'contest_name'=>$contest_name, |
||
| 306 | 'cid'=>$cid, |
||
| 307 | 'custom_info' => $customInfo, |
||
| 308 | 'clarification_list' => $clarificationList, |
||
| 309 | 'contest_ended' => $contest_ended, |
||
| 310 | 'clearance'=> $clearance, |
||
| 311 | 'basic'=>$basicInfo, |
||
| 312 | ]); |
||
| 313 | } |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Show the Contest Print Page. |
||
| 317 | * |
||
| 318 | * @return Response |
||
| 319 | */ |
||
| 320 | public function print($cid) |
||
| 321 | { |
||
| 322 | $contestModel=new ContestModel(); |
||
| 323 | $clearance=$contestModel->judgeClearance($cid, Auth::user()->id); |
||
| 324 | if (!$clearance) { |
||
| 325 | return Redirect::route('contest.detail', ['cid' => $cid]); |
||
| 326 | } |
||
| 327 | $basicInfo=$contestModel->basic($cid); |
||
| 328 | $contest_name=$contestModel->contestName($cid); |
||
| 329 | $customInfo=$contestModel->getCustomInfo($cid); |
||
| 330 | return view('contest.board.print', [ |
||
| 331 | 'page_title'=>"Print", |
||
| 332 | 'navigation' => "Contest", |
||
| 333 | 'site_title'=>$contest_name, |
||
| 334 | 'contest_name'=>$contest_name, |
||
| 335 | 'cid'=>$cid, |
||
| 336 | 'custom_info' => $customInfo, |
||
| 337 | 'clearance'=> $clearance, |
||
| 338 | 'basic'=>$basicInfo, |
||
| 339 | ]); |
||
| 340 | } |
||
| 341 | |||
| 342 | /** |
||
| 343 | * Show the Contest Admin Page. |
||
| 344 | * |
||
| 345 | * @return Response |
||
| 346 | */ |
||
| 347 | public function admin($cid) |
||
| 373 | ]); |
||
| 374 | } |
||
| 375 | |||
| 376 | public function downloadContestAccountXlsx($cid) |
||
| 377 | { |
||
| 378 | $contestModel=new ContestModel(); |
||
| 379 | $clearance=$contestModel->judgeClearance($cid, Auth::user()->id); |
||
| 380 | if ($clearance <= 2) { |
||
| 381 | return Redirect::route('contest_detail', ['cid' => $cid]); |
||
| 382 | } |
||
| 383 | $account=$contestModel->getContestAccount($cid); |
||
| 384 | if($account==null){ |
||
| 385 | return ; |
||
| 386 | }else{ |
||
| 387 | $AccountExport=new AccountExport($account); |
||
| 388 | $filename="ContestAccount$cid"; |
||
| 389 | return Excel::download($AccountExport, $filename.'.xlsx'); |
||
| 390 | } |
||
| 391 | } |
||
| 392 | |||
| 393 | public function analysis($cid){ |
||
| 411 | ]); |
||
| 412 | } |
||
| 413 | } |
||
| 414 |