ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCertificateObjectsForUserPreloader.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
27  private static array $certificates = [];
29 
30  public function __construct(ilUserCertificateRepository $userCertificateRepository)
31  {
32  $this->userCertificateRepository = $userCertificateRepository;
33  }
34 
39  public function preLoad(int $userId, array $objIds): void
40  {
41  if (!array_key_exists($userId, self::$certificates)) {
42  self::$certificates[$userId] = [];
43  }
44 
45  $objectIdsWithUserCertificate = $this->userCertificateRepository->fetchObjectIdsWithCertificateForUser(
46  $userId,
47  array_diff($objIds, self::$certificates[$userId])
48  );
49 
50  self::$certificates[$userId] = array_unique(array_merge(
51  $objectIdsWithUserCertificate,
52  self::$certificates[$userId]
53  ));
54  }
55 
56  public function isPreloaded(int $userId, int $objId): bool
57  {
58  if (false === array_key_exists($userId, self::$certificates)) {
59  return false;
60  }
61 
62  if (true === in_array($objId, self::$certificates[$userId], true)) {
63  return true;
64  }
65 
66  return false;
67  }
68 }
$objId
Definition: xapitoken.php:57
__construct(ilUserCertificateRepository $userCertificateRepository)