Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
decision_tree_question_type_select.inc
1 <?php
18 require_once SQ_PACKAGES_PATH.'/cms/page_templates/page_decision_tree/decision_tree_question/decision_tree_question.inc';
19 
20 
33 {
34 
35 
42  function __construct($assetid=0)
43  {
44  parent::__construct($assetid);
45 
46  }//end constructor
47 
48 
56  function _getAllowedLinks()
57  {
58  $page_links = parent::_getAllowedLinks();
59  return $page_links;
60 
61  }//end _getAllowedLinks()
62 
63 
70  function getHtmlField(){
71 
72  if ($this->attr('style') == 'DROP_DOWN') {
73  $replacement = $this->getHtmlSelectField();
74  } else {
75  $replacement = $this->getHtmlRadioField();
76  }
77  return $replacement;
78 
79  }
80 
87  function getHtmlSelectField()
88  {
89  $name = 'q'.$this->id;
90 
91  // prepare a valid value for the field id
92  $extras = 'id="'.str_replace(':', '_', $name).'" '.$this->attr('extra');
93  $extras .= ' onChange="get_next_step(this.value,'.$this->id.')"';
94 
95  $default_value = $this->attr('empty_key');
96  // If the default value is NULL on some configuration, make it empty string to prevent infinite loop.
97  if (is_null($default_value)) {
98  $default_value = '';
99  }//end if
100 
101  ob_start();
102  combo_box($name, $this->getOptions(), FALSE, $default_value, 0, $extras);
103  $html = ob_get_contents();
104  ob_end_clean();
105  return $html;
106 
107  }//end getHtmlSelectField()
108 
109 
116  function getHtmlRadioField()
117  {
118  $name = 'q'.$this->id;
119  // prepare a valid value for the field id
120 
121  $default_value = $this->attr('empty_key');
122  // If the default value is NULL on some configuration, make it empty string to prevent infinite loop.
123  if (is_null($default_value)) {
124  $default_value = '';
125  }//end if
126 
127  $options = $this->getOptions();
128  $onclick = 'get_next_step(this.value,'.$this->id.')';
129 
130  ob_start();
131  echo "<ul>";
132  $i = 0;
133  foreach ($options as $value => $title){
134  if ($value === $default_value) continue;
135  $for = htmlspecialchars($name.'_'.$i);
136  $extras = 'id="'.$name.'_'.$i.'" '.$this->attr('extra');
137  if ($i == 0) {
138  //special treatment for the first radio box so the javascript can identify this question.
139  $extras = 'id="'.$name.'" '.$this->attr('extra');
140  $for = $name;
141  }
142  echo "<li>";
143  radio_button($this->attr('name'), $value, FALSE, $onclick, $extras);
144  label($title, $for);
145  echo "</li>";
146  $i++;
147  }
148  echo "</ul>";
149  $html = ob_get_contents();
150  ob_end_clean();
151  return $html;
152 
153  }//end getHtmlRadioField()
154 
155 
162  function getOptions()
163  {
164  $options = $this->attr('options');
165 
166  if (count($options) > 0) {
167  $decoded_options = Array();
168  $decoded_options[$this->attr('empty_key')] = $this->attr('empty_text');
169  // remove empty options
170  foreach (array_keys($options) as $k) {
171  if ($options[$k] != '') {
172  $decoded_options[html_entity_decode($k, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)] = html_entity_decode($options[$k], ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
173  }
174  }
175  $options = $decoded_options;
176  }
177 
178  return $options;
179 
180  }//end getOptions()
181 
182 
183 }//end class
184 ?>