Working with users

CXM users are represented through the Service API as User objects, containing information such as:

  • email address
  • name
  • role
  • user group membership

Person records

If the user has a CXM Person record associated with them, this is also attached to the User object.

<?php

// Output Person details if the User has one
if ($currentUser->hasPerson()) {
    $person = $currentUser->getPerson();
    print 'Full name: ' . $person->getFullName() . PHP_EOL;
    print 'Telephone: ' . $person->getTelephonePrimary() . PHP_EOL;
    if ($person->hasAddress()) {
        print 'Address: ' . $person->getAddress()->getSummary() . PHP_EOL;
    }
}

You can use the UserManager and PersonManager in the ServiceApiClient to perform various operations with these objects.

Organisation membership

If the user is a member of an organisation and the requesting user either has the "View all organisations" privilege or belongs to the organisation, an OrganisationMembership object is available on the User.

The user's role within the organisation can also be fetched from the OrganisationMembership.

<?php

if ($currentUser->getOrganisationMembership()) {
    $membership = $currentUser->getOrganisationMembership();

    print 'User role: ' . $membership->getRole() . PHP_EOL;
    print 'Organisation name: ' . $membership->getOrganisation()->getName() . PHP_EOL;
}

results matching ""

    No results matching ""