ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
UserLanguage.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
29 use ilObjUser;
30 
31 class UserLanguage implements Condition
32 {
33  public function __construct(
34  private readonly CriterionContent $criterion,
35  private readonly UserLanguageDefinition $definition,
36  private readonly UI $ui
37  ) {
38  }
39 
40  public function asComponent(): Component
41  {
42  return $this->ui->create()->legacy()->content(sprintf(
43  '<div><b>%s</b><br/>%s</div>',
44  $this->definition->translatedType(),
45  $this->definition->translatedLanguage($this->criterion->arguments()['lng'])
46  ));
47  }
48 
49  public function eval(ilObjUser $user): bool
50  {
51  $user_lang = $user->getLanguage() ?: $this->ui->getDefaultLanguage();
52  return strtoupper($user_lang) === strtoupper($this->criterion->arguments()['lng']);
53  }
54 
55  public function definition(): ConditionDefinition
56  {
57  return $this->definition;
58  }
59 
60  public function knownToNeverMatchWith(Condition $other): bool
61  {
62  return $other instanceof (self::class);
63  }
64 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(private readonly CriterionContent $criterion, private readonly UserLanguageDefinition $definition, private readonly UI $ui)