Abstract list working in general, tested with single example
This commit is contained in:
@@ -11,6 +11,9 @@ abstract class AbstractClubsViewSingle extends HtmlView
|
||||
{
|
||||
|
||||
protected $address;
|
||||
/**
|
||||
* @var AbstractCommonClubsModel
|
||||
*/
|
||||
protected $object;
|
||||
protected $isNew;
|
||||
|
||||
@@ -23,32 +26,28 @@ abstract class AbstractClubsViewSingle extends HtmlView
|
||||
$input = Factory::getApplication()->input;
|
||||
$id = $input->get->get('id');
|
||||
|
||||
$modelClass = 'Clubs' . $this->getModelName();
|
||||
$controllerName = $this->getControllerName();
|
||||
|
||||
$controller = $this->getControllerName();
|
||||
if($id === 'new')
|
||||
{
|
||||
$this->address = Route::_("index.php?option=com_clubs&task={$controller}.new");
|
||||
$this->object = call_user_func(array($modelClass, 'create' . $this->getModelName()));
|
||||
$this->address = Route::_("index.php?option=com_clubs&task={$controllerName}.new");
|
||||
$this->object = $this->createNewObject();
|
||||
$this->isNew = true;
|
||||
}
|
||||
else if(is_numeric($id))
|
||||
{
|
||||
$this->address = Route::_("index.php?option=com_clubs&task={$controller}.change");
|
||||
$this->object = call_user_func(array($modelClass, 'load' . $this->getModelName()), (int) $id);
|
||||
$id = (int) $id;
|
||||
$this->address = Route::_("index.php?option=com_clubs&task={$controllerName}.change&id=$id");
|
||||
$this->object = $this->loadObject($id);
|
||||
$this->isNew = false;
|
||||
}
|
||||
else
|
||||
throw new Exception('Need an object id.');
|
||||
|
||||
if($input->get->get('data', null, 'json') != null)
|
||||
throw new Exception('Need a valid object id.');
|
||||
|
||||
$jsonData = $input->get->get('data', null, 'json');
|
||||
if($jsonData !== null)
|
||||
{
|
||||
// Restore previous data
|
||||
$dataurl = $input->get->get('data', null, 'json');
|
||||
$data = json_decode($dataurl, true);
|
||||
|
||||
$controller = $this->getElementController();
|
||||
$controller->applyData($this->object, $data);
|
||||
$this->object->unpack($jsonData);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -61,26 +60,45 @@ abstract class AbstractClubsViewSingle extends HtmlView
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
protected abstract function getViewName();
|
||||
// protected abstract function getViewName();
|
||||
|
||||
protected function getControllerName()
|
||||
protected abstract function getControllerName();
|
||||
|
||||
// protected function getModelName()
|
||||
// {
|
||||
// $name = $this->getViewName();
|
||||
// return $this->capitalize($name);
|
||||
// }
|
||||
|
||||
// protected function getModelClass()
|
||||
// {
|
||||
// return 'Clubs' . $this->getModelName();
|
||||
// }
|
||||
|
||||
// private function capitalize($s)
|
||||
// {
|
||||
// $first = substr($s, 0, 1);
|
||||
// $rest = substr($s, 1);
|
||||
// return strtoupper($first) . $rest;
|
||||
// }
|
||||
|
||||
// protected abstract function getElementController();
|
||||
|
||||
/**
|
||||
* @return AbstractCommonClubsModelFactory
|
||||
*/
|
||||
protected abstract function getFactory();
|
||||
|
||||
protected function createNewObject()
|
||||
{
|
||||
return $this->getViewName();
|
||||
$factory = $this->getFactory();
|
||||
return $factory->createNew();
|
||||
}
|
||||
|
||||
protected function getModelName()
|
||||
protected function loadObject($id)
|
||||
{
|
||||
$name = $this->getViewName();
|
||||
return $this->capitalize($name);
|
||||
$factory = $this->getFactory();
|
||||
return $factory->loadById($id);
|
||||
}
|
||||
|
||||
private function capitalize($s)
|
||||
{
|
||||
$first = substr($s, 0, 1);
|
||||
$rest = substr($s, 1);
|
||||
return strtoupper($first) . $rest;
|
||||
}
|
||||
|
||||
protected abstract function getElementController();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user