-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathTrain.php
48 lines (44 loc) · 1.49 KB
/
Train.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use App\TrainProblem;
use App\Submission;
class Train extends Model
{
protected $table = "train_info";
protected $primaryKey = "train_id";
public function getUserChapter($uid)
{
$train_id = $this->train_id;
$trainingObj = Train::where('train_id', $train_id)->first();
$chapter_in = 1;
for($i = 1; $i <= $trainingObj->train_chapter; $i++)
{
$trainingProblemObj = TrainProblem::where([
'train_id' => $train_id,
'chapter_id' => $i
])->get();
if(isset($trainingProblemObj) && $chapter_in == $i)
$checkChapterAc = 1;
$problem_num = 0;
foreach($trainingProblemObj as $trainingProblem)
{
if(!$trainingProblem->problem->getNumberOfUsedContests())
{
$submissionObj = Submission::select('uid')->where([
'uid' => $uid,
'pid' => $trainingProblem->problem_id,
'result' => 'Accepted'
])->orderby('runid','asc')->first();
if(isset($submissionObj) && $checkChapterAc == 1)
$checkChapterAc = 1;
else
$checkChapterAc = 0;
}
}
if($checkChapterAc == 1)
$chapter_in = $i + 1;
}
return $chapter_in;
}
}