Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding 'count' parameter to tag API.

Closes #340
  • Loading branch information...
commit 3ed055a48773e756dcdc97b50b56af41064ce01f 1 parent 1b2aa09
Jaisen Mathai jmathai authored
2  src/html/assets/themes/beisel/templates/tags.php
View
@@ -8,7 +8,7 @@
<ol class="tag-cloud">
<?php foreach($tags as $tag) { ?>
<li class="size-<?php Utility::safe($tag['weight']); ?>">
- <a href="<?php Url::photosView("tags-{$tag['id']}"); ?>" title="<?php Utility::safe($tag[$tagField]); ?> photos"><?php Utility::safe($tag['id']); ?></a>
+ <a href="<?php Url::photosView("tags-{$tag['id']}"); ?>" title="<?php Utility::safe($tag['count']); ?> photos"><?php Utility::safe($tag['id']); ?></a>
</li>
<?php } ?>
</ol>
2  src/html/assets/themes/default/templates/tags.php
View
@@ -5,7 +5,7 @@
<ol class="tag-cloud">
<?php foreach($tags as $tag) { ?>
<li class="size-<?php Utility::safe($tag['weight']); ?>">
- <a href="<?php Url::photosView("tags-{$tag['id']}"); ?>" title="<?php Utility::safe($tag[$tagField]); ?> photos"><?php Utility::safe($tag['id']); ?></a>
+ <a href="<?php Url::photosView("tags-{$tag['id']}"); ?>" title="<?php Utility::safe($tag['count']); ?> photos"><?php Utility::safe($tag['id']); ?></a>
</li>
<?php } ?>
</ol>
8 src/libraries/controllers/ApiTagController.php
View
@@ -67,7 +67,15 @@ public static function list_()
$filters = array();
if(User::isOwner())
$filters['permission'] = 0;
+
+ $tagField = User::isOwner() ? 'countPrivate' : 'countPublic';
+
$tags = getDb()->getTags($filters);
+ foreach($tags as $key => $tag)
+ {
+ $tags[$key]['count'] = $tag[$tagField];
+ unset($tags[$key]['countPublic'], $tags[$key]['countPrivate'], $tags[$key]['owner']);
+ }
return self::success('Tags for the user', $tags);
}
}
4 src/libraries/controllers/TagController.php
View
@@ -15,9 +15,7 @@ public static function list_()
{
$tags = getApi()->invoke("/tags/list.json");
$groupedTags = Tag::groupByWeight($tags['result']);
- $tagField = User::isOwner() ? 'countPrivate' : 'countPublic';
-
- $body = getTheme()->get(Utility::getTemplate('tags.php'), array('tags' => $groupedTags, 'tagField' => $tagField));
+ $body = getTheme()->get(Utility::getTemplate('tags.php'), array('tags' => $groupedTags));
getTheme()->display(Utility::getTemplate('template.php'), array('body' => $body, 'page' => 'tags'));
}
}
11 src/libraries/models/Tag.php
View
@@ -105,7 +105,6 @@ public static function updateTagCounts($existingTags, $updatedTags, $permission,
*/
public static function groupByWeight($tags = null)
{
- $tagField = User::isOwner() ? 'countPrivate' : 'countPublic';
if($tags === null)
{
$tags = getApi()->invoke("/tags/list.json");
@@ -118,10 +117,10 @@ public static function groupByWeight($tags = null)
{
foreach($tags as $tag)
{
- if($tag[$tagField] < $minTags)
- $minTags = $tag[$tagField];
- if($tag[$tagField] > $maxTags)
- $maxTags = $tag[$tagField];
+ if($tag['count'] < $minTags)
+ $minTags = $tag['count'];
+ if($tag['count'] > $maxTags)
+ $maxTags = $tag['count'];
}
// we create 10 groups based on count using %s
@@ -129,7 +128,7 @@ public static function groupByWeight($tags = null)
// step needs to be float so we don't divide by zero
$step = floatval($range / 9);
foreach($tags as $key => $tag)
- $tags[$key]['weight'] = intval(($tag[$tagField]-$minTags) / $step)+1;
+ $tags[$key]['weight'] = intval(($tag['count']-$minTags) / $step)+1;
}
return $tags;
}
Please sign in to comment.
Something went wrong with that request. Please try again.