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')) {
|
if (current_user_can('submit_transcriptions')) {
|
||||||
$post = get_post($post_id);
|
$post = get_post($post_id);
|
||||||
if (!empty($post)) {
|
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);
|
$results = $wpdb->get_results($query);
|
||||||
if (!empty($results)) {
|
if (!empty($results)) {
|
||||||
$valid_results = array();
|
$valid_results = array();
|
||||||
|
@ -104,7 +104,7 @@ class WhatDidTheySay {
|
||||||
*/
|
*/
|
||||||
function add_queued_transcription_to_post($post_id, $transcript_info) {
|
function add_queued_transcription_to_post($post_id, $transcript_info) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
if (current_user_can('approve_transcriptions')) {
|
if (current_user_can('approve_transcriptions')) {
|
||||||
$post = get_post($post_id);
|
$post = get_post($post_id);
|
||||||
if (!empty($post)) {
|
if (!empty($post)) {
|
||||||
|
@ -116,11 +116,11 @@ class WhatDidTheySay {
|
||||||
}
|
}
|
||||||
if ($ok) {
|
if ($ok) {
|
||||||
extract($transcript_info);
|
extract($transcript_info);
|
||||||
$user = get_userdata($user_id);
|
$user = wp_get_current_user();
|
||||||
if (!empty($user)) {
|
if (!empty($user)) {
|
||||||
$query = $wpdb->prepare(
|
$query = $wpdb->prepare(
|
||||||
"INSERT INTO %s (post_id, user_id, language, transcript) VALUES (%d, %d, %s, %s)",
|
"INSERT INTO " . $this->table . "(post_id, user_id, language, transcript) VALUES (%d, %d, %s, %s)",
|
||||||
$this->table, $post_id, $user_id, $language, $transcript
|
$post_id, $user->ID, $language, $transcript
|
||||||
);
|
);
|
||||||
|
|
||||||
return $wpdb->query($query);
|
return $wpdb->query($query);
|
||||||
|
@ -141,7 +141,7 @@ class WhatDidTheySay {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
if (current_user_can('submit_transcriptions')) {
|
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);
|
$result = $wpdb->get_results($query);
|
||||||
|
|
||||||
if (is_array($result)) {
|
if (is_array($result)) {
|
||||||
|
@ -151,8 +151,8 @@ class WhatDidTheySay {
|
||||||
$result->{$field} = $update_info[$field];
|
$result->{$field} = $update_info[$field];
|
||||||
}
|
}
|
||||||
$query = $wpdb->prepare(
|
$query = $wpdb->prepare(
|
||||||
"UPDATE %s SET language = %s, transcript = %s WHERE id = %d",
|
"UPDATE " . $this->table . " SET language = %s, transcript = %s WHERE id = %d",
|
||||||
$this->table, $result->language, $result->transcript, $result->id
|
$result->language, $result->transcript, $result->id
|
||||||
);
|
);
|
||||||
$wpdb->query($query);
|
$wpdb->query($query);
|
||||||
return true;
|
return true;
|
||||||
|
@ -171,9 +171,9 @@ class WhatDidTheySay {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
if (current_user_can('submit_transcriptions')) {
|
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))) {
|
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);
|
$wpdb->query($query);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -186,7 +186,7 @@ class WhatDidTheySay {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
if (current_user_can('approve_transcriptions')) {
|
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);
|
$result = $wpdb->get_results($query);
|
||||||
if (is_array($result)) {
|
if (is_array($result)) {
|
||||||
if (count($result) == 1) {
|
if (count($result) == 1) {
|
||||||
|
@ -196,13 +196,23 @@ class WhatDidTheySay {
|
||||||
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);
|
||||||
|
|
||||||
$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);
|
$result = $wpdb->query($query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
function delete_transcript($post_id, $language) {
|
||||||
if (current_user_can('approve_transcriptions')) {
|
if (current_user_can('approve_transcriptions')) {
|
||||||
|
|
|
@ -139,7 +139,6 @@ class WhatDidTheySayAdmin {
|
||||||
if (current_user_can('submit_transcriptions')) {
|
if (current_user_can('submit_transcriptions')) {
|
||||||
switch ($queue_transcript_info['action']) {
|
switch ($queue_transcript_info['action']) {
|
||||||
case 'submit_queued_transcript':
|
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);
|
$result = $this->what_did_they_say->add_queued_transcription_to_post($queue_transcript_info['post_id'], $queue_transcript_info);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$updated = __('Transcript added to queue.', 'what-did-they-say');
|
$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 {
|
class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
|
||||||
function setUp() {
|
function setUp() {
|
||||||
_reset_wp();
|
_reset_wp();
|
||||||
|
_set_user_capabilities('submit_transcriptions', 'approve_transcriptions', 'change_languages');
|
||||||
}
|
}
|
||||||
|
|
||||||
function testReadLanguageData() {
|
function testReadLanguageData() {
|
||||||
|
@ -86,6 +87,7 @@ class WhatDidTheySayAdminTest extends PHPUnit_Framework_TestCase {
|
||||||
function testHandleUpdateCapabilities() {
|
function testHandleUpdateCapabilities() {
|
||||||
$admin = new WhatDidTheySayAdmin();
|
$admin = new WhatDidTheySayAdmin();
|
||||||
update_option('what-did-they-say-options', $admin->default_options);
|
update_option('what-did-they-say-options', $admin->default_options);
|
||||||
|
_set_user_capabilities('edit_users');
|
||||||
|
|
||||||
$admin->handle_update_capabilities(array(
|
$admin->handle_update_capabilities(array(
|
||||||
'action' => 'capabilities',
|
'action' => 'capabilities',
|
||||||
|
|
|
@ -15,7 +15,6 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
||||||
function testSaveTranscription() {
|
function testSaveTranscription() {
|
||||||
wp_insert_post(array('ID' => 1));
|
wp_insert_post(array('ID' => 1));
|
||||||
|
|
||||||
|
|
||||||
$what = $this->getMock('WhatDidTheySay', array('is_user_allowed_to_update'));
|
$what = $this->getMock('WhatDidTheySay', array('is_user_allowed_to_update'));
|
||||||
|
|
||||||
$what->save_transcript(1, "en", "This is a transcript");
|
$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_user(array('ID' => 1, 'first_name' => 'Test', 'last_name' => 'User'));
|
||||||
wp_insert_post(array('ID' => 1));
|
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,
|
$this->what->table,
|
||||||
1, 1, "en", "This is a transcript");
|
1, 1, "en", "This is a transcript");
|
||||||
|
|
||||||
|
@ -120,7 +121,7 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
||||||
->method('prepare')
|
->method('prepare')
|
||||||
->will($this->returnValue($expected_query));
|
->will($this->returnValue($expected_query));
|
||||||
|
|
||||||
$what = $this->getMock('WhatDidTheySay', array('is_user_allowed_to_update'));
|
$what = new WhatDidTheySay();
|
||||||
|
|
||||||
if ($expected_result === true) {
|
if ($expected_result === true) {
|
||||||
$wpdb->expects($this->once())
|
$wpdb->expects($this->once())
|
||||||
|
@ -128,11 +129,10 @@ class WhatDidTheySayTest extends PHPUnit_Framework_TestCase {
|
||||||
->with($expected_query)
|
->with($expected_query)
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals($expected_result, $what->add_queued_transcription_to_post(
|
$this->assertEquals($expected_result, $what->add_queued_transcription_to_post(
|
||||||
1,
|
1,
|
||||||
array(
|
array(
|
||||||
'user_id' => 1,
|
|
||||||
'language' => 'en',
|
'language' => 'en',
|
||||||
'transcript' => "This is a transcript"
|
'transcript' => "This is a transcript"
|
||||||
)
|
)
|
||||||
|
|
|
@ -116,9 +116,27 @@ function transcripts_display($dropdown_message = null, $single_language_message
|
||||||
|
|
||||||
function the_media_transcript_queue_editor() {
|
function the_media_transcript_queue_editor() {
|
||||||
global $post, $what_did_they_say;
|
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')) { ?>
|
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[_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[action]" value="submit_queued_transcript" />
|
||||||
<input type="hidden" name="wdts[post_id]" value="<?php echo $post->ID ?>" />
|
<input type="hidden" name="wdts[post_id]" value="<?php echo $post->ID ?>" />
|
||||||
|
@ -135,7 +153,7 @@ function the_media_transcript_queue_editor() {
|
||||||
<?php _e('Transcription:', 'what-did-they-say') ?><br />
|
<?php _e('Transcription:', 'what-did-they-say') ?><br />
|
||||||
<textarea style="height: 200px; width: 90%" name="wdts[transcript]"></textarea>
|
<textarea style="height: 200px; width: 90%" name="wdts[transcript]"></textarea>
|
||||||
</label>
|
</label>
|
||||||
<input type="submit" value="<?php _e('Submit New Transcription', 'what-did-they-say') ?>" />
|
<input type="submit" value="<?php _e('Submit New Transcription', 'what-did-they-say') ?>" />
|
||||||
</form>
|
</form>
|
||||||
<?php }
|
<?php }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue