Skip to content

Instantly share code, notes, and snippets.

@robertbasic
Created October 5, 2012 13:54
Show Gist options
  • Select an option

  • Save robertbasic/3839911 to your computer and use it in GitHub Desktop.

Select an option

Save robertbasic/3839911 to your computer and use it in GitHub Desktop.
<?php
namespace Blog\View\Helper;
use Hex\View\Helper\ServiceLocatorAwareHelper;
use Zend\Tag\Cloud as ZendTagCloud;
use Zend\Tag\Cloud\Decorator\HtmlCloud as TagCloudDecorator;
use Zend\Tag\Cloud\Decorator\HtmlTag as TagCloudTag;
class TagCloud extends ServiceLocatorAwareHelper
{
protected $service = null;
public function __invoke()
{
$tags = $this->getService()->getMostUsedTags(40);
if(count($tags) < 1) {
return false;
}
$cloudDecorator = new TagCloudDecorator();
$cloudDecorator->setHtmlTags(array(
'div' => array('class' => 'Zend_Tag_Cloud')
));
$cloudDecorator->setSeparator(', ');
$tagDecorator = new TagCloudTag();
$tagDecorator->setHtmlTags(array(
'span'
));
$tagDecorator->setMinFontSize(12);
$cloud = new ZendTagCloud(array(
'cloudDecorator' => $cloudDecorator,
'tagDecorator' => $tagDecorator
));
foreach($tags as $tag) {
$url = $this->getView()->url('blog-tag', array('slug' => $tag->slug));
$cloud->appendTag(array(
'title' => $tag->title,
'weight' => $tag->num,
'params' => array(
'url' => $url
)
));
}
return $this->getView()->partial('_tag_cloud.phtml', array('cloud' => $cloud));
}
protected function getService()
{
if($this->service === null) {
$sm = $this->getServiceLocator()->getServiceLocator();
$this->service = $sm->get('blogServiceTag');
}
return $this->service;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment