ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
UserLanguage.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29use ilObjUser;
30
31class 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
56 {
57 return $this->definition;
58 }
59
60 public function knownToNeverMatchWith(Condition $other): bool
61 {
62 return $other instanceof (self::class);
63 }
64}
__construct(private readonly CriterionContent $criterion, private readonly UserLanguageDefinition $definition, private readonly UI $ui)
User class.
A component is the most general form of an entity in the UI.
Definition: Component.php:28