Inserted basic structure for clubs and models

This commit is contained in:
2019-04-17 16:41:28 +02:00
parent b08b01689f
commit 893dc754f0
7 changed files with 788 additions and 0 deletions

View File

@@ -0,0 +1,191 @@
<?php
// No direct access.
use Joomla\CMS\Factory;
defined('_JEXEC') or die;
class ClubsPlace
{
protected $id;
protected $name;
protected $address;
protected $area;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* @return string
*/
public function getArea()
{
return $this->area;
}
/**
* @param string $address
*/
public function setAddress(string $address)
{
$this->address = $address;
}
/**
* @param string $area
*/
public function setArea(string $area)
{
$this->area = $area;
}
protected function loadData(array $data)
{
$this->id = $data['id'];
$this->name = $data['name'];
}
protected function __construct()
{}
public static function loadOffers()
{
$dbo = Factory::getDbo();
$q = $dbo->getQuery(true);
$q->select('*')
->from('#__club_offers');
$dbo->setQuery($q);
$dbo->execute();
$list = $dbo->loadAssocList('id');
$ret = array();
foreach($list as $o)
{
$oo = new ClubsOffer();
$oo->loadData($o);
$ret[] = $oo;
}
return $ret;
}
public static function loadOffer(int $id)
{
$dbo = Factory::getDbo();
$q = $dbo->getQuery(true);
$q->select('*')->from('#__club_offers')->where('id=' . (int) $id);
$dbo->setQuery($q);
$dbo->execute();
$row = $dbo->loadAssoc();
if($row == null)
{
throw new Exception("No offer found.");
// TODO
}
$offer = new ClubsOffer();
$offer->loadData($row);
return $offer;
}
public static function createOffer()
{
$offer = new ClubsOffer();
$offer->id = 'new';
return $offer;
}
public function save()
{
if($this->id === 'new')
$this->insertOffer();
else
$this->updateOffer();
}
private function insertOffer()
{
$dbo = Factory::getDbo();
$q = $dbo->getQuery(true);
$vname = $q->q($this->name);
$q->insert('#__club_offers')
->columns(array('name'))
->values("$vname")
;
$dbo->transactionStart();
$dbo->setQuery($q);
$dbo->execute();
$this->id = $dbo->insertid();
$dbo->transactionCommit();
}
private function updateOffer()
{
$dbo = Factory::getDbo();
$q = $dbo->getQuery(true);
$vname = $q->q($this->name);
$q->update('#__club_offers')
->set(array(
"name=$vname"
))
->where("id=". (int) $this->id)
;
$dbo->setQuery($q);
$dbo->execute();
}
public function delete()
{
if($this->id === 'new')
return;
$dbo = Factory::getDbo();
$q = $dbo->getQuery(true);
$q->delete('#__club_offers')
->where('id=' . (int) $this->id);
$dbo->setQuery($q);
$dbo->execute();
}
}