Passed
Pull Request — master (#414)
by John
12:18
created
app/Models/Eloquent/Message.php 1 patch
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -17,78 +17,78 @@  discard block
 block discarded – undo
17 17
      */
18 18
     public static function send($config)
19 19
     {
20
-        if(!empty($config['type'])){
21
-            if($config['type'] == 1) { //to a leader that member apply to join the group
22
-                $messages = Message::where([
20
+        if (!empty($config['type'])) {
21
+            if ($config['type']==1) { //to a leader that member apply to join the group
22
+                $messages=Message::where([
23 23
                     'receiver' => $config['receiver'],
24 24
                     'type'     => $config['type'],
25 25
                     'unread'   => 1
26 26
                 ])->get();
27
-                if(!empty($messages)) {
28
-                    foreach($messages as $message) {
29
-                        $data = json_decode($message->data,true);
30
-                        if($data['group']['gcode'] == $config['data']['group']['gcode']) {
31
-                            array_push($data['user'],$config['data']['user'][0]);
32
-                            $message->data = json_encode($data);
27
+                if (!empty($messages)) {
28
+                    foreach ($messages as $message) {
29
+                        $data=json_decode($message->data, true);
30
+                        if ($data['group']['gcode']==$config['data']['group']['gcode']) {
31
+                            array_push($data['user'], $config['data']['user'][0]);
32
+                            $message->data=json_encode($data);
33 33
                             $message->save();
34 34
                             return true;
35 35
                         }
36 36
                     }
37 37
                 }
38
-            }elseif ($config['type'] == 2) { //to a leader that member agree to join the group
39
-                $messages = Message::where([
38
+            }elseif ($config['type']==2) { //to a leader that member agree to join the group
39
+                $messages=Message::where([
40 40
                     'receiver' => $config['receiver'],
41 41
                     'type'     => $config['type'],
42 42
                     'unread'   => 1
43 43
                 ])->get();
44
-                if(!empty($messages)) {
45
-                    foreach($messages as $message) {
46
-                        $data = json_decode($message->data,true);
47
-                        if($data['group'] == $config['data']['group']) {
48
-                            array_push($data['user'],$config['data']['user'][0]);
49
-                            $message->data = json_encode($data);
44
+                if (!empty($messages)) {
45
+                    foreach ($messages as $message) {
46
+                        $data=json_decode($message->data, true);
47
+                        if ($data['group']==$config['data']['group']) {
48
+                            array_push($data['user'], $config['data']['user'][0]);
49
+                            $message->data=json_encode($data);
50 50
                             $message->save();
51 51
                             return true;
52 52
                         }
53 53
                     }
54 54
                 }
55
-            }elseif ($config['type'] == 3) { //to a person that solution was passed
56
-                $message = Message::where([
55
+            }elseif ($config['type']==3) { //to a person that solution was passed
56
+                $message=Message::where([
57 57
                     'receiver' => $config['receiver'],
58 58
                     'type'     => $config['type'],
59 59
                     'unread'   => 1
60 60
                 ])->first();
61
-                if(!empty($message)) {
62
-                    $data = json_decode($message->data,true);
63
-                    array_push($data,$config['data']);
64
-                    $message->data = json_encode($data);
61
+                if (!empty($message)) {
62
+                    $data=json_decode($message->data, true);
63
+                    array_push($data, $config['data']);
64
+                    $message->data=json_encode($data);
65 65
                     $message->save();
66 66
                     return true;
67 67
                 }
68
-            }elseif ($config['type'] == 4) { //to a person that solution was blocked
69
-                $message = Message::where([
68
+            }elseif ($config['type']==4) { //to a person that solution was blocked
69
+                $message=Message::where([
70 70
                     'receiver' => $config['receiver'],
71 71
                     'type'     => $config['type'],
72 72
                     'unread'   => 1
73 73
                 ])->first();
74
-                if(!empty($message)) {
75
-                    $data = json_decode($message->data,true);
76
-                    array_push($data,$config['data']);
77
-                    $message->data = json_encode($data);
74
+                if (!empty($message)) {
75
+                    $data=json_decode($message->data, true);
76
+                    array_push($data, $config['data']);
77
+                    $message->data=json_encode($data);
78 78
                     $message->save();
79 79
                     return true;
80 80
                 }
81 81
             }
82 82
         }
83
-        $message = new Message;
84
-        $message->sender = $config['sender'];
85
-        $message->receiver = $config['receiver'];
86
-        $message->title = $config['title'];
87
-        if(isset($config['data']) && isset($config['type'])){
88
-            $message->type = $config['type'] ?? null;
89
-            $message->data = json_encode($config['data']);
90
-        }else{
91
-            $message->content = $config['content'];
83
+        $message=new Message;
84
+        $message->sender=$config['sender'];
85
+        $message->receiver=$config['receiver'];
86
+        $message->title=$config['title'];
87
+        if (isset($config['data']) && isset($config['type'])) {
88
+            $message->type=$config['type'] ?? null;
89
+            $message->data=json_encode($config['data']);
90
+        } else {
91
+            $message->content=$config['content'];
92 92
         }
93 93
         /*
94 94
         if(isset($config['reply'])){
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
             $message->reply = $config['allow_reply'];
99 99
         }
100 100
         */
101
-        $message->official = 1;
101
+        $message->official=1;
102 102
         $message->save();
103 103
         return true;
104 104
     }
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
     {
133 133
 
134 134
         return static::with('sender_user')
135
-            ->where('receiver',$uid)
136
-            ->orderBy('unread','desc')
137
-            ->orderBy('updated_at','desc')
135
+            ->where('receiver', $uid)
136
+            ->orderBy('unread', 'desc')
137
+            ->orderBy('updated_at', 'desc')
138 138
             ->paginate(15);
139 139
     }
140 140
 
@@ -147,9 +147,9 @@  discard block
 block discarded – undo
147 147
      */
148 148
     public static function read($mid)
149 149
     {
150
-        $message = static::with('sender_user')->find($mid);
151
-        if(!empty($message)){
152
-            $message->unread = 0;
150
+        $message=static::with('sender_user')->find($mid);
151
+        if (!empty($message)) {
152
+            $message->unread=0;
153 153
             $message->save();
154 154
         }
155 155
         return $message;
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
      */
165 165
     public static function allRead($uid)
166 166
     {
167
-        return static::where('receiver',$uid)
167
+        return static::where('receiver', $uid)
168 168
             ->update(['unread' => 0]);
169 169
     }
170 170
 
@@ -192,20 +192,20 @@  discard block
 block discarded – undo
192 192
      */
193 193
     public static function remove($messages)
194 194
     {
195
-        $del_count = 0;
196
-        if(is_array($messages)){
195
+        $del_count=0;
196
+        if (is_array($messages)) {
197 197
             foreach ($messages as $mid) {
198
-                $message = static::find($mid);
199
-                if(!empty($message)){
198
+                $message=static::find($mid);
199
+                if (!empty($message)) {
200 200
                     $message->delete();
201
-                    $del_count ++;
201
+                    $del_count++;
202 202
                 }
203 203
             }
204
-        }else{
205
-            $message = static::find($messages);
206
-            if(!empty($message)){
204
+        } else {
205
+            $message=static::find($messages);
206
+            if (!empty($message)) {
207 207
                 $message->delete();
208
-                $del_count ++;
208
+                $del_count++;
209 209
             }
210 210
         }
211 211
         return $del_count;
@@ -213,36 +213,36 @@  discard block
 block discarded – undo
213 213
 
214 214
     public function getContentAttribute($value)
215 215
     {
216
-        if(!empty($this->type)){
217
-            $data = json_decode($this->data,true);
218
-            $content = '';
219
-            if($this->type == 1) {
220
-                foreach($data['user'] as $user) {
221
-                    $content .= "[{$user['name']}]({$user['url']}), ";
216
+        if (!empty($this->type)) {
217
+            $data=json_decode($this->data, true);
218
+            $content='';
219
+            if ($this->type==1) {
220
+                foreach ($data['user'] as $user) {
221
+                    $content.="[{$user['name']}]({$user['url']}), ";
222 222
                 }
223
-                $content = substr($content,0,strlen($content)-2);
224
-                $content .= " want to join your group [{$data['group']['name']}]({$data['group']['url']})";
223
+                $content=substr($content, 0, strlen($content)-2);
224
+                $content.=" want to join your group [{$data['group']['name']}]({$data['group']['url']})";
225 225
                 return $content;
226
-            }elseif($this->type == 2) {
227
-                foreach($data['user'] as $user) {
228
-                    $content .= "[{$user['name']}]({$user['url']}), ";
226
+            }elseif ($this->type==2) {
227
+                foreach ($data['user'] as $user) {
228
+                    $content.="[{$user['name']}]({$user['url']}), ";
229 229
                 }
230
-                $content = substr($content,0,strlen($content)-2);
231
-                $content .= " have agreed to join your group [{$data['group']['name']}]({$data['group']['url']})";
230
+                $content=substr($content, 0, strlen($content)-2);
231
+                $content.=" have agreed to join your group [{$data['group']['name']}]({$data['group']['url']})";
232 232
                 return $content;
233 233
             } //todo
234
-        }else{
234
+        } else {
235 235
             return $value;
236 236
         }
237 237
     }
238 238
 
239 239
     public function sender_user()
240 240
     {
241
-        return $this->belongsTo('App\Models\Eloquent\UserModel','sender','id');
241
+        return $this->belongsTo('App\Models\Eloquent\UserModel', 'sender', 'id');
242 242
     }
243 243
 
244 244
     public function receiver_user()
245 245
     {
246
-        return $this->belongsTo('App\Models\Eloquent\UserModel','receiver','id');
246
+        return $this->belongsTo('App\Models\Eloquent\UserModel', 'receiver', 'id');
247 247
     }
248 248
 }
Please login to merge, or discard this patch.
app/Models/Eloquent/GroupMember.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,10 +13,10 @@
 block discarded – undo
13 13
     protected $primaryKey='gmid';
14 14
 
15 15
     public function user() {
16
-        return $this->belongsTo('App\Models\Eloquent\UserModel','uid','id');
16
+        return $this->belongsTo('App\Models\Eloquent\UserModel', 'uid', 'id');
17 17
     }
18 18
 
19 19
     public function group() {
20
-        return $this->belongsTo('App\Models\Eloquent\Group','gid','gid');
20
+        return $this->belongsTo('App\Models\Eloquent\Group', 'gid', 'gid');
21 21
     }
22 22
 }
Please login to merge, or discard this patch.
app/Models/Eloquent/GroupBanned.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,13 +9,13 @@
 block discarded – undo
9 9
 {
10 10
     use SoftDeletes;
11 11
 
12
-    protected $fillable = ['group_id', 'abuse_id', 'reason', 'removed_at'];
12
+    protected $fillable=['group_id', 'abuse_id', 'reason', 'removed_at'];
13 13
 
14 14
     public function abuse() {
15 15
         return $this->belongsTo('\App\Models\Eloquent\Abuse');
16 16
     }
17 17
 
18 18
     public function group() {
19
-        return $this->belongsTo('\App\Models\Eloquent\Group',null,'gid');
19
+        return $this->belongsTo('\App\Models\Eloquent\Group', null, 'gid');
20 20
     }
21 21
 }
Please login to merge, or discard this patch.
app/Models/Eloquent/Dojo/Dojo.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
     public function canPass()
28 28
     {
29 29
         $tot=0;
30
-        foreach($this->problems->sortBy('order') as $problem){
30
+        foreach ($this->problems->sortBy('order') as $problem) {
31 31
             $problem=$problem->problem;
32 32
             $tot+=$problem->problem_status['color']=='wemd-green-text';
33 33
         }
@@ -41,11 +41,11 @@  discard block
 block discarded – undo
41 41
 
42 42
     public function getAvailabilityAttribute()
43 43
     {
44
-        foreach(explode(',', $this->precondition) as $dojo_id){
45
-            if(blank($dojo_id)) continue;
46
-            if(!DojoPass::isPassed($dojo_id)) return 'locked';
44
+        foreach (explode(',', $this->precondition) as $dojo_id) {
45
+            if (blank($dojo_id)) continue;
46
+            if (!DojoPass::isPassed($dojo_id)) return 'locked';
47 47
         }
48
-        return $this->passed?'passed':'available';
48
+        return $this->passed ? 'passed' : 'available';
49 49
     }
50 50
 
51 51
 }
Please login to merge, or discard this patch.
app/Models/Eloquent/Dojo/DojoPass.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,9 +26,9 @@
 block discarded – undo
26 26
 
27 27
     public static function isPassed($dojo_id)
28 28
     {
29
-        return Auth::check()?self::where([
29
+        return Auth::check() ?self::where([
30 30
             "dojo_id"=>$dojo_id,
31 31
             "user_id"=>Auth::user()->id,
32
-        ])->count()>0:false;
32
+        ])->count()>0 : false;
33 33
     }
34 34
 }
Please login to merge, or discard this patch.
app/Models/Eloquent/Group.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 
11 11
     public function members()
12 12
     {
13
-        return $this->hasMany('App\Models\Eloquent\GroupMember', 'gid','gid');
13
+        return $this->hasMany('App\Models\Eloquent\GroupMember', 'gid', 'gid');
14 14
     }
15 15
 
16 16
     public function banneds()
@@ -20,11 +20,11 @@  discard block
 block discarded – undo
20 20
 
21 21
     public function getLeaderAttribute()
22 22
     {
23
-        return $this->members()->where('role',3)->first()->user;
23
+        return $this->members()->where('role', 3)->first()->user;
24 24
     }
25 25
 
26 26
     public function getLinkAttribute()
27 27
     {
28
-        return route('group.detail',['gcode' => $this->gcode]);
28
+        return route('group.detail', ['gcode' => $this->gcode]);
29 29
     }
30 30
 }
Please login to merge, or discard this patch.
app/Models/Eloquent/ContestModel.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -18,28 +18,28 @@  discard block
 block discarded – undo
18 18
     const CREATED_AT=null;
19 19
 
20 20
     //Repository function
21
-    public function participants($ignore_frozen = true)
21
+    public function participants($ignore_frozen=true)
22 22
     {
23
-        if($this->registration){
24
-            $participants = ContestParticipant::where('cid',$this->cid)->get();
23
+        if ($this->registration) {
24
+            $participants=ContestParticipant::where('cid', $this->cid)->get();
25 25
             $participants->load('user');
26
-            $users = new EloquentCollection;
26
+            $users=new EloquentCollection;
27 27
             foreach ($participants as $participant) {
28
-                $user = $participant->user;
28
+                $user=$participant->user;
29 29
                 $users->add($user);
30 30
             }
31 31
             return $users->unique();
32
-        }else{
32
+        } else {
33 33
             $this->load('submissions.user');
34
-            if($ignore_frozen){
35
-                $frozen_time = $this->frozen_time;
36
-                $submissions = $this->submissions()->where('submission_date','<',$frozen_time)->get();
37
-            }else{
38
-                $submissions = $this->submissions;
34
+            if ($ignore_frozen) {
35
+                $frozen_time=$this->frozen_time;
36
+                $submissions=$this->submissions()->where('submission_date', '<', $frozen_time)->get();
37
+            } else {
38
+                $submissions=$this->submissions;
39 39
             }
40
-            $users = new EloquentCollection;
40
+            $users=new EloquentCollection;
41 41
             foreach ($submissions as $submission) {
42
-                $user = $submission->user;
42
+                $user=$submission->user;
43 43
                 $users->add($user);
44 44
             }
45 45
             return $users->unique();
@@ -49,18 +49,18 @@  discard block
 block discarded – undo
49 49
     // Repository/Service? function
50 50
     public function rankRefresh()
51 51
     {
52
-        $ret = [];
53
-        $participants = $this->participants();
54
-        $contest_problems = $this->problems;
52
+        $ret=[];
53
+        $participants=$this->participants();
54
+        $contest_problems=$this->problems;
55 55
         $contest_problems->load('problem');
56
-        if($this->rule == 1){
56
+        if ($this->rule==1) {
57 57
             // ACM/ICPC Mode
58 58
             foreach ($participants as $participant) {
59 59
                 $prob_detail=[];
60 60
                 $totPen=0;
61 61
                 $totScore=0;
62 62
                 foreach ($contest_problems as $contest_problem) {
63
-                    $prob_stat = $contest_problem->userStatus($participant);
63
+                    $prob_stat=$contest_problem->userStatus($participant);
64 64
                     $prob_detail[]=[
65 65
                         'ncode'=>$contest_problem->ncode,
66 66
                         'pid'=>$contest_problem->pid,
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
                     "problem_detail" => $prob_detail
87 87
                 ];
88 88
             }
89
-            usort($ret, function ($a, $b) {
89
+            usort($ret, function($a, $b) {
90 90
                 if ($a["score"]==$b["score"]) {
91 91
                     if ($a["penalty"]==$b["penalty"]) {
92 92
                         return 0;
@@ -103,43 +103,43 @@  discard block
 block discarded – undo
103 103
             });
104 104
             Cache::tags(['contest', 'rank'])->put($this->cid, $ret, 60);
105 105
             return $ret;
106
-        }else{
106
+        } else {
107 107
             // IO Mode
108
-            $c = new OutdatedContestModel();
108
+            $c=new OutdatedContestModel();
109 109
             return $c->contestRankCache($this->cid);
110 110
         }
111 111
     }
112 112
 
113 113
     public function problems()
114 114
     {
115
-        return $this->hasMany('App\Models\Eloquent\ContestProblem','cid','cid');
115
+        return $this->hasMany('App\Models\Eloquent\ContestProblem', 'cid', 'cid');
116 116
     }
117 117
 
118 118
     public function submissions()
119 119
     {
120
-        return $this->hasMany('App\Models\Eloquent\SubmissionModel','cid','cid');
120
+        return $this->hasMany('App\Models\Eloquent\SubmissionModel', 'cid', 'cid');
121 121
     }
122 122
 
123 123
     public function group()
124 124
     {
125
-        return $this->hasOne('App\Models\Eloquent\Group','gid','gid');
125
+        return $this->hasOne('App\Models\Eloquent\Group', 'gid', 'gid');
126 126
     }
127 127
 
128 128
     public function getFrozenTimeAttribute()
129 129
     {
130
-        $end_time = strtotime($this->end_time);
131
-        return $end_time - $this->froze_length;
130
+        $end_time=strtotime($this->end_time);
131
+        return $end_time-$this->froze_length;
132 132
     }
133 133
 
134 134
     public static function getProblemSet($cid, $renderLatex=false)
135 135
     {
136 136
         $ret=[];
137
-        $problemset=ContestProblemModel::where('cid', $cid)->orderBy('number','asc')->get();
138
-        foreach($problemset as $problem){
137
+        $problemset=ContestProblemModel::where('cid', $cid)->orderBy('number', 'asc')->get();
138
+        foreach ($problemset as $problem) {
139 139
             $problemDetail=ProblemModel::find($problem->pid);
140 140
             $problemRet=(new OutdatedProblemModel())->detail($problemDetail->pcode);
141
-            if ($renderLatex){
142
-                foreach (['description','input','output','note'] as $section){
141
+            if ($renderLatex) {
142
+                foreach (['description', 'input', 'output', 'note'] as $section) {
143 143
                     $problemRet['parsed'][$section]=latex2Image($problemRet['parsed'][$section]);
144 144
                 }
145 145
             }
@@ -153,6 +153,6 @@  discard block
 block discarded – undo
153 153
 
154 154
     public function isJudgingComplete()
155 155
     {
156
-        return $this->submissions->whereIn('verdict',['Waiting','Pending'])->count()==0;
156
+        return $this->submissions->whereIn('verdict', ['Waiting', 'Pending'])->count()==0;
157 157
     }
158 158
 }
Please login to merge, or discard this patch.
app/Models/Eloquent/ProblemModel.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,12 +17,12 @@
 block discarded – undo
17 17
 
18 18
     public function submissions()
19 19
     {
20
-        return $this->hasMany('App\Models\Eloquent\SubmissionModel','pid','pid');
20
+        return $this->hasMany('App\Models\Eloquent\SubmissionModel', 'pid', 'pid');
21 21
     }
22 22
 
23 23
     public function getProblemStatusAttribute()
24 24
     {
25
-        if(Auth::check()){
25
+        if (Auth::check()) {
26 26
             $prob_status=(new OutdatedSubmissionModel())->getProblemStatus($this->pid, Auth::user()->id);
27 27
             if (empty($prob_status)) {
28 28
                 return [
Please login to merge, or discard this patch.
app/Models/Eloquent/UserBanned.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@
 block discarded – undo
9 9
 {
10 10
     use SoftDeletes;
11 11
 
12
-    protected $fillable = ['user_id', 'abuse_id', 'reason', 'removed_at'];
12
+    protected $fillable=['user_id', 'abuse_id', 'reason', 'removed_at'];
13 13
 
14 14
     public function abuse() {
15 15
         return $this->belongsTo('\App\Models\Eloquent\Abuse');
Please login to merge, or discard this patch.