@Sinnbeck
<?php
namespace App\Models;
use \DateTimeInterface;
use App\Support\HasAdvancedFilter;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\DB;
use App\Models\Golfclub;
use App\Models\Schedule;
use App\Models\Playersround;
use App\Models\Startlist;
use App\Models\Clubmessage;
use App\Models\StartlistParticipant;
use App\Facades\GpsService;
use Carbon\Carbon;
class Gpstracker extends BaseModel
{
use HasAdvancedFilter;
use SoftDeletes;
use HasFactory;
public $table = 'gpstrackers';
public static function getgpsdata($golfID)
{
$gpsdata = DB::table('gpstrackers')
->select('*')
->whereIn('id', function ($query) use ($golfID) {
$query->selectRaw('MAX(id) as id')
->from('gpstrackers')
->where('gpstrackers.golfclub_id', $golfID)
->where('gpstrackers.flight', '<>', 0)
->where('gpstrackers.type', '<>', 5)
->groupBy('gpstrackers.flight','gpstrackers.startliste_participant_ref_id');
})->get();
return $gpsdata;
}
public static function getAllextgpsdata()
{
$query = DB::table('externalgpsdata')
->select('externalgpsdata.*')
->get();
return $query;
}
public static function getconfigclub($golfID)
{
$query = DB::table('configurations')
->select('configurations.*', 'golfclubs.name')
->where('configurations.golfclub_id', $golfID)
->leftJoin('golfclubs', 'golfclubs.id', '=', 'configurations.golfclub_id')
->first();
return $query;
}
public static function getcourcesgolfclub($golfID)
{
$query = DB::table('configurations')
->select('configurations.*', 'golfclubs.name')
->where('configurations.golfclub_id', $golfID)
->leftJoin('golfclubs', 'golfclubs.id', '=', 'configurations.golfclub_id')
->first();
return $query;
}
public static function countnumberofclubmessages($golfID)
{
$randomItem = Clubmessage::inRandomOrder()->where('golfclubid_id',$golfID)->first(); // Henter en tilfeldig rad
$randomId = $randomItem->id; // Henter ID-en fra raden
return $randomId;
}
public static function getrandomtips($golfID)
{
$randomnr = Gpstracker::countnumberofclubmessages($golfID);
return $randomnr;
}
public static function getLastTrackingPlayer($startlist_part_ID,$golfID, $tidspunkt, $Player_ID, $courceid, $tracker)
{
$now = Carbon::now();
$maxRegDateStart = Carbon::parse($now->format('Y-m-d') . ' 00:00:00');
$maxRegDateStop = Carbon::parse($now->format('Y-m-d') . ' 23:59:59');
$gpsdata = Gpstracker::where([
['startliste_participant_ref_id', '=', $startlist_part_ID],
['regdate', '>', $maxRegDateStart->toDateTimeString()],
['regdate', '<', $maxRegDateStop->toDateTimeString()],
])
->orderBy('id', 'DESC')
->limit(1)
->first();
// $datoen = date("Y-m-d");
// $from1 = $datoen . ' 00:01:00';
// $to1 = $datoen . ' ' . $tidspunkt;
// $trackernumber = null;
// if($tracker){
// $trackernumber = $tracker->trackernumber;
// }
// if($tracker){
// $query = DB::table('gpstrackers')
// ->select('gpstrackers.*', 'users.name')
// ->leftJoin('users', 'gpstrackers.player_id_ref', '=', 'users.id')
// ->whereIn('gpstrackers.id', function ($query) use ($from1, $to1, $golfID, $trackernumber, $courceid , $startlist_part_ID) {
// $query->selectRaw('MAX(gpstrackers.id) as id')
// ->from('gpstrackers')
// ->leftJoin('users', 'gpstrackers.player_id_ref', '=', 'users.id')
// ->whereBetween('gpstrackers.regdate', [$from1, $to1])
// ->where('gpstrackers.golfclub_id', $golfID)
// ->where('gpstrackers.trackernumber', $trackernumber)
// ->where('gpstrackers.startliste_participant_ref_id', $startlist_part_ID)
// ->where('gpstrackers.courcegolfclub_id', $courceid)
// ->groupBy('gpstrackers.flight','gpstrackers.startliste_participant_ref_id');
// });
// } else {
// $query = DB::table('gpstrackers')
// ->select('gpstrackers.*', 'users.name')
// ->leftJoin('users', 'gpstrackers.player_id_ref', '=', 'users.id')
// ->whereIn('gpstrackers.id', function ($query) use ($from1, $to1, $golfID, $startlist_part_ID, $courceid) {
// $query->selectRaw('MAX(gpstrackers.id) as id')
// ->from('gpstrackers')
// ->leftJoin('users', 'gpstrackers.player_id_ref', '=', 'users.id')
// // ->leftJoin('startlists_participants', 'gpstrackers.startliste_participant_ref_id', '=', 'startlists_participants.id')
// ->whereBetween('gpstrackers.regdate', [$from1, $to1])
// ->where('gpstrackers.golfclub_id', $golfID)
// ->where('gpstrackers.startliste_participant_ref_id',$startlist_part_ID)
// ->where('gpstrackers.courcegolfclub_id', $courceid)
// ->groupBy('gpstrackers.flight','gpstrackers.startliste_participant_ref_id');
// });
// }
// $gpsdata = $query->first();
return $gpsdata;
}
public static function getLastTimeusedPlayer($golfID, $tidspunkt, $hole, $courceid, $playerID, $tracker)
{
$datoen = date("Y-m-d");
$from1 = $datoen . ' 00:01:00';
$to1 = $datoen . ' ' . $tidspunkt;
// $to1=$datoen.' '.date("HH:mm:ss");
$trackernumber = null;
if($tracker){
$trackernumber = $tracker->trackernumber;
}
if($trackernumber){
$query = DB::table('gpstrackers')
->select('gpstrackers.timeused')
->whereIn('gpstrackers.id', function ($query) use ($from1, $to1, $golfID, $trackernumber, $courceid, $hole) {
$query->selectRaw('MAX(gpstrackers.id) as id')
->from('gpstrackers')
->leftJoin('users', 'gpstrackers.player_id_ref', '=', 'users.id')
->whereBetween('gpstrackers.regdate', [$from1, $to1])
->where('gpstrackers.golfclub_id', $golfID)
->where('gpstrackers.trackernumber', '<>', $trackernumber)
->where('gpstrackers.hole', $hole)
->where('gpstrackers.courcegolfclub_id', $courceid)
->groupBy('gpstrackers.flight','gpstrackers.startliste_participant_ref_id');
});
} else {
$query = DB::table('gpstrackers')
->select('gpstrackers.timeused')
->whereIn('gpstrackers.id', function ($query) use ($from1, $to1, $golfID, $playerID, $courceid, $hole) {
$query->selectRaw('MAX(gpstrackers.id) as id')
->from('gpstrackers')
->leftJoin('users', 'gpstrackers.player_id_ref', '=', 'users.id')
->whereBetween('gpstrackers.regdate', [$from1, $to1])
->where('gpstrackers.golfclub_id', $golfID)
->where('gpstrackers.player_id_ref', '<>', $playerID)
->where('gpstrackers.hole', $hole)
->where('gpstrackers.courcegolfclub_id', $courceid)
->groupBy('gpstrackers.flight','gpstrackers.startliste_participant_ref_id');
});
}
$gpsdata = $query->first();
if ($gpsdata) {
$timeusedplayer = $gpsdata->timeused;
} else {
$timeusedplayer = 0;
}
return $timeusedplayer;
}
public static function storeTimeused($id, $timeused)
{
$query = Gpstracker::find($id);
if (!$query) {
return false;
}
$query->update(['timeused' => $timeused]);
return true;
}
public static function convertToMinits($time)
{
$timer = intval(substr($time, 0, 2));
$minutter = intval(substr($time, 3, 2));
$tottimer = $timer * 60;
return $tottimer + $minutter;
}
public static function statusflybanen()
{
return 1;
}
public static function timeUsedPlayer($golfID, $courceID, $startid, $tidnaa, $anthull, $timeused, $starthull, $slutthull, $type)
{
// Tid brukt til nå
if ($type === 1) {
$tid1 = Gpstracker::convertToMinits($tidnaa);
$tid2 = Gpstracker::convertToMinits($startid);
if ($tid1 <= $tid2) {
return '0:0';
}
$timeused = $tid1 - $tid2;
$hours = floor($timeused / 60);
$min = $timeused - ($hours * 60);
if ($hours < 10) {
$hours = '0' . $hours;
}
if ($min < 10) {
$min = '0' . $min;
}
$timeUsed = $hours . ":" . $min;
}
if ($type === 2) {
$timescedule = Schedule::getsceduleinfoclub($golfID, $courceID);
$sumtimetousehole = 0;
for ($i = 1; $i <= $anthull; $i++) {
if ($i === 1) {
$sumtimetousehole = $sumtimetousehole + $timescedule->hull_1;
}
if ($i === 2) {
$sumtimetousehole = $sumtimetousehole + $timescedule->hull_2;
}
if ($i === 3) {
$sumtimetousehole = $sumtimetousehole + $timescedule->hull_3;
}
if ($i === 4) {
$sumtimetousehole = $sumtimetousehole + $timescedule->hull_4;
}
if ($i === 5) {
$sumtimetousehole = $sumtimetousehole + $timescedule->hull_5;
}
if ($i === 6) {
$sumtimetousehole = $sumtimetousehole + $timescedule->hull_6;
}
if ($i === 7) {
$sumtimetousehole = $sumtimetousehole + $timescedule->hull_7;
}
if ($i === 8) {
$sumtimetousehole = $sumtimetousehole + $timescedule->hull_8;
}
if ($i === 9) {
$sumtimetousehole = $sumtimetousehole + $timescedule->hull_9;
}
if ($i === 10) {
$sumtimetousehole = $sumtimetousehole + $timescedule->hull_10;
}
if ($i === 11) {
$sumtimetousehole = $sumtimetousehole + $timescedule->hull_11;
}
if ($i === 12) {
$sumtimetousehole = $sumtimetousehole + $timescedule->hull_12;
}
if ($i === 13) {
$sumtimetousehole = $sumtimetousehole + $timescedule->hull_13;
}
if ($i === 14) {
$sumtimetousehole = $sumtimetousehole + $timescedule->hull_14;
}
if ($i === 15) {
$sumtimetousehole = $sumtimetousehole + $timescedule->hull_15;
}
if ($i === 16) {
$sumtimetousehole = $sumtimetousehole + $timescedule->hull_16;
}
if ($i === 17) {
$sumtimetousehole = $sumtimetousehole + $timescedule->hull_17;
}
if ($i === 18) {
$sumtimetousehole = $sumtimetousehole + $timescedule->hull_18;
}
}
$startet = Gpstracker::convertToMinits($startid);
$totidsum = $sumtimetousehole + $startet + $timeused;
$hours = floor($totidsum / 60);
$min = $totidsum - ($hours * 60);
if ($hours < 10) {
$hours = '0' . $hours;
}
if ($min < 10) {
$min = '0' . $min;
}
//$diff = $first->diff( $second );
$timeUsed = $hours . ":" . $min;
}
return $timeUsed;
}
public static function infoaboutflowcource($courceID, $golfID, $tid, $dagdato, $type)
{
$flytdata = Gpstracker::getTimeused($courceID, $golfID, $tid, $dagdato,false);
$returntext = 'Ingen data';
if ($flytdata) {
$antgr = 0;
$antred = 0;
$antor = 0;
$tot = 0;
if ($flytdata) {
foreach ($flytdata as $items) {
$timeusedplayer = $items->timeused;
if ($timeusedplayer < 4) {
$antgr++;
}
if (($timeusedplayer > 3) and ($timeusedplayer < 8)) {
$antor++;
}
if ($timeusedplayer > 7) {
$antred++;
}
$tot++;
}
}
if($tot>0){
$gronnepros = intval(($antgr / $tot) * 100);
$orangepros = intval(($antor / $tot) * 100);
$redpros = intval(($antred / $tot) * 100);
} else {
$gronnepros = 0;
$orangepros = 0;
$redpros = 0;
}
if ($type === 1) {
$returnvalue = 1;
if ($redpros > 0) {
$returnvalue = 3;
}
if (($redpros === 0) and ($orangepros > 3)) {
$returnvalue = 2;
}
} else {
$returnvalue = 1;
if ($redpros > 0) {
$returnvalue = 3;
}
if (($redpros === 0) and ($orangepros > 30)) {
$returnvalue = 2;
}
}
}
return $returnvalue;
}
public static function calculatetimeusedHole($timestart,$timeend)
{
try {
// Parse the start and end times
$start = \Carbon\Carbon::createFromFormat('H:i', $timestart);
$end = \Carbon\Carbon::createFromFormat('H:i', $timeend);
// Calculate the difference in minutes
$minutes = $start->diffInMinutes($end);
return $minutes;
} catch (\Exception $e) {
// Handle invalid time formats or other errors
return response()->json([
'error' => 'Invalid time format or calculation error',
]);
}
}
public static function infoaboutflowPlayer($timeused)
{
$returntext = 'Du bruker alt for lang tid';
if ($timeused < 4) {
$returntext = 'Du er veldig god på tid';
}
if (($timeused > 3) and ($timeused < 8)) {
$returntext = 'Du henger litt etter tidskjema';
}
return $returntext;
}
public static function getinfoplayerwhere($lat2, $lon2, $golfID, $courceID)
{
// Check where player are
$query = DB::table('googlemapinfos')
->select('googlemapinfos.*')
->where('googlemapinfos.golfclub_id', $golfID)
->where('googlemapinfos.courcegolfclub_id', $courceID)
->where('googlemapinfos.longmin', '<=', $lon2)
->where('googlemapinfos.longmax', '>=', $lon2)
->where('googlemapinfos.latmin', '<=', $lat2)
->where('googlemapinfos.latmax', '>=', $lat2)
->orderBy('googlemapinfos.whereareyou', 'ASC');
$playerinfo = $query->first();
if (!$playerinfo) {
return false;
}
return $playerinfo;
}
public static function Checkifinsidegeofence($lat2, $lon2, $golfID, $courceID)
{
$wherareyou = 7; // Geofence area
// Check where player are
$startround = DB::table('mapinfos')
->select('mapinfos.id','mapinfos.hole','mapinfos.whereareyou','mapinfos.golfclub_id','mapinfos.courcegolfclub_id','mapinfos.created_at')
->where('mapinfos.golfclub_id', $golfID)
->where('mapinfos.courcegolfclub_id', $courceID)
->where('mapinfos.whereareyou', $wherareyou)
->whereRaw("ST_Contains(position, ST_GeomFromText(?))", ["POINT($lat2 $lon2)"])
->orderBy('mapinfos.whereareyou', 'ASC')
->first();
return $startround;
}
public static function getinfoplayerwherePoly($lat2, $lon2, $golfID, $courceID)
{
$wherareyou_arr = array('1','5','6');
// Check where player are
$query = DB::table('mapinfos')
->select('mapinfos.id','mapinfos.hole','mapinfos.whereareyou','mapinfos.golfclub_id','mapinfos.courcegolfclub_id','mapinfos.created_at')
->where('mapinfos.golfclub_id', $golfID)
->where('mapinfos.courcegolfclub_id', $courceID)
->whereIn('mapinfos.whereareyou', $wherareyou_arr )
->whereRaw("ST_Contains(position, ST_GeomFromText(?))", ["POINT($lat2 $lon2)"])
->orderBy('mapinfos.whereareyou', 'ASC');
$playerinfo = $query->first();
if (!$playerinfo) {
return false;
}
return $playerinfo;
}
public static function getinfoplayerPolyNoStartlist($lat, $long)
{
$wherareyou_arr = array('1','5','6');
// Check where player are
$query = DB::table('mapinfos')
->select('mapinfos.*')
->whereIn('mapinfos.whereareyou', $wherareyou_arr )
->whereRaw("ST_Contains(position, ST_GeomFromText(?))", ["POINT($lat $long)"])
->orderBy('mapinfos.whereareyou', 'ASC')
->first();
// $playerinfo = $query->first();
return $query;
}
public static function getTimeusedNew($courceid, $golfID, $tidspunkt, $datoen, $liveupdate)
{
$from1 = Carbon::now()->format('Y-m-d') . ' 00:00';
$status = 3;
$query = DB::table(DB::raw('(SELECT gpstrackers.*, users.name,
ROW_NUMBER() OVER (PARTITION BY gpstrackers.flight, gpstrackers.startliste_participant_ref_id ORDER BY gpstrackers.id DESC) AS row_num
FROM gpstrackers
JOIN startlists_participants ON gpstrackers.startliste_participant_ref_id = startlists_participants.id
JOIN startlists ON startlists_participants.startlist_id = startlists.id
LEFT JOIN users ON gpstrackers.player_id_ref = users.id
WHERE gpstrackers.regdate > $from1
AND gpstrackers.golfclub_id = $golfID
AND gpstrackers.courcegolfclub_id = $courceid
AND startlists.status = $status
) AS ranked'))
->select('ranked.*', 'ranked.name')
->where('ranked.row_num', '=', 1);
$gpsdata = $query->get();
return $gpsdata;
}
public static function getTimeused($courceid, $golfID, $tidspunkt, $datoen, $liveupdate)
{
$from1 = Carbon::now()->format('Y-m-d') . ' 00:00';
$status = 3;
$test1 = 1;
if($liveupdate=='false'){
$query = DB::table('gpstrackers')
->select('gpstrackers.*', 'users.name')
->leftJoin('users', 'gpstrackers.player_id_ref', '=', 'users.id')
->whereIn('gpstrackers.id', function ($query) use ($from1, $golfID, $courceid) {
$query->selectRaw('MAX(gpstrackers.id) as id')
->from('gpstrackers')
->leftJoin('users', 'gpstrackers.player_id_ref', '=', 'users.id')
->Join('startlists_participants', 'gpstrackers.startliste_participant_ref_id', '=', 'startlists_participants.id')
->Join('startlists', 'startlists_participants.startlist_id', '=', 'startlists.id')
->where('gpstrackers.regdate', '>', $from1)
->where('gpstrackers.golfclub_id', $golfID)
->when($courceid > 0, function ($query) use ($courceid) {
$query->where('gpstrackers.courcegolfclub_id', $courceid);
})
// ->groupBy('gpstrackers.flight', 'gpstrackers.player_id_ref');
->groupBy('gpstrackers.flight','gpstrackers.startliste_participant_ref_id');
});
} else {
$query = DB::table('gpstrackers')
->select('gpstrackers.*', 'users.name')
->leftJoin('users', 'gpstrackers.player_id_ref', '=', 'users.id')
->whereIn('gpstrackers.id', function ($query) use ($from1, $golfID, $courceid, $status) {
$query->selectRaw('MAX(gpstrackers.id) as id')
->from('gpstrackers')
->leftJoin('users', 'gpstrackers.player_id_ref', '=', 'users.id')
->Join('startlists_participants', 'gpstrackers.startliste_participant_ref_id', '=', 'startlists_participants.id')
->Join('startlists', 'startlists_participants.startlist_id', '=', 'startlists.id')
->where('gpstrackers.regdate', '>', $from1)
->where('gpstrackers.golfclub_id', $golfID)
->where('startlists.status',$status)
->when($courceid > 0, function ($query) use ($courceid) {
$query->where('gpstrackers.courcegolfclub_id', $courceid);
})
// ->groupBy('gpstrackers.flight', 'gpstrackers.player_id_ref');
->groupBy('gpstrackers.flight','gpstrackers.startliste_participant_ref_id');
});
}
$gpsdata = $query->get();
return $gpsdata;
}
public static function getHolesGooglemap($request,$golfID)
{
//$courceid = $request->courceid;
$flagget = $request->flagg;
$green = $request->green;
$orange = $request->orange;
$red = $request->red;
$judge = $request->judge;
$toilet = $request->toilet;
$holenumber = $request->holenumber;
$dl = $request->dl;
$bm = $request->bm;
$td = $request->td;
$range = $request->range;
$tl = $request->tl;
$tidspunkt = $request->tidspunkt;
$courceid = $request->courceid;
$datoen = $request->datoen;
$status=3;
$tidvalgt = $request->tidvalgt;
$liveupdate = $request->liveupdate;
if($courceid == 0){
if ($holenumber == 'true') {
$holesclub = DB::table('holesclub')
->select('*', DB::raw('"dummy" as name'))
->where('holesclub.golfclub_id', $golfID)
//->where('holesclub.courcegolfclub_id', $courceid)
->get();
}
return $holesclub;
}
if ($holenumber == 'true') {
$holesclub = DB::table('holesclub')
->select('*', DB::raw('"dummy" as name'))
->where('holesclub.golfclub_id', $golfID)
->where('holesclub.courcegolfclub_id', $courceid)
->get();
}
return $holesclub;
}
public static function getgpsdataplayer($request, $golfID)
{
$flagget = $request->flagg;
$green = $request->green;
$orange = $request->orange;
$red = $request->red;
$judge = $request->judge;
$toilet = $request->toilet;
$holenumber = $request->holenumber;
$dl = $request->dl;
$bm = $request->bm;
$td = $request->td;
$range = $request->range;
$tl = $request->tl;
$tidspunkt = $request->tidspunkt;
$courceid = $request->courceid;
$datoen = $request->datoen;
$status=3;
$tidvalgt = $request->tidvalgt;
$liveupdate = $request->liveupdate;
$from1 = $datoen . ' 00:00:01';
$to1 = $datoen . ' ' . $tidspunkt;
if($liveupdate=='true'){
$to1 = $datoen . ' ' . '23:59:59';
}
// get all players last position
if($liveupdate=='false'){
$query = DB::table('gpstrackers')
->select('gpstrackers.*', 'users.name')
->leftJoin('users', 'gpstrackers.player_id_ref', '=', 'users.id')
->whereIn('gpstrackers.id', function ($query) use ($from1, $to1, $golfID, $courceid) {
$query->selectRaw('MAX(gpstrackers.id) as id')
->from('gpstrackers')
// ->leftJoin('users', 'gpstrackers.player_id_ref', '=', 'users.id')
->Join('startlists_participants', 'gpstrackers.startliste_participant_ref_id', '=', 'startlists_participants.id')
->Join('startlists', 'startlists_participants.startlist_id', '=', 'startlists.id')
->whereBetween('gpstrackers.regdate', [$from1, $to1])
->where('gpstrackers.golfclub_id', $golfID)
->when($courceid > 0, function ($query) use ($courceid) {
$query->where('gpstrackers.courcegolfclub_id', $courceid);
})
->groupBy('gpstrackers.flight','gpstrackers.startliste_participant_ref_id');
});
} else {
$query = DB::table('gpstrackers')
->select('gpstrackers.*', 'users.name')
->leftJoin('users', 'gpstrackers.player_id_ref', '=', 'users.id')
->whereIn('gpstrackers.id', function ($query) use ($from1, $to1, $golfID, $courceid, $status) {
$query->selectRaw('MAX(gpstrackers.id) as id')
->from('gpstrackers')
//->leftJoin('users', 'gpstrackers.player_id_ref', '=', 'users.id')
->Join('startlists_participants', 'gpstrackers.startliste_participant_ref_id', '=', 'startlists_participants.id')
->Join('startlists', 'startlists_participants.startlist_id', '=', 'startlists.id')
->whereBetween('gpstrackers.regdate', [$from1, $to1])
->where('gpstrackers.golfclub_id', $golfID)
->where('startlists.status',$status)
->when($courceid > 0, function ($query) use ($courceid) {
$query->where('gpstrackers.courcegolfclub_id', $courceid);
})
->groupBy('gpstrackers.flight','gpstrackers.startliste_participant_ref_id');
});
}
// if ($holenumber == 'true') {
// $query1 = DB::table('holesclub')
// ->select('*', DB::raw('"dummy" as name'))
// ->where('holesclub.golfclub_id', $golfID)
// ->where('holesclub.courcegolfclub_id', $courceid);
// $query->union($query1);
// }
if ($flagget == 'true') {
$query2 = DB::table('flagpositions')
->select('*', DB::raw('"dummy" as name'))
->where('flagpositions.courcegolfclub_id', $courceid)
->where('flagpositions.golfclub_id', $golfID);
$query->union($query2);
}
$query3 = DB::table('objectsclub')
->select('*', DB::raw('"dummy" as name'))
->where('objectsclub.golfclub_id', $golfID);
$query->union($query3);
if ($judge == 'true') {
$query4 = DB::table('gpstrackers')
->select('gpstrackers.*', 'users.name')
->leftJoin('users', 'gpstrackers.player_id_ref', '=', 'users.id')
->where('gpstrackers.type', 3)
->where('gpstrackers.courcegolfclub_id', $courceid)
->where('gpstrackers.golfclub_id', $golfID);
$query->union($query4);
}
if ($flagget == 'false') {
$query->where('type', '<>', 2);
}
if ($judge == 'false') {
$query->where('type', '<>', 3);
}
if ($toilet == 'false') {
$query->where('type', '<>', 5);
}
if ($holenumber == 'false') {
$query->where('type', '<>', 7);
}
if ($dl == 'false') {
$query->where('type', '<>', 12);
}
if ($bm == 'false') {
$query->where('type', '<>', 8);
}
if ($td == 'false') {
$query->where('type', '<>', 9);
}
if ($tl == 'false') {
$query->where('type', '<>', 10);
}
if ($range == 'false') {
$query->where('type', '<>', 11);
}
if ($green == 'false') {
$query->where('colormarker', '<>', 1);
}
if ($orange == 'false') {
$query->where('colormarker', '<>', 2);
}
if ($red == 'false') {
$query->where('colormarker', '<>', 3);
}
$gpsdata = $query->get();
return $gpsdata;
}
public static function getlastmessuregpstracker($userId)
{
// $startlistParticipant = StartlistParticipant::where(function($q) use($userId) {
// $q->where([
// ['tracker_id', null],
// ['user_id', $userId]
// ])
// ->orWhere(function($q2) use($userId) {
// $q2->where([
// ['tracker_id', null]
// ])
// ->whereHas('trackergps', function($q3) use($userId) {
// $q3->where('user_id', $userId);
// });
// });
// })
// ->orderBy('id', 'DESC')
// ->limit(1)
// ->whereHas('startlist', function($q) {
// $q->where('active', true);
// })
// ->first();
// if (!$startlistParticipant) {
// return false;
// }
// if ($startlistParticipant->has('gpstracker')) {
// return self::whereHas('startlistParticipant', function($q) use($startlistParticipant) {
// $q->where('id', $startlistParticipant->id);
// })
// ->orderBy('id', 'DESC')
// ->limit(1)
// ->get()
// ->makeHidden('golfclub')
// ->map(function($gpstracker) {
// $gpstracker->messageapp = $gpstracker->golfclub->messageapp;
// return $gpstracker;
// });
// }
// return self::whereHas('startlistParticipant', function($q) use($startlistParticipant) {
// $q->where('startlist_id', $startlistParticipant->startlist_id);
// })
// ->orderBy('id', 'DESC')
// ->limit(1)
// ->get()
// ->makeHidden('golfclub')
// ->map(function($gpstracker) {
// $gpstracker->messageapp = $gpstracker->golfclub->messageapp;
// return $gpstracker;
// });
// Andrew Versjon 1
// return self::whereHas('startlistParticipant', function($q) use($userId) {
// $q->where(function($q2) use($userId) {
// $q2->where([
// ['tracker_id', null],
// ['user_id', $userId]
// ])
// ->orWhere(function($q3) use($userId) {
// $q3->where([
// ['tracker_id', null]
// ])
// ->whereHas('trackergps', function($q4) use($userId) {
// $q4->where('user_id', $userId);
// });
// });
// })
// ->orderBy('id', 'DESC')
// ->limit(1)
// ->whereHas('startlist', function($q2) {
// $q2->where('active', true);
// });
// })
// ->orderBy('id', 'DESC')
// ->limit(1)
// ->get()
// ->makeHidden('golfclub')
// ->map(function($gpstracker) {
// $gpstracker->messageapp = $gpstracker->golfclub->messageapp;
// return $gpstracker;
// });
$startlistParticipant = StartlistParticipant::getCurrentFromUser($userId);
if (!$startlistParticipant) {
return null;
}
// $idtest = $startlistParticipant->start;
// $startlistparti = DB::table('startlists_participants')
// ->select('startlists_participants.*')
// ->where('startlists_participants.startlist_id', $idtest)
// ->first();
if($startlistParticipant){
$startlistpatID = $startlistParticipant->id;
} else {
return null;
}
$query = DB::table('gpstrackers')
->select('gpstrackers.*','clubmessages.message')
->leftJoin('clubmessages', 'gpstrackers.clubmessage_id', '=', 'clubmessages.id')
->where('startliste_participant_ref_id', $startlistpatID)
//->groupBy('gpstrackers.id')
->orderBy('id', 'DESC')
->LIMIT(1)
->get();
return $query;
}
public static function getgpsholenumbers($request, $golfID)
{
$holenumber = $request->holenumber;
$query = DB::table('holesclub');
$query->where('golfclub_id', $golfID);
if ($holenumber == false) {
$query->where('type', '==', 99);
}
$gpsdata = $query->get();
return $gpsdata;
}
protected $dates = [
'created_at',
'updated_at',
'deleted_at',
];
protected $orderable = [
'id',
'golfclub.name',
'place',
'hole',
'dist_hole',
'latitude',
'longitude',
'timeused',
];
protected $filterable = [
'id',
'golfclub.name',
'place',
'hole',
'dist_hole',
'latitude',
'longitude',
'timeused',
];
protected $fillable = [
'golfclub_id',
'place',
'hole',
'dist_hole',
'latitude',
'longitude',
'timeused',
'created_at',
'updated_at',
'deleted_at',
];
public function golfclub()
{
return $this->belongsTo(Golfclub::class);
}
public function startlistParticipant(): BelongsTo
{
return $this->belongsTo(StartlistParticipant::class, 'startliste_participant_ref_id', 'id');
}
}