diff options
author | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-05-28 15:37:19 +0000 |
---|---|---|
committer | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-05-28 15:37:19 +0000 |
commit | 99180ff5df07cd20c67cdf8d11b7f21bcd917544 (patch) | |
tree | 75d7a2bfc06d52bcf4c194d4f0b9187ae63ddab7 /engine/lib | |
parent | 82d30dcb3cc20330d72c30c3fee08b3b99689409 (diff) | |
download | elgg-99180ff5df07cd20c67cdf8d11b7f21bcd917544.tar.gz elgg-99180ff5df07cd20c67cdf8d11b7f21bcd917544.tar.bz2 |
Added new tagcloud functions
git-svn-id: https://code.elgg.org/elgg/trunk@744 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r-- | engine/lib/tags.php | 89 |
1 files changed, 88 insertions, 1 deletions
diff --git a/engine/lib/tags.php b/engine/lib/tags.php index 9055a1d02..388b88d5e 100644 --- a/engine/lib/tags.php +++ b/engine/lib/tags.php @@ -63,5 +63,92 @@ $cloud[$k] = calculate_tag_size($min, $max, $v, $buckets); return $cloud; - } + }
+
+ /**
+ * Get an array of tags with weights for use with the output/tagcloud view.
+ *
+ * @param int $threshold Get the threshold of minimum number of each tags to bother with (ie only show tags where there are more than $threshold occurances)
+ * @param int $limit Number of tags to return
+ * @param string $metadata_name Optionally, the name of the field you want to grab for
+ * @param string $entity_type Optionally, the entity type ('object' etc)
+ * @param string $entity_subtype The entity subtype, optionally
+ * @param int $owner_guid The GUID of the tags owner, optionally
+ * @param int $site_guid Optionally, the site to restrict to (default is the current site)
+ * @return array|false Array of objects with ->tag and ->total values, or false on failure
+ */
+
+ function get_tags($threshold = 1, $limit = 10, $metadata_name = "", $entity_type = "object", $entity_subtype = "", $owner_guid = "", $site_guid = -1) {
+
+ global $CONFIG;
+
+ $threshold = (int) $threshold;
+ $limit = (int) $limit;
+
+ if (!empty($metadata_name)) {
+ $metadata_name = (int) get_metastring_id($metadata_name);
+ } else {
+ $metadata_name = 0;
+ }
+ $entity_subtype = get_subtype_id($entity_type, $entity_subtype);
+ $entity_type = sanitise_string($entity_type);
+
+ $owner_guid = (int) $owner_guid;
+
+ if ($site_guid < 0) {
+ $site_guid = $CONFIG->site_id;
+ }
+
+ $access = get_access_list();
+
+ $query = "SELECT {$CONFIG->dbprefix}msvalue.string as tag, count(msvalue.id) as total ";
+ $query .= "FROM entities e join metadata md on md.entity_guid = e.guid ";
+ $query .= " join entity_subtypes subtype on subtype.id = e.subtype ";
+ $query .= " join metastrings msvalue on msvalue.id = md.value_id ";
+
+ $query .= " where 1 ";
+
+ if ($metadata_name > 0) {
+ $query .= " and md.name_id = {$metadata_name} ";
+ }
+ if ($site_guid > 0) {
+ $query .= " and e.site_guid = {$site_guid} ";
+ }
+ if ($entity_subtype > 0) {
+ $query .= " and e.subtype = {$entity_subtype} ";
+ }
+ if ($entity_type != "") {
+ $query .= " and e.type = '{$entity_type}' ";
+ }
+ if ($owner_guid > 0) {
+ $query .= " and e.owner_guid = {$owner_guid} ";
+ }
+
+ $query .= " and (e.access_id in {$access} or (e.access_id = 0 and e.owner_guid = {$_SESSION['id']}))";
+
+ $query .= " group by msvalue.string having total > {$threshold} order by total desc limit {$limit} ";
+
+ return get_data($query);
+
+ }
+
+ /**
+ * Loads and displays a tagcloud given particular criteria.
+ *
+ * @param int $threshold Get the threshold of minimum number of each tags to bother with (ie only show tags where there are more than $threshold occurances)
+ * @param int $limit Number of tags to return
+ * @param string $metadata_name Optionally, the name of the field you want to grab for
+ * @param string $entity_type Optionally, the entity type ('object' etc)
+ * @param string $entity_subtype The entity subtype, optionally
+ * @param int $owner_guid The GUID of the tags owner, optionally
+ * @param int $site_guid Optionally, the site to restrict to (default is the current site)
+ * @return string THe HTML (or other, depending on view type) of the tagcloud.
+ */
+
+ function display_tagcloud($threshold = 1, $limit = 10, $metadata_name = "", $entity_type = "object", $entity_subtype = "", $owner_guid = "", $site_guid = -1) {
+
+ return elgg_view("output/tagcloud",array('value' => get_tags($threshold, $limit, $metadata_name, $entity_type, $entity_subtype, $owner_guid, $site_guid),'object' => $entity_type, 'subtype' => $entity_subtype));
+
+ }
+ ?>
\ No newline at end of file |