on-page queue editor working
This commit is contained in:
parent
4aee4ba21f
commit
eec73ad64d
|
@ -80,7 +80,7 @@ class WhatDidTheySay {
|
|||
if (current_user_can('submit_transcriptions')) {
|
||||
$post = get_post($post_id);
|
||||
if (!empty($post)) {
|
||||
$query = $wpdb->prepare('SELECT * FROM %s WHERE post_id = %d', $this->table, $post_id);
|
||||
$query = $wpdb->prepare('SELECT * FROM ' . $this->table . ' WHERE post_id = %d', $post_id);
|
||||
$results = $wpdb->get_results($query);
|
||||
if (!empty($results)) {
|
||||
$valid_results = array();
|
||||
|
@ -116,11 +116,11 @@ class WhatDidTheySay {
|
|||
}
|
||||
if ($ok) {
|
||||
extract($transcript_info);
|
||||
$user = get_userdata($user_id);
|
||||
$user = wp_get_current_user();
|
||||
if (!empty($user)) {
|
||||
$query = $wpdb->prepare(
|
||||
"INSERT INTO %s (post_id, user_id, language, transcript) VALUES (%d, %d, %s, %s)",
|
||||
$this->table, $post_id, $user_id, $language, $transcript
|
||||
"INSERT INTO " . $this->table . "(post_id, user_id, language, transcript) VALUES (%d, %d, %s, %s)",
|
||||
$post_id, $user->ID, $language, $transcript
|
||||
);
|
||||
|
||||
return $wpdb->query($query);
|
||||
|
@ -141,7 +141,7 @@ class WhatDidTheySay {
|
|||
global $wpdb;
|
||||
|
||||
if (current_user_can('submit_transcriptions')) {
|
||||
$query = $wpdb->prepare("SELECT * FROM %s WHERE id = %d", $this->table, $update_info['id']);
|
||||
$query = $wpdb->prepare("SELECT * FROM " . $this->table . " WHERE id = %d", $update_info['id']);
|
||||
$result = $wpdb->get_results($query);
|
||||
|
||||
if (is_array($result)) {
|
||||
|
@ -151,8 +151,8 @@ class WhatDidTheySay {
|
|||
$result->{$field} = $update_info[$field];
|
||||
}
|
||||
$query = $wpdb->prepare(
|
||||
"UPDATE %s SET language = %s, transcript = %s WHERE id = %d",
|
||||
$this->table, $result->language, $result->transcript, $result->id
|
||||
"UPDATE " . $this->table . " SET language = %s, transcript = %s WHERE id = %d",
|
||||
$result->language, $result->transcript, $result->id
|
||||
);
|
||||
$wpdb->query($query);
|
||||
return true;
|
||||
|
@ -171,9 +171,9 @@ class WhatDidTheySay {
|
|||
global $wpdb;
|
||||
|
||||
if (current_user_can('submit_transcriptions')) {
|
||||
$query = $wpdb->prepare("SELECT id FROM %s WHERE id = %d", $this->table, $transcription_id);
|
||||
$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 %s WHERE id = %d", $this->table, $transcription_id);
|
||||
$query = $wpdb->prepare("DELETE FROM " . $this->table . " WHERE id = %d", $transcription_id);
|
||||
$wpdb->query($query);
|
||||
|
||||
return true;
|
||||
|
@ -186,7 +186,7 @@ class WhatDidTheySay {
|
|||
global $wpdb;
|
||||
|
||||
if (current_user_can('approve_transcriptions')) {
|
||||
$query = $wpdb->prepare("SELECT * from %s WHERE id = %d", $this->table, $transcription_id);
|
||||
$query = $wpdb->prepare("SELECT * from " . $this->table . " WHERE id = %d", $transcription_id);
|
||||
$result = $wpdb->get_results($query);
|
||||
if (is_array($result)) {
|
||||
if (count($result) == 1) {
|
||||
|
@ -196,7 +196,7 @@ class WhatDidTheySay {
|
|||
if (!empty($post)) {
|
||||
$this->save_transcript($result->post_id, $result->language, $result->transcript);
|
||||
|
||||
$query = $wpdb->prepare("DELETE FROM %s WHERE id = %d", $this->table, $transcription_id);
|
||||
$query = $wpdb->prepare("DELETE FROM " . $this->table . " WHERE id = %d", $transcription_id);
|
||||
$result = $wpdb->query($query);
|
||||
}
|
||||
}
|
||||
|
@ -204,6 +204,16 @@ class WhatDidTheySay {
|
|||
}
|
||||
}
|
||||
|
||||
function get_queued_transcriptions_for_user_and_post($user_id, $post_id) {
|
||||
global $wpdb;
|
||||
|
||||
if (current_user_can('submit_transcriptions')) {
|
||||
$query = $wpdb->prepare("SELECT * FROM " . $this->table . " WHERE user_id = %d AND post_id = %d", $user_id, $post_id);
|
||||
return $wpdb->get_results($query);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function delete_transcript($post_id, $language) {
|
||||
if (current_user_can('approve_transcriptions')) {
|
||||
$post = get_post($post_id);
|
||||
|
|
|
@ -139,7 +139,6 @@ class WhatDidTheySayAdmin {
|
|||
if (current_user_can('submit_transcriptions')) {
|
||||
switch ($queue_transcript_info['action']) {
|
||||
case 'submit_queued_transcript':
|
||||
var_dump($queue_transcript_info);
|
||||
$result = $this->what_did_they_say->add_queued_transcription_to_post($queue_transcript_info['post_id'], $queue_transcript_info);
|
||||
if ($result) {
|
||||
$updated = __('Transcript added to queue.', 'what-did-they-say');
|
||||
|
|
|
@ -7,6 +7,7 @@ require_once(dirname(__FILE__) . '/../classes/WhatDidTheySayAdmin.php');
|
|||
class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
|
||||
function setUp() {
|
||||
_reset_wp();
|
||||
_set_user_capabilities('submit_transcriptions', 'approve_transcriptions', 'change_languages');
|
||||
}
|
||||
|
||||
function testReadLanguageData() {
|
||||
|
@ -86,6 +87,7 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
|
|||
function testHandleUpdateCapabilities() {
|
||||
$admin = new WhatDidTheySayAdmin();
|
||||
update_option('what-did-they-say-options', $admin->default_options);
|
||||
_set_user_capabilities('edit_users');
|
||||
|
||||
$admin->handle_update_capabilities(array(
|
||||
'action' => 'capabilities',
|
||||
|
|
|
@ -15,7 +15,6 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
|||
function testSaveTranscription() {
|
||||
wp_insert_post(array('ID' => 1));
|
||||
|
||||
|
||||
$what = $this->getMock('WhatDidTheySay', array('is_user_allowed_to_update'));
|
||||
|
||||
$what->save_transcript(1, "en", "This is a transcript");
|
||||
|
@ -110,7 +109,9 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
|||
wp_insert_user(array('ID' => 1, 'first_name' => 'Test', 'last_name' => 'User'));
|
||||
wp_insert_post(array('ID' => 1));
|
||||
|
||||
$expected_query = sprintf("INSERT INTO '%s' (post_id, user_id, language, transcript) VALUES ('%d', '%d', '%s', '%s')",
|
||||
wp_set_current_user(1);
|
||||
|
||||
$expected_query = sprintf("INSERT INTO %s (post_id, user_id, language, transcript) VALUES ('%d', '%d', '%s', '%s')",
|
||||
$this->what->table,
|
||||
1, 1, "en", "This is a transcript");
|
||||
|
||||
|
@ -120,7 +121,7 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
|||
->method('prepare')
|
||||
->will($this->returnValue($expected_query));
|
||||
|
||||
$what = $this->getMock('WhatDidTheySay', array('is_user_allowed_to_update'));
|
||||
$what = new WhatDidTheySay();
|
||||
|
||||
if ($expected_result === true) {
|
||||
$wpdb->expects($this->once())
|
||||
|
@ -132,7 +133,6 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
|||
$this->assertEquals($expected_result, $what->add_queued_transcription_to_post(
|
||||
1,
|
||||
array(
|
||||
'user_id' => 1,
|
||||
'language' => 'en',
|
||||
'transcript' => "This is a transcript"
|
||||
)
|
||||
|
|
|
@ -117,8 +117,26 @@ function transcripts_display($dropdown_message = null, $single_language_message
|
|||
function the_media_transcript_queue_editor() {
|
||||
global $post, $what_did_they_say;
|
||||
|
||||
$queued_transcripts_for_user = false;
|
||||
|
||||
$user = wp_get_current_user();
|
||||
if (!empty($user)) {
|
||||
$queued_transcripts_for_user = $what_did_they_say->get_queued_transcriptions_for_user_and_post($user->ID, $post->ID);
|
||||
}
|
||||
|
||||
if (current_user_can('submit_transcriptions')) { ?>
|
||||
<form method="post">
|
||||
<?php if (is_array($queued_transcripts_for_user)) { ?>
|
||||
<div class="queued-transcriptions">
|
||||
<h3><?php _e('Your queued transcriptions', 'what-did-they-say') ?></h3>
|
||||
<?php foreach ($queued_transcripts_for_user as $transcript) { ?>
|
||||
<h4><?php echo $what_did_they_say->get_language_name($transcript->language) ?></h4>
|
||||
<div>
|
||||
<?php echo $transcript->transcript ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<form method="post" class="transcript-editor">
|
||||
<input type="hidden" name="wdts[_nonce]" value="<?php echo wp_create_nonce('what-did-they-say') ?>" />
|
||||
<input type="hidden" name="wdts[action]" value="submit_queued_transcript" />
|
||||
<input type="hidden" name="wdts[post_id]" value="<?php echo $post->ID ?>" />
|
||||
|
|
Loading…
Reference in New Issue