Made user class work with abstract classes
This commit is contained in:
@@ -34,7 +34,7 @@ abstract class AbstractClubsController extends BaseController
|
||||
$this->filterPreCheck($values);
|
||||
|
||||
// Check the input data
|
||||
$error = ! $this->checkDataIsValid($values, true);
|
||||
$error = ! $this->checkDataIsValid($values, true, Null);
|
||||
|
||||
$view = $this->getNameOfView();
|
||||
|
||||
@@ -66,7 +66,7 @@ abstract class AbstractClubsController extends BaseController
|
||||
$this->filterPreCheck($values);
|
||||
|
||||
// Check the input data
|
||||
$error = ! $this->checkDataIsValid($values, false);
|
||||
$error = ! $this->checkDataIsValid($values, false, $obj);
|
||||
|
||||
$view = $this->getNameOfView();
|
||||
|
||||
@@ -101,7 +101,7 @@ abstract class AbstractClubsController extends BaseController
|
||||
|
||||
protected function filterPreCheck(&$values){}
|
||||
|
||||
protected function checkDataIsValid($values, bool $isNew)
|
||||
protected function checkDataIsValid($values, bool $isNew, $obj)
|
||||
{
|
||||
$error = false;
|
||||
// Check existence of the required fields
|
||||
@@ -147,7 +147,10 @@ abstract class AbstractClubsController extends BaseController
|
||||
|
||||
$data = array();
|
||||
foreach($this->getDataMapping() as $m => $i)
|
||||
$data[$m] = $values[$m];
|
||||
{
|
||||
if(isset($values[$m]))
|
||||
$data[$m] = $values[$m];
|
||||
}
|
||||
|
||||
return urlencode(json_encode($data));
|
||||
}
|
||||
@@ -156,7 +159,12 @@ abstract class AbstractClubsController extends BaseController
|
||||
|
||||
public function applyData($obj, $values)
|
||||
{
|
||||
foreach($this->getDataMapping() as $m => $v)
|
||||
$this->applyDataToObject($obj, $values, $this->getDataMapping());
|
||||
}
|
||||
|
||||
protected function applyDataToObject($obj, $values, $mapping)
|
||||
{
|
||||
foreach($mapping as $m => $v)
|
||||
{
|
||||
$functionName = $this->getSetterMethodName($m, $v);
|
||||
|
||||
@@ -165,14 +173,14 @@ abstract class AbstractClubsController extends BaseController
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = (isset($values[$m])) ? $values[$m] : null;
|
||||
$value = (isset($values[$m]) && strlen($values[$m]) > 0) ? $values[$m] : null;
|
||||
$obj->$functionName($value);
|
||||
}
|
||||
}
|
||||
|
||||
private function getSetterMethodName($m, $options)
|
||||
{
|
||||
if(isset($options['setter']))
|
||||
if(array_key_exists('setter', $options))
|
||||
return $options['setter'];
|
||||
|
||||
$firstChar = substr($m, 0, 1);
|
||||
|
||||
Reference in New Issue
Block a user