Skip to content

Commit

Permalink
#5 Some relationships made bidirectional.
Browse files Browse the repository at this point in the history
  • Loading branch information
automatix committed Jul 1, 2018
1 parent 2011172 commit 59975aa
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 3 deletions.
Binary file modified docs/database/riquest_generated.mwb
Binary file not shown.
Binary file modified docs/database/riquest_generated.mwb.bak
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Base/Entity/Answer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Answer extends AbstractEntity
/**
* @var QuestionTask
*
* @ORM\ManyToOne(targetEntity="App\Base\Entity\Tasks\QuestionTask")
* @ORM\ManyToOne(targetEntity="App\Base\Entity\Tasks\QuestionTask", inversedBy="answers")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="question_id", referencedColumnName="id", nullable=false)
* })
Expand Down
2 changes: 1 addition & 1 deletion src/Base/Entity/ContentBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class ContentBlock extends AbstractEntity
/**
* @var Message
*
* @ORM\ManyToOne(targetEntity="Message")
* @ORM\ManyToOne(targetEntity="Message", inversedBy="contentBlocks")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="message_id", referencedColumnName="id", nullable=false)
* })
Expand Down
39 changes: 38 additions & 1 deletion src/Base/Entity/Message.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace App\Base\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
Expand All @@ -22,13 +24,26 @@ class Message extends AbstractEntity
/**
* @var MessageStack
*
* @ORM\ManyToOne(targetEntity="MessageStack")
* @ORM\ManyToOne(targetEntity="MessageStack", inversedBy="messages")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="message_stack_id", referencedColumnName="id", nullable=false)
* })
*/
private $messageStack;

/**
* @var Collection
*
* @ORM\OneToMany(targetEntity="App\Base\Entity\ContentBlock", mappedBy="message")
*/
private $contentBlocks;

public function __construct()
{
parent::__construct();
$this->contentBlocks = new ArrayCollection();
}

public function getOrder(): ?int
{
return $this->order;
Expand All @@ -50,4 +65,26 @@ public function setMessageStack(?MessageStack $messageStack): self
$this->messageStack = $messageStack;
return $this;
}

public function getContentBlocks(): Collection
{
return $this->contentBlocks;
}

public function addContentBlock(ContentBlock $contentBlock): self
{
if (!$this->contentBlocks->contains($contentBlock)) {
$this->contentBlocks[] = $contentBlock;
}
return $this;
}

public function removeContentBlock(ContentBlock $contentBlock): self
{
if ($this->contentBlocks->contains($contentBlock)) {
$this->contentBlocks->removeElement($contentBlock);
}
return $this;
}

}
35 changes: 35 additions & 0 deletions src/Base/Entity/MessageStack.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace App\Base\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
Expand All @@ -18,5 +20,38 @@
abstract class MessageStack extends AbstractEntity
{

/**
* @var Collection
*
* @ORM\OneToMany(targetEntity="App\Base\Entity\Message", mappedBy="messageStack")
*/
private $messages;

public function __construct()
{
parent::__construct();
$this->messages = new ArrayCollection();
}

public function getMessages(): Collection
{
return $this->messages;
}

public function addMessage(Message $message): self
{
if (!$this->messages->contains($message)) {
$this->messages[] = $message;
}
return $this;
}

public function removeMessage(Message $message): self
{
if ($this->messages->contains($message)) {
$this->messages->removeElement($message);
}
return $this;
}

}
38 changes: 38 additions & 0 deletions src/Base/Entity/Tasks/QuestionTask.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php
namespace App\Base\Entity\Tasks;

use App\Base\Entity\Answer;
use App\Base\Entity\Task;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
Expand All @@ -19,6 +22,19 @@ class QuestionTask extends Task
*/
private $text;

/**
* @var Collection
*
* @ORM\OneToMany(targetEntity="App\Base\Entity\Answer", mappedBy="question")
*/
private $answers;

public function __construct()
{
parent::__construct();
$this->answers = new ArrayCollection();
}

public function getText(): ?string
{
return $this->text;
Expand All @@ -29,4 +45,26 @@ public function setText(?string $text): self
$this->text = $text;
return $this;
}

public function getAnswers(): Collection
{
return $this->answers;
}

public function addAnswer(Answer $answer): self
{
if (!$this->answers->contains($answer)) {
$this->answers[] = $answer;
}
return $this;
}

public function removeAnswer(Answer $answer): self
{
if ($this->answers->contains($answer)) {
$this->answers->removeElement($answer);
}
return $this;
}

}

0 comments on commit 59975aa

Please sign in to comment.