aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-30 20:59:14 +0000
committernickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-30 20:59:14 +0000
commitc9c73cec5c1f4ba333d44f7751eeb7e7e606bbe8 (patch)
treea6dea6af4e8b33f2bec1d51aa636515b35b83c55
parentd5ea193dfb80cd5d35d02428363f9ce18aa01205 (diff)
downloadelgg-c9c73cec5c1f4ba333d44f7751eeb7e7e606bbe8.tar.gz
elgg-c9c73cec5c1f4ba333d44f7751eeb7e7e606bbe8.tar.bz2
Deprecating get_entities_from_access_id().
git-svn-id: http://code.elgg.org/elgg/trunk@3610 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--CHANGES.txt1
-rw-r--r--engine/lib/access.php99
-rw-r--r--engine/tests/objects/users.php10
3 files changed, 58 insertions, 52 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 3a7321df7..d2c31aca3 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -18,6 +18,7 @@ http://code.elgg.org/elgg/.....
* Deprecated get_entities(). Use elgg_get_entities().
* Deprecated get_entities_from_metadata(). Use elgg_get_entities_from_metadata().
* Deprecated get_entities_from_relationship() and g_e_f_relationships_and_meta(). Use elgg_get_entities_from_relationship().
+ * Deprecated get_entities_from_access_id(). Use elgg_get_entities_from_access_id().
* Reorganized directory file path to rely on GUID instead of username.
Services API:
diff --git a/engine/lib/access.php b/engine/lib/access.php
index dd8295b9f..29dbd764d 100644
--- a/engine/lib/access.php
+++ b/engine/lib/access.php
@@ -656,6 +656,8 @@ function elgg_view_access_collections($owner_guid) {
/**
* Get entities with the specified access collection id.
*
+ * @deprecated 1.7. Use elgg_get_entities_from_access_id()
+ *
* @param $collection_id
* @param $entity_type
* @param $entity_subtype
@@ -668,70 +670,63 @@ function elgg_view_access_collections($owner_guid) {
* @return unknown_type
*/
function get_entities_from_access_id($collection_id, $entity_type = "", $entity_subtype = "", $owner_guid = 0, $limit = 10, $offset = 0, $order_by = "", $site_guid = 0, $count = false) {
- global $CONFIG;
-
+ // log deprecated warning
+ elgg_log('get_entities_from_access_id() was deprecated in 1.7 by elgg_get_entities()!', 'WARNING');
+
if (!$collection_id) {
- return false;
+ return FALSE;
}
+
+ // build the options using given parameters
+ $options = array();
+ $options['limit'] = $limit;
+ $options['offset'] = $offset;
+ $options['count'] = $count;
- $entity_type = sanitise_string($entity_type);
- $entity_subtype = get_subtype_id($entity_type, $entity_subtype);
- $limit = (int)$limit;
- $offset = (int)$offset;
+ if ($entity_type) {
+ $options['type'] = sanitise_string($entity_type);
+ }
+
+ if ($entity_subtype) {
+ $options['subtype'] = $entity_subtype;
+ }
+
+ if ($site_guid) {
+ $options['site_guid'] = $site_guid;
+ }
- if ($order_by == "") {
- $order_by = "e.time_created desc";
- } else {
- $order_by = "e.time_created, {$order_by}";
+ if ($order_by) {
+ $options['order_by'] = sanitise_string("e.time_created, $order_by");
}
- $order_by = sanitise_string($order_by);
- $site_guid = (int) $site_guid;
if ((is_array($owner_guid) && (count($owner_guid)))) {
- foreach($owner_guid as $key => $guid) {
- $owner_guid[$key] = (int) $guid;
+ $options['owner_guids'] = array();
+ foreach($owner_guid as $guid) {
+ $options['owner_guids'][] = $guid;
}
- } else {
- $owner_guid = (int) $owner_guid;
}
- if ($site_guid == 0)
- $site_guid = $CONFIG->site_guid;
-
- //$access = get_access_list();
-
- $where = array("e.access_id = $collection_id");
-
- if ($entity_type!=="")
- $where[] = "e.type='$entity_type'";
- if ($entity_subtype)
- $where[] = "e.subtype=$entity_subtype";
- if ($site_guid > 0)
- $where[] = "e.site_guid = {$site_guid}";
- if (is_array($owner_guid)) {
- $where[] = "e.container_guid in (".implode(",",$owner_guid).")";
- } else if ($owner_guid > 0)
- $where[] = "e.container_guid = {$owner_guid}";
-
- if (!$count) {
- $query = "SELECT distinct e.* ";
- } else {
- $query = "SELECT count(distinct e.guid) as total ";
+
+ if ($site_guid) {
+ $options['site_guid'] = $site_guid;
}
- $query .= "from {$CONFIG->dbprefix}entities e where";
- foreach ($where as $w)
- $query .= " $w and ";
- $query .= get_access_sql_suffix("e"); // Add access controls
- //$query .= ' and ' . get_access_sql_suffix("m"); // Add access controls
+ return elgg_get_entities_from_access_id($collection_id, $options);
+}
- if (!$count) {
- $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
- return get_data($query, "entity_row_to_elggstar");
- } else {
- if ($row = get_data_row($query))
- return $row->total;
- }
- return false;
+/**
+ * Retrieve entities for a given access collection
+ *
+ * @param int $collection_id
+ * @param array $options @see elgg_get_entities()
+ * @return array
+ * @since 1.7
+ */
+function elgg_get_entities_from_access_id($collection_id, array $options=array()) {
+ // restrict the resultset to access collection provided
+ $options['wheres'] = "e.access_id = '$collection_id'";
+
+ // return entities with the desired options
+ return elgg_get_entities($options);
}
/**
diff --git a/engine/tests/objects/users.php b/engine/tests/objects/users.php
index 358a80f1c..ace683a82 100644
--- a/engine/tests/objects/users.php
+++ b/engine/tests/objects/users.php
@@ -152,6 +152,16 @@ class ElggCoreUserTest extends ElggCoreUnitTest {
$this->user->delete();
}
+ public function testElggUserDelete() {
+ $guid = $this->user->save();
+
+ // delete object
+ $this->assertTrue($this->user->delete());
+
+ // check GUID not in database
+ $this->assertFalse($this->fetchUser($guid));
+ }
+
protected function fetchUser($guid) {
global $CONFIG;