Created
March 15, 2010 20:53
-
-
Save vlucas/333322 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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, | |
)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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