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