ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
61  $suffix = '_a';
62  }
63  else
64  {
65  $suffix = '_p';
66  }
67  return $suffix;
68  }
69 
73  protected function render()
74  {
75  $this->renderStateButton();
76  $states = $this->relation->getCurrentPossibleTargetStates();
77  foreach($states as $target_state)
78  {
79  $this->renderTargetState($target_state);
80  }
81  }
82 
86  protected function getTemplateVariablePrefix()
87  {
88  return '';
89  }
90 
94  protected function renderStateButton()
95  {
96  $state_id = ilStr::convertUpperCamelCaseToUnderscoreCase($this->relation->getState()->getName());
97 
98  $this->tpl->setVariable(
99  $this->getTemplateVariablePrefix() . 'BUTTON_TXT',
100  $this->lng->txt(
101  'buddy_bs_btn_txt_' . $state_id . $this->getLanguageVariableSuffix()
102  )
103  );
104  }
105 
109  protected function renderTargetState(ilBuddySystemRelationState $target_state)
110  {
111  $state_id = ilStr::convertUpperCamelCaseToUnderscoreCase($this->relation->getState()->getName());
112  $target_state_id = ilStr::convertUpperCamelCaseToUnderscoreCase($target_state->getName());
113 
114  $this->tpl->setVariable(
115  $this->getTemplateVariablePrefix() . 'TARGET_STATE_' . strtoupper($target_state_id),
116  get_class($target_state)
117  );
118  $this->tpl->setVariable(
119  $this->getTemplateVariablePrefix() . 'TARGET_STATE_ACTION_' . strtoupper($target_state_id),
120  $target_state->getAction()
121  );
122  $this->tpl->setVariable(
123  $this->getTemplateVariablePrefix() . 'TARGET_STATE_TXT_' . strtoupper($target_state_id),
124  $this->lng->txt(
125  'buddy_bs_act_btn_txt_' . $state_id . '_to_' . $target_state_id
126  )
127  );
128  }
129 
133  public function getHtml()
134  {
135  $this->render();
136  return $this->tpl->get();
137  }
138 }
static convertUpperCamelCaseToUnderscoreCase($value)
Convert a value given in camel case conversion to underscore case conversion (e.g.
Interface ilBuddySystemRelationStateButtonRenderer.
special template class to simplify handling of ITX/PEAR
Class ilBuddySystemRelation.
global $DIC
Interface ilBuddySystemRelationState.