function addUser($user_guid, $collection_id)
{
$collection_id = (int) $collection_id;
$user_guid = (int) $user_guid;
$user = get_user($user_guid);
$collection = $this->get($collection_id);
if (!$user instanceof ElggUser || !$collection) {
return false;
}
$params = array('collection_id' => $collection_id, 'user_guid' => $user_guid);
$result = $this->hooks->trigger('access:collections:add_user', 'collection', $params, true);
if ($result == false) {
return false;
}
$db = $this->db;
$prefix = $db->prefix;
// if someone tries to insert the same data twice, we do a no-op on duplicate key
$q = "INSERT INTO {$prefix}access_collection_membership\n\t\t\t\tSET access_collection_id = {$collection_id}, user_guid = {$user_guid}\n\t\t\t\tON DUPLICATE KEY UPDATE user_guid = user_guid";
$result = $db->insertData($q);
return $result !== false;
}