aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/annotations.php
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-02-04 13:05:44 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-02-04 13:05:44 +0000
commita8d7ea23f8868aa70dd6fe87482e3b860e0b615f (patch)
treed05bc4749587fcd8141d70d5c1ca505793150ac2 /engine/lib/annotations.php
parent114bf6e56152d407f660cf5060972f3bfa4fd8ff (diff)
downloadelgg-a8d7ea23f8868aa70dd6fe87482e3b860e0b615f.tar.gz
elgg-a8d7ea23f8868aa70dd6fe87482e3b860e0b615f.tar.bz2
Moves access permissions references over to using the ACCESS_* constants defined in access.php. Refs #687
git-svn-id: https://code.elgg.org/elgg/trunk@2639 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/annotations.php')
-rw-r--r--engine/lib/annotations.php280
1 files changed, 140 insertions, 140 deletions
diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php
index 8c177ffff..bfac0d557 100644
--- a/engine/lib/annotations.php
+++ b/engine/lib/annotations.php
@@ -98,13 +98,13 @@
function delete()
{
return delete_annotation($this->id);
- }
-
- /**
- * Get a url for this annotation.
- *
- * @return string
- */
+ }
+
+ /**
+ * Get a url for this annotation.
+ *
+ * @return string
+ */
public function getURL() { return get_annotation_url($this->guid); }
// SYSTEM LOG INTERFACE ////////////////////////////////////////////////////////////
@@ -156,7 +156,7 @@
* @param int $owner_guid
* @param int $access_id
*/
- function create_annotation($entity_guid, $name, $value, $value_type, $owner_guid, $access_id = 0)
+ function create_annotation($entity_guid, $name, $value, $value_type, $owner_guid, $access_id = ACCESS_PRIVATE)
{
global $CONFIG;
@@ -183,16 +183,16 @@
system_log($entity, 'annotate');
// If ok then add it
- $result = insert_data("INSERT into {$CONFIG->dbprefix}annotations (entity_guid, name_id, value_id, value_type, owner_guid, time_created, access_id) VALUES ($entity_guid,'$name',$value,'$value_type', $owner_guid, $time, $access_id)");
- if ($result!==false) {
- $obj = get_annotation($result);
- if (trigger_elgg_event('create', 'annotation', $obj)) {
- return true;
- } else {
- delete_annotation($result);
- }
- }
-
+ $result = insert_data("INSERT into {$CONFIG->dbprefix}annotations (entity_guid, name_id, value_id, value_type, owner_guid, time_created, access_id) VALUES ($entity_guid,'$name',$value,'$value_type', $owner_guid, $time, $access_id)");
+ if ($result!==false) {
+ $obj = get_annotation($result);
+ if (trigger_elgg_event('create', 'annotation', $obj)) {
+ return true;
+ } else {
+ delete_annotation($result);
+ }
+ }
+
return $result;
}
@@ -230,16 +230,16 @@
if (!$name) return false;
// If ok then add it
- $result = update_data("UPDATE {$CONFIG->dbprefix}annotations set value_id='$value', value_type='$value_type', access_id=$access_id, owner_guid=$owner_guid where id=$annotation_id and name_id='$name' and $access");
- if ($result!==false) {
- $obj = get_annotation($annotation_id);
- if (trigger_elgg_event('update', 'annotation', $obj)) {
- return true;
- } else {
- delete_annotation($annotation_id);
- }
- }
-
+ $result = update_data("UPDATE {$CONFIG->dbprefix}annotations set value_id='$value', value_type='$value_type', access_id=$access_id, owner_guid=$owner_guid where id=$annotation_id and name_id='$name' and $access");
+ if ($result!==false) {
+ $obj = get_annotation($annotation_id);
+ if (trigger_elgg_event('update', 'annotation', $obj)) {
+ return true;
+ } else {
+ delete_annotation($annotation_id);
+ }
+ }
+
return $result;
}
@@ -334,98 +334,98 @@
$query .= " order by $order_by limit $offset,$limit"; // Add order and limit
return get_data($query, "row_to_elggannotation");
- }
-
- /**
- * Return a list of entities which are annotated with a specific annotation.
- * These can be ordered by when the annotation was created/updated.
- *
- * @param string $entity_type Type of entity.
- * @param string $entity_subtype Subtype of entity.
- * @param string $name Name of annotation.
- * @param string $value Value of annotation.
- * @param int $owner_guid Owner.
- * @param int $group_guid Group container. Currently this is only supported if $entity_type == 'object'
- * @param int $limit Maximum number of results to return.
- * @param int $offset Place to start.
+ }
+
+ /**
+ * Return a list of entities which are annotated with a specific annotation.
+ * These can be ordered by when the annotation was created/updated.
+ *
+ * @param string $entity_type Type of entity.
+ * @param string $entity_subtype Subtype of entity.
+ * @param string $name Name of annotation.
+ * @param string $value Value of annotation.
+ * @param int $owner_guid Owner.
+ * @param int $group_guid Group container. Currently this is only supported if $entity_type == 'object'
+ * @param int $limit Maximum number of results to return.
+ * @param int $offset Place to start.
* @param string $order_by How to order results.
- * @param boolean $count Whether to count entities rather than return them
- */
- function get_entities_from_annotations($entity_type = "", $entity_subtype = "", $name = "", $value = "", $owner_guid = 0, $group_guid = 0, $limit = 10, $offset = 0, $order_by = "asc", $count = false)
- {
- global $CONFIG;
-
- $entity_type = sanitise_string($entity_type);
- $entity_subtype = get_subtype_id($entity_type, $entity_subtype);
- if ($name)
- {
- $name = get_metastring_id($name);
-
- if ($name === false)
- $name = 0;
- }
- if ($value != "") $value = get_metastring_id($value);
- if (is_array($owner_guid)) {
- if (sizeof($owner_guid) > 0) {
- foreach($owner_guid as $key => $val) {
- $owner_guid[$key] = (int) $val;
- }
- } else {
- $owner_guid = 0;
- }
- } else {
- $owner_guid = (int)$owner_guid;
- }
- $group_guid = (int)$group_guid;
-
- $limit = (int)$limit;
- $offset = (int)$offset;
- if($order_by == 'asc')
- $order_by = "maxtime asc";
-
- if($order_by == 'desc')
- $order_by = "maxtime desc";
-
- $where = array();
-
- if ($entity_type != "")
- $where[] = "e.type='$entity_type'";
-
- if ($entity_subtype != "")
- $where[] = "e.subtype='$entity_subtype'";
-
- if ($owner_guid != 0 && !is_array($owner_guid)) {
- $where[] = "a.owner_guid=$owner_guid";
- } else {
- if (is_array($owner_guid))
- $where[] = "a.owner_guid in (" . implode(",",$owner_guid) . ")";
- }
-
- if (($group_guid != 0) && ($entity_type=='object'))
- $where[] = "e.container_guid = $group_guid";
-
- if ($name !== "")
- $where[] = "a.name_id='$name'";
-
- if ($value != "")
- $where[] = "a.value_id='$value'";
-
+ * @param boolean $count Whether to count entities rather than return them
+ */
+ function get_entities_from_annotations($entity_type = "", $entity_subtype = "", $name = "", $value = "", $owner_guid = 0, $group_guid = 0, $limit = 10, $offset = 0, $order_by = "asc", $count = false)
+ {
+ global $CONFIG;
+
+ $entity_type = sanitise_string($entity_type);
+ $entity_subtype = get_subtype_id($entity_type, $entity_subtype);
+ if ($name)
+ {
+ $name = get_metastring_id($name);
+
+ if ($name === false)
+ $name = 0;
+ }
+ if ($value != "") $value = get_metastring_id($value);
+ if (is_array($owner_guid)) {
+ if (sizeof($owner_guid) > 0) {
+ foreach($owner_guid as $key => $val) {
+ $owner_guid[$key] = (int) $val;
+ }
+ } else {
+ $owner_guid = 0;
+ }
+ } else {
+ $owner_guid = (int)$owner_guid;
+ }
+ $group_guid = (int)$group_guid;
+
+ $limit = (int)$limit;
+ $offset = (int)$offset;
+ if($order_by == 'asc')
+ $order_by = "maxtime asc";
+
+ if($order_by == 'desc')
+ $order_by = "maxtime desc";
+
+ $where = array();
+
+ if ($entity_type != "")
+ $where[] = "e.type='$entity_type'";
+
+ if ($entity_subtype != "")
+ $where[] = "e.subtype='$entity_subtype'";
+
+ if ($owner_guid != 0 && !is_array($owner_guid)) {
+ $where[] = "a.owner_guid=$owner_guid";
+ } else {
+ if (is_array($owner_guid))
+ $where[] = "a.owner_guid in (" . implode(",",$owner_guid) . ")";
+ }
+
+ if (($group_guid != 0) && ($entity_type=='object'))
+ $where[] = "e.container_guid = $group_guid";
+
+ if ($name !== "")
+ $where[] = "a.name_id='$name'";
+
+ if ($value != "")
+ $where[] = "a.value_id='$value'";
+
if ($count) {
$query = "SELECT count(distinct e.guid) as total ";
} else {
$query = "SELECT e.*, max(a.time_created) as maxtime ";
- }
+ }
$query .= "from {$CONFIG->dbprefix}annotations a JOIN {$CONFIG->dbprefix}entities e on e.guid = a.entity_guid ";
if ($value != "")
- $query .= " JOIN {$CONFIG->dbprefix}metastrings v on a.value_id=v.id";
-
- if (($group_guid != 0) && ($entity_type=='object')) $query .= "JOIN {$CONFIG->dbprefix}objects_entity o on o.guid = e.guid";
- $query .= " where";
-
- foreach ($where as $w)
- $query .= " $w and ";
- $query .= get_access_sql_suffix("a"); // Add access controls
+ $query .= " JOIN {$CONFIG->dbprefix}metastrings v on a.value_id=v.id";
+
+ if (($group_guid != 0) && ($entity_type=='object')) $query .= "JOIN {$CONFIG->dbprefix}objects_entity o on o.guid = e.guid";
+ $query .= " where";
+
+ foreach ($where as $w)
+ $query .= " $w and ";
+ $query .= get_access_sql_suffix("a"); // Add access controls
$query .= ' and ' . get_access_sql_suffix("e"); // Add access controls
if ($count) {
@@ -434,7 +434,7 @@
} else {
$query .= " group by a.entity_guid order by $order_by limit $offset,$limit"; // Add order and limit
return get_data($query, "entity_row_to_elggstar");
- }
+ }
}
/**
@@ -596,7 +596,7 @@
$query = "SELECT $sum(ms.string) as sum from {$CONFIG->dbprefix}annotations a JOIN {$CONFIG->dbprefix}entities e on a.entity_guid = e.guid JOIN {$CONFIG->dbprefix}metastrings ms on a.value_id=ms.id WHERE ";
foreach ($where as $w)
$query .= " $w and ";
- $query .= get_access_sql_suffix("a"); // now add access
+ $query .= get_access_sql_suffix("a"); // now add access
$query .= ' and ' . get_access_sql_suffix("e"); // now add access
$row = get_data_row($query);
@@ -841,32 +841,32 @@
}
return $returnvalue;
- }
-
- /**
- * Get the URL for this item of metadata, by default this links to the export handler in the current view.
- *
- * @param int $id
- */
- function get_annotation_url($id)
- {
- $id = (int)$id;
-
- if ($extender = get_annotation($id)) {
- return get_extender_url($extender);
- }
- return false;
- }
-
-
- /**
- * Register an annotation url handler.
- *
- * @param string $function_name The function.
- * @param string $extender_name The name, default 'all'.
- */
- function register_annotation_url_handler($function_name, $extender_name = "all") {
- return register_extender_url_handler($function_name, 'annotation', $extender_name);
+ }
+
+ /**
+ * Get the URL for this item of metadata, by default this links to the export handler in the current view.
+ *
+ * @param int $id
+ */
+ function get_annotation_url($id)
+ {
+ $id = (int)$id;
+
+ if ($extender = get_annotation($id)) {
+ return get_extender_url($extender);
+ }
+ return false;
+ }
+
+
+ /**
+ * Register an annotation url handler.
+ *
+ * @param string $function_name The function.
+ * @param string $extender_name The name, default 'all'.
+ */
+ function register_annotation_url_handler($function_name, $extender_name = "all") {
+ return register_extender_url_handler($function_name, 'annotation', $extender_name);
}
/** Register the hook */