Skip to content

Instantly share code, notes, and snippets.

@vlucas
Created March 15, 2010 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vlucas/333322 to your computer and use it in GitHub Desktop.
Save vlucas/333322 to your computer and use it in GitHub Desktop.
<?php
# app/Modules/Events/views/indexAction.html.php
?>
<div class="section recent-tags">
<h3>
Recent Tags
<span class="f-right"><a href="<?php echo $this->kernel->url('module', array('module' => 'Tags')); ?>" title="view more tags">View All</span>
</h3>
<?php
// Get tag cloud from Tags module
echo $this->kernel->dispatch('Tags', 'tagCloud', array('conference'));
?>
<div class="clear"></div>
</div>
<?php
# app/Modules/Tags/Controller.php
class Module_Tags_Controller extends Alloy_Module_Controller
{
// (snip) ...
/**
* Genereate a tag cloud from tags
*/
public function tagCloud($tagType = 'conference')
{
// Fetch upcoming conferences tags
$mapper = $this->mapper();
$tags = $mapper->getRecentTagsByType($tagType);
// Return view
return $this->view(__FUNCTION__)
->set(array(
'tags' => $tags,
));
}
}
<?php
# app/Modules/Tags/views/tagCloud.html.php
?>
<ul class="tag-cloud">
<?php
// Get tags in array of 'name' => 'frequency'
$tags = $this->tags->toArray('name', 'frequency');
if($tags) {
$tagFrequencyMax = max(array_values($tags));
$tagFrequencyMin = min(array_values($tags));
$tagHighlightMin = $tagFrequencyMax / 2;
ksort($tags); // Sort alphabetically by tag name
}
$i = 0;
foreach($tags as $tagName => $tagFrequency):
?>
<li class="<?= ($i++ % 2 === 0) ? 'odd' : 'even' ?><?php echo ($tagFrequency > $tagHighlightMin ? ' tag-highlight' : ''); ?>">
<span class="tag">
<a href="<?php echo $this->kernel->url('module', array('module' => 'Events'), array('tag' => $tagName)); ?>">
<?php echo $tagName; ?>
</a>
</span>
</li>
<?php endforeach; ?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment