Added second class to debug 1:n relation, which is working in general

This commit is contained in:
Christian Wolf 2019-05-22 15:47:10 +02:00
parent b868f0fe86
commit cb624c19eb
5 changed files with 54 additions and 4 deletions

View File

@ -141,10 +141,14 @@ abstract class AbstractCommonClubsModel
private function loadExternalReferenceAsObject($className, $value)
{
if(is_string($value) && preg_match('/^[0-9]+$/', $value))
$value = (int) $value;
if(! is_int($value))
throw new Exception('Reference with non-integer value');
$factory = $this->getFactoryOfClass($className);
$factoryName = $this->getFactoryNameOfClass($className);
$factory = new $factoryName();
return $factory->loadById($value);
}
@ -157,7 +161,7 @@ abstract class AbstractCommonClubsModel
* @param string $className
* @return AbstractCommonClubsModelFactory
*/
private function getFactoryOfClass($className)
private function getFactoryNameOfClass($className)
{
if(empty(self::CLASSNAME_MAP[$className]))
{

View File

@ -16,7 +16,7 @@ class CommonClubsModelFactoryClub extends AbstractCommonClubsModelFactory
'iban'=>array(),
'bic'=>array(),
'charitable'=>array('type'=>'int'),
'president'=>array('type'=>'int', 'ref'=>'CommonClubsModelUser')
'president'=>array('type'=>'ref', 'ref'=>'CommonClubsModelUser')
);
}

View File

@ -0,0 +1,27 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class CommonClubsModelFactoryUser extends AbstractCommonClubsModelFactory
{
public function getAttributes()
{
return array(
'user'=>array(),
'name'=>array()
);
}
public function getTableName()
{
return '#__club_users';
}
public function getClassName()
{
return 'CommonClubsModelUser';
}
}

View File

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

View File

@ -13,4 +13,4 @@ ClubName: <?php echo $this->club->getMail(); ?> <br />
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(); ?> <br />
ClubName: <?php echo $this->club->getPresident()->getName(); ?> <br />