aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-04 17:20:14 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-04 17:20:14 +0000
commit2af331994f9aae9c2d80cda57ef822c226f180ab (patch)
tree3208a87897196ae18a911e81e0416473c9b9031a
parente1fb557e88e9cb763f9f1006b80bf52756d62386 (diff)
downloadelgg-2af331994f9aae9c2d80cda57ef822c226f180ab.tar.gz
elgg-2af331994f9aae9c2d80cda57ef822c226f180ab.tar.bz2
Added $entity->canEdit() (true|false)
git-svn-id: https://code.elgg.org/elgg/trunk@405 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/entities.php38
1 files changed, 38 insertions, 0 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index 92b658ef2..eba5b8a4d 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -241,6 +241,16 @@
{
return get_annotations_max($this->getGUID(), "","",$name);
}
+
+ /**
+ * Determines whether or not the specified user (by default the current one) can edit the entity
+ *
+ * @param int $user_guid The user GUID, optionally (defaults to the currently logged in user)
+ * @return true|false
+ */
+ function canEdit($user_guid = 0) {
+ return can_edit_entity($this->getGUID(),$user_guid);
+ }
public function getAccessID() { return $this->get('access_id'); }
public function getGUID() { return $this->get('guid'); }
@@ -728,6 +738,34 @@
return $tmp;
}
}
+
+ /**
+ * Determines whether or not the specified user can edit the specified entity.
+ *
+ * This is extendible by registering a plugin hook taking in the parameters 'entity' and 'user',
+ * which are the entity and user entities respectively
+ *
+ * @see register_plugin_hook
+ *
+ * @param int $entity_guid The GUID of the entity
+ * @param int $user_guid The GUID of the user
+ * @return true|false Whether the specified user can edit the specified entity.
+ */
+ function can_edit_entity($entity_guid, $user_guid = 0) {
+
+ if ($user_guid == 0) {
+ $user = $_SESSION['user'];
+ } else {
+ $user = get_entity($user_guid);
+ }
+ $entity = get_entity($entity_guid);
+
+ if ($entity->getOwner() == $user->getGUID()) return true;
+ if ($entity->type == "user" && $entity->getGUID() == $user->getGUID()) return true;
+
+ return trigger_plugin_hook('permissions_check',$entity->type,array('entity' => $entity, 'user' => $user),false);
+
+ }
/** Register the import hook */
register_plugin_hook("import", "all", "import_entity_plugin_hook", 0);