Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
slider_bar.inc
1 <?php
18 require_once SQ_ATTRIBUTES_PATH.'/int/int.inc';
19 
43 {
44 
45 
53  function Asset_Attribute_Slider_Bar($attributeid=0, $value=NULL)
54  {
55  $this->Asset_Attribute($attributeid, $value);
56 
57  // apply default params where necessary
58  $this->_params['allow_empty'] = FALSE;
59  $this->_params['allow_negative'] = FALSE;
60  if (!isset($this->_params['range_lower'])) {
61  $this->_params['range_lower'] = 0;
62  }
63  if (!isset($this->_params['range_upper'])) {
64  $this->_params['range_upper'] = 10;
65  }
66 
67  // default edit params
68  if (!isset($this->_edit_params['lower_text'])) {
69  $this->_edit_params['lower_text'] = 'Lower';
70  }
71  if (!isset($this->_edit_params['upper_text'])) {
72  $this->_edit_params['upper_text'] = 'upper';
73  }
74 
75 
76  }//end constructor
77 
78 
88  function setEditParams(&$node)
89  {// TODO TOF TEST
90  if (!Asset_Attribute::setEditParams($node)) {
91  return FALSE;
92  }
93  $this->_edit_params['lower_text'] = translate((string)$node->attributes()->lower_text);
94  $this->_edit_params['upper_text'] = translate((string)$node->attributes()->upper_text);
95  return TRUE;
96 
97  }//end setEditParams()
98 
99 
109  function paint($prefix, $read_only=FALSE)
110  {
111  if ($this->value !== '') {
112  $this->value = (int)$this->value;
113  }
114  $textbox_extras = $read_only ? 'disabled="disabled"' : '';
115  require_once SQ_LIB_PATH.'/html_form/html_form.inc';
116  ?>
117  <div class="slider-container">
118  <div class="slider-label-left">
119  <?php echo $this->_edit_params['lower_text']; ?>
120  <span>= <?php echo $this->_params['range_lower']; ?></span>
121  </div>
122  <?php int_text_box($prefix, $this->value, TRUE, 4, $this->_params['range_lower'], $this->_params['range_upper'], 0, FALSE, $textbox_extras); ?>
123  <div class="slider-label-right">
124  <?php echo $this->_edit_params['upper_text']; ?>
125  <span>= <?php echo $this->_params['range_upper']; ?></span>
126  </div>
127  &nbsp;
128  </div>
129  <script type="text/javascript" src="<?php echo sq_web_path('lib'); ?>/js/slider_bar.js"></script>
130  <style type="text/css">
131  @import url(<?php echo sq_web_path('lib');?>/web/css/slider_bar.css);
132  </style>
133  <?php
134 
135  }//end paint()
136 
137 
146  function process($prefix)
147  {
148  if (!isset($_REQUEST[$prefix])) return FALSE;
149  $value = $_REQUEST[$prefix];
150  if ($value !== '') $value = (int)$value;
151  if ($this->value != $value && $this->setValue($value)) {
152  $this->processed = TRUE;
153  } else {
154  $this->processed = FALSE;
155  }
156 
157  }//end process()
158 
159 
168  function validateValue(&$value)
169  {
170  $value = trim($value);
171 
172  $allow_negative = array_get_index($this->_params, 'allow_negative', TRUE);
173  $allow_empty = array_get_index($this->_params, 'allow_empty', TRUE);
174 
175  if ($allow_empty && ($value === '')) {
176  return TRUE;
177  }
178 
179  if (!$allow_negative && $value < 0) {
180  return FALSE;
181  }
182 
183  $new_value = (int)$value;
184 
185  // we are comparing by string here, reason is that passing in a string as $value
186  // becomes comparing $value with zero which is TRUE. So instead we would be comparing
187  // it with a string '0', which is FALSE and what we want for it to invalidate.
188  // Only genuine ints will pass through.
189  if ((string)$new_value != $value) return FALSE;
190  return TRUE;
191 
192  }//end validateValue()
193 
194 
195 }//end class
196 
197 ?>