Skip to content

Commit

Permalink
Adds the Serialiser for the SnippetTemplateField
Browse files Browse the repository at this point in the history
  • Loading branch information
terwey committed Apr 28, 2014
1 parent a429b20 commit 62f29cd
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 12 deletions.
3 changes: 1 addition & 2 deletions newscoop/library/Newscoop/Entity/Snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ class Snippet
protected $name;

/**
* @ORM\OneToMany(targetEntity="Newscoop\Entity\Snippet\SnippetField", mappedBy="snippet", cascade={"persist", "remove"}, indexBy="name")
* @ORM\OneToMany(targetEntity="Newscoop\Entity\Snippet\SnippetField", mappedBy="snippet", cascade={"persist", "remove"}, indexBy="fieldName")
* @var Doctrine\Common\Collections\ArrayCollection
* @Type("ArrayCollection<string, Newscoop\Entity\Snippet\SnippetField>")
*/
protected $fields;

Expand Down
2 changes: 1 addition & 1 deletion newscoop/library/Newscoop/Entity/Snippet/SnippetField.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SnippetField
protected $id;

/**
* @ORM\ManyToOne(targetEntity="Newscoop\Entity\Snippet", inversedBy="templateFields")
* @ORM\ManyToOne(targetEntity="Newscoop\Entity\Snippet", inversedBy="fields")
* @ORM\JoinColumn(name="SnippetId", referencedColumnName="Id", nullable=false)
* @var Newscoop\Entity\Snippet
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SnippetTemplate
protected $controller;

/**
* @ORM\OneToMany(targetEntity="Newscoop\Entity\Snippet\SnippetTemplate\SnippetTemplateField", mappedBy="template", cascade={"persist"})
* @ORM\OneToMany(targetEntity="Newscoop\Entity\Snippet\SnippetTemplate\SnippetTemplateField", mappedBy="template", cascade={"persist"}, indexBy="templateFieldName")
* @var Doctrine\Common\Collections\ArrayCollection
*/
protected $fields;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SnippetTemplateField
* @ORM\Column(name="Name", type="string")
* @var string
*/
protected $name;
protected $templateFieldName;

/**
* @ORM\Column(name="Type", type="string")
Expand Down Expand Up @@ -89,19 +89,19 @@ public function setId($id)
*/
public function getName()
{
return $this->name;
return $this->templateFieldName;
}

/**
* Setter for name
*
* @param string $name
* @param string $templateFieldName
*
* @return Newscoop\Entity\Snippet\SnippetTemplate\SnippetTemplateField
*/
public function setName($name)
public function setName($templateFieldName)
{
$this->name = $name;
$this->templateFieldName = $templateFieldName;

return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function getSnippetAction($id, $show)
* @Route("/articles/{number}/{language}/snippets.{_format}/{show}", defaults={"_format"="json", "show"="enabled"})
* @Route("/snippets/article/{number}/{language}.{_format}/{show}", defaults={"_format"="json", "show"="enabled"})
* @Method("GET")
* @View(serializerGroups={"details"})
* @View(serializerGroups={"list"})
*/
public function getSnippetsForArticleAction(Request $request, $number, $language, $show)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Newscoop\Entity\Snippet:
read_only: true
groups: ["details", "list"]
serialized_name: fields
type: ArrayCollection<string, Newscoop\Entity\Snippet\SnippetField>
accessor:
getter: getFields
template:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,59 @@ Newscoop\Entity\Snippet\SnippetTemplate:
type: string
groups: ["details", "list"]
serialized_name: name
template:
controller:
expose: true
ready_only: true
type: string
groups: ["details"]
serialized_name: controller
templateCode:
expose: true
read_only: true
type: string
groups: ["details"]
serialized_name: template
fields:
expose: true
read_only: true
groups: ["details", "list"]
serialized_name: fields
type: ArrayCollection<string, Newscoop\Entity\Snippet\SnippetTemplate\SnippetTemplateField>
accessor:
getter: getFields
favourite:
expose: true
read_only: true
type: boolean
groups: ["details", "list"]
serialized_name: template
serialized_name: favourite
enabled:
expose: true
read_only: true
type: boolean
groups: ["list", "details"]
serialized_name: enabled
iconInactive:
expose: true
read_only: true
type: string
groups: ["details"]
serialized_name: iconInactive
iconActive:
expose: true
read_only: true
type: string
groups: ["details"]
serialized_name: iconActive
created:
expose: true
read_only: true
type: DateTime
groups: ["details"]
serialized_name: created
modified:
expose: true
read_only: true
type: DateTime
groups: ["details"]
serialized_name: modified
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Newscoop\Entity\Snippet\SnippetTemplate\SnippetTemplateField:
exclusion_policy: ALL
properties:
id:
expose: true
read_only: true
type: integer
groups: ["details"]
serialized_name: id
templateFieldName:
expose: true
read_only: true
type: string
groups: ["details", "list"]
serialized_name: name
type:
expose: true
read_only: true
type: string
groups: ["details", "list"]
serialized_name: type
scope:
expose: true
read_only: true
type: string
groups: ["details", "list"]
serialized_name: scope

0 comments on commit 62f29cd

Please sign in to comment.