class-wpml-tm-batch-report.php
2.15 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
80
81
82
83
84
85
<?php
/**
* Class WPML_TM_Batch_Report
*/
class WPML_TM_Batch_Report {
const BATCH_REPORT_OPTION = '_wpml_batch_report';
/**
* @var WPML_TM_Blog_Translators
*/
private $blog_translators;
/**
* WPML_TM_Batch_Report constructor.
*
* @param WPML_TM_Blog_Translators $blog_translators
*/
public function __construct( WPML_TM_Blog_Translators $blog_translators) {
$this->blog_translators = $blog_translators;
}
/**
* @param WPML_Translation_Job $job
*/
public function set_job( WPML_Translation_Job $job ) {
$batch_jobs = $batch_jobs_raw = $this->get_jobs();
$job_fields = $job->get_basic_data();
if ( WPML_User_Jobs_Notification_Settings::is_new_job_notification_enabled( $job_fields->translator_id ) ) {
$lang_pair = $job_fields->source_language_code . '|' . $job_fields->language_code;
$batch_jobs[ (int) $job_fields->translator_id ][$lang_pair][] = array(
'element_id' => isset( $job_fields->original_doc_id ) ? $job_fields->original_doc_id : null,
'type' => strtolower( $job->get_type() ),
'job_id' => $job->get_id(),
);
}
if ( $batch_jobs_raw !== $batch_jobs ) {
update_option( self::BATCH_REPORT_OPTION, $batch_jobs, 'no' );
}
}
/**
* @return array
*/
public function get_unassigned_jobs() {
$batch_jobs = $this->get_jobs();
$unassigned_jobs = array();
if( array_key_exists( 0, $batch_jobs ) ) {
$unassigned_jobs = $batch_jobs[0];
}
return $unassigned_jobs;
}
/**
* @return array
*/
public function get_unassigned_translators() {
$assigned_translators = array_keys( $this->get_jobs() );
$blog_translators = wp_list_pluck( $this->blog_translators->get_blog_translators() , 'ID');
return array_diff( $blog_translators, $assigned_translators );
}
/**
* @return array
*/
public function get_jobs() {
return get_option( self::BATCH_REPORT_OPTION ) ? get_option( self::BATCH_REPORT_OPTION ) : array();
}
public function reset_batch_report( $translator_id ) {
$batch_jobs = $this->get_jobs();
if ( array_key_exists( $translator_id, $batch_jobs ) ) {
unset( $batch_jobs[$translator_id] );
}
update_option( self::BATCH_REPORT_OPTION, $batch_jobs, 'no' );
}
}