Commit 9290248a authored by Hermann Mayer's avatar Hermann Mayer

Implemented 'sortable' Tags on Articles. (sortable = matchable)

parent 44784e62
......@@ -369,8 +369,9 @@ erreichen, oder über Google+.
->setAuthor($this->getReference('admin-user'))
->setIcon('icon-font')
->addTag(new Tag('Doctrine'))
->addTag(new Tag('Many-to-Many'))
->addTag(new Tag('Mapping'))
->addTag(new Tag('Entities'), Tag::MATCH_LOW)
->addTag(new Tag('Many-to-Many'), Tag::MATCH)
->addTag(new Tag('Mapping'), Tag::MATCH)
->addTag(new Tag('Sortierung'))
->addComment($comment)
;
......
......@@ -66,10 +66,15 @@ abstract class AbstractPage
protected $navigation;
/**
* @ORM\ManyToMany(targetEntity="Tag", inversedBy="pages", cascade={"persist"})
* @ORM\JoinTable(name="content_tags")
**/
protected $tags;
* @ORM\OneToMany(
* targetEntity="AbstractPageTag",
* mappedBy="abstractPage",
* cascade={"persist", "remove"},
* orphanRemoval=true
* )
* @ORM\OrderBy({"match" = "DESC"})
*/
protected $abstractPageTag;
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="pages")
......@@ -399,12 +404,17 @@ abstract class AbstractPage
/**
* Add tags
*
* @param Jity\HomepageBundle\Entity\Tag $tags
* @param Jity\HomepageBundle\Entity\Tag $tag
* @return AbstractPage
*/
public function addTag(\Jity\HomepageBundle\Entity\Tag $tags)
public function addTag(\Jity\HomepageBundle\Entity\Tag $tag, $match = null)
{
$this->tags[] = $tags;
// Build new relation object to handle join entity correct
$rel = new \Jity\HomepageBundle\Entity\AbstractPageTag($this, $tag);
$rel->setMatch($match);
// Add relation object to collection
$this->abstractPageTag[] = $rel;
return $this;
}
......@@ -414,9 +424,15 @@ abstract class AbstractPage
*
* @param Jity\HomepageBundle\Entity\Tag $tags
*/
public function removeTag(\Jity\HomepageBundle\Entity\Tag $tags)
public function removeTag(\Jity\HomepageBundle\Entity\Tag $tag)
{
$this->tags->removeElement($tags);
// Iterate over all join entities to find the correct
foreach ($this->abstractPageTag as $rel) {
if ($rel->getTag() === $tag) {
$this->abstractPageTag->removeElement($rel);
$rel->getTag()->removePage($this);
}
}
}
/**
......@@ -426,6 +442,16 @@ abstract class AbstractPage
*/
public function getTags()
{
return $this->tags;
$collection = new \Doctrine\Common\Collections\ArrayCollection();
foreach ($this->abstractPageTag as $rel) {
$tag = $rel->getTag();
$tag->match = $rel->getMatch();
$collection->add($tag);
}
return $collection;
}
}
<?php
namespace Jity\HomepageBundle\Entity;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Jity\HomepageBundle\Entity\AbstractPage;
use Jity\HomepageBundle\Entity\Tag;
/**
* @ORM\Entity
* @ORM\Table(name="contents_tags")
*/
class AbstractPageTag
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(
* targetEntity="AbstractPage",
* inversedBy="abstractPageTag",
* cascade={"persist"}
* )
* @ORM\JoinColumn(name="content_id", referencedColumnName="id", nullable=false)
**/
protected $abstractPage;
/**
* @ORM\ManyToOne(
* targetEntity="Tag",
* inversedBy="abstractPageTag",
* cascade={"persist"}
* )
* @ORM\JoinColumn(name="tag_id", referencedColumnName="id", nullable=false)
**/
protected $tag;
/**
* @ORM\Column(name="`match`", type="integer")
*/
protected $match;
/**
* __construct
*
* @param Sidebar $sidebar
* @param Section $section
* @access public
* @return void
*/
public function __construct(AbstractPage $page, Tag $tag)
{
$this->abstractPage = $page;
$this->tag = $tag;
$this->match = Tag::MATCH_HIGH;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set match
*
* @param integer $match
* @return SidebarSection
*/
public function setMatch($match)
{
if (in_array($match, array(Tag::MATCH_HIGH, Tag::MATCH, Tag::MATCH_LOW))) {
$this->match = $match;
}
return $this;
}
/**
* Get matching of this
*
* @return integer
*/
public function getMatch()
{
return $this->match;
}
/**
* Set page
*
* @param Jity\HomepageBundle\Entity\AbstractPage $page
* @return AbstractPageTag
*/
public function setPage(\Jity\HomepageBundle\Entity\AbstractPage $page)
{
$this->abstractPage = $page;
return $this;
}
/**
* Get sidebar
*
* @return Jity\HomepageBundle\Entity\AbstractPage
*/
public function getPage()
{
return $this->abstractPage;
}
/**
* Set tag
*
* @param Jity\HomepageBundle\Entity\Tag $tag
* @return AbstractPageTag
*/
public function setTag(\Jity\HomepageBundle\Entity\Tag $tag)
{
$this->tag = $tag;
return $this;
}
/**
* Get tag
*
* @return Jity\HomepageBundle\Entity\Tag
*/
public function getTag()
{
return $this->tag;
}
}
......@@ -142,4 +142,4 @@ class SidebarSection
{
return $this->section;
}
}
\ No newline at end of file
}
......@@ -13,6 +13,10 @@ use JMS\SerializerBundle\Annotation\Exclude;
*/
class Tag
{
const MATCH_HIGH = 100;
const MATCH = 66;
const MATCH_LOW = 33;
/**
* @ORM\Id
* @ORM\Column(type="integer")
......@@ -26,9 +30,20 @@ class Tag
protected $name;
/**
* @ORM\ManyToMany(targetEntity="AbstractPage", mappedBy="tags")
**/
protected $pages;
* @ORM\OneToMany(
* targetEntity="AbstractPageTag",
* mappedBy="tag",
* cascade={"persist", "remove"},
* orphanRemoval=true
* )
* @Exclude
*/
protected $abstractPageTag;
/**
* @var match
*/
public $match;
/**
......@@ -77,26 +92,37 @@ class Tag
}
/**
* Add pages
* Add page
*
* @param Jity\HomepageBundle\Entity\Page $pages
* @param Jity\HomepageBundle\Entity\Page $page
* @return Tag
*/
public function addPage(\Jity\HomepageBundle\Entity\AbstractPage $pages)
public function addPage(\Jity\HomepageBundle\Entity\AbstractPage $page, $match = null)
{
$this->pages[] = $pages;
// Build new relation object to handle join entity correct
$rel = new \Jity\HomepageBundle\Entity\AbstractPageTag($page, $this);
$rel->setMatch($match);
// Add relation object to collection
$this->abstractPageTag[] = $rel;
return $this;
}
/**
* Remove pages
* Remove page
*
* @param Jity\HomepageBundle\Entity\Page $pages
* @param Jity\HomepageBundle\Entity\Page $page
*/
public function removePage(\Jity\HomepageBundle\Entity\AbstractPage $pages)
public function removePage(\Jity\HomepageBundle\Entity\AbstractPage $page)
{
$this->pages->removeElement($pages);
// Iterate over all join entities to find the correct
foreach ($this->abstractPageTag as $rel) {
if ($rel->getPage() === $page) {
$this->abstractPageTag->removeElement($rel);
$rel->getPage()->removeTag($this);
}
}
}
/**
......@@ -106,6 +132,13 @@ class Tag
*/
public function getPages()
{
return $this->pages;
$collection = new \Doctrine\Common\Collections\ArrayCollection();
foreach ($this->abstractPageTag as $rel) {
$collection->add($rel->getPage());
}
return $collection;
}
}
......@@ -69,6 +69,10 @@ input[type="url"], input[type="search"], input[type="tel"], input[type="color"],
color: #F9F9F9;
}
.label-warning, .badge-warning {
background-color: #B96D49;
}
.center-lined {
background-color: #DEDEDE;
}
......
......@@ -115,6 +115,10 @@ input[type="url"], input[type="search"], input[type="tel"], input[type="color"],
color: #D9D9D9;
}
.label-warning, .badge-warning {
background-color: #B96D49;
}
.modal {
display: none;
background-color: #000;
......
......@@ -60,7 +60,23 @@
<div class="blog-article-activity-section span3">
<h4>Tags</h4>
{% for tag in article.tags %}
<span class="badge badge-{{ (loop.index is even) ? 'inverse' : 'important' }}">{{ tag.name }}</span>
{% set flag = '' %}
{% set desc = '' %}
{% if tag.match == 100 %}
{% set flag = 'badge-important' %}
{% set desc = 'Sehr zutreffend' %}
{% elseif tag.match == 66 %}
{% set flag = 'badge-warning' %}
{% set desc = 'Trifft zu' %}
{% elseif tag.match == 33 %}
{% set flag = 'badge-inverse' %}
{% set desc = 'Trifft entfernt zu' %}
{% endif %}
<span class="badge {{ flag }}" title="{{ desc }}">{{ tag.name }}</span>
{% endfor %}
</div>
{% endif %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment