482 lines
16 KiB
PHP
482 lines
16 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Tables\Columns;
|
|
|
|
use App\Filament\Resources\Events\Tables\EventsTable;
|
|
use App\Models\Bookmaker;
|
|
use Filament\Tables\Columns\Column;
|
|
|
|
class ColumnOdds extends Column
|
|
{
|
|
protected string $view = 'filament.tables.columns.column-odds';
|
|
|
|
public $data;
|
|
|
|
protected $filter;
|
|
|
|
protected $bettype;
|
|
|
|
public $slots;
|
|
|
|
public $bookmaker;
|
|
|
|
protected $max;
|
|
|
|
protected $min;
|
|
|
|
protected $columns;
|
|
|
|
protected $client;
|
|
|
|
protected $filter_compare_bookmaker;
|
|
|
|
protected $compare_bookmaker_id;
|
|
|
|
protected $filter_compare_mode;
|
|
|
|
protected $favorits = [];
|
|
|
|
public $compare;
|
|
|
|
public $partner;
|
|
|
|
public $partner_icon;
|
|
|
|
protected ?array $odds_labels;
|
|
|
|
protected bool $state = true;
|
|
|
|
public function loadData($record)
|
|
{
|
|
$this->getData($record);
|
|
|
|
$this->setCompareDifferences();
|
|
$this->favorits = ['h2w' => 0, 'a2w' => 0, 'h3w' => 0, 'd3w' => 0, 'a3w' => 0, 'home' => 0, 'away' => 0, 'margin' => 0];
|
|
if ($this->filter_compare_bookmaker) {
|
|
if ($this->filter_compare_mode == 'Favorit') {
|
|
$this->setFavorits($record);
|
|
} elseif ($this->filter_compare_mode == 'X') {
|
|
$this->favorits = ['h2w' => 0, 'a2w' => 0, 'h3w' => 0, 'd3w' => 1, 'a3w' => 0, 'home' => 0, 'away' => 0, 'margin' => 0];
|
|
} elseif ($this->filter_compare_mode == 'Margin') {
|
|
$this->favorits = ['h2w' => 0, 'a2w' => 0, 'h3w' => 0, 'd3w' => 0, 'a3w' => 0, 'home' => 0, 'away' => 0, 'margin' => 1];
|
|
}
|
|
}
|
|
|
|
if (! $this->data) {
|
|
$this->state = false;
|
|
|
|
return;
|
|
}
|
|
|
|
$this->setPartnerIcon();
|
|
|
|
$this->setSlots();
|
|
|
|
$this->has_data = count($this->data);
|
|
|
|
$this->compare_bookmaker_id = 0;
|
|
|
|
$order = $this->bookmaker;
|
|
$this->data = $this->data->sortBy(function ($model) use ($order) {
|
|
return array_search($model->bookmaker_id, $order);
|
|
});
|
|
|
|
$this->setCompare($record);
|
|
|
|
return $this->data;
|
|
}
|
|
|
|
/*******************************
|
|
* PARENT
|
|
*******************************/
|
|
public function bettype(string $bettype): static
|
|
{
|
|
$this->bettype = $bettype;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setCompareDifferences()
|
|
{
|
|
$filters = $this->getTable()->getFilters();
|
|
$filters = [$filters];
|
|
foreach ($filters as $value) {
|
|
$filter = $value['events']->getState();
|
|
}
|
|
if (isset($filter['filter_compare_differences'])) {
|
|
$tmp = explode('-', $filter['filter_compare_differences']);
|
|
$this->filter_compare_bookmaker = (int) $tmp[2];
|
|
$this->filter_compare_mode = $tmp[0];
|
|
} else {
|
|
$this->filter_compare_bookmaker = 0;
|
|
}
|
|
}
|
|
|
|
/*******************************
|
|
* GETTER
|
|
*******************************/
|
|
|
|
public function getCompareBookmaker()
|
|
{
|
|
return $this->filter_compare_bookmaker;
|
|
}
|
|
|
|
public function getBettype()
|
|
{
|
|
return $this->bettype;
|
|
}
|
|
|
|
public function getColumns()
|
|
{
|
|
return $this->columns;
|
|
}
|
|
|
|
public function getPartnerBookmakerIcon()
|
|
{
|
|
return $this->partner_icon;
|
|
}
|
|
|
|
public function getSlots()
|
|
{
|
|
if (auth()->user()->is_multiline_direct) {
|
|
return $this->bookmaker;
|
|
} else {
|
|
return $this->slots;
|
|
}
|
|
}
|
|
|
|
public function getState(): bool
|
|
{
|
|
return $this->state;
|
|
}
|
|
|
|
public function getClient()
|
|
{
|
|
return $this->client;
|
|
}
|
|
|
|
public function getCompare()
|
|
{
|
|
return $this->compare;
|
|
}
|
|
|
|
public function getPartner()
|
|
{
|
|
return $this->partner;
|
|
}
|
|
|
|
public function getMax()
|
|
{
|
|
return $this->max;
|
|
}
|
|
|
|
public function getMin()
|
|
{
|
|
return $this->min;
|
|
}
|
|
|
|
public function getFavorits()
|
|
{
|
|
return $this->favorits;
|
|
}
|
|
|
|
public function getCompareBookmakerId()
|
|
{
|
|
return $this->compare_bookmaker_id;
|
|
}
|
|
|
|
public function getData($record)
|
|
{
|
|
$this->client = null;
|
|
$this->partner = null;
|
|
$this->data = null;
|
|
switch ($this->bettype) {
|
|
case 'odds_2ways':
|
|
$this->data = $record->odds_2ways;
|
|
$this->client = $record->odds_2ways->where('bookmaker_id', auth()->user()->bookmaker_id)->first();
|
|
$this->partner = $record->odds_2ways->where('bookmaker_id', auth()->user()->partner_bookmaker_id)->first();
|
|
break;
|
|
|
|
case 'odds_2ways_s1':
|
|
$this->data = $record->odds_2ways_s1;
|
|
$this->client = $record->odds_2ways_s1->where('bookmaker_id', auth()->user()->bookmaker_id)->first();
|
|
$this->partner = $record->odds_2ways_s1->where('bookmaker_id', auth()->user()->partner_bookmaker_id)->first();
|
|
break;
|
|
|
|
case 'odds_3ways':
|
|
$this->data = $record->odds_3ways;
|
|
$this->client = $record->odds_3ways->where('bookmaker_id', auth()->user()->bookmaker_id)->first();
|
|
$this->partner = $record->odds_3ways->where('bookmaker_id', auth()->user()->partner_bookmaker_id)->first();
|
|
break;
|
|
|
|
case 'odds_3ways_ht':
|
|
$this->data = $record->odds_3ways_ht;
|
|
$this->client = $record->odds_3ways_ht->where('bookmaker_id', auth()->user()->bookmaker_id)->first();
|
|
$this->partner = $record->odds_3ways_ht->where('bookmaker_id', auth()->user()->partner_bookmaker_id)->first();
|
|
break;
|
|
|
|
case 'odds_dc':
|
|
$this->data = $record->odds_dc;
|
|
$this->client = $record->odds_dc->where('bookmaker_id', auth()->user()->bookmaker_id)->first();
|
|
$this->partner = $record->odds_dc->where('bookmaker_id', auth()->user()->partner_bookmaker_id)->first();
|
|
break;
|
|
|
|
case 'odds_dnb':
|
|
$this->data = $record->odds_dnb;
|
|
$this->client = $record->odds_dnb->where('bookmaker_id', auth()->user()->bookmaker_id)->first();
|
|
$this->partner = $record->odds_dnb->where('bookmaker_id', auth()->user()->partner_bookmaker_id)->first();
|
|
break;
|
|
|
|
case 'odds_ggng':
|
|
$this->data = $record->odds_ggng;
|
|
$this->client = $record->odds_ggng->where('bookmaker_id', auth()->user()->bookmaker_id)->first();
|
|
$this->partner = $record->odds_ggng->where('bookmaker_id', auth()->user()->partner_bookmaker_id)->first();
|
|
break;
|
|
|
|
case 'odds_points':
|
|
$this->data = $record->odds_points;
|
|
$this->client = $record->odds_points->where('bookmaker_id', auth()->user()->bookmaker_id)->first();
|
|
$this->partner = $record->odds_points->where('bookmaker_id', auth()->user()->partner_bookmaker_id)->first();
|
|
break;
|
|
|
|
case 'odds_points_ht':
|
|
$this->data = $record->odds_points_ht;
|
|
$this->client = $record->odds_points_ht->where('bookmaker_id', auth()->user()->bookmaker_id)->first();
|
|
$this->partner = $record->odds_points_ht->where('bookmaker_id', auth()->user()->partner_bookmaker_id)->first();
|
|
break;
|
|
|
|
case 'odds_points_q1':
|
|
$this->data = $record->odds_points_q1;
|
|
$this->client = $record->odds_points_q1->where('bookmaker_id', auth()->user()->bookmaker_id)->first();
|
|
$this->partner = $record->odds_points_q1->where('bookmaker_id', auth()->user()->partner_bookmaker_id)->first();
|
|
break;
|
|
|
|
case 'odds_totals':
|
|
$this->data = $record->odds_totals;
|
|
$this->client = $record->odds_totals->where('bookmaker_id', auth()->user()->bookmaker_id)->first();
|
|
$this->partner = $record->odds_totals->where('bookmaker_id', auth()->user()->partner_bookmaker_id)->first();
|
|
break;
|
|
|
|
case 'odds_totals_ht':
|
|
$this->data = $record->odds_totals_ht;
|
|
$this->client = $record->odds_totals_ht->where('bookmaker_id', auth()->user()->bookmaker_id)->first();
|
|
$this->partner = $record->odds_totals_ht->where('bookmaker_id', auth()->user()->partner_bookmaker_id)->first();
|
|
break;
|
|
|
|
case 'odds_totals_q1':
|
|
$this->data = $record->odds_totals_q1;
|
|
$this->client = $record->odds_totals_q1->where('bookmaker_id', auth()->user()->bookmaker_id)->first();
|
|
$this->partner = $record->odds_totals_q1->where('bookmaker_id', auth()->user()->partner_bookmaker_id)->first();
|
|
break;
|
|
|
|
case 'odds_tq':
|
|
$this->data = $record->odds_tq;
|
|
$this->client = $record->odds_tq->where('bookmaker_id', auth()->user()->bookmaker_id)->first();
|
|
$this->partner = $record->odds_tq->where('bookmaker_id', auth()->user()->partner_bookmaker_id)->first();
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
public function getOddsLabels()
|
|
{
|
|
switch ($this->bettype) {
|
|
case 'odds_tq':
|
|
case 'odds_2ways':
|
|
case 'odds_2ways_s1':
|
|
case 'odds_dnb':
|
|
$this->columns = 2;
|
|
$this->odds_labels = ['1', '2'];
|
|
break;
|
|
|
|
case 'odds_3ways':
|
|
case 'odds_3ways_ht':
|
|
$this->columns = 3;
|
|
$this->odds_labels = ['1', 'X', '2'];
|
|
break;
|
|
|
|
case 'odds_dc':
|
|
$this->columns = 3;
|
|
$this->odds_labels = ['1X', '12', 'X2'];
|
|
break;
|
|
|
|
case 'odds_ggng':
|
|
$this->columns = 2;
|
|
$this->odds_labels = ['GG', 'NG'];
|
|
break;
|
|
|
|
case 'odds_points':
|
|
case 'odds_points_ht':
|
|
case 'odds_points_q1':
|
|
$this->columns = 3;
|
|
$this->odds_labels = ['H', 'A', 'HC'];
|
|
break;
|
|
|
|
case 'odds_totals':
|
|
case 'odds_totals_ht':
|
|
case 'odds_totals_q1':
|
|
$this->columns = 3;
|
|
$this->odds_labels = ['O', 'U', 'T'];
|
|
break;
|
|
}
|
|
|
|
return $this->odds_labels;
|
|
}
|
|
|
|
/*******************************
|
|
* SETTER
|
|
*******************************/
|
|
|
|
public function setFavorits($record)
|
|
{
|
|
if ($this->filter_compare_bookmaker) {
|
|
switch ($this->bettype) {
|
|
case 'odds_2ways':
|
|
$tmp = $record->odds_2ways->where('bookmaker_id', $this->filter_compare_bookmaker)->first();
|
|
if ($tmp->h2w < $tmp->a2w) {
|
|
$this->favorits['h2w'] = 1;
|
|
} else {
|
|
$this->favorits['a2w'] = 1;
|
|
}
|
|
break;
|
|
|
|
case 'odds_3ways':
|
|
$tmp = $record->odds_3ways->where('bookmaker_id', $this->filter_compare_bookmaker)->first();
|
|
if ($tmp->h3w < $tmp->d3w && $tmp->h3w < $tmp->a3w) {
|
|
$this->favorits['h3w'] = 1;
|
|
} elseif ($tmp->d3w < $tmp->a3w) {
|
|
$this->favorits['d3w'] = 1;
|
|
} else {
|
|
$this->favorits['a3w'] = 1;
|
|
}
|
|
break;
|
|
|
|
case 'odds_points':
|
|
$tmp = $record->odds_points->where('bookmaker_id', $this->filter_compare_bookmaker)->first();
|
|
if ($tmp->home < $tmp->away) {
|
|
$this->favorits['home'] = 1;
|
|
} else {
|
|
$this->favorits['away'] = 1;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function setMinMax($record)
|
|
{
|
|
switch ($this->bettype) {
|
|
case 'odds_2ways':
|
|
case 'odds_2ways_s1':
|
|
$this->max['h2w'] = $record->odds_2ways->max('h2w');
|
|
$this->max['a2w'] = $record->odds_2ways->max('a2w');
|
|
$this->min['h2w'] = $record->odds_2ways->min('h2w');
|
|
$this->min['h2w'] = $record->odds_2ways->min('h2w');
|
|
break;
|
|
|
|
case 'odds_3ways':
|
|
case 'odds_3ways_ht':
|
|
$this->max['h3w'] = $record->odds_3ways_ht->max('h3w');
|
|
$this->max['d3w'] = $record->odds_3ways_ht->max('d3w');
|
|
$this->max['a3w'] = $record->odds_3ways_ht->max('a3w');
|
|
$this->min['h3w'] = $record->odds_3ways_ht->min('h3w');
|
|
$this->min['d3w'] = $record->odds_3ways_ht->min('d3w');
|
|
$this->min['a3w'] = $record->odds_3ways_ht->min('a3w');
|
|
break;
|
|
|
|
case 'odds_dc':
|
|
$this->max['dc1x'] = $record->odds_dc->max('dc1x');
|
|
$this->max['dc12'] = $record->odds_dc->max('dc12');
|
|
$this->max['dcx2'] = $record->odds_dc->max('dcx2');
|
|
$this->min['dc1x'] = $record->odds_dc->min('dc1x');
|
|
$this->min['dc12'] = $record->odds_dc->min('dc12');
|
|
$this->min['dcx2'] = $record->odds_dc->min('dcx2');
|
|
break;
|
|
case 'odds_dnb':
|
|
$this->max['dnb1'] = $record->odds_dnb->max('dnb1');
|
|
$this->max['dnb2'] = $record->odds_dnb->max('dnb2');
|
|
$this->min['dnb1'] = $record->odds_dnb->min('dnb1');
|
|
$this->min['dnb2'] = $record->odds_dnb->min('dnb2');
|
|
break;
|
|
|
|
case 'odds_ggng':
|
|
$this->max['gg'] = $record->odds_ggng->max('gg');
|
|
$this->max['ng'] = $record->odds_ggng->max('ng');
|
|
$this->min['gg'] = $record->odds_ggng->min('gg');
|
|
$this->min['ng'] = $record->odds_ggng->min('ng');
|
|
break;
|
|
case 'odds_points':
|
|
case 'odds_points_ht':
|
|
case 'odds_points_q1':
|
|
$this->max['home'] = $record->odds_points->max('home');
|
|
$this->max['away'] = $record->odds_points->max('away');
|
|
$this->min['home'] = $record->odds_points->min('home');
|
|
$this->min['away'] = $record->odds_points->min('away');
|
|
break;
|
|
|
|
case 'odds_totals':
|
|
case 'odds_totals_ht':
|
|
case 'odds_totals_q1':
|
|
$this->max['over'] = $record->odds_totals->max('over');
|
|
$this->max['under'] = $record->odds_totals->max('under');
|
|
$this->min['over'] = $record->odds_totals->min('over');
|
|
$this->min['under'] = $record->odds_totals->min('under');
|
|
break;
|
|
|
|
case 'odds_tq':
|
|
$this->max['htq'] = $record->odds_tq->max('htq');
|
|
$this->max['atq'] = $record->odds_tq->max('atq');
|
|
$this->min['htq'] = $record->odds_tq->min('htq');
|
|
$this->min['atq'] = $record->odds_tq->min('atq');
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function setCompare($record)
|
|
{
|
|
$this->compare = null;
|
|
|
|
$this->data->filter(function ($model) {
|
|
|
|
if ($model->flags == 1 && $model->bookmaker_id != auth()->user()->bookmaker_id) {
|
|
|
|
$filter = $this->filter[$model->bookmaker_id] ?? 0;
|
|
|
|
if ($filter) {
|
|
if ($this->bettype == 'odds_dc') {
|
|
if ($model->margin <= $filter['margin'] * 2) {
|
|
$this->compare = $this->data->where('bookmaker_id', $model->bookmaker_id)->first();
|
|
$this->compare_bookmaker_id = $model->bookmaker_id;
|
|
|
|
return;
|
|
}
|
|
} else {
|
|
if ($model->margin <= $filter['margin']) {
|
|
$this->compare = $this->data->where('bookmaker_id', $model->bookmaker_id)->first();
|
|
$this->compare_bookmaker_id = $model->bookmaker_id;
|
|
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public function setPartnerIcon()
|
|
{
|
|
$this->partner_icon = Bookmaker::where('id', auth()->user()->partner_bookmaker_id)->value('icon');
|
|
}
|
|
|
|
public function setSlots()
|
|
{
|
|
$this->slots = EventsTable::$slots[$this->bettype];
|
|
|
|
$this->bookmaker = EventsTable::$bookmaker[$this->bettype];
|
|
|
|
$this->filter = EventsTable::$filter[$this->bettype];
|
|
}
|
|
}
|