| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace App\Model;
- use Illuminate\Database\Eloquent\Model;
- use App\Model\Privillage\Role;
- use App\Model\TahunProgramDetail;
- use Auth;
- use Illuminate\Database\Eloquent\SoftDeletes;
- class TemplateProgram extends Model
- {
- use SoftDeletes;
- protected $table = 'template_program';
- protected $fillable = [
- 'nama',
- 'status',
- 'created_by',
- 'modified_by',
- 'logo',
- 'is_required'
- ];
- public function itemProgram(){
- return $this->hasMany('App\Model\ItemProgram', 'id_template');
- }
- public function templateProgramDetail(){
- return $this->hasMany('App\Model\TemplateProgramDetail', 'id_template_program');
- }
- public function templateProgramRole(){
- return $this->hasMany('App\Model\TemplateProgramRole', 'id_template_program');
- }
- public function tahunProgram(){
- return $this->belongsToMany('App\Model\TahunProgram', 'tb_tahun_program_detail','id_tahun_program', 'id_template_program');
- }
- public function tahunProgramDetail(){
- return $this->hasMany('App\Model\TahunProgramDetail', 'id_template_program');
- }
- /**
- * @return mixed
- */
- public function getTotalPeriodeActiveAttribute()
- {
- $total_periode = 0;
- if(!empty($this->tahunProgramDetail)){
- $total_periode = TahunProgramDetail::where('id_template_program',$this->id);
- $year = date('Y');
- $total_periode = $total_periode->whereHas('tahunProgram',function($q) use($year){
- $q->where('value',$year);
- });
- //if user not admin
- if(!empty(Auth::user())){
- $getStatus = Role::where('id',Auth::user()->role_id)->value('akses');
- if(!empty($getStatus) && $getStatus!='administrator'){
- $id_upt = Auth::user()->upt;
- $total_periode = $total_periode->where('unit',$id_upt);
- }
- }
- $total_periode = $total_periode->count();
- }
- return $total_periode;
-
- }
- /**
- * @return mixed
- */
- public function getTotalPeriodeAttribute()
- {
- $total_periode = 0;
- if(!empty($this->tahunProgramDetail)){
- $total_periode = $this->tahunProgramDetail;
- //if user not admin
- if(!empty(Auth::user())){
- $getStatus = Role::where('id',Auth::user()->role_id)->value('akses');
- if(!empty($getStatus) && $getStatus!='administrator'){
- $id_upt = Auth::user()->upt;
- $total_periode = $total_periode->where('unit',$id_upt);
- }
- }
- $total_periode = $total_periode->count();
- }
- return $total_periode;
-
- }
- }
|