2023-10-26 20:26:28 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Tournament extends Model
|
|
|
|
{
|
|
|
|
protected $dbTable = "tournaments";
|
|
|
|
protected $dbFields = array(
|
|
|
|
'registered' => ['type' => 'datetime', 'required', 'unique', 'autoValMethod' => 'getDateTime'],
|
|
|
|
'name' => ['type' => 'text', 'required'],
|
|
|
|
'date' => ['type' => 'datetime','required'],
|
|
|
|
'duration' => ['type' => 'int'], //in days
|
|
|
|
'text' => ['type' => 'text'],
|
|
|
|
'url' => ['type' => 'text'], //if there is one
|
2023-10-26 21:32:37 +02:00
|
|
|
'logo' => ['type' => 'text', 'default' => 'https://pictshare.net/prrnrk.jpg'],
|
|
|
|
'admins' => ['type'=> 'array', 'default'=>[]],
|
2023-10-27 11:52:31 +02:00
|
|
|
'members' => ['type'=> 'array', 'default'=>[]],
|
2023-10-30 22:20:13 +01:00
|
|
|
'runs' => ['type'=> 'array', 'default'=>[]],
|
2023-10-26 20:26:28 +02:00
|
|
|
);
|
|
|
|
|
2023-10-27 11:52:31 +02:00
|
|
|
function joinUser($tournament = false)
|
|
|
|
{
|
|
|
|
if ($tournament == false)
|
|
|
|
$tournament = $this->id;
|
|
|
|
|
|
|
|
if (!$this->exists($tournament))
|
|
|
|
return false;
|
|
|
|
else {
|
|
|
|
if (!in_array($_SESSION['user']->id, $this->data['members']))
|
|
|
|
$this->data['members'][] = $_SESSION['user']->id;
|
|
|
|
if(!in_array($tournament,$_SESSION['user']->data['tournaments']))
|
|
|
|
{
|
|
|
|
$_SESSION['user']->data['tournaments'][] = $tournament;
|
|
|
|
$_SESSION['user']->save();
|
|
|
|
}
|
|
|
|
$this->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeUser($tournament = false)
|
|
|
|
{
|
|
|
|
if ($tournament == false)
|
|
|
|
$tournament = $this->id;
|
|
|
|
|
|
|
|
if (!$this->exists($tournament))
|
|
|
|
return false;
|
|
|
|
else {
|
|
|
|
if (in_array($_SESSION['user']->id, $this->data['members']))
|
|
|
|
$this->data['members'] = array_diff($this->data['members'],[$_SESSION['user']->id]);
|
|
|
|
if(in_array($tournament,$_SESSION['user']->data['tournaments']))
|
|
|
|
{
|
|
|
|
$_SESSION['user']->data['tournaments'] = array_diff($_SESSION['user']->data['tournaments'],[$tournament]);
|
|
|
|
$_SESSION['user']->save();
|
|
|
|
}
|
|
|
|
$this->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-26 21:18:32 +02:00
|
|
|
function isMyEvent($tournament = false)
|
|
|
|
{
|
|
|
|
if ($tournament == false)
|
|
|
|
$tournament = $this->id;
|
|
|
|
|
|
|
|
if (!$this->exists($tournament))
|
|
|
|
return false;
|
|
|
|
else {
|
|
|
|
if (in_array($tournament, $_SESSION['user']->data['tournaments']))
|
|
|
|
return true;
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
}
|
2023-10-26 21:32:37 +02:00
|
|
|
|
|
|
|
function amIAdmin($tournament = false)
|
|
|
|
{
|
|
|
|
if ($tournament == false)
|
|
|
|
$tournament = $this->id;
|
|
|
|
|
|
|
|
if (!$this->exists($tournament))
|
|
|
|
return false;
|
|
|
|
else {
|
|
|
|
if (in_array($_SESSION['user']->id, $this->data['admins']))
|
|
|
|
return true;
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
}
|
2023-10-27 11:52:31 +02:00
|
|
|
|
|
|
|
function getAdmins($tournament = false)
|
|
|
|
{
|
|
|
|
if ($tournament == false)
|
|
|
|
$tournament = $this->id;
|
|
|
|
|
|
|
|
if (!$this->exists($tournament))
|
|
|
|
return false;
|
|
|
|
else {
|
|
|
|
$admins = [];
|
|
|
|
foreach($this->data['admins'] as $admin)
|
|
|
|
{
|
|
|
|
$u = new User();
|
|
|
|
$u->load($admin);
|
|
|
|
$admins[] = $u->getDataFiltered();
|
|
|
|
}
|
|
|
|
return $admins;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getMembers($tournament = false)
|
|
|
|
{
|
|
|
|
if ($tournament == false)
|
|
|
|
$tournament = $this->id;
|
|
|
|
|
|
|
|
if (!$this->exists($tournament))
|
|
|
|
return false;
|
|
|
|
else {
|
|
|
|
$members = [];
|
|
|
|
foreach($this->data['members'] as $member)
|
|
|
|
{
|
|
|
|
$u = new User();
|
|
|
|
$u->load($member);
|
|
|
|
$members[] = $u->getDataFiltered();
|
|
|
|
}
|
|
|
|
return $members;
|
|
|
|
}
|
|
|
|
}
|
2023-10-26 20:26:28 +02:00
|
|
|
}
|