ILIAS  release_8 Revision v8.24
class.ilAbstractBuddySystemRelationStateButtonRenderer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
28 protected int $usrId;
29 protected ilTemplate $tpl;
30 protected ilLanguage $lng;
31
33 {
34 global $DIC;
35
36 $this->usrId = $usrId;
37 $this->relation = $relation;
38
39 $this->tpl = new ilTemplate(
40 'tpl.buddy_system_state_' . ilStr::convertUpperCamelCaseToUnderscoreCase($this->relation->getState()->getName()) . '.html',
41 true,
42 true,
43 'Services/Contact/BuddySystem'
44 );
45
46 $this->lng = $DIC['lng'];
47 }
48
49 protected function getLanguageVariableSuffix(): string
50 {
51 $suffix = '_p';
52 if ($this->relation->isOwnedByActor()) {
53 $suffix = '_a';
54 }
55
56 return $suffix;
57 }
58
59 protected function render(): void
60 {
61 $this->renderStateButton();
62 $states = $this->relation->getCurrentPossibleTargetStates();
63 foreach ($states as $target_state) {
64 $this->renderTargetState($target_state);
65 }
66 }
67
68 protected function getTemplateVariablePrefix(): string
69 {
70 return '';
71 }
72
73 protected function renderStateButton(): void
74 {
75 $state_id = ilStr::convertUpperCamelCaseToUnderscoreCase($this->relation->getState()->getName());
76
77 $this->tpl->setVariable(
78 $this->getTemplateVariablePrefix() . 'BUTTON_TXT',
79 $this->lng->txt(
80 'buddy_bs_btn_txt_' . $state_id . $this->getLanguageVariableSuffix()
81 )
82 );
83 }
84
85 protected function renderTargetState(ilBuddySystemRelationState $target_state): void
86 {
87 $state_id = ilStr::convertUpperCamelCaseToUnderscoreCase($this->relation->getState()->getName());
88 $target_state_id = ilStr::convertUpperCamelCaseToUnderscoreCase($target_state->getName());
89
90 $this->tpl->setVariable(
91 $this->getTemplateVariablePrefix() . 'TARGET_STATE_' . strtoupper($target_state_id),
92 get_class($target_state)
93 );
94 $this->tpl->setVariable(
95 $this->getTemplateVariablePrefix() . 'TARGET_STATE_ACTION_' . strtoupper($target_state_id),
96 $target_state->getAction()
97 );
98 $this->tpl->setVariable(
99 $this->getTemplateVariablePrefix() . 'TARGET_STATE_TXT_' . strtoupper($target_state_id),
100 $this->lng->txt(
101 'buddy_bs_act_btn_txt_' . $state_id . '_to_' . $target_state_id
102 )
103 );
104 }
105
106 public function getHtml(): string
107 {
108 $this->render();
109
110 return $this->tpl->get();
111 }
112}
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
global $DIC
Definition: feed.php:28
Interface ilBuddySystemRelationState.