diff options
author | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-07-18 18:23:50 +0000 |
---|---|---|
committer | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-07-18 18:23:50 +0000 |
commit | 361bff59658e6119b76e7ff31cd67c6054c93c8f (patch) | |
tree | 115c0eb308aa1312f7e69b52506eb625a2887c0d | |
parent | 0c997a2fe195542c1cdec5b828cea87d0992dc78 (diff) | |
download | elgg-361bff59658e6119b76e7ff31cd67c6054c93c8f.tar.gz elgg-361bff59658e6119b76e7ff31cd67c6054c93c8f.tar.bz2 |
Moved container_guid to entities, modified a bunch of functions.
git-svn-id: https://code.elgg.org/elgg/trunk@1473 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r-- | engine/lib/annotations.php | 2 | ||||
-rw-r--r-- | engine/lib/elgglib.php | 2 | ||||
-rw-r--r-- | engine/lib/entities.php | 29 | ||||
-rw-r--r-- | engine/lib/group.php | 45 | ||||
-rw-r--r-- | engine/lib/objects.php | 11 | ||||
-rw-r--r-- | engine/lib/pageowner.php | 4 | ||||
-rw-r--r-- | engine/lib/users.php | 4 | ||||
-rw-r--r-- | engine/schema/mysql.sql | 4 | ||||
-rw-r--r-- | mod/groups/actions/addtogroup.php | 13 | ||||
-rw-r--r-- | views/default/page_elements/title.php | 2 |
10 files changed, 78 insertions, 38 deletions
diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php index f6060755e..b79a94273 100644 --- a/engine/lib/annotations.php +++ b/engine/lib/annotations.php @@ -395,7 +395,7 @@ } if (($group_guid != 0) && ($entity_type=='object')) - $where[] = "o.container_guid = $group_guid"; + $where[] = "e.container_guid = $group_guid"; if ($name !== "") $where[] = "a.name_id='$name'"; diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 066299644..3854dd8dc 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -163,7 +163,7 @@ }
if ($vars['page_owner'] != -1) {
if (!isset($usercache[$vars['page_owner']])) {
- $vars['page_owner_user'] = get_user($vars['page_owner']);
+ $vars['page_owner_user'] = get_entity($vars['page_owner']);
$usercache[$vars['page_owner']] = $vars['page_owner_user'];
} else {
$vars['page_owner_user'] = $usercache[$vars['page_owner']];
diff --git a/engine/lib/entities.php b/engine/lib/entities.php index 57578362c..ad793b907 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -75,7 +75,8 @@ $this->attributes['guid'] = ""; $this->attributes['type'] = ""; $this->attributes['subtype'] = ""; - $this->attributes['owner_guid'] = $_SESSION['guid']; + $this->attributes['owner_guid'] = $_SESSION['guid'];
+ $this->attributes['container_guid'] = $_SESSION['guid']; $this->attributes['site_guid'] = 0; $this->attributes['access_id'] = 0; $this->attributes['time_created'] = ""; @@ -483,7 +484,7 @@ } else { - $this->attributes['guid'] = create_entity($this->attributes['type'], $this->attributes['subtype'], $this->attributes['owner_guid'], $this->attributes['access_id']); // Create a new entity (nb: using attribute array directly 'cos set function does something special!) + $this->attributes['guid'] = create_entity($this->attributes['type'], $this->attributes['subtype'], $this->attributes['owner_guid'], $this->attributes['access_id'], $this->attributes['site_guid'], $this->attributes['container_guid']); // Create a new entity (nb: using attribute array directly 'cos set function does something special!) if (!$this->attributes['guid']) throw new IOException(elgg_echo('IOException:BaseEntitySaveFailed')); // Save any unsaved metadata @@ -969,7 +970,7 @@ * @param int $owner_guid * @param int $access_id */ - function update_entity($guid, $owner_guid, $access_id) + function update_entity($guid, $owner_guid, $access_id) { global $CONFIG, $ENTITY_CACHE; @@ -1005,7 +1006,7 @@ * @param int $site_guid The site to add this entity to. Leave as 0 (default) for the current site. * @return mixed The new entity's GUID, or false on failure */ - function create_entity($type, $subtype, $owner_guid, $access_id, $site_guid = 0) + function create_entity($type, $subtype, $owner_guid, $access_id, $site_guid = 0, $container_guid = 0) { global $CONFIG; @@ -1020,7 +1021,7 @@ if ($type=="") throw new InvalidParameterException(elgg_echo('InvalidParameterException:EntityTypeNotSet')); - return insert_data("INSERT into {$CONFIG->dbprefix}entities (type, subtype, owner_guid, site_guid, access_id, time_created, time_updated) values ('$type',$subtype, $owner_guid, $site_guid, $access_id, $time, $time)"); + return insert_data("INSERT into {$CONFIG->dbprefix}entities (type, subtype, owner_guid, site_guid, container_guid, access_id, time_created, time_updated) values ('$type',$subtype, $owner_guid, $site_guid, $container_guid, $access_id, $time, $time)"); } /** @@ -1120,9 +1121,11 @@ * @param int $limit The number of entities to return; 10 by default * @param int $offset The indexing offset, 0 by default * @param boolean $count Set to true to get a count rather than the entities themselves (limits and offsets don't apply in this context). Defaults to false. - * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites. + * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
+ * @param int|array $container_guid The container or containers to get entities from (default: all containers).
+ * @return array A list of entities. */ - function get_entities($type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0) + function get_entities($type = "", $subtype = "", $owner_guid = 0, $order_by = "", $limit = 10, $offset = 0, $count = false, $site_guid = 0, $container_guid = null) { global $CONFIG; @@ -1159,7 +1162,17 @@ } if ($site_guid > 0) $where[] = "site_guid = {$site_guid}"; - +
+ if (!is_null($container_guid)) {
+ if (is_array($container_guid)) {
+ foreach($container_guid as $key => $val) $container_guid[$key] = (int) $val;
+ $where[] = "container_guid in (" . implode(",",$container_guid) . ")";
+ } else {
+ $container_guid = (int) $container_guid;
+ $where[] = "container_guid = {$container_guid}";
+ }
+ }
+ if (!$count) { $query = "SELECT * from {$CONFIG->dbprefix}entities where "; } else { diff --git a/engine/lib/group.php b/engine/lib/group.php index b0c6d3346..90ee650f3 100644 --- a/engine/lib/group.php +++ b/engine/lib/group.php @@ -146,6 +146,34 @@ { return get_group_members($this->getGUID(), $limit, $offset, 0 , $count); } +
+ /**
+ * For compatibility with ElggUser
+ */
+ public function getFriends($subtype = "", $limit = 10, $offset = 0) {
+ return get_group_members($this->getGUID(), $limit, $offset);
+ }
+
+ /**
+ * For compatibility with ElggUser
+ */
+ public function getFriendsOf($subtype = "", $limit = 10, $offset = 0) {
+ return get_group_members($this->getGUID(), $limit, $offset);
+ }
+
+ /**
+ * For compatibility with ElggUser
+ */
+ public function isFriend() {
+ return $this->isMember();
+ }
+
+ /**
+ * For compatibility with ElggUser
+ */
+ public function isFriendOf() {
+ return $this->isMember();
+ }
/** * Returns whether the current group is public membership or not. @@ -165,8 +193,9 @@ * @param ElggUser $user The user * @return bool */ - public function isMember(ElggUser $user) - { + public function isMember($user = 0) + {
+ if ($user == 0) $user = $_SESSION['user']; return is_group_member($this->getGUID(), $user->getGUID()); } @@ -266,8 +295,9 @@ if (($container) && ($user)) { - // Basics, see if the user is a member of the group. - if (!$container->isMember($user)) return false; + // Basics, see if the user is a member of the group.
+ if ($container instanceof ElggGroup) + if (!$container->isMember($user)) return false; // See if anyone else has anything to say return trigger_plugin_hook('group_permissions_check',$entity->type,array('container' => $container, 'user' => $user), false); @@ -358,6 +388,7 @@ return false; } +
/** * Delete a group's extra data. @@ -490,7 +521,7 @@ $where[] = "e.site_guid = {$site_guid}"; if ($container_guid > 0) - $where[] = "o.container_guid = {$container_guid}"; + $where[] = "e.container_guid = {$container_guid}"; if (!$count) { $query = "SELECT * from {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}objects_entity o on e.guid=o.guid where "; @@ -569,7 +600,7 @@ if ($site_guid > 0) $where[] = "e.site_guid = {$site_guid}"; if ($container_guid > 0) - $where[] = "o.container_guid = {$container_guid}"; + $where[] = "e.container_guid = {$container_guid}"; if (is_array($owner_guid)) { $where[] = "e.owner_guid in (".implode(",",$owner_guid).")"; } else if ($owner_guid > 0) @@ -656,7 +687,7 @@ if ($owner_guid > 0) $where[] = "e.owner_guid = {$owner_guid}"; if ($container_guid > 0) - $where[] = "o.container_guid = {$container_guid}"; + $where[] = "e.container_guid = {$container_guid}"; if ($count) { $query = "SELECT count(e.guid) as total "; diff --git a/engine/lib/objects.php b/engine/lib/objects.php index 2067fe5c2..d2f90bdfd 100644 --- a/engine/lib/objects.php +++ b/engine/lib/objects.php @@ -259,18 +259,15 @@ *
* @param int $guid The guid of the entity you're creating (as obtained by create_entity)
* @param string $title The title of the object
- * @param string $description The object's description - * @param int $container_guid The object's container guid (defaults to the current logged in user)
+ * @param string $description The object's description
*/
- function create_object_entity($guid, $title, $description, $container_guid = 0)
+ function create_object_entity($guid, $title, $description)
{
global $CONFIG;
$guid = (int)$guid;
$title = sanitise_string($title);
$description = sanitise_string($description); - $container_guid = (int)$container_guid;
- if (!$container_guid) $container_guid = $_SESSION['guid']; $row = get_entity_as_row($guid);
@@ -278,7 +275,7 @@ { // Core entities row exists and we have access to it if ($exists = get_data_row("select guid from {$CONFIG->dbprefix}objects_entity where guid = {$guid}")) { - $result = update_data("UPDATE {$CONFIG->dbprefix}objects_entity set title='$title', description='$description', container_guid=$container_guid where guid=$guid"); + $result = update_data("UPDATE {$CONFIG->dbprefix}objects_entity set title='$title', description='$description' where guid=$guid"); if ($result!=false) { // Update succeeded, continue @@ -294,7 +291,7 @@ { // Update failed, attempt an insert. - $result = insert_data("INSERT into {$CONFIG->dbprefix}objects_entity (guid, container_guid, title, description) values ($guid, $container_guid, '$title','$description')"); + $result = insert_data("INSERT into {$CONFIG->dbprefix}objects_entity (guid, title, description) values ($guid, '$title','$description')"); if ($result!==false) { $entity = get_entity($guid); if (trigger_elgg_event('create',$entity->type,$entity)) { diff --git a/engine/lib/pageowner.php b/engine/lib/pageowner.php index 607fb6629..57c083f02 100644 --- a/engine/lib/pageowner.php +++ b/engine/lib/pageowner.php @@ -35,7 +35,7 @@ }
}
if ($owner = get_input("owner_guid")) {
- if ($user = get_user($owner)) {
+ if ($user = get_entity($owner)) {
return $user->getGUID();
} else {
return 0;
@@ -62,7 +62,7 @@ global $CONFIG;
$page_owner = page_owner();
if ($page_owner > 0)
- return get_user($page_owner);
+ return get_entity($page_owner);
return false;
diff --git a/engine/lib/users.php b/engine/lib/users.php index 229735960..e3e76c8c5 100644 --- a/engine/lib/users.php +++ b/engine/lib/users.php @@ -517,7 +517,7 @@ * @return false|array An array of ElggObjects or false, depending on success
*/
function get_user_objects($user_guid, $subtype = "", $limit = 10, $offset = 0) {
- $ntt = get_entities('object',$subtype, $user_guid, "time_created desc", $limit, $offset);
+ $ntt = get_entities('object',$subtype, $user_guid, "time_created desc", $limit, $offset,false,0,array(0,$user_guid));
return $ntt;
}
@@ -529,7 +529,7 @@ * @return int The number of objects the user owns (of this subtype)
*/
function count_user_objects($user_guid, $subtype = "") {
- $total = get_entities('object', $subtype, $user_guid, "time_created desc", null, null, true);
+ $total = get_entities('object', $subtype, $user_guid, "time_created desc", null, null, true, 0, array(0, $user_guid));
return $total;
}
diff --git a/engine/schema/mysql.sql b/engine/schema/mysql.sql index a93706c73..b223984db 100644 --- a/engine/schema/mysql.sql +++ b/engine/schema/mysql.sql @@ -31,6 +31,7 @@ CREATE TABLE `prefix_entities` ( `owner_guid` bigint(20) unsigned NOT NULL,
`site_guid` bigint(20) unsigned NOT NULL,
+ `container_guid` bigint(20) unsigned NOT NULL,
`access_id` int(11) NOT NULL,
`time_created` int(11) NOT NULL,
@@ -96,8 +97,7 @@ CREATE TABLE `prefix_access_collection_membership` ( -- Extra information relating to "objects"
CREATE TABLE `prefix_objects_entity` (
- `guid` bigint(20) unsigned NOT NULL, - `container_guid` bigint(20) unsigned NOT NULL,
+ `guid` bigint(20) unsigned NOT NULL,
`title` text NOT NULL,
`description` text NOT NULL,
diff --git a/mod/groups/actions/addtogroup.php b/mod/groups/actions/addtogroup.php index 1910a8196..eb079e959 100644 --- a/mod/groups/actions/addtogroup.php +++ b/mod/groups/actions/addtogroup.php @@ -21,12 +21,11 @@ $user_guid = array($user_guid); $group_guid = get_input('group_guid'); - + if (sizeof($user_guid)) foreach ($user_guid as $u_id) { $requested = false; - $user = get_entity($u_id); - $group = get_entity($group_guid); + if ($user = get_entity($u_id) && $group = get_entity($group_guid)) { if ($_SESSION['user']->getGUID() == $group->owner_guid) { @@ -87,12 +86,12 @@ else register_error(elgg_echo("groups:usernotinvited")); } - } + }
+ }
+ else
+ register_error(elgg_echo("groups:notowner")); } - else - register_error(elgg_echo("groups:notowner")); } forward($forward_url); - exit; ?>
\ No newline at end of file diff --git a/views/default/page_elements/title.php b/views/default/page_elements/title.php index e2e397aea..04dc8eea7 100644 --- a/views/default/page_elements/title.php +++ b/views/default/page_elements/title.php @@ -14,7 +14,7 @@ */
$page_owner = page_owner();
- $page_owner_user = get_user($page_owner);
+ $page_owner_user = get_entity($page_owner);
$submenu = get_submenu(); // elgg_view('canvas_header/submenu');
if (!empty($submenu)) $submenu = "<ul>" . $submenu . "</ul>";
|