}
/**
- * 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);
}
/**
* @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) {
}
// 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);
}
/**
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();
}
$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;
}
}
(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)");
}