You are here

public function MoxtraService::setUser in Opigno Moxtra 3.x

Same name and namespace in other branches
  1. 8 src/MoxtraService.php \Drupal\opigno_moxtra\MoxtraService::setUser()

Create / Update Moxtra user.

Parameters

mixed $account: User account.

File

src/MoxtraService.php, line 355

Class

MoxtraService
Implements Moxtra REST API.

Namespace

Drupal\opigno_moxtra

Code

public function setUser($account = NULL) {
  if (!empty($account)) {
    $prefix = $this
      ->prefix($account);
    $is_moxtra_admin = $account
      ->getEmail() == $this->moxtraConnector
      ->getEmail();
    $user_data = [
      'unique_id' => $prefix . $account
        ->id(),
      'first_name' => $account
        ->getDisplayName(),
      'user_type' => $this
        ->isManager($account) || $is_moxtra_admin ? 'Internal' : 'Client',
      'admin' => $is_moxtra_admin,
      'email' => $prefix . $account
        ->getEmail(),
      'timezone' => $account
        ->getTimeZone(),
    ];
    $uri = implode('/', [
      $this->moxtraConnector
        ->getUrl(),
      'v1',
      $this->moxtraConnector
        ->getOrgId(),
      'user',
    ]);
    $uri .= '?access_token=' . ($token = $this->moxtraConnector
      ->getToken(1));
    $this->moxtraConnector
      ->request($uri, $user_data);
  }
}