| 1 |
<?php |
| 2 |
|
| 3 |
class VP_Control_Field_Sorter extends VP_Control_FieldMulti implements VP_MultiSelectable |
| 4 |
{ |
| 5 |
|
| 6 |
private $_max_selection; |
| 7 |
|
| 8 |
public function __construct() |
| 9 |
{ |
| 10 |
parent::__construct(); |
| 11 |
$this->_value = array(); |
| 12 |
} |
| 13 |
|
| 14 |
public static function withArray($arr = array(), $class_name = null) |
| 15 |
{ |
| 16 |
if(is_null($class_name)) |
| 17 |
$instance = new self(); |
| 18 |
else |
| 19 |
$instance = new $class_name; |
| 20 |
$instance->set_max_selection(isset($arr['max_selection']) ? $arr['max_selection'] : false); |
| 21 |
$instance->_basic_make($arr); |
| 22 |
|
| 23 |
return $instance; |
| 24 |
} |
| 25 |
|
| 26 |
protected function _setup_data() |
| 27 |
{ |
| 28 |
$opt = array( |
| 29 |
'maximumSelectionSize' => $this->get_max_selection(), |
| 30 |
); |
| 31 |
$this->add_data('opt', VP_Util_Text::make_opt($opt)); |
| 32 |
$this->add_data('opt_raw', $opt); |
| 33 |
parent::_setup_data(); |
| 34 |
} |
| 35 |
|
| 36 |
public function render($is_compact = false) |
| 37 |
{ |
| 38 |
$this->_setup_data(); |
| 39 |
$this->add_data('is_compact', $is_compact); |
| 40 |
return VP_View::instance()->load('control/sorter', $this->get_data()); |
| 41 |
} |
| 42 |
|
| 43 |
public function get_max_selection() { |
| 44 |
return $this->_max_selection; |
| 45 |
} |
| 46 |
|
| 47 |
public function set_max_selection($_max_selection) { |
| 48 |
$this->_max_selection = $_max_selection; |
| 49 |
return $this; |
| 50 |
} |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* EOF |
| 56 |
*/ |