class-wpml-tm-batch-report-email-process.php
1.38 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
<?php
/**
* Class WPML_TM_Batch_Report_Email_Process
*/
class WPML_TM_Batch_Report_Email_Process {
/**
* @var WPML_TM_Batch_Report
*/
private $batch_report;
/**
* @var WPML_TM_Batch_Report_Email_Builder
*/
private $email_builder;
/**
* WPML_TM_Batch_Report_Email_Process constructor.
*
* @param WPML_TM_Batch_Report $batch_report
* @param WPML_TM_Batch_Report_Email_Builder $email_builder
*/
public function __construct( WPML_TM_Batch_Report $batch_report, WPML_TM_Batch_Report_Email_Builder $email_builder ) {
$this->batch_report = $batch_report;
$this->email_builder = $email_builder;
}
public function process_emails() {
$batch_jobs = $this->batch_report->get_jobs();
$this->email_builder->prepare_assigned_jobs_emails( $batch_jobs );
$this->email_builder->prepare_unassigned_jobs_emails( $batch_jobs );
$this->send_emails();
}
private function send_emails() {
$headers = array();
$headers[] = 'Content-type: text/html; charset=UTF-8';
foreach ( $this->email_builder->get_emails() as $email ) {
$email['attachment'] = isset( $email['attachment'] ) ? $email['attachment'] : array();
$email_sent = wp_mail( $email['email'], $email['subject'], $email['body'], $headers, $email['attachment'] );
if ( $email_sent ) {
$this->batch_report->reset_batch_report( $email['translator_id'] );
}
}
$this->batch_report->reset_batch_report( 0 );
}
}