improve search
This commit is contained in:
parent
40b3d22820
commit
a6e1438231
|
@ -2,6 +2,7 @@
|
|||
|
||||
class WDTSTranscriptManager {
|
||||
var $key = null;
|
||||
var $search_key = null;
|
||||
var $post_id = null;
|
||||
var $allow_multiple = false;
|
||||
|
||||
|
@ -68,12 +69,22 @@ class WDTSTranscriptManager {
|
|||
$transcripts = $new_transcripts;
|
||||
}
|
||||
|
||||
$this->_update_search_field($transcripts);
|
||||
|
||||
return update_post_meta($this->post_id, $this->key, $transcripts);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function _update_search_field($transcripts) {
|
||||
if (!empty($this->search_key)) {
|
||||
$search_lines = array();
|
||||
foreach ($transcripts as $transcript) { $search_lines[] = $transcript['transcript']; }
|
||||
update_post_meta($this->post_id, $this->search_key, implode(" ", $search_lines));
|
||||
}
|
||||
}
|
||||
|
||||
function delete_transcript($language = null) {
|
||||
return $this->_delete_transcript_by_field('language', $language);
|
||||
}
|
||||
|
@ -94,6 +105,8 @@ class WDTSTranscriptManager {
|
|||
}
|
||||
}
|
||||
|
||||
$this->_update_search_field($new_transcripts);
|
||||
|
||||
update_post_meta($this->post_id, $this->key, $new_transcripts);
|
||||
return $deleted_transcript;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ class WDTSQueuedTranscript extends WDTSTranscriptManager {
|
|||
|
||||
class WDTSApprovedTranscript extends WDTSTranscriptManager {
|
||||
var $key = "approved_transcripts";
|
||||
var $search_key = "approved_transcripts_words";
|
||||
}
|
||||
|
||||
?>
|
|
@ -80,7 +80,7 @@ class WhatDidTheySayAdmin {
|
|||
|
||||
$search = get_query_var('s');
|
||||
if (!empty($search)) {
|
||||
$where .= $wpdb->prepare(" OR ($wpdb->postmeta.meta_key = %s ", 'approved_transcripts');
|
||||
$where .= $wpdb->prepare(" OR ($wpdb->postmeta.meta_key = %s ", 'approved_transcripts_words');
|
||||
$search = addslashes_gpc($search);
|
||||
$where .= " AND $wpdb->postmeta.meta_value LIKE '%$search%') ";
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
|
|||
|
||||
$this->w = new WDTSTranscriptManager(1);
|
||||
$this->w->key = "test";
|
||||
$this->w->search_key = "test_search";
|
||||
}
|
||||
|
||||
function testSaveTranscript() {
|
||||
|
@ -36,6 +37,8 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
|
|||
get_post_meta(1, $this->w->key, true)
|
||||
);
|
||||
|
||||
$this->assertEquals("this is a transcript", get_post_meta(1, $this->w->search_key, true));
|
||||
|
||||
$this->w->save_transcript(array(
|
||||
'language' => 'en',
|
||||
'transcript' => 'this is another transcript'
|
||||
|
@ -53,6 +56,8 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
|
|||
get_post_meta(1, $this->w->key, true)
|
||||
);
|
||||
|
||||
$this->assertEquals("this is another transcript", get_post_meta(1, $this->w->search_key, true));
|
||||
|
||||
$this->w->save_transcript(array(
|
||||
'language' => 'fr',
|
||||
'transcript' => "il s'agit d'une nouvelle transcription"
|
||||
|
@ -76,6 +81,8 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
|
|||
get_post_meta(1, $this->w->key, true)
|
||||
);
|
||||
|
||||
$this->assertEquals("this is another transcript il s'agit d'une nouvelle transcription", get_post_meta(1, $this->w->search_key, true));
|
||||
|
||||
$this->w->allow_multiple = true;
|
||||
|
||||
$this->w->save_transcript(array(
|
||||
|
@ -106,6 +113,8 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
|
|||
),
|
||||
get_post_meta(1, $this->w->key, true)
|
||||
);
|
||||
|
||||
$this->assertEquals("this is another transcript il s'agit d'une nouvelle transcription this is yet another transcript", get_post_meta(1, $this->w->search_key, true));
|
||||
}
|
||||
|
||||
function testDeleteTranscript() {
|
||||
|
@ -129,6 +138,8 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
|
|||
'key' => 1
|
||||
),
|
||||
), get_post_meta(1, $this->w->key, true));
|
||||
|
||||
$this->assertEquals("il s'agit d'une nouvelle transcription", get_post_meta(1, $this->w->search_key, true));
|
||||
}
|
||||
|
||||
function testDeleteTranscriptByKey() {
|
||||
|
@ -160,6 +171,8 @@ class WDTSTranscriptTest extends PHPUnit_Framework_TestCase {
|
|||
'key' => 1
|
||||
),
|
||||
), get_post_meta(1, $this->w->key, true));
|
||||
|
||||
$this->assertEquals("il s'agit d'une nouvelle transcription", get_post_meta(1, $this->w->search_key, true));
|
||||
}
|
||||
|
||||
function testGetLanguages() {
|
||||
|
|
Loading…
Reference in New Issue