handle managing transcripts

This commit is contained in:
John Bintz 2009-08-19 18:54:12 -04:00
parent 7a643f4fef
commit f1b39cf269
4 changed files with 95 additions and 18 deletions

View File

@ -171,13 +171,8 @@ class WhatDidTheySay {
global $wpdb; global $wpdb;
if (current_user_can('submit_transcriptions')) { if (current_user_can('submit_transcriptions')) {
$query = $wpdb->prepare("SELECT id FROM " . $this->table . " WHERE id = %d", $transcription_id);
if (!is_null($wpdb->get_var($query))) {
$query = $wpdb->prepare("DELETE FROM " . $this->table . " WHERE id = %d", $transcription_id); $query = $wpdb->prepare("DELETE FROM " . $this->table . " WHERE id = %d", $transcription_id);
$wpdb->query($query); return $wpdb->query($query);
return true;
}
} }
return false; return false;
} }
@ -195,9 +190,7 @@ class WhatDidTheySay {
$post = get_post($result->post_id); $post = get_post($result->post_id);
if (!empty($post)) { if (!empty($post)) {
$this->save_transcript($result->post_id, $result->language, $result->transcript); $this->save_transcript($result->post_id, $result->language, $result->transcript);
$this->delete_queued_transcription($transcription_id);
$query = $wpdb->prepare("DELETE FROM " . $this->table . " WHERE id = %d", $transcription_id);
$result = $wpdb->query($query);
} }
} }
} }

View File

@ -41,6 +41,7 @@ class WhatDidTheySayAdmin {
add_action('admin_menu', array(&$this, 'admin_menu')); add_action('admin_menu', array(&$this, 'admin_menu'));
add_action('admin_notices', array(&$this, 'admin_notices')); add_action('admin_notices', array(&$this, 'admin_notices'));
add_action('admin_init', array(&$this, 'admin_init'));
wp_enqueue_script('prototype'); wp_enqueue_script('prototype');
@ -61,6 +62,10 @@ class WhatDidTheySayAdmin {
$this->read_language_file(); $this->read_language_file();
} }
function admin_init() {
wp_enqueue_script('scriptaculous-effects');
}
function the_media_transcript($transcript) { function the_media_transcript($transcript) {
return '<div class="transcript">' . $transcript . '</div>'; return '<div class="transcript">' . $transcript . '</div>';
} }
@ -137,7 +142,7 @@ class WhatDidTheySayAdmin {
function handle_update_queue_transcript($queue_transcript_info) { function handle_update_queue_transcript($queue_transcript_info) {
$updated = false; $updated = false;
if (current_user_can('submit_transcriptions')) { if (current_user_can('submit_transcriptions')) {
if ($what_did_they_say->get_allow_transcripts_for_post($queue_transcript_info['post_id'])) { if ($this->what_did_they_say->get_allow_transcripts_for_post($queue_transcript_info['post_id'])) {
switch ($queue_transcript_info['action']) { switch ($queue_transcript_info['action']) {
case 'submit_queued_transcript': case 'submit_queued_transcript':
$result = $this->what_did_they_say->add_queued_transcription_to_post($queue_transcript_info['post_id'], $queue_transcript_info); $result = $this->what_did_they_say->add_queued_transcription_to_post($queue_transcript_info['post_id'], $queue_transcript_info);
@ -167,7 +172,23 @@ class WhatDidTheySayAdmin {
break; break;
} }
} }
$this->what_did_they_say->set_allow_transcripts_for_post($post_transcript_info['post_id'], isset($post_transcript_info['allow_on_post'])); $this->what_did_they_say->set_allow_transcripts_for_post($post_transcript_info['post_id'], isset($post_transcript_info['allow_on_post']));
$queued_transcriptions = $this->what_did_they_say->get_queued_transcriptions_for_post($post_transcript_info['post_id']);
if (is_array($queued_transcriptions)) {
$transcriptions_to_delete = array();
foreach ($queued_transcriptions as $transcription) { $transcriptions_to_delete[$transcription->id] = true; }
if (isset($post_transcript_info['queue'])) {
foreach ($post_transcript_info['queue'] as $id => $keep) { unset($transcriptions_to_delete[$id]); }
}
foreach (array_keys($transcriptions_to_delete) as $id) {
$this->what_did_they_say->delete_queued_transcription($id);
}
}
$updated = __('Transcripts updated', 'what-did-they-say'); $updated = __('Transcripts updated', 'what-did-they-say');
break; break;
} }
@ -317,6 +338,8 @@ class WhatDidTheySayAdmin {
$options = get_option('what-did-they-say-options'); $options = get_option('what-did-they-say-options');
$transcripts = $this->what_did_they_say->get_transcripts($post->ID); $transcripts = $this->what_did_they_say->get_transcripts($post->ID);
$queued_transcriptions = $this->what_did_they_say->get_queued_transcriptions_for_post($post->ID);
$nonce = wp_create_nonce('what-did-they-say'); $nonce = wp_create_nonce('what-did-they-say');
include(dirname(__FILE__) . '/meta-box.inc'); include(dirname(__FILE__) . '/meta-box.inc');
} }

View File

@ -7,9 +7,35 @@
<?php _e('Allow new transcripts to be submitted for this post', 'what-did-they-say') ?> <?php _e('Allow new transcripts to be submitted for this post', 'what-did-they-say') ?>
</label> </label>
</p> </p>
<?php if (is_array($queued_transcriptions) && !empty($queued_transcriptions)) { ?>
<p><strong><?php _e('Manage queued transcripts:', 'what-did-they-say') ?></strong></p>
<?php foreach ($queued_transcriptions as $transcription) {
$user = get_userdata($transcription->user_id);
if (!empty($user)) { ?>
<div class="queued-transcription-holder">
<input type="hidden" name="wdts[queue][<?php echo $transcription->id ?>]" value="keep" />
<input type="hidden" name="wdts[language][<?php echo $transcription->id ?>]" value="<?php echo $transcription->language ?>" />
<p><?php
printf(
__('From <strong>%s</strong> in <strong>%s</strong>:', 'what-did-they-say'),
$user->display_name,
$this->what_did_they_say->get_language_name($transcription->language)
)
?></p>
<div class="queued-transcription"><?php echo $transcription->transcript ?></div>
<div class="queued-transcription-raw" style="display:none"><?php echo $transcription->transcript ?></div>
<div style="padding: 10px 0">
<a href="#" class="approve-transcript button">Approve</a>
<a href="#" class="delete-transcript button">Delete</a>
</div>
</div>
<?php } ?>
<?php } ?>
<?php } ?>
<p> <p>
<label> <label>
<?php _e('Edit transcript for:', 'what-did-they-say') ?> <?php _e('Edit provided transcript for:', 'what-did-they-say') ?>
<select name="wdts[language]" id="wdts-language"> <select name="wdts[language]" id="wdts-language">
<?php foreach ($options['languages'] as $code => $info) { ?> <?php foreach ($options['languages'] as $code => $info) { ?>
<option value="<?php echo $code ?>" <?php echo $info['default'] ? 'selected="selected"' : '' ?>><?php echo $info['name'] ?></option> <option value="<?php echo $code ?>" <?php echo $info['default'] ? 'selected="selected"' : '' ?>><?php echo $info['name'] ?></option>
@ -29,4 +55,43 @@
} }
switch_transcript(); switch_transcript();
Event.observe($('wdts-language'), 'change', switch_transcript); Event.observe($('wdts-language'), 'change', switch_transcript);
$$('.approve-transcript').each(function(b) {
Event.observe(b, 'click', function(e) {
Event.stop(e);
var lang = b.parentNode.parentNode.select("input[name*=[language]]").shift();
if (lang) {
lang = lang.value;
var editor = $('wdts-transcripts-' + lang);
var raw_transcript = b.parentNode.parentNode.select(".queued-transcription-raw").shift();
if (raw_transcript && editor) {
var ok = true;
if (editor.value.match(/[^ ]/)) {
ok = confirm('<?php _e('This will overwrite the current transcript. Are you sure?', 'what-did-they-say') ?>');
}
if (ok) {
editor.value = raw_transcript.innerHTML;
var p = b.parentNode.parentNode;
new Effect.Fade(p, {
'afterFinish': function() { p.parentNode.removeChild(p); }
});
}
}
}
});
});
$$('.delete-transcript').each(function(b) {
Event.observe(b, 'click', function(e) {
Event.stop(e);
if (confirm('<?php _e('This will delete the queued transcript. Are you sure?', 'what-did-they-say') ?>')) {
var p = b.parentNode.parentNode;
new Effect.Fade(p, {
'afterFinish': function() { p.parentNode.removeChild(p); }
});
}
});
});
</script> </script>

View File

@ -204,10 +204,6 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
$wpdb = $this->getMock('wpdb', array('prepare', 'get_var', 'query')); $wpdb = $this->getMock('wpdb', array('prepare', 'get_var', 'query'));
$wpdb->expects($this->once())
->method('get_var')
->will($this->returnValue(in_array($transcript_id_to_delete, $valid_transcripts) ? $transcript_id_to_delete : null));
if (in_array($transcript_id_to_delete, $valid_transcripts)) { if (in_array($transcript_id_to_delete, $valid_transcripts)) {
$wpdb->expects($this->once()) $wpdb->expects($this->once())
->method('query'); ->method('query');