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