*/
public function getEntriesTagsAction(Entry $entry)
{
+ $json = $this->get('serializer')->serialize($entry, 'json');
+
+ return new Response($json, 200, array('application/json'));
}
/**
namespace Wallabag\CoreBundle\Entity;
+use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Hateoas\Configuration\Annotation as Hateoas;
*/
private $user;
+ /**
+ * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist", "merge"})
+ * @ORM\JoinTable(name="tags_entries",
+ * joinColumns={@ORM\JoinColumn(name="entry_id", referencedColumnName="id")},
+ * inverseJoinColumns={@ORM\JoinColumn(name="tag_id", referencedColumnName="id")}
+ * )
+ */
+ private $tags;
+
/*
* @param User $user
*/
public function __construct(User $user)
{
$this->user = $user;
+ $this->tags = new ArrayCollection();
}
/**
{
$this->isPublic = $isPublic;
}
+
+ /**
+ * @return ArrayCollection<Tag>
+ */
+ public function getTags()
+ {
+ return $this->tags;
+ }
+
+ /**
+ * @param Tag $tag
+ */
+ public function addTag(Tag $tag)
+ {
+ $this->tags[] = $tag;
+ }
}
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\XmlRoot;
+use JMS\Serializer\Annotation\ExclusionPolicy;
+use JMS\Serializer\Annotation\Expose;
/**
* Tag
* @XmlRoot("tag")
* @ORM\Table(name="tag")
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TagRepository")
+ * @ExclusionPolicy("all")
*/
class Tag
{
/**
* @var integer
*
+ * @Expose
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
/**
* @var string
*
+ * @Expose
* @ORM\Column(name="label", type="text")
*/
private $label;
+ /**
+ * @ORM\ManyToMany(targetEntity="Entry", mappedBy="tags", cascade={"persist", "merge"})
+ */
+ private $entries;
+
/**
* Get id
*
+++ /dev/null
-<?php
-
-namespace Wallabag\CoreBundle\Entity;
-
-use Doctrine\ORM\Mapping as ORM;
-
-/**
- * TagsEntries
- *
- * @ORM\Table(name="tags_entries")
- * @ORM\Entity
- */
-class TagsEntries
-{
- /**
- * @var integer
- *
- * @ORM\Column(name="id", type="integer")
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- private $id;
-
- /**
- * @var integer
- *
- * @ORM\Column(name="entry_id", type="integer")
- */
- private $entryId;
-
- /**
- * @var integer
- *
- * @ORM\Column(name="tag_id", type="integer")
- */
- private $tagId;
-
- /**
- * Get id
- *
- * @return integer
- */
- public function getId()
- {
- return $this->id;
- }
-
- /**
- * Set entryId
- *
- * @param integer $entryId
- * @return TagsEntries
- */
- public function setEntryId($entryId)
- {
- $this->entryId = $entryId;
-
- return $this;
- }
-
- /**
- * Get entryId
- *
- * @return integer
- */
- public function getEntryId()
- {
- return $this->entryId;
- }
-
- /**
- * Set tagId
- *
- * @param integer $tagId
- * @return TagsEntries
- */
- public function setTagId($tagId)
- {
- $this->tagId = $tagId;
-
- return $this;
- }
-
- /**
- * Get tagId
- *
- * @return integer
- */
- public function getTagId()
- {
- return $this->tagId;
- }
-}
class TagRepository extends EntityRepository
{
+ public function findByEntries($entryId)
+ {
+ $qb = $this->createQueryBuilder('t')
+ ->select('t')
+ ->leftJoin('t.id', 'u')
+ ->where('e.isStarred = true')
+ ->andWhere('u.id =:userId')->setParameter('userId', $userId)
+ ->orderBy('e.createdAt', 'desc')
+ ->getQuery();
+ $paginator = new Paginator($qb);
+
+ return $paginator;
+ }
}
$this->assertEquals(404, $client->getResponse()->getStatusCode());
}
-
- public function testGetOneTag()
- {
- $client = $this->createClient();
- $client->request('GET', '/api/salts/admin.json');
- $salt = json_decode($client->getResponse()->getContent());
-
- $headers = $this->generateHeaders('admin', 'test', $salt[0]);
-
- $tag = $client->getContainer()
- ->get('doctrine.orm.entity_manager')
- ->getRepository('WallabagCoreBundle:Tag')
- ->findOneByLabel('foo');
-
- if (!$tag) {
- $this->markTestSkipped('No content found in db.');
- }
-
- $client->request('GET', '/api/tags/'.$tag->getLabel().'.json', array(), array(), $headers);
-
- $this->assertEquals(json_encode($tag), $client->getResponse()->getContent());
-
- $this->assertTrue(
- $client->getResponse()->headers->contains(
- 'Content-Type',
- 'application/json'
- )
- );
- }
}