| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace App\Model;
- use Illuminate\Database\Eloquent\Model;
- use App\Model\Privillage\Role;
- use App\Model\TahunProgramDetail;
- use Auth;
- class TemplateProgramDetail extends Model
- {
- protected $table = 'template_program_detail';
- protected $fillable = [
- 'id_template_program',
- 'nama',
- 'created_at',
- 'updated_at'
- ];
- public function templateProgram(){
- return $this->belongsTo('App\Model\TemplateProgram', 'id_template_program');
- }
- public function itemProgram(){
- return $this->hasMany('App\Model\ItemProgram', 'id_template_program_detail');
- }
- /**
- * @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;
-
- }
- }
|