Added a very basic Tag Cloud
This commit is contained in:
parent
9281d8dab1
commit
dea174d090
@ -34,6 +34,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="content">
|
<div id="content">
|
||||||
<div id="content-padding"></div>
|
<div id="content-padding"></div>
|
||||||
|
{% if tagCloud|length > 0 %}
|
||||||
|
<div id="tag-cloud">
|
||||||
|
{% for cloudItem in tagCloud %}
|
||||||
|
<a href="{{ path('GergelyPolonkaiFrontBundle_blogTagList', { name: cloudItem.name }) }}" class="size{{ cloudItem.size }}">{{ cloudItem.name }}</a>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
<div id="menu">
|
<div id="menu">
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="{{ path('GergelyPolonkaiFrontBundle_about') }}">About me</a></li>
|
<li><a href="{{ path('GergelyPolonkaiFrontBundle_about') }}">About me</a></li>
|
||||||
|
50
src/GergelyPolonkai/FrontBundle/Twig/TagCloud.php
Normal file
50
src/GergelyPolonkai/FrontBundle/Twig/TagCloud.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
namespace GergelyPolonkai\FrontBundle\Twig;
|
||||||
|
|
||||||
|
use Symfony\Bridge\Doctrine\RegistryInterface;
|
||||||
|
use JMS\DiExtraBundle\Annotation as DI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of tagCloud
|
||||||
|
*
|
||||||
|
* @author polesz
|
||||||
|
*
|
||||||
|
* @DI\Service
|
||||||
|
* @DI\Tag("twig.extension")
|
||||||
|
*/
|
||||||
|
class TagCloud extends \Twig_Extension
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Symfony\Bridge\Doctrine\RegistryInterface $doctrine
|
||||||
|
*/
|
||||||
|
private $doctrine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @DI\InjectParams()
|
||||||
|
*/
|
||||||
|
public function __construct(RegistryInterface $doctrine) {
|
||||||
|
$this->doctrine = $doctrine;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getGlobals()
|
||||||
|
{
|
||||||
|
$tagCloudQuery = $this->doctrine->getEntityManager()->createQuery('SELECT t, count(tg) ct FROM GergelyPolonkaiFrontBundle:Tag t LEFT JOIN t.tagging tg GROUP BY t.id ORDER BY t.name');
|
||||||
|
$tagCloudList = $tagCloudQuery->getResult();
|
||||||
|
$tagCloud = array();
|
||||||
|
foreach ($tagCloudList as $cloudElement) {
|
||||||
|
$tag = $cloudElement[0];
|
||||||
|
$tagCount = $cloudElement['ct'];
|
||||||
|
$size = ($tagCount == 0) ? 0 : floor(log($tagCount, 10));
|
||||||
|
if ($size > 5) $size = 5;
|
||||||
|
$tagCloud[] = array('name' => $tag->getName(), 'size' => $size);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'tagCloud' => $tagCloud,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName() {
|
||||||
|
return 'gergelypolonkaifront_tagcloud';
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user