class-wpml-st-db-mappers-strings.php
1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
class WPML_ST_DB_Mappers_Strings {
/**
* @var wpdb
*/
private $wpdb;
/**
* @param wpdb $wpdb
*/
public function __construct( wpdb $wpdb ) {
$this->wpdb = $wpdb;
}
/**
* @param string $context
*
* @return array
*/
public function get_all_by_context( $context ) {
$where = strpos( $context, '%' ) === false ? '=' : 'LIKE';
$query = "
SELECT * FROM {$this->wpdb->prefix}icl_strings
WHERE context {$where} %s
";
$query = $this->wpdb->prepare( $query, esc_sql( $context ) );
return $this->wpdb->get_results( $query, ARRAY_A );
}
/**
* Get a single string row by its domain and value
*
* @param string $domain
* @param string $value
*
* @return array
*/
public function getByDomainAndValue( $domain, $value ) {
$sql = "SELECT * FROM {$this->wpdb->prefix}icl_strings WHERE `context` = %s and `value` = %s";
return $this->wpdb->get_row( $this->wpdb->prepare( $sql, $domain, $value ) );
}
/**
* Get a single string row by its id
*
* @param int $id
*
* @return array
*/
public function getById( $id ) {
$sql = "SELECT * FROM {$this->wpdb->prefix}icl_strings WHERE id = %d";
return $this->wpdb->get_row( $this->wpdb->prepare( $sql, $id ) );
}
}