| 1 |
<?php |
| 2 |
|
| 3 |
class VP_Control_Field_Slider extends VP_Control_Field |
| 4 |
{ |
| 5 |
|
| 6 |
private $_min; |
| 7 |
|
| 8 |
private $_max; |
| 9 |
|
| 10 |
private $_step; |
| 11 |
|
| 12 |
public function __construct() |
| 13 |
{ |
| 14 |
parent::__construct(); |
| 15 |
} |
| 16 |
|
| 17 |
public static function withArray($arr = array(), $class_name = null) |
| 18 |
{ |
| 19 |
if(is_null($class_name)) |
| 20 |
$instance = new self(); |
| 21 |
else |
| 22 |
$instance = new $class_name; |
| 23 |
$instance->set_min(isset($arr['min']) ? $arr['min'] : 0); |
| 24 |
$instance->set_max(isset($arr['max']) ? $arr['max'] : 100); |
| 25 |
$instance->set_step(isset($arr['step']) ? $arr['step'] : 1); |
| 26 |
$instance->_basic_make($arr); |
| 27 |
return $instance; |
| 28 |
} |
| 29 |
|
| 30 |
protected function _setup_data() |
| 31 |
{ |
| 32 |
$opt = array( |
| 33 |
'min' => $this->get_min(), |
| 34 |
'max' => $this->get_max(), |
| 35 |
'step' => $this->get_step(), |
| 36 |
'value' => $this->get_value(), |
| 37 |
); |
| 38 |
$this->add_data('opt', VP_Util_Text::make_opt($opt)); |
| 39 |
$this->add_data('opt_raw', $opt); |
| 40 |
parent::_setup_data(); |
| 41 |
} |
| 42 |
|
| 43 |
public function render($is_compact = false) |
| 44 |
{ |
| 45 |
// Setup Data |
| 46 |
$this->_setup_data(); |
| 47 |
$this->add_data('is_compact', $is_compact); |
| 48 |
return VP_View::instance()->load('control/slider', $this->get_data()); |
| 49 |
} |
| 50 |
|
| 51 |
protected function _basic_make($arr) |
| 52 |
{ |
| 53 |
parent::_basic_make($arr); |
| 54 |
$default = $this->get_default(); |
| 55 |
$default = $this->validate_value($default); |
| 56 |
$this->set_default($default); |
| 57 |
} |
| 58 |
|
| 59 |
protected function validate_value($_value) |
| 60 |
{ |
| 61 |
$out_range = (floatval($_value) < $this->get_min()) || (floatval($_value) > $this->get_max()); |
| 62 |
|
| 63 |
if (is_null($_value) || $out_range) |
| 64 |
return $this->get_min(); |
| 65 |
else |
| 66 |
return $_value; |
| 67 |
} |
| 68 |
|
| 69 |
public function set_value($_value) |
| 70 |
{ |
| 71 |
$_value = $this->validate_value($_value); |
| 72 |
parent::set_value($_value); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Get the min value |
| 77 |
* |
| 78 |
* @return Integer Minimum value of slider |
| 79 |
*/ |
| 80 |
public function get_min() { |
| 81 |
return $this->_min; |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Set the min value |
| 86 |
* |
| 87 |
* @param Integer $_min Minimum value of slider |
| 88 |
*/ |
| 89 |
public function set_min($_min) { |
| 90 |
$this->_min = $_min; |
| 91 |
return $this; |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Get the max value |
| 96 |
* |
| 97 |
* @return Integer Maximum value of slider |
| 98 |
*/ |
| 99 |
public function get_max() { |
| 100 |
return $this->_max; |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Set the max value |
| 105 |
* |
| 106 |
* @param Integer $_max Maximum value of slider |
| 107 |
*/ |
| 108 |
public function set_max($_max) { |
| 109 |
$this->_max = $_max; |
| 110 |
return $this; |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Get the step value |
| 115 |
* |
| 116 |
* @return Integer Step value of slider |
| 117 |
*/ |
| 118 |
public function get_step() { |
| 119 |
return $this->_step; |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* Set the step value |
| 124 |
* |
| 125 |
* @param Integer $_step Step value of slider |
| 126 |
*/ |
| 127 |
public function set_step($_step) { |
| 128 |
$this->_step = $_step; |
| 129 |
return $this; |
| 130 |
} |
| 131 |
|
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* EOF |
| 136 |
*/ |