1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
|
7
|
|
|
class User_special_need extends Base_Model |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* The database table used by the model. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $table = 'user_special_needs'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Attributes that should be mass-assignable. |
19
|
|
|
* |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
protected $fillable = ['special_need_date', 'comment', 'security_user_id', 'special_need_type_id', 'special_need_difficulty_id', 'modified_user_id', 'modified', 'created_user_id', 'created']; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The attributes excluded from the model's JSON form. |
26
|
|
|
* |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
protected $hidden = []; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The attributes that should be casted to native types. |
33
|
|
|
* |
34
|
|
|
* @var array |
35
|
|
|
*/ |
36
|
|
|
protected $casts = []; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The attributes that should be mutated to dates. |
40
|
|
|
* |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
protected $dates = ['special_need_date', 'modified', 'created']; |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public static function isDuplicated($inputs) |
47
|
|
|
{ |
48
|
|
|
return self::where('security_user_id', '=', $inputs['security_user_id']) |
49
|
|
|
->where('special_need_type_id', '=', $inputs['special_need_type_id']) |
50
|
|
|
->where('special_need_difficulty_id', '=', $inputs['special_need_difficulty_id'])->exists(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public static function createOrUpdate($studentId, $row, $file) |
54
|
|
|
{ |
55
|
|
|
if (!empty($row['special_need'])) { |
56
|
|
|
$specialNeed = Special_need_difficulty::where('name', '=', $row['special_need'])->first(); |
57
|
|
|
$data = [ |
58
|
|
|
'special_need_date' => now(), |
59
|
|
|
'security_user_id' => $studentId, |
60
|
|
|
'special_need_type_id' => 1, |
61
|
|
|
'special_need_difficulty_id' => $specialNeed->id, |
62
|
|
|
'created_user_id' => $file['security_user_id'] |
63
|
|
|
]; |
64
|
|
|
if (!self::isDuplicated($data)) { |
65
|
|
|
self::create($data); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|