ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAbstractBuddySystemRelationStateButtonRenderer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 protected ilTemplate $tpl;
24 protected ilLanguage $lng;
25
26 public function __construct(
27 protected int $usrId,
29 ?ilLanguage $lng = null
30 ) {
31 global $DIC;
32
33 $this->tpl = new ilTemplate(
34 'tpl.buddy_system_state_' . ilStr::convertUpperCamelCaseToUnderscoreCase($this->relation->getState()->getName()) . '.html',
35 true,
36 true,
37 'components/ILIAS/Contact/BuddySystem'
38 );
39
40 $this->tpl->setVariable('MENU_ID', uniqid('buddy-system-menu', true));
41
42 $this->lng = $lng ?? $DIC['lng'];
43 }
44
45 protected function getLanguageVariableSuffix(): string
46 {
47 $suffix = '_p';
48 if ($this->relation->isOwnedByActor()) {
49 $suffix = '_a';
50 }
51
52 return $suffix;
53 }
54
55 protected function render(): void
56 {
57 $this->renderStateButton();
58 $states = $this->relation->getCurrentPossibleTargetStates();
59 foreach ($states as $target_state) {
60 $this->renderTargetState($target_state);
61 }
62 }
63
64 protected function getTemplateVariablePrefix(): string
65 {
66 return '';
67 }
68
69 protected function renderStateButton(): void
70 {
71 $state_id = ilStr::convertUpperCamelCaseToUnderscoreCase($this->relation->getState()->getName());
72
73 $this->tpl->setVariable(
74 $this->getTemplateVariablePrefix() . 'BUTTON_TXT',
75 $this->lng->txt(
76 'buddy_bs_btn_txt_' . $state_id . $this->getLanguageVariableSuffix()
77 )
78 );
79 }
80
81 protected function renderTargetState(ilBuddySystemRelationState $target_state): void
82 {
83 $state_id = ilStr::convertUpperCamelCaseToUnderscoreCase($this->relation->getState()->getName());
84 $target_state_id = ilStr::convertUpperCamelCaseToUnderscoreCase($target_state->getName());
85
86 $this->tpl->setVariable(
87 $this->getTemplateVariablePrefix() . 'TARGET_STATE_' . strtoupper($target_state_id),
88 $target_state::class
89 );
90 $this->tpl->setVariable(
91 $this->getTemplateVariablePrefix() . 'TARGET_STATE_ACTION_' . strtoupper($target_state_id),
92 $target_state->getAction()
93 );
94 $this->tpl->setVariable(
95 $this->getTemplateVariablePrefix() . 'TARGET_STATE_TXT_' . strtoupper($target_state_id),
96 $this->lng->txt(
97 'buddy_bs_act_btn_txt_' . $state_id . '_to_' . $target_state_id
98 )
99 );
100 }
101
102 public function getHtml(): string
103 {
104 $this->render();
105
106 return $this->tpl->get();
107 }
108}
$relation
__construct(protected int $usrId, protected ilBuddySystemRelation $relation, ?ilLanguage $lng=null)
Class ilBuddySystemRelation.
language handling
static convertUpperCamelCaseToUnderscoreCase(string $value)
Convert a value given in camel case conversion to underscore case conversion (e.g.
special template class to simplify handling of ITX/PEAR
Interface ilBuddySystemRelationState.
global $DIC
Definition: shib_login.php:26