ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilAbstractBuddySystemRelationStateButtonRenderer.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3
9{
11 protected $relation;
12
14 protected $usrId;
15
17 protected $tpl;
18
20 protected $lng;
21
27 {
28 global $DIC;
29
30 $this->usrId = $usrId;
31 $this->relation = $relation;
32
33 $this->tpl = new ilTemplate(
34 'tpl.buddy_system_state_' . ilStr::convertUpperCamelCaseToUnderscoreCase($this->relation->getState()->getName()) . '.html',
35 true,
36 true,
37 'Services/Contact/BuddySystem'
38 );
39
40 $this->lng = $DIC['lng'];
41 }
42
46 protected function getLanguageVariableSuffix() : string
47 {
48 $suffix = '_p';
49 if ($this->relation->isOwnedByActor()) {
50 $suffix = '_a';
51 }
52
53 return $suffix;
54 }
55
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
71 protected function getTemplateVariablePrefix() : string
72 {
73 return '';
74 }
75
79 protected function renderStateButton() : void
80 {
81 $state_id = ilStr::convertUpperCamelCaseToUnderscoreCase($this->relation->getState()->getName());
82
83 $this->tpl->setVariable(
84 $this->getTemplateVariablePrefix() . 'BUTTON_TXT',
85 $this->lng->txt(
86 'buddy_bs_btn_txt_' . $state_id . $this->getLanguageVariableSuffix()
87 )
88 );
89 }
90
94 protected function renderTargetState(ilBuddySystemRelationState $target_state) : void
95 {
96 $state_id = ilStr::convertUpperCamelCaseToUnderscoreCase($this->relation->getState()->getName());
97 $target_state_id = ilStr::convertUpperCamelCaseToUnderscoreCase($target_state->getName());
98
99 $this->tpl->setVariable(
100 $this->getTemplateVariablePrefix() . 'TARGET_STATE_' . strtoupper($target_state_id),
101 get_class($target_state)
102 );
103 $this->tpl->setVariable(
104 $this->getTemplateVariablePrefix() . 'TARGET_STATE_ACTION_' . strtoupper($target_state_id),
105 $target_state->getAction()
106 );
107 $this->tpl->setVariable(
108 $this->getTemplateVariablePrefix() . 'TARGET_STATE_TXT_' . strtoupper($target_state_id),
109 $this->lng->txt(
110 'buddy_bs_act_btn_txt_' . $state_id . '_to_' . $target_state_id
111 )
112 );
113 }
114
118 public function getHtml() : string
119 {
120 $this->render();
121
122 return $this->tpl->get();
123 }
124}
An exception for terminatinating execution or to throw for unit testing.
Class ilBuddySystemRelation.
static convertUpperCamelCaseToUnderscoreCase($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.
$DIC
Definition: xapitoken.php:46