Move lists can be employed to allow a user to move items between two
or more lists. Move lists are handled by the MU_Move_List class.
Consider the following example, in which staff people can be moved
between offices:
$move_list = new MU_Move_List('staff_offices');
$move_list->title = 'Move lists';
$move_list->instructions = 'Use the arrow buttons to move staff people between offices.';
$move_list->sorter = 'list_sort';
$list1 = array(
'tepeds' => 'Tepe, Dirk',
'moosejc' => 'Moose, John',
'kingmatm' => 'Kingman, Tim',
'covertka' => 'Covert, Kent');
$list2 = array(
'tholesm' => 'Thole, Steve',
'coopermj' => 'Cooper, Micah');
$list3 = array(
'basiltm' => 'Norviel, Taryn',
'winterskm' => 'Winters, Kirk');
$move_list->add_list('gaskill', $list1, 'Gaskill Hall');
$move_list->add_list('unassigned', $list2, 'Unassigned');
$move_list->add_list('hoyt', $list3, 'Hoyt Hall');
$move_list->add_user_action('done', ' Done ');
$body->add_object($move_list);
function list_sort ($name, &$list) {
if ($name == 'hoyt') {
arsort($list); //reverse the order of this sort
} else {
asort($list);
}
}
The output from this code can be seen in the "Move Lists"
example included with Marmot.
Just as with MU_Form
or MU_Inline_Form,
we must first create a new instance of MU_Move_List. We can then set class
properties like title and instructions.
The sorter property is used to specify the name of a
function that will be used to sort the contents of the lists.
$move_list = new MU_Move_List('staff_offices');
$move_list->title = 'Move lists';
$move_list->instructions = 'Use the arrow buttons to move staff people between offices.';
$move_list->sorter = 'list_sort';
Now we can create associative arrays containing the contents of our
lists and add them using the add_list() method,
which accepts a name, an array, and a label:
$list1 = array(
'tepeds' => 'Tepe, Dirk',
'moosejc' => 'Moose, John',
'kingmatm' => 'Kingman, Tim',
'covertka' => 'Covert, Kent');
$list2 = array(
'tholesm' => 'Thole, Steve',
'coopermj' => 'Cooper, Micah');
$list3 = array(
'basiltm' => 'Norviel, Taryn',
'winterskm' => 'Winters, Kirk');
$move_list->add_list('gaskill', $list1, 'Gaskill Hall');
$move_list->add_list('unassigned', $list2, 'Unassigned');
$move_list->add_list('hoyt', $list3, 'Hoyt Hall');
Finally, a submit button is added and the move list is added to the
document's body:
$move_list->add_user_action('done', ' Done ');
$body->add_object($move_list);