class-wpml-st-icl-string-translations.php
1.53 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
class WPML_ST_ICL_String_Translations extends WPML_WPDB_User {
private $table = 'icl_string_translations';
private $string_id = 0;
private $lang_code;
private $id;
/**
* WPML_ST_ICL_String_Translations constructor.
*
* @param wpdb $wpdb
* @param int $string_id
* @param string $lang_code
*/
public function __construct( &$wpdb, $string_id, $lang_code ) {
parent::__construct( $wpdb );
$string_id = (int) $string_id;
if ( $string_id > 0 && $lang_code ) {
$this->string_id = $string_id;
$this->lang_code = $lang_code;
} else {
throw new InvalidArgumentException(
'Invalid String ID: '
. $string_id . ' or language_code: ' . $lang_code
);
}
}
/**
* @return int|string
*/
public function translator_id() {
return $this->wpdb->get_var(
$this->wpdb->prepare(
" SELECT translator_id
FROM {$this->wpdb->prefix}{$this->table}
WHERE id = %d LIMIT 1",
$this->id()
)
);
}
/**
* @return string
*/
public function value() {
return $this->wpdb->get_var(
$this->wpdb->prepare(
" SELECT value
FROM {$this->wpdb->prefix}{$this->table}
WHERE id = %d LIMIT 1",
$this->id()
)
);
}
/**
* @return int
*/
public function id() {
return (int) ( $this->id
? $this->id
: $this->wpdb->get_var(
$this->wpdb->prepare(
" SELECT id
FROM {$this->wpdb->prefix}{$this->table}
WHERE string_id = %d AND language = %s
LIMIT 1",
$this->string_id,
$this->lang_code
)
) );
}
}