wpml-st-string-dependencies-records.php
1.19 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_String_Dependencies_Records {
/** @var wpdb $wpdb */
private $wpdb;
public function __construct( wpdb $wpdb ) {
$this->wpdb = $wpdb;
}
/**
* @param string $type
* @param int $id
*
* @return int
*/
public function get_parent_id_from( $type, $id ) {
switch ( $type ) {
case 'package':
$query = "SELECT post_id FROM {$this->wpdb->prefix}icl_string_packages WHERE ID = %d";
break;
case 'string':
$query = "SELECT string_package_id FROM {$this->wpdb->prefix}icl_strings WHERE id = %d";
break;
default:
return 0;
}
return (int) $this->wpdb->get_var( $this->wpdb->prepare( $query, $id ) );
}
/**
* @param string $type
* @param int $id
*
* @return array
*/
public function get_child_ids_from( $type, $id ) {
switch ( $type ) {
case 'post':
$query = "SELECT id FROM {$this->wpdb->prefix}icl_string_packages WHERE post_id = %d";
break;
case 'package':
$query = "SELECT ID FROM {$this->wpdb->prefix}icl_strings WHERE string_package_id = %d";
break;
default:
return array();
}
$ids = $this->wpdb->get_col( $this->wpdb->prepare( $query, $id ) );
return array_map( 'intval', $ids );
}
}