]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #2050: Added subtype parameter to can_write_to_container functions and hooks
authorewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 3 Nov 2010 04:42:50 +0000 (04:42 +0000)
committerewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 3 Nov 2010 04:42:50 +0000 (04:42 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@7221 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/classes/ElggEntity.php
engine/lib/entities.php

index ef38bee6b5f022cda4835706d15ada84dff94ee6..66aca035ed5f809c5d1d87c931dca763f61861bd 100644 (file)
@@ -651,14 +651,16 @@ abstract class ElggEntity extends ElggData implements
        }
 
        /**
-        * Can a user write to this entity's container.
+        * Can a user write to this entity
         *
         * @param int $user_guid The user.
-        *
+        * @param string $type The type of entity we're looking to write 
+        * @param string $subtype The subtype of the entity we're looking to write
+        * 
         * @return bool
         */
-       public function canWriteToContainer($user_guid = 0) {
-               return can_write_to_container($user_guid, $this->getGUID());
+       public function canWriteToContainer($user_guid = 0, $type = 'all', $subtype = 'all') {
+               return can_write_to_container($user_guid, $this->guid, $type, $subtype);
        }
 
        /**
index d497fe4669bab0524861a5c9a5afb92b3cd8a1d9..5a5643da4f3eb28ca91a4f15de6d1a1ba3d98bf8 100644 (file)
@@ -444,9 +444,7 @@ function update_entity($guid, $owner_guid, $access_id, $container_guid = null) {
  * @return bool
  * @link http://docs.elgg.org/DataModel/Containers
  */
-function can_write_to_container($user_guid = 0, $container_guid = 0, $entity_type = 'all') {
-       global $CONFIG;
-
+function can_write_to_container($user_guid = 0, $container_guid = 0, $type = 'all', $subtype = 'all') {
        $user_guid = (int)$user_guid;
        $user = get_entity($user_guid);
        if (!$user) {
@@ -482,8 +480,8 @@ function can_write_to_container($user_guid = 0, $container_guid = 0, $entity_typ
        }
 
        // See if anyone else has anything to say
-       return trigger_plugin_hook('container_permissions_check', $entity_type,
-               array('container' => $container, 'user' => $user), $return);
+       return trigger_plugin_hook('container_permissions_check', $type,
+               array('container' => $container, 'user' => $user, 'subtype' => $subtype), $return);
 }
 
 /**
@@ -515,7 +513,7 @@ $container_guid = 0) {
        global $CONFIG;
 
        $type = sanitise_string($type);
-       $subtype = add_subtype($type, $subtype);
+       $subtype_id = add_subtype($type, $subtype);
        $owner_guid = (int)$owner_guid;
        $access_id = (int)$access_id;
        $time = time();
@@ -528,11 +526,11 @@ $container_guid = 0) {
        }
 
        $user = get_loggedin_user();
-       if (!can_write_to_container($user->guid, $owner_guid, $type)) {
+       if (!can_write_to_container($user->guid, $owner_guid, $type, $subtype)) {
                return false;
        }
        if ($owner_guid != $container_guid) {
-               if (!can_write_to_container($user->guid, $container_guid, $type)) {
+               if (!can_write_to_container($user->guid, $container_guid, $type, $subtype)) {
                        return false;
                }
        }
@@ -544,7 +542,7 @@ $container_guid = 0) {
                (type, subtype, owner_guid, site_guid, container_guid,
                        access_id, time_created, time_updated, last_action)
                values
-               ('$type',$subtype, $owner_guid, $site_guid, $container_guid,
+               ('$type',$subtype_id, $owner_guid, $site_guid, $container_guid,
                        $access_id, $time, $time, $time)");
 }