Simple controllers (offer and position) are workign in the new oo format

This commit is contained in:
2019-06-04 16:51:50 +02:00
parent 616a0b7dd9
commit 16e7ed0bc0
17 changed files with 275 additions and 70 deletions

View File

@@ -0,0 +1,55 @@
<?php
// No direct access.
defined('_JEXEC') or die;
abstract class AbstractCommonClubsControllerMapping
{
protected $required;
protected $name;
public function __construct($name, $required = true)
{
$this->name = $name;
$this->required = $required;
}
/**
* @param mixed $value
* @return bool
*/
public function requiredDataAvailable($value)
{
if($this->required && ($value === null || $value === ''))
return false;
return true;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param JInput $input
* @param string $name
* @return string
*/
public abstract function getFilteredValue($input, $name);
/**
* @param mixed $value
* @return boolean
*/
public function rawValueValid($value)
{
return true;
}
}

View File

@@ -40,9 +40,12 @@ abstract class AbstractCommonClubsModel
return $this->new;
}
public function setValues($values)
public function setValues($values, $unpack = false)
{
$this->values = $values;
if($unpack)
$this->values = $this->unpackExternalReferencesFromKeys($values);
else
$this->values = $values;
}
protected function setValue($key, $value)
@@ -351,4 +354,9 @@ abstract class AbstractCommonClubsModel
$this->setValues($vals);
}
public function dataIsValid()
{
return true;
}
}

View File

@@ -8,7 +8,10 @@ abstract class AbstractCommonClubsModelColumn
protected $alias;
protected $column;
protected $required;
/**
* @var AbstractCommonClubsControllerMapping
*/
protected $filter;
public function getAlias()
{
@@ -20,17 +23,12 @@ abstract class AbstractCommonClubsModelColumn
return $this->column;
}
public function isRequired()
{
return $this->required;
}
public abstract function isSimpleType();
public function __construct($alias, $required = true, $column = null)
public function __construct($alias, $filter, $column = null)
{
$this->alias = $alias;
$this->required = $required;
$this->filter = $filter;
if(isset($column))
$this->column = $column;
else
@@ -71,4 +69,9 @@ abstract class AbstractCommonClubsModelColumn
return $value;
}
public function getFilter()
{
return $this->filter;
}
}

View File

@@ -0,0 +1,14 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class CommonClubsControllerMappingCmd extends AbstractCommonClubsControllerMapping
{
public function getFilteredValue($input, $name)
{
return $input->getCmd($name);
}
}

View File

@@ -0,0 +1,14 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class CommonClubsControllerMappingFloat extends AbstractCommonClubsControllerMapping
{
public function getFilteredValue($input, $name)
{
return $input->getFloat($name);
}
}

View File

@@ -0,0 +1,14 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class CommonClubsControllerMappingInt extends AbstractCommonClubsControllerMapping
{
public function getFilteredValue($input, $name)
{
return $input->getInt($name);
}
}

View File

@@ -0,0 +1,44 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class CommonClubsControllerMappingRef extends AbstractCommonClubsControllerMapping
{
/**
* @var AbstractCommonClubsModelFactory
*/
protected $factory;
/**
* @param string $name
* @param AbstractCommonClubsModelFactory $factory
* @param boolean $required
*/
public function __construct($name, $factory, $required = true)
{
parent::__construct($name, $required);
$this->factory = $factory;
}
public function getFilteredValue($input, $name)
{
return $input->getInt($name);
}
public function rawValueValid($value)
{
try
{
$this->factory->loadById((int) $value);
}
catch(ElementNotFoundException $e)
{
return false;
}
return true;
}
}

View File

@@ -0,0 +1,14 @@
<?php
// No direct access.
defined('_JEXEC') or die;
class CommonClubsControllerMappingString extends AbstractCommonClubsControllerMapping
{
public function getFilteredValue($input, $name)
{
return $input->getString($name);
}
}

View File

@@ -14,9 +14,9 @@ class CommonClubsModelColumnRef extends AbstractCommonClubsModelColumn
protected $className;
public function __construct($alias, $className, $required=true, $column=null)
public function __construct($alias, $className, $column=null)
{
parent::__construct($alias, $required, $column);
parent::__construct($alias, $column);
if(empty($className))
throw new Exception('Classname must be non-empty.');

View File

@@ -8,7 +8,7 @@ class CommonClubsModelFactoryOffer extends AbstractCommonClubsModelFactory
protected function fetchAttributes()
{
return array(
new CommonClubsModelColumnString('name')
new CommonClubsModelColumnString('name', new CommonClubsControllerMappingString('Bezeichnung'))
);
}

View File

@@ -8,7 +8,7 @@ class CommonClubsModelFactoryPosition extends AbstractCommonClubsModelFactory
protected function fetchAttributes()
{
return array(
new CommonClubsModelColumnString('name')
new CommonClubsModelColumnString('name', new CommonClubsControllerMappingString('Bezeichnung'))
);
}