Skip to content

Commit

Permalink
Update User.php
Browse files Browse the repository at this point in the history
  • Loading branch information
pvgennip committed Oct 23, 2020
1 parent 276e51c commit 049aacc
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,31 +135,31 @@ public function allChecklists()
return Checklist::whereIn('id', $checklist_ids);
}

public function groupHives($mine = false)
public function groupHives($editable = false)
{
$group_ids = $this->groups->pluck('id')->toArray();

$hive_ids = [];
if ($mine)
if ($editable)
$hive_ids = DB::table('group_hive')->where('edit_hive', 1)->whereIn('group_id',$group_ids)->distinct('hive_id')->pluck('hive_id')->toArray();
else
$hive_ids = DB::table('group_hive')->whereIn('group_id',$group_ids)->distinct('hive_id')->pluck('hive_id')->toArray();
//die(print_r(['group_ids'=>$group_ids,'hive_ids'=>$hive_ids]));
return Hive::whereIn('id',$hive_ids);
}

public function allHives($mine = false) // Including Group hives
public function allHives($editable = false) // Including Group hives
{
$own_ids = $this->hives()->pluck('id');
$hiv_ids = $this->groupHives($mine)->pluck('id');
$hiv_ids = $this->groupHives($editable)->pluck('id');
$all_ids = $own_ids->merge($hiv_ids);
return Hive::whereIn('id',$all_ids);
}

public function allInspections($mine = false) // Including Group hive locations
public function allInspections($editable = false) // Including Group hive locations
{
$own_ids = $this->inspections()->pluck('id');
$hiv_ids = $this->groupHives($mine)->pluck('id');
$hiv_ids = $this->groupHives($editable)->pluck('id');
$ins_ids = DB::table('inspection_hive')->whereIn('hive_id',$hiv_ids)->distinct('inspection_id')->pluck('inspection_id')->toArray();
$all_ids = $own_ids->merge($ins_ids);
return Inspection::whereIn('id',$all_ids);
Expand All @@ -170,20 +170,20 @@ public function locations()
return $this->hasMany(Location::class);
}

public function allLocations($mine = false) // Including Group hive locations
public function allLocations($editable = false) // Including Group hive locations
{
$own_ids = $this->locations()->pluck('id');
$hiv_ids = $this->groupHives($mine)->pluck('id');
$hiv_ids = $this->groupHives($editable)->pluck('id');
$loc_ids = DB::table('hives')->whereIn('id',$hiv_ids)->distinct('hive_id')->pluck('location_id')->toArray();
$all_ids = $own_ids->merge($loc_ids);
return Location::whereIn('id',$all_ids);
}


public function allDevices($mine = false) // Including Group hive locations
public function allDevices($editable = false) // Including Group hive locations
{
$own_ids = $this->devices()->pluck('id');
$hiv_ids = $this->groupHives($mine)->pluck('id');
$hiv_ids = $this->groupHives($editable)->pluck('id');
$sen_ids = DB::table('sensors')->whereIn('hive_id',$hiv_ids)->distinct('hive_id')->pluck('id')->toArray();
$all_ids = $own_ids->merge($sen_ids);
return Device::whereIn('id',$all_ids);
Expand Down

0 comments on commit 049aacc

Please sign in to comment.