class-wpml-st-strings-stats.php
1.2 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
<?php
class WPML_ST_Strings_Stats {
/**
* @var SitePress
*/
private $sitepress;
/**
* @var wpdb
*/
private $wpdb;
/**
* @var array
*/
private $stats;
public function __construct( wpdb $wpdb, SitePress $sitepress ) {
$this->wpdb = $wpdb;
$this->sitepress = $sitepress;
}
/**
* @param string $component_name
* @param string $type
* @param string $domain
*/
public function update( $component_name, $type, $domain ) {
$count = $this->get_count( $domain );
$string_settings = $this->sitepress->get_setting( 'st' );
$string_settings[ $type . '_localization_domains' ][ $component_name ][ $domain ] = $count;
$this->sitepress->set_setting( 'st', $string_settings, true );
$this->sitepress->save_settings();
}
/**
* @param string $domain
*
* @return int
*/
private function get_count( $domain ) {
if ( ! $this->stats ) {
$this->set_stats();
}
return isset( $this->stats[ $domain ] ) ? (int) $this->stats[ $domain ]->count : 0;
}
private function set_stats() {
$count_query = 'SELECT context, COUNT(id) count FROM ' . $this->wpdb->prefix . 'icl_strings GROUP BY context';
$this->stats = $this->wpdb->get_results( $count_query, OBJECT_K );
}
}