Change characterViewpoint to be one-to-one, bidirectional.

This commit is contained in:
Austen McDonald
2016-08-01 10:04:11 +00:00
parent a2fb425632
commit b38cc22094
2 changed files with 34 additions and 9 deletions
+9 -6
View File
@@ -47,7 +47,7 @@ class Character implements CharacterInterface, CreateableInterface
private $level = 1;
/** @OneToMany(targetEntity="CharacterProperty", mappedBy="owner", cascade={"persist"}) */
private $properties;
/** @OneToMany(targetEntity="CharacterViewpoint", mappedBy="owner", cascade={"persist"}) */
/** @OneToOne(targetEntity="CharacterViewpoint", mappedBy="owner", cascade={"persist"}) */
private $characterViewpoint;
/**
* @ManyToMany(targetEntity="MessageThread", inversedBy="participants", cascade={"persist"})
@@ -90,7 +90,6 @@ class Character implements CharacterInterface, CreateableInterface
public function __construct()
{
$this->properties = new ArrayCollection();
$this->characterViewpoint = new ArrayCollection();
$this->buffs = new ArrayCollection();
$this->messageThreads = new ArrayCollection();
}
@@ -253,11 +252,15 @@ class Character implements CharacterInterface, CreateableInterface
*/
public function getCharacterViewpoint()
{
if (count($this->characterViewpoint) === 0) {
return null;
}
return $this->characterViewpoint;
}
return $this->characterViewpoint->first();
/**
* Sets the current character viewpoint.
*/
public function setCharacterViewpoint(CharacterViewpoint $v)
{
$this->characterViewpoint = $v;
}
/**
+25 -3
View File
@@ -20,7 +20,7 @@ class CharacterViewpoint implements CreateableInterface
use Creator;
use SceneBasics;
/** @Id @ManyToOne(targetEntity="Character", inversedBy="id", cascade="persist") */
/** @Id @OneToOne(targetEntity="Character", inversedBy="characterViewpoint", cascade="persist") */
private $owner;
/** @Column(type="array") */
private $actions = [];
@@ -61,6 +61,10 @@ class CharacterViewpoint implements CreateableInterface
$this->setTitle($scene->getTitle());
$this->setDescription($scene->getDescription());
$this->setTemplate($scene->getTemplate());
$this->setActions([]);
$this->setAttachments([]);
$this->setData([]);
}
/**
@@ -81,6 +85,24 @@ class CharacterViewpoint implements CreateableInterface
$this->actions = $actions;
}
/**
* Returns all attachments.
* @return array
*/
public function getAttachments(): array
{
return $this->attachments;
}
/**
* Sets attachments.
* @param array $actions
*/
public function setAttachments(array $attachments)
{
$this->attachments = $attachments;
}
/**
* Returns all data
* @return array
@@ -126,8 +148,8 @@ class CharacterViewpoint implements CreateableInterface
public function findActionById(string $id)
{
foreach ($this->getActions() as $group) {
foreach ($group->getSctions() as $a) {
if ($a->getId() == $actionId) {
foreach ($group->getActions() as $a) {
if ($a->getId() == $id) {
return $a;
}
}