Added functionality to create joins using OOD

This commit is contained in:
Christian Wolf 2019-05-29 18:11:14 +02:00
parent d93a02e779
commit 4fa01d4cc0
5 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,62 @@
<?php
// No direct access.
defined('_JEXEC') or die;
abstract class AbstractCommonClubsModelJoin
{
protected $tablename;
protected $alias;
protected $condition;
/**
* @var AbstractCommonClubsModelColumn[]
*/
protected $columns;
public function getAlias()
{
return $this->alias;
}
public function getTableName()
{
return $this->tablename;
}
public function getOnCondition()
{
return $this->condition;
}
public function getColumns()
{
return $this->columns;
}
/**
*
* @param JDatabaseQuery $q
*/
public function join($q)
{
$str = "{$this->tablename} AS {$this->alias}";
if(isset($this->condition))
$str .= " ON {$this->condition}";
$this->addJoin($q, $str);
foreach($this->columns as $c)
{
$qc = $q->q("{$this->alias}." . $c->getColumn(), $c->getAlias());
$q->select($qc);
}
}
/**
*
* @param JDatabaseQuery $q
* @param String $str
*/
protected abstract function addJoin($q, $str);
}

View File

@ -0,0 +1,12 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class CommonClubsModelJoinInner extends AbstractCommonClubsModelJoin
{
protected function addJoin($q, $str)
{
$q->innerJoin($str);
}
}

View File

@ -0,0 +1,12 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class CommonClubsModelJoinLeft extends AbstractCommonClubsModelJoin
{
protected function addJoin($q, $str)
{
$q->leftJoin($str);
}
}

View File

@ -0,0 +1,12 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class CommonClubsModelJoinOuter extends AbstractCommonClubsModelJoin
{
protected function addJoin($q, $str)
{
$q->outerJoin($str);
}
}

View File

@ -0,0 +1,12 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class CommonClubsModelJoinRight extends AbstractCommonClubsModelJoin
{
protected function addJoin($q, $str)
{
$q->rightJoin($str);
}
}