function poll_delete_choices($poll) { $choices = poll_get_choices($poll); if ($choices) { foreach ($choices as $choice) { $choice->delete(); } } }
<?php // TODO: add ability to reorder poll questions? $poll = elgg_extract('poll', $vars); $body = ''; $i = 0; if ($poll) { $choices = poll_get_choices($poll); if ($choices) { foreach ($choices as $choice) { $body .= '<div id="choice_container_' . $i . '">'; $body .= elgg_view('input/text', array('name' => 'choice_text_' . $i, 'value' => $choice->text, 'class' => 'poll_input-poll-choice')); $body .= '<a href="#" alt="' . elgg_echo('poll:delete_choice') . '" title="' . elgg_echo('poll:delete_choice') . '" id="choice_delete_' . $i . '" onclick="javascript:poll_delete_choice(' . $i . '); return false;">'; $body .= '<img src="' . elgg_get_site_url() . 'mod/poll/graphics/16-em-cross.png"></a>'; $body .= '</div>'; $i += 1; } } } $body .= elgg_view('input/hidden', array('name' => 'number_of_choices', 'id' => 'number_of_choices', 'value' => $i)); $body .= '<div id="new_choices_area"></div>'; $body .= elgg_view('input/button', array('id' => 'add_choice', 'value' => elgg_echo('poll:add_choice'), 'type' => 'button', 'class' => 'elgg-button elgg-button-action')); echo $body; ?> <script type="text/javascript"> $('#add_choice').click( function() { var cnum = parseInt($('#number_of_choices').val()); $('#number_of_choices').val(cnum+1); var new_html = '<div id="choice_container_'+cnum+'">';
<?php elgg_load_library('elgg:poll'); // Make sure that entries for disabled entities also get upgraded $access_status = access_get_show_hidden_status(); access_show_hidden_entities(true); $poll_batch = new ElggBatch('elgg_get_entities', array('type' => 'object', 'subtype' => 'poll', 'limit' => false)); foreach ($poll_batch as $poll) { if (!poll_get_choices($poll) && is_array($poll->responses)) { $i = 0; $choices = $poll->responses; foreach ($choices as $choice) { $poll_choice = new ElggObject(); $poll_choice->owner_guid = $poll->owner_guid; $poll_choice->container_guid = $poll->container_guid; $poll_choice->subtype = "poll_choice"; $poll_choice->text = $choice; $poll_choice->display_order = $i * 10; $poll_choice->access_id = $poll->access_id; $poll_choice->save(); add_entity_relationship($poll_choice->guid, 'poll_choice', $poll->guid); $i += 1; } $poll->deleteMetadata('responses'); $poll->save(); } } access_show_hidden_entities($access_status); forward(REFERER);