aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
authoricewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-03-12 12:39:55 +0000
committericewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-03-12 12:39:55 +0000
commit49e74d749168f844f82494169f0b6987da0e4234 (patch)
tree1a75ada90ae3e1c72fc27ba503c3608d0834f107 /engine/lib
parentbddeb141b3bca07b25c3d23e207adbaed7e94e4e (diff)
downloadelgg-49e74d749168f844f82494169f0b6987da0e4234.tar.gz
elgg-49e74d749168f844f82494169f0b6987da0e4234.tar.bz2
Marcus Povey <marcus@dushka.co.uk>
* Subtyping on annotations and metadata git-svn-id: https://code.elgg.org/elgg/trunk@187 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/annotations.php24
-rw-r--r--engine/lib/metadata.php30
-rw-r--r--engine/lib/metastrings.php24
-rw-r--r--engine/lib/sites.php2
4 files changed, 54 insertions, 26 deletions
diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php
index 5a2bed865..91a8dce01 100644
--- a/engine/lib/annotations.php
+++ b/engine/lib/annotations.php
@@ -143,14 +143,15 @@
* @param int $limit
* @param int $offset
*/
- function get_annotations($entity_id = 0, $entity_type = "", $name = "", $value = "", $owner_id = 0, $order_by = "created desc", $limit = 10, $offset = 0)
+ function get_annotations($entity_id = 0, $entity_type = "", $entity_subtype = "", $name = "", $value = "", $owner_id = 0, $order_by = "created desc", $limit = 10, $offset = 0)
{
global $CONFIG;
$entity_id = (int)$entity_id;
$entity_type = sanitise_string(trim($entity_type));
+ $entity_subtype = sanitise_string($entity_subtype);
$name = sanitise_string(trim($name));
- $value = sanitise_string(trim($value));
+ $value = get_metastring_id($value);
$owner_id = (int)$owner_id;
@@ -162,26 +163,29 @@
$where = array();
if ($entity_id != 0)
- $where[] = "entity_id=$entity_id";
+ $where[] = "o.entity_id=$entity_id";
if ($entity_type != "")
- $where[] = "entity_type='$entity_type'";
+ $where[] = "o.entity_type='$entity_type'";
if ($owner_id != 0)
- $where[] = "owner_id=$owner_id";
+ $where[] = "o.owner_id=$owner_id";
if ($name != "")
- $where[] = "name='$name'";
+ $where[] = "o.name='$name'";
if ($value != "")
- $where[] = "value='$value'";
+ $where[] = "o.value='$value'";
+
+ if ($entity_subtype != "")
+ $where[] = "s.id=" . get_entity_subtype($entity_id, $entity_type);
// add access controls
$access = get_access_list();
- $where[] = "(access_id in {$access} or (access_id = 0 and owner_id = {$_SESSION['id']}))";
+ $where[] = "(o.access_id in {$access} or (o.access_id = 0 and o.owner_id = {$_SESSION['id']}))";
// construct query.
- $query = "SELECT * from {$CONFIG->dbprefix}annotations where ";
+ $query = "SELECT * from {$CONFIG->dbprefix}annotations o LEFT JOIN {$CONFIG->dbprefix}entity_subtypes s on o.entity_id=s.entity_id and o.entity_type=s.entity_type where ";
for ($n = 0; $n < count($where); $n++)
{
if ($n > 0) $query .= " and ";
@@ -301,7 +305,7 @@
$entity_id = (int)$entity_id;
$entity_type = sanitise_string($entity_type);
$name = sanitise_string($name);
- $value = sanitise_string($value);
+ $value = get_metastring_id($value);
$value_type = sanitise_string($value_type);
$owner_id = (int)$owner_id;
$access = get_access_list();
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index e82af716e..dc657ec34 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -248,14 +248,15 @@
* @param int $offset
* @return array of ElggMetadata
*/
- function get_metadatas($entity_id = 0, $entity_type = "", $name = "", $value = "", $value_type = "", $owner_id = 0, $order_by = "created desc", $limit = 10, $offset = 0)
+ function get_metadatas($entity_id = 0, $entity_type = "", $entity_subtype = "", $name = "", $value = "", $value_type = "", $owner_id = 0, $order_by = "created desc", $limit = 10, $offset = 0)
{
global $CONFIG;
$entity_id = (int)$entity_id;
$entity_type = sanitise_string(trim($entity_type));
+ $entity_subtype = sanitise_string($entity_subtype);
$name = sanitise_string(trim($name));
- $value = sanitise_string(trim($value));
+ $value = get_metastring_id($value);
$value_type = sanitise_string(trim($value_type));
$owner_id = (int)$owner_id;
$order_by = sanitise_string($order_by);
@@ -263,36 +264,41 @@
$limit = (int)$limit;
$offset = (int)$offset;
+ $join = "";
+
// Construct query
$where = array();
if ($entity_id != 0)
- $where[] = "entity_id=$entity_id";
+ $where[] = "o.entity_id=$entity_id";
if ($entity_type != "")
- $where[] = "entity_type='$entity_type'";
+ $where[] = "o.entity_type='$entity_type'";
if ($owner_id != 0)
- $where[] = "owner_id=$owner_id";
+ $where[] = "o.owner_id=$owner_id";
if ($name != "")
- $where[] = "name='$name'";
+ $where[] = "o.name='$name'";
if ($value != "")
- $where[] = "value='$value'";
+ $where[] = "o.value='$value'";
if ($value_type != "")
- $where[] = "value_type='$value_type'";
+ $where[] = "o.value_type='$value_type'";
+
+ if ($entity_subtype != "")
+ $where[] = "s.id=" . get_entity_subtype($entity_id, $entity_type);
// add access controls
$access = get_access_list();
- $where[] = "(access_id in {$access} or (access_id = 0 and owner_id = {$_SESSION['id']}))";
+ $where[] = "(o.access_id in {$access} or (o.access_id = 0 and o.owner_id = {$_SESSION['id']}))";
if ($entity_subtype!="")
$where[] = "";
// construct query.
- $query = "SELECT * from {$CONFIG->dbprefix}metadata where ";
+ $query = "SELECT o.* from {$CONFIG->dbprefix}metadata o LEFT JOIN {$CONFIG->dbprefix}entity_subtypes s on o.entity_id=s.entity_id and o.entity_type=s.entity_type where ";
for ($n = 0; $n < count($where); $n++)
{
if ($n > 0) $query .= " and ";
@@ -314,9 +320,9 @@
* @param int $offset
* @return mixed Array of objects or false.
*/
- function get_objects_from_metadatas($entity_id = 0, $entity_type = "", $name = "", $value = "", $value_type = "", $owner_id = 0, $order_by = "created desc", $limit = 10, $offset = 0)
+ function get_objects_from_metadatas($entity_id = 0, $entity_type = "", $entity_subtype = "", $name = "", $value = "", $value_type = "", $owner_id = 0, $order_by = "created desc", $limit = 10, $offset = 0)
{
- $results = get_metadatas($entity_id, $entity_type, $name, $value, $value_type, $owner_id, $order_by, $limit, $offset);
+ $results = get_metadatas($entity_id, $entity_type, $entity_subtype, $name, $value, $value_type, $owner_id, $order_by, $limit, $offset);
$objects = false;
if ($results)
diff --git a/engine/lib/metastrings.php b/engine/lib/metastrings.php
index 17c9a751b..b4d076eab 100644
--- a/engine/lib/metastrings.php
+++ b/engine/lib/metastrings.php
@@ -11,6 +11,24 @@
* @link http://elgg.org/
*/
+ /**
+ * Return the meta string id for a given tag, or false.
+ *
+ * @param string $tag The value (whatever that is) to be stored
+ * @return mixed Integer tag or false.
+ */
+ function get_metastring_id($tag)
+ {
+ global $CONFIG;
+
+ $tag = sanitise_string($tag);
+
+ $row = get_data_row("SELECT * from {$CONFIG->dbprefix}metastrings where tag='$tag' limit 1");
+ if ($row)
+ return $row->id;
+
+ return false;
+ }
/**
* Add a metastring.
@@ -25,10 +43,10 @@
$tag = sanitise_string($tag);
- $row = get_data_row("SELECT * from {$CONFIG->dbprefix}metastrings where tag='$tag' limit 1");
- if ($row)
- return $row->id;
+ $id = get_metastring_id($tag);
+ if ($id) return $id;
return insert_data("INSERT into {$CONFIG->dbprefix}metastrings (tag) values ('$tag')");
}
+
?> \ No newline at end of file
diff --git a/engine/lib/sites.php b/engine/lib/sites.php
index 1b55e1972..07c4d6e58 100644
--- a/engine/lib/sites.php
+++ b/engine/lib/sites.php
@@ -497,7 +497,7 @@
$offset = (int)$offset;
$owner_id = (int)$owner_id; if ($owner_id==0) $owner_id = $_SESSION['id']; // Consider adding the option to change in param?
- return get_annotations($site_id, 'site', "","", $owner_id, "created desc", $limit, $offset);
+ return get_annotations($site_id, 'site', "", "","", $owner_id, "created desc", $limit, $offset);
}
/**