Test Setup Failed
Push — master ( 93675a...ba3342 )
by Mohamed
14:07 queued 12s
created

createExaminationData()   A

Complexity

Conditions 4
Paths 12

Size

Total Lines 20
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 4
eloc 17
nc 12
nop 2
dl 0
loc 20
rs 9.7
c 2
b 0
f 1
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Support\Facades\Log;
6
use Illuminate\Database\Eloquent\Model;
7
8
class Institution_student_admission extends Base_Model
9
{
10
11
    public const CREATED_AT = 'created';
12
13
    public const UPDATED_AT = 'modified';
14
15
    /**
16
     * The database table used by the model.
17
     *
18
     * @var string
19
     */
20
    protected $table = 'institution_student_admission';
21
22
    /**
23
     * Attributes that should be mass-assignable.
24
     *
25
     * @var array
26
     */
27
    protected $fillable = ['start_date', 'end_date', 'student_id', 'status_id', 'assignee_id', 'institution_id', 'academic_period_id', 'education_grade_id', 'institution_class_id', 'comment', 'modified_user_id', 'modified', 'created_user_id', 'created', 'admission_id'];
28
29
    /**
30
     * The attributes excluded from the model's JSON form.
31
     *
32
     * @var array
33
     */
34
    protected $hidden = [];
35
36
    /**
37
     * The attributes that should be casted to native types.
38
     *
39
     * @var array
40
     */
41
    protected $casts = [];
42
43
    /**
44
     * The attributes that should be mutated to dates.
45
     *
46
     * @var array
47
     */
48
    protected $dates = ['modified', 'created', 'modified', 'created', 'start_date', 'end_date', 'modified', 'created'];
49
50
    /**
51
     * Create new Institution student admission from examination data
52
     *
53
     * @param [type] $student
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
54
     * @param [type] $admissionInfo
55
     * @return void
56
     */
57
    public static function createExaminationData($student, $admissionInfo)
58
    {
59
        try {
60
            $data = [
61
                'start_date' => $admissionInfo['academic_period']->start_date,
62
                'start_year' => $admissionInfo['academic_period']->start_year,
63
                'end_date' => $admissionInfo['academic_period']->end_date,
64
                'end_year' => $admissionInfo['academic_period']->end_year,
65
                'student_id' => $student['id'],
66
                'status_id' => 124,
67
                'institution_id' => $admissionInfo['instituion']->id,
68
                'academic_period_id' => $admissionInfo['academic_period']->id,
69
                'education_grade_id' => $admissionInfo['education_grade']->id,
70
                'institution_class_id' => (($admissionInfo['instituion_class']  != []) && (count($admissionInfo['instituion_class'])==1)) ? $admissionInfo['instituion_class']['id'] : null,
71
                'comment' => 'Imported From Examination Data',
72
                'created_user_id' => 1
73
            ];
74
            self::create($data);
75
        } catch (\Throwable $th) {
76
            Log::error($th);
77
        }
78
    }
79
}
80