ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilAbstractBuddySystemRelationStateButtonRenderer.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Contact/BuddySystem/interfaces/interface.ilBuddySystemRelationStateButtonRenderer.php';
5 require_once 'Services/Utilities/classes/class.ilStr.php';
6 
12 {
16  protected $relation;
17 
21  protected $user_id;
22 
26  protected $tpl;
27 
31  protected $lng;
32 
38  {
39  global $DIC;
40 
41  $this->user_id = $user_id;
42  $this->relation = $relation;
43 
44  $this->tpl = new ilTemplate(
45  'tpl.buddy_system_state_' . ilStr::convertUpperCamelCaseToUnderscoreCase($this->relation->getState()->getName()) . '.html',
46  true,
47  true,
48  'Services/Contact/BuddySystem'
49  );
50 
51  $this->lng = $DIC['lng'];
52  }
53 
57  protected function getLanguageVariableSuffix()
58  {
59  if ($this->relation->isOwnedByRequest()) {
60  $suffix = '_a';
61  } else {
62  $suffix = '_p';
63  }
64  return $suffix;
65  }
66 
70  protected function render()
71  {
72  $this->renderStateButton();
73  $states = $this->relation->getCurrentPossibleTargetStates();
74  foreach ($states as $target_state) {
75  $this->renderTargetState($target_state);
76  }
77  }
78 
82  protected function getTemplateVariablePrefix()
83  {
84  return '';
85  }
86 
90  protected function renderStateButton()
91  {
92  $state_id = ilStr::convertUpperCamelCaseToUnderscoreCase($this->relation->getState()->getName());
93 
94  $this->tpl->setVariable(
95  $this->getTemplateVariablePrefix() . 'BUTTON_TXT',
96  $this->lng->txt(
97  'buddy_bs_btn_txt_' . $state_id . $this->getLanguageVariableSuffix()
98  )
99  );
100  }
101 
105  protected function renderTargetState(ilBuddySystemRelationState $target_state)
106  {
107  $state_id = ilStr::convertUpperCamelCaseToUnderscoreCase($this->relation->getState()->getName());
108  $target_state_id = ilStr::convertUpperCamelCaseToUnderscoreCase($target_state->getName());
109 
110  $this->tpl->setVariable(
111  $this->getTemplateVariablePrefix() . 'TARGET_STATE_' . strtoupper($target_state_id),
112  get_class($target_state)
113  );
114  $this->tpl->setVariable(
115  $this->getTemplateVariablePrefix() . 'TARGET_STATE_ACTION_' . strtoupper($target_state_id),
116  $target_state->getAction()
117  );
118  $this->tpl->setVariable(
119  $this->getTemplateVariablePrefix() . 'TARGET_STATE_TXT_' . strtoupper($target_state_id),
120  $this->lng->txt(
121  'buddy_bs_act_btn_txt_' . $state_id . '_to_' . $target_state_id
122  )
123  );
124  }
125 
129  public function getHtml()
130  {
131  $this->render();
132  return $this->tpl->get();
133  }
134 }
static convertUpperCamelCaseToUnderscoreCase($value)
Convert a value given in camel case conversion to underscore case conversion (e.g.
global $DIC
Definition: saml.php:7
Interface ilBuddySystemRelationStateButtonRenderer.
special template class to simplify handling of ITX/PEAR
Class ilBuddySystemRelation.
Interface ilBuddySystemRelationState.