Added first association of clubs. Current structure does not allow for joins.

This commit is contained in:
Christian Wolf 2019-05-17 15:27:03 +02:00
parent c459e1d332
commit f8df0c3fc4
5 changed files with 120 additions and 3 deletions

View File

@ -29,12 +29,18 @@ abstract class AbstractClubsModel
$this->$m = $data[$m];
}
protected static function loadElements(string $tableName, string $className)
protected static function loadElements(string $tableName, string $className, $where = null)
{
$dbo = Factory::getDbo();
$q = $dbo->getQuery(true);
$q->select('*')
->from($tableName);
if(isset($where))
{
$q->where($where);
}
$dbo->setQuery($q);
$dbo->execute();
$list = $dbo->loadAssocList();
@ -60,7 +66,10 @@ abstract class AbstractClubsModel
{
$dbo = Factory::getDbo();
$q = $dbo->getQuery(true);
$q->select('*')->from($tableName)->where('id=' . (int) $id);
$q->select('*')->from($tableName);
$q->where('id=' . (int) $id);
$dbo->setQuery($q);
$dbo->execute();

View File

@ -198,7 +198,21 @@ class ClubsClub extends AbstractClubsModel
$club->id = 'new';
return $club;
}
public function getPlaces()
{
return ClubsPlace::loadPlacesOfClub($this->id);
}
public function getOffers()
{
}
protected function loadCustomData($assoc)

View File

@ -0,0 +1,73 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class ClubsOfferAssociation extends AbstractClubsModel
{
protected $offerid;
protected $clubid;
public function getOffer()
{
return ClubsOffer::loadOffer($this->offerid);
}
public function getClub()
{
return ClubsClub::loadClub($this->clubid);
}
public function setOffer($offer)
{
$this->offerid = $offer->getId();
}
public function getName()
{
return $this->getOffer()->getName();
}
public function setClub($club)
{
$this->clubid = $club->getId();
}
protected function __construct()
{}
private const tableName = '#__club_offer_assocs';
private const className = 'ClubsOfferAssociation';
public static function loadOfferAssociationsOfClub($club)
{
$cid = $club->getId();
return self::loadElements(self::tableName, self::className, "clubid = $cid");
// FIXME Use join to make access faster
}
public static function loadOfferAssociation(int $id)
{
return self::loadElement($id, self::tableName, self::className);
}
public static function createOfferAssociation()
{
$offer = new ClubsOfferAssociation();
// $offer->id = 'new';
return $offer;
}
protected function getDataMappings()
{
// return array('name');
}
protected function getTableName()
{
return self::tableName;
}
}

View File

@ -9,6 +9,7 @@ class ClubsPlace extends AbstractClubsModel
protected $name;
protected $address;
protected $area;
protected $clubid;
/**
* @return string
@ -57,6 +58,18 @@ class ClubsPlace extends AbstractClubsModel
{
$this->area = $area;
}
public function getClub()
{
return ClubsClub::loadClub($this->clubid);
}
public function setClub($club)
{
$this->clubid = $club->getId();
}
protected function __construct()
{}
@ -66,6 +79,10 @@ class ClubsPlace extends AbstractClubsModel
return self::loadElements(self::tableName, self::className);
}
public static function loadPlacesOfClub($clubId)
{
return self::loadElements(self::tableName, self::className, "clubid = $clubId");
}
public static function loadPlace(int $id)
{
@ -81,7 +98,7 @@ class ClubsPlace extends AbstractClubsModel
protected function getDataMappings()
{
return array('name', 'address', 'area');
return array('name', 'address', 'area', 'clubid');
}
private const tableName = '#__club_places';

View File

@ -34,6 +34,10 @@ class ClubsPosition extends AbstractClubsModel
return self::loadElements(self::tableName, self::className);
}
// public static function loadPositions($clubId)
// {
// return self::loadElements(self::tableName, self::className, "clubid = $clubId");
// }
public static function loadPosition(int $id)
{