First approach to port user classes to abstract MVC classes as well

This commit is contained in:
2019-04-18 15:59:44 +02:00
parent 47c81d3ce9
commit 17e737b64c
4 changed files with 152 additions and 326 deletions

View File

@@ -34,7 +34,7 @@ abstract class AbstractClubsController extends BaseController
$this->filterPreCheck($values);
// Check the input data
$error = $this->checkData($values);
$error = ! $this->checkDataIsValid($values, true);
$view = $this->getNameOfView();
@@ -66,7 +66,7 @@ abstract class AbstractClubsController extends BaseController
$this->filterPreCheck($values);
// Check the input data
$error = $this->checkData($values);
$error = ! $this->checkDataIsValid($values, false);
$view = $this->getNameOfView();
@@ -101,7 +101,7 @@ abstract class AbstractClubsController extends BaseController
protected function filterPreCheck(&$values){}
protected function checkData($values)
protected function checkDataIsValid($values, bool $isNew)
{
$error = false;
// Check existence of the required fields
@@ -119,7 +119,7 @@ abstract class AbstractClubsController extends BaseController
}
}
return $error;
return ! $error;
}
protected function fieldValid($name, $value, $options)
@@ -142,18 +142,29 @@ abstract class AbstractClubsController extends BaseController
private function packData($values)
{
// FIXME Multiple bugs: filtering not working as expected and Mapping msut be checked
$this->filterPrePacking($values);
$data = array();
foreach($this->getDataMapping() as $i)
$data[$i] = $values[$i];
foreach($this->getDataMapping() as $m => $i)
$data[$m] = $values[$m];
return urlencode(json_encode($data));
}
protected function filterPrePacking(&$values){}
public function applyData($obj, $values)
{
foreach($this->getDataMapping() as $m => $v)
{
$functionName = $this->getSetterMethodName($m, $v);
if($functionName === null)
{
continue;
}
$value = (isset($values[$m])) ? $values[$m] : null;
$obj->$functionName($value);
}