1:n relations have been successfully read.

This commit is contained in:
Christian Wolf 2019-05-22 16:07:01 +02:00
parent cb624c19eb
commit 7c18f48b2a
6 changed files with 65 additions and 1 deletions

View File

@ -10,6 +10,8 @@ class ElementNotFoundException extends Exception
abstract class AbstractCommonClubsModelFactory
{
// TODO Attribures as objects allowing to use polymophism in filtering/parsing/checking/sql building
/*
* This method should return an array to configure the trivially accessible values.

View File

@ -56,5 +56,8 @@ class CommonClubsModelClub extends AbstractCommonClubsModel
return $this->getValues()['president'];
}
public function getPlaces()
{
return $this->fetchAssociatedElements(new CommonClubsModelFactoryPlace(), 'clubid');
}
}

View File

@ -0,0 +1,27 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class CommonClubsModelFactoryPlace extends AbstractCommonClubsModelFactory
{
public function getAttributes()
{
return array(
'name'=>array(),
'club'=>array('col'=>'clubid', 'type'=>'ref', 'ref'=>'CommonClubsModelClub')
);
}
public function getTableName()
{
return '#__club_places';
}
public function getClassName()
{
return 'CommonClubsModelPlace';
}
}

View File

@ -0,0 +1,23 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class CommonClubsModelPlace extends AbstractCommonClubsModel
{
protected function getFactory()
{
return new CommonClubsModelFactoryPlace();
}
public function getName()
{
return $this->getValues()['name'];
}
public function getClub()
{
return $this->getValues()['club'];
}
}

View File

@ -14,3 +14,6 @@ ClubName: <?php echo $this->club->getIban(); ?> <br />
ClubName: <?php echo $this->club->getBic(); ?> <br />
ClubName: <?php echo $this->club->isCharitable(); ?> <br />
ClubName: <?php echo $this->club->getPresident()->getName(); ?> <br />
<?php foreach($this->club->getPlaces() as $place): ?>
Place: <?php echo $place->getName(); ?><br>
<?php endforeach; ?>

View File

@ -19,6 +19,12 @@ class ClubsViewTest extends HtmlView
$this->club = $this->clubs[0];
$c = $this->club;
$p = $c->getPresident();
$id = $p->getId();
$places = $c->getPlaces();
parent::display($tpl);
}