Successfully tested create, update and delete of trivial elements
This commit is contained in:
parent
23941f32d3
commit
8b25925ec4
@ -6,6 +6,9 @@ use Joomla\CMS\Factory;
|
|||||||
// No direct access.
|
// No direct access.
|
||||||
defined('_JEXEC') or die;
|
defined('_JEXEC') or die;
|
||||||
|
|
||||||
|
class AssociatedObjectUnsavedException extends Exception
|
||||||
|
{}
|
||||||
|
|
||||||
abstract class AbstractCommonClubsModel
|
abstract class AbstractCommonClubsModel
|
||||||
{
|
{
|
||||||
// TODO Adddata validator
|
// TODO Adddata validator
|
||||||
@ -27,9 +30,9 @@ abstract class AbstractCommonClubsModel
|
|||||||
|
|
||||||
private $values = null;
|
private $values = null;
|
||||||
|
|
||||||
protected function getValues()
|
protected function getValues($force = false)
|
||||||
{
|
{
|
||||||
if(is_null($this->values))
|
if(is_null($this->values) || $force)
|
||||||
$this->loadDataFromDatabase();
|
$this->loadDataFromDatabase();
|
||||||
|
|
||||||
return $this->values;
|
return $this->values;
|
||||||
@ -128,7 +131,14 @@ abstract class AbstractCommonClubsModel
|
|||||||
if(is_null($vals[$k]))
|
if(is_null($vals[$k]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
$vals[$k] = $vals[$k]->getId();
|
$id = $vals[$k]->getId();
|
||||||
|
|
||||||
|
if($id === 'new')
|
||||||
|
{
|
||||||
|
throw new AssociatedObjectUnsavedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$vals[$k] = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $vals;
|
return $vals;
|
||||||
|
@ -36,9 +36,9 @@ abstract class AbstractCommonClubsModelFactory
|
|||||||
public abstract function getAttributes();
|
public abstract function getAttributes();
|
||||||
|
|
||||||
private $attributes = null;
|
private $attributes = null;
|
||||||
private function fetchAttributes()
|
private function fetchAttributes($force = False)
|
||||||
{
|
{
|
||||||
if($this->attributes === null)
|
if($this->attributes === null || $force)
|
||||||
$this->attributes = $this->getAttributes();
|
$this->attributes = $this->getAttributes();
|
||||||
|
|
||||||
return $this->attributes;
|
return $this->attributes;
|
||||||
|
@ -34,4 +34,10 @@ class CommonClubsModelPlace extends AbstractCommonClubsModel
|
|||||||
{
|
{
|
||||||
$this->setValue('area', $area);
|
$this->setValue('area', $area);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setClub($club)
|
||||||
|
{
|
||||||
|
$this->setValue('club', $club);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -17,3 +17,6 @@ ClubName: <?php echo $this->club->getPresident()->getName(); ?> <br />
|
|||||||
<?php foreach($this->club->getPlaces() as $place): ?>
|
<?php foreach($this->club->getPlaces() as $place): ?>
|
||||||
Place: <?php echo $place->getName(); ?><br>
|
Place: <?php echo $place->getName(); ?><br>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
|
<h1>Output</h1>
|
||||||
|
<pre><?php print_r($this->log); ?></pre>
|
@ -14,6 +14,8 @@ class ClubsViewTest extends HtmlView
|
|||||||
{
|
{
|
||||||
ToolbarHelper::title('Test');
|
ToolbarHelper::title('Test');
|
||||||
|
|
||||||
|
$this->log = '';
|
||||||
|
|
||||||
$factory = new CommonClubsModelFactoryClub();
|
$factory = new CommonClubsModelFactoryClub();
|
||||||
$this->clubs = $factory->loadElements();
|
$this->clubs = $factory->loadElements();
|
||||||
|
|
||||||
@ -27,6 +29,20 @@ class ClubsViewTest extends HtmlView
|
|||||||
// $places[0]->setName("abc");
|
// $places[0]->setName("abc");
|
||||||
// $places[0]->save();
|
// $places[0]->save();
|
||||||
|
|
||||||
|
$pfactory = new CommonClubsModelFactoryPlace();
|
||||||
|
$np = $pfactory->createNew();
|
||||||
|
$np->setName('MyName');
|
||||||
|
$np->setClub($c);
|
||||||
|
//$np->save();
|
||||||
|
$np->getId();
|
||||||
|
|
||||||
|
$np = $c->getPlaces()[1];
|
||||||
|
$np->getName();
|
||||||
|
$np->setName('foo2 with new Name');
|
||||||
|
// $np->save();
|
||||||
|
// $np->delete();
|
||||||
|
$this->log = $np;
|
||||||
|
|
||||||
parent::display($tpl);
|
parent::display($tpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user