Author: weaverryan
Date: 2010-02-07 21:25:39 +0100 (Sun, 07 Feb 2010)
New Revision: 27668
Modified:
plugins/sfSympalTagsPlugin/branches/1.4/lib/model/doctrine/PluginsfSympalTagTable.class.php
Log:
[1.4][sfSympalTagsPlugin][1.0] Adding a method that returns an array of tags
assigned to a particular ContentType
Modified:
plugins/sfSympalTagsPlugin/branches/1.4/lib/model/doctrine/PluginsfSympalTagTable.class.php
===================================================================
---
plugins/sfSympalTagsPlugin/branches/1.4/lib/model/doctrine/PluginsfSympalTagTable.class.php
2010-02-07 20:24:58 UTC (rev 27667)
+++
plugins/sfSympalTagsPlugin/branches/1.4/lib/model/doctrine/PluginsfSympalTagTable.class.php
2010-02-07 20:25:39 UTC (rev 27668)
@@ -82,4 +82,43 @@
return implode(', ', $tagsArray);
}
+
+ /**
+ * Retrieves all of the tags used for a specific content type. The
+ * returned list is an array ordered with the most popular tags first.
+ * The array has the following format:
+ * array(
+ * 'tag name' => # of times used,
+ * 'tag' => 5,
+ * );
+ *
+ * @param string $model The name of the ContentType )e.g. sfSympalBlogPost
+ * @param integer $num The number of tags to return
+ */
+ public function retrieveTagsForContentType($model, $num = null)
+ {
+ $q = Doctrine_Core::getTable('sfSympalTag')->createQuery('t')
+ ->select('t.name, count(t.name) count')
+ ->innerJoin('t.ContentTags ct')
+ ->innerJoin('ct.Content c')
+ ->innerJoin('c.'.$model.' p')
+ ->innerJoin('c.Type t2')
+ ->orderBy('count DESC')
+ ->groupBy('t.name');
+
+ if ($num !== null)
+ {
+ $q->limit($num);
+ }
+
+ $results = $q->execute(array(), Doctrine_Core::HYDRATE_NONE);
+
+ $tags = array();
+ foreach ($results as $result)
+ {
+ $tags[$result[0]] = $result[1];
+ }
+
+ return $tags;
+ }
}
\ No newline at end of file
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.