Elgg\Database\AccessCollections::addUser PHP Method

addUser() public method

Triggers the 'access:collections:add_user', 'collection' plugin hook.
public addUser ( integer $user_guid, integer $collection_id ) : boolean
$user_guid integer The GUID of the user to add
$collection_id integer The ID of the collection to add them to
return boolean
    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;
    }