@@ -9,15 +9,15 @@ discard block |
||
| 9 | 9 | class ProblemModel extends Model |
| 10 | 10 | { |
| 11 | 11 | protected $table='problem'; |
| 12 | - protected $primaryKey = 'pid'; |
|
| 13 | - const UPDATED_AT = "update_date"; |
|
| 12 | + protected $primaryKey='pid'; |
|
| 13 | + const UPDATED_AT="update_date"; |
|
| 14 | 14 | |
| 15 | 15 | public function detail($pcode, $cid=null) |
| 16 | 16 | { |
| 17 | 17 | $prob_detail=DB::table($this->table)->where("pcode", $pcode)->first(); |
| 18 | 18 | // [Depreciated] Joint Query was depreciated here for code maintenance reasons |
| 19 | 19 | if (!is_null($prob_detail)) { |
| 20 | - if($prob_detail["force_raw"]) { |
|
| 20 | + if ($prob_detail["force_raw"]) { |
|
| 21 | 21 | $prob_detail["parsed"]=[ |
| 22 | 22 | "description"=>$prob_detail["description"], |
| 23 | 23 | "input"=>$prob_detail["input"], |
@@ -95,10 +95,10 @@ discard block |
||
| 95 | 95 | return DB::table("oj")->where('oid', $oid)->first(); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - public function solutionList($pid,$uid=null) |
|
| 98 | + public function solutionList($pid, $uid=null) |
|
| 99 | 99 | { |
| 100 | - if(is_null($uid)) { |
|
| 101 | - $details=DB::table("problem_solution")->join("users","id","=","problem_solution.uid")->where(['problem_solution.pid'=>$pid,'problem_solution.audit'=>1])->first(); |
|
| 100 | + if (is_null($uid)) { |
|
| 101 | + $details=DB::table("problem_solution")->join("users", "id", "=", "problem_solution.uid")->where(['problem_solution.pid'=>$pid, 'problem_solution.audit'=>1])->first(); |
|
| 102 | 102 | } else { |
| 103 | 103 | $details=DB::table("problem_solution")->join( |
| 104 | 104 | "users", |
@@ -128,22 +128,22 @@ discard block |
||
| 128 | 128 | "type" |
| 129 | 129 | ])->get()->all(); |
| 130 | 130 | } |
| 131 | - foreach($details as &$d){ |
|
| 131 | + foreach ($details as &$d) { |
|
| 132 | 132 | $d["content_parsed"]=clean(Markdown::convertToHtml($d["content"])); |
| 133 | 133 | } |
| 134 | 134 | return $details; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - public function solution($pid,$uid) |
|
| 137 | + public function solution($pid, $uid) |
|
| 138 | 138 | { |
| 139 | - $details=DB::table("problem_solution")->join("users","id","=","uid")->where(['pid'=>$pid,'uid'=>$uid])->first(); |
|
| 139 | + $details=DB::table("problem_solution")->join("users", "id", "=", "uid")->where(['pid'=>$pid, 'uid'=>$uid])->first(); |
|
| 140 | 140 | return $details; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - public function addSolution($pid,$uid,$content) |
|
| 143 | + public function addSolution($pid, $uid, $content) |
|
| 144 | 144 | { |
| 145 | - $details=DB::table("problem_solution")->where(['pid'=>$pid,'uid'=>$uid])->first(); |
|
| 146 | - if(empty($details)){ |
|
| 145 | + $details=DB::table("problem_solution")->where(['pid'=>$pid, 'uid'=>$uid])->first(); |
|
| 146 | + if (empty($details)) { |
|
| 147 | 147 | DB::table("problem_solution")->insert([ |
| 148 | 148 | "uid"=>$uid, |
| 149 | 149 | "pid"=>$pid, |
@@ -157,26 +157,26 @@ discard block |
||
| 157 | 157 | return false; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - public function voteSolution($psoid,$uid,$type) |
|
| 160 | + public function voteSolution($psoid, $uid, $type) |
|
| 161 | 161 | { |
| 162 | - $val=$type?1:-1; |
|
| 162 | + $val=$type ? 1 : -1; |
|
| 163 | 163 | $details=DB::table("problem_solution")->where(['psoid'=>$psoid])->first(); |
| 164 | - if(empty($details)) return ["ret"=>false]; |
|
| 164 | + if (empty($details)) return ["ret"=>false]; |
|
| 165 | 165 | |
| 166 | - $userVote=DB::table("problem_solution_vote")->where(['uid'=>$uid,"psoid"=>$psoid])->first(); |
|
| 166 | + $userVote=DB::table("problem_solution_vote")->where(['uid'=>$uid, "psoid"=>$psoid])->first(); |
|
| 167 | 167 | |
| 168 | - if(!empty($userVote)){ |
|
| 169 | - DB::table("problem_solution_vote")->where(['uid'=>$uid,"psoid"=>$psoid])->delete(); |
|
| 170 | - if($userVote["type"]==$type){ |
|
| 168 | + if (!empty($userVote)) { |
|
| 169 | + DB::table("problem_solution_vote")->where(['uid'=>$uid, "psoid"=>$psoid])->delete(); |
|
| 170 | + if ($userVote["type"]==$type) { |
|
| 171 | 171 | DB::table("problem_solution")->where([ |
| 172 | 172 | 'psoid'=>$psoid |
| 173 | 173 | ])->update([ |
| 174 | - "votes"=>$details["votes"]+($userVote["type"]==1?-1:1), |
|
| 174 | + "votes"=>$details["votes"]+($userVote["type"]==1 ?-1 : 1), |
|
| 175 | 175 | ]); |
| 176 | - return ["ret"=>true,"votes"=>$details["votes"]+($userVote["type"]==1?-1:1),"select"=>-1]; //disvote |
|
| 177 | - }elseif($userVote["type"]==1){ |
|
| 176 | + return ["ret"=>true, "votes"=>$details["votes"]+($userVote["type"]==1 ?-1 : 1), "select"=>-1]; //disvote |
|
| 177 | + }elseif ($userVote["type"]==1) { |
|
| 178 | 178 | $val--; |
| 179 | - }else{ |
|
| 179 | + } else { |
|
| 180 | 180 | $val++; |
| 181 | 181 | } |
| 182 | 182 | } |
@@ -193,20 +193,20 @@ discard block |
||
| 193 | 193 | "type"=>$type, |
| 194 | 194 | ]); |
| 195 | 195 | |
| 196 | - return ["ret"=>true,"votes"=>$details["votes"]+$val,"select"=>$type]; |
|
| 196 | + return ["ret"=>true, "votes"=>$details["votes"]+$val, "select"=>$type]; |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - public function removeSolution($psoid,$uid) |
|
| 199 | + public function removeSolution($psoid, $uid) |
|
| 200 | 200 | { |
| 201 | - if(empty(DB::table("problem_solution")->where(['psoid'=>$psoid,'uid'=>$uid])->first())) return false; |
|
| 202 | - DB::table("problem_solution")->where(['psoid'=>$psoid,'uid'=>$uid])->delete(); |
|
| 201 | + if (empty(DB::table("problem_solution")->where(['psoid'=>$psoid, 'uid'=>$uid])->first())) return false; |
|
| 202 | + DB::table("problem_solution")->where(['psoid'=>$psoid, 'uid'=>$uid])->delete(); |
|
| 203 | 203 | return true; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - public function updateSolution($psoid,$uid,$content) |
|
| 206 | + public function updateSolution($psoid, $uid, $content) |
|
| 207 | 207 | { |
| 208 | - if(empty(DB::table("problem_solution")->where(['psoid'=>$psoid,'uid'=>$uid])->first())) return false; |
|
| 209 | - DB::table("problem_solution")->where(['psoid'=>$psoid,'uid'=>$uid])->update([ |
|
| 208 | + if (empty(DB::table("problem_solution")->where(['psoid'=>$psoid, 'uid'=>$uid])->first())) return false; |
|
| 209 | + DB::table("problem_solution")->where(['psoid'=>$psoid, 'uid'=>$uid])->update([ |
|
| 210 | 210 | "content"=>$content, |
| 211 | 211 | "audit"=>0, |
| 212 | 212 | "updated_at"=>date("Y-m-d H:i:s"), |
@@ -161,7 +161,9 @@ discard block |
||
| 161 | 161 | { |
| 162 | 162 | $val=$type?1:-1; |
| 163 | 163 | $details=DB::table("problem_solution")->where(['psoid'=>$psoid])->first(); |
| 164 | - if(empty($details)) return ["ret"=>false]; |
|
| 164 | + if(empty($details)) { |
|
| 165 | + return ["ret"=>false]; |
|
| 166 | + } |
|
| 165 | 167 | |
| 166 | 168 | $userVote=DB::table("problem_solution_vote")->where(['uid'=>$uid,"psoid"=>$psoid])->first(); |
| 167 | 169 | |
@@ -174,9 +176,9 @@ discard block |
||
| 174 | 176 | "votes"=>$details["votes"]+($userVote["type"]==1?-1:1), |
| 175 | 177 | ]); |
| 176 | 178 | return ["ret"=>true,"votes"=>$details["votes"]+($userVote["type"]==1?-1:1),"select"=>-1]; //disvote |
| 177 | - }elseif($userVote["type"]==1){ |
|
| 179 | + } elseif($userVote["type"]==1){ |
|
| 178 | 180 | $val--; |
| 179 | - }else{ |
|
| 181 | + } else{ |
|
| 180 | 182 | $val++; |
| 181 | 183 | } |
| 182 | 184 | } |
@@ -198,14 +200,18 @@ discard block |
||
| 198 | 200 | |
| 199 | 201 | public function removeSolution($psoid,$uid) |
| 200 | 202 | { |
| 201 | - if(empty(DB::table("problem_solution")->where(['psoid'=>$psoid,'uid'=>$uid])->first())) return false; |
|
| 203 | + if(empty(DB::table("problem_solution")->where(['psoid'=>$psoid,'uid'=>$uid])->first())) { |
|
| 204 | + return false; |
|
| 205 | + } |
|
| 202 | 206 | DB::table("problem_solution")->where(['psoid'=>$psoid,'uid'=>$uid])->delete(); |
| 203 | 207 | return true; |
| 204 | 208 | } |
| 205 | 209 | |
| 206 | 210 | public function updateSolution($psoid,$uid,$content) |
| 207 | 211 | { |
| 208 | - if(empty(DB::table("problem_solution")->where(['psoid'=>$psoid,'uid'=>$uid])->first())) return false; |
|
| 212 | + if(empty(DB::table("problem_solution")->where(['psoid'=>$psoid,'uid'=>$uid])->first())) { |
|
| 213 | + return false; |
|
| 214 | + } |
|
| 209 | 215 | DB::table("problem_solution")->where(['psoid'=>$psoid,'uid'=>$uid])->update([ |
| 210 | 216 | "content"=>$content, |
| 211 | 217 | "audit"=>0, |
@@ -111,8 +111,8 @@ discard block |
||
| 111 | 111 | if (empty($basic)) { |
| 112 | 112 | return ResponseModel::err(3001); |
| 113 | 113 | } |
| 114 | - $ret=$problemModel->addSolution($pid,Auth::user()->id,$content); |
|
| 115 | - return $ret?ResponseModel::success(200):ResponseModel::err(3003); |
|
| 114 | + $ret=$problemModel->addSolution($pid, Auth::user()->id, $content); |
|
| 115 | + return $ret ?ResponseModel::success(200) : ResponseModel::err(3003); |
|
| 116 | 116 | } |
| 117 | 117 | /** |
| 118 | 118 | * The Ajax Problem Solution Discussion Update. |
@@ -127,8 +127,8 @@ discard block |
||
| 127 | 127 | $problemModel=new ProblemModel(); |
| 128 | 128 | $psoid=$all_data["psoid"]; |
| 129 | 129 | $content=$all_data["content"]; |
| 130 | - $ret=$problemModel->updateSolution($psoid,Auth::user()->id,$content); |
|
| 131 | - return $ret?ResponseModel::success(200):ResponseModel::err(3004); |
|
| 130 | + $ret=$problemModel->updateSolution($psoid, Auth::user()->id, $content); |
|
| 131 | + return $ret ?ResponseModel::success(200) : ResponseModel::err(3004); |
|
| 132 | 132 | } |
| 133 | 133 | /** |
| 134 | 134 | * The Ajax Problem Solution Discussion Delete. |
@@ -142,8 +142,8 @@ discard block |
||
| 142 | 142 | $all_data=$request->all(); |
| 143 | 143 | $problemModel=new ProblemModel(); |
| 144 | 144 | $psoid=$all_data["psoid"]; |
| 145 | - $ret=$problemModel->removeSolution($psoid,Auth::user()->id); |
|
| 146 | - return $ret?ResponseModel::success(200):ResponseModel::err(3004); |
|
| 145 | + $ret=$problemModel->removeSolution($psoid, Auth::user()->id); |
|
| 146 | + return $ret ?ResponseModel::success(200) : ResponseModel::err(3004); |
|
| 147 | 147 | } |
| 148 | 148 | /** |
| 149 | 149 | * The Ajax Problem Solution Discussion Vote. |
@@ -158,8 +158,8 @@ discard block |
||
| 158 | 158 | $problemModel=new ProblemModel(); |
| 159 | 159 | $psoid=$all_data["psoid"]; |
| 160 | 160 | $type=$all_data["type"]; |
| 161 | - $ret=$problemModel->voteSolution($psoid,Auth::user()->id,$type); |
|
| 162 | - return $ret["ret"]?ResponseModel::success(200,null,["votes"=>$ret["votes"],"select"=>$ret["select"]]):ResponseModel::err(3004); |
|
| 161 | + $ret=$problemModel->voteSolution($psoid, Auth::user()->id, $type); |
|
| 162 | + return $ret["ret"] ?ResponseModel::success(200, null, ["votes"=>$ret["votes"], "select"=>$ret["select"]]) : ResponseModel::err(3004); |
|
| 163 | 163 | } |
| 164 | 164 | /** |
| 165 | 165 | * The Ajax Problem Solution Submit. |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | |
| 254 | 254 | $all_data=$request->all(); |
| 255 | 255 | |
| 256 | - $crawler = new Crawler($all_data["name"], $all_data["action"], $all_data["con"], $all_data["cached"]); |
|
| 256 | + $crawler=new Crawler($all_data["name"], $all_data["action"], $all_data["con"], $all_data["cached"]); |
|
| 257 | 257 | |
| 258 | 258 | return ResponseModel::success(200, null, $crawler->data); |
| 259 | 259 | } |
@@ -86,8 +86,8 @@ |
||
| 86 | 86 | if ($problem->isBlocked($prob_detail["pid"])) { |
| 87 | 87 | return abort('403'); |
| 88 | 88 | } |
| 89 | - $solution=$problem->solutionList($prob_detail["pid"],Auth::check()?Auth::user()->id:null); |
|
| 90 | - $submitted=Auth::check()?$problem->solution($prob_detail["pid"],Auth::user()->id):[]; |
|
| 89 | + $solution=$problem->solutionList($prob_detail["pid"], Auth::check() ?Auth::user()->id : null); |
|
| 90 | + $submitted=Auth::check() ? $problem->solution($prob_detail["pid"], Auth::user()->id) : []; |
|
| 91 | 91 | return is_null($prob_detail) ? redirect("/problem") : view('problem.solution', [ |
| 92 | 92 | 'page_title'=> "Solution", |
| 93 | 93 | 'site_title'=>"NOJ", |