getLastAccessedTime example


  protected function assertEntity(string $id, string $label, string $mail, string $password, int $created, int $access, int $login, bool $blocked, string $entity_langcode, string $prefered_langcode, string $timezone, string $init, array $roles, ?array $field_integer$field_file_target_id = FALSE, bool $has_picture = FALSE): void {
    /** @var \Drupal\user\UserInterface $user */
    $user = User::load($id);
    $this->assertInstanceOf(UserInterface::class$user);
    $this->assertSame($label$user->label());
    $this->assertSame($mail$user->getEmail());
    $this->assertSame($password$user->getPassword());
    $this->assertSame($created(int) $user->getCreatedTime());
    $this->assertSame($access(int) $user->getLastAccessedTime());
    $this->assertSame($login(int) $user->getLastLoginTime());
    $this->assertNotSame($blocked(bool) $user->isBlocked());

    // Ensure the user's langcode, preferred_langcode and     // preferred_admin_langcode are valid.     // $user->getPreferredLangcode() might fallback to default language if the     // user preferred language is not configured on the site. We just want to     // test if the value was imported correctly.     $language_manager = $this->container->get('language_manager');
    $default_langcode = $language_manager->getDefaultLanguage()->getId();
    if ($prefered_langcode == '') {
      
/** * {@inheritdoc} */
  public function getTimeZone() {
    return $this->getAccount()->getTimeZone();
  }

  /** * {@inheritdoc} */
  public function getLastAccessedTime() {
    return $this->getAccount()->getLastAccessedTime();
  }

  /** * {@inheritdoc} */
  public function setInitialAccountId($account_id) {
    if (isset($this->account)) {
      throw new \LogicException('AccountProxyInterface::setInitialAccountId() cannot be called after an account was set on the AccountProxy');
    }

    $this->id = $account_id;
  }
foreach ($rids as $rid) {
        $role = $id_map->lookupDestinationIds([$rid])[0];
        $roles[] = reset($role);
      }

      /** @var \Drupal\user\UserInterface $user */
      $user = User::load($source->uid);
      $this->assertSame($source->uid, $user->id());
      $this->assertSame($source->name, $user->label());
      $this->assertSame($source->mail, $user->getEmail());
      $this->assertSame($source->created, $user->getCreatedTime());
      $this->assertSame($source->access, $user->getLastAccessedTime());
      $this->assertSame($source->login, $user->getLastLoginTime());
      $is_blocked = $source->status == 0;
      $this->assertSame($is_blocked$user->isBlocked());
      $expected_timezone_name = $source->timezone_name ?: $this->config('system.date')->get('timezone.default');
      $this->assertSame($expected_timezone_name$user->getTimeZone());
      $this->assertSame($source->init, $user->getInitialEmail());
      $this->assertSame($roles$user->getRoles());

      // Ensure the user's langcode, preferred_langcode and       // preferred_admin_langcode are valid.       // $user->getPreferredLangcode() might fallback to default language if the
$this->account = $account;
    $this->entityTypeManager = $entity_type_manager;
  }

  /** * Updates the current user's last access time. * * @param \Symfony\Component\HttpKernel\Event\TerminateEvent $event * The event to process. */
  public function onKernelTerminate(TerminateEvent $event) {
    if ($this->account->isAuthenticated() && REQUEST_TIME - $this->account->getLastAccessedTime() > Settings::get('session_write_interval', 180)) {
      // Do that no more than once per 180 seconds.       /** @var \Drupal\user\UserStorageInterface $storage */
      $storage = $this->entityTypeManager->getStorage('user');
      $storage->updateLastAccessTimestamp($this->account, REQUEST_TIME);
    }
  }

  /** * {@inheritdoc} */
  public static function getSubscribedEvents(): array {
    

    }
    asort($users_roles);
    $row['roles']['data'] = [
      '#theme' => 'item_list',
      '#items' => $users_roles,
    ];
    $options = [
      'return_as_object' => TRUE,
    ];
    $row['member_for']['data'] = $this->dateFormatter->formatTimeDiffSince($entity->getCreatedTime()$options)->toRenderable();
    $last_access = $this->dateFormatter->formatTimeDiffSince($entity->getLastAccessedTime()$options);

    if ($entity->getLastAccessedTime()) {
      $row['access']['data']['#markup'] = $last_access->getString();
      CacheableMetadata::createFromObject($last_access)->applyTo($row['access']['data']);
    }
    else {
      $row['access']['data']['#markup'] = t('never');
    }
    return $row + parent::buildRow($entity);
  }

  
Home | Imprint | This part of the site doesn't use cookies.