class-wpml-tm-emails-settings.php
4.11 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
class WPML_TM_Emails_Settings {
const TEMPLATE = 'emails-settings.twig';
const COMPLETED_JOB_FREQUENCY = 'completed_frequency';
const NOTIFY_IMMEDIATELY = 1;
const NOTIFY_DAILY = 2;
const NOTIFY_WEEKLY = 3;
/**
* @var IWPML_Template_Service
*/
private $template_service;
/**
* @var array
*/
private $tm;
public function __construct( IWPML_Template_Service $template_service, TranslationManagement $tm ) {
$this->template_service = $template_service;
$this->tm = $tm;
}
public function add_hooks() {
add_action( 'wpml_tm_translation_notification_setting_after', array( $this, 'render' ) );
add_action( 'wpml_tm_notification_settings_saved', array( $this, 'remove_scheduled_summary_email' ) );
}
public function render() {
echo $this->template_service->show( $this->get_model(), self::TEMPLATE );
}
private function get_model() {
return array(
'strings' => array(
'section_title_translator' => __( 'Notification emails to translators', 'wpml-translation-management' ),
'label_new_job' => __( 'Notify translators when new jobs are waiting for them', 'wpml-translation-management' ),
'label_include_xliff' => __( 'Include XLIFF files in the notification emails', 'wpml-translation-management' ),
'label_resigned_job' => __( 'Notify translators when they are removed from jobs', 'wpml-translation-management' ),
'section_title_manager' => __( 'Notification emails to the translation manager', 'wpml-translation-management' ),
'label_completed_job' => esc_html__( 'Notify the translation manager when jobs are completed %s', 'wpml-translation-management' ),
'label_overdue_job' => esc_html__( 'Notify the translation manager when jobs are late by %s days', 'wpml-translation-management' ),
),
'settings' => array(
'new_job' => array(
'value' => self::NOTIFY_IMMEDIATELY,
'checked' => checked( self::NOTIFY_IMMEDIATELY, $this->tm->settings['notification']['new-job'], false ),
),
'include_xliff' => array(
'value' => 1,
'checked' => checked( 1, $this->tm->settings['notification']['include_xliff'], false ),
'disabled' => disabled( 0, $this->tm->settings['notification']['new-job'], false ),
),
'resigned' => array(
'value' => self::NOTIFY_IMMEDIATELY,
'checked' => checked( self::NOTIFY_IMMEDIATELY, $this->tm->settings['notification']['resigned'], false ),
),
'completed' => array(
'value' => 1,
'checked' => checked( self::NOTIFY_IMMEDIATELY, $this->tm->settings['notification']['completed'], false ),
),
'completed_frequency' => array(
'options' => array(
array(
'label' => __( 'immediately', 'wpml-translation-management' ),
'value' => self::NOTIFY_IMMEDIATELY,
'checked' => selected( self::NOTIFY_IMMEDIATELY, $this->tm->settings['notification'][ self::COMPLETED_JOB_FREQUENCY ], false ),
),
array(
'label' => __( 'once a day', 'wpml-translation-management' ),
'value' => self::NOTIFY_DAILY,
'checked' => selected( self::NOTIFY_DAILY, $this->tm->settings['notification'][ self::COMPLETED_JOB_FREQUENCY ], false ),
),
array(
'label' => __( 'once a week', 'wpml-translation-management' ),
'value' => self::NOTIFY_WEEKLY,
'checked' => selected( self::NOTIFY_WEEKLY, $this->tm->settings['notification'][ self::COMPLETED_JOB_FREQUENCY ], false ),
),
),
'disabled' => disabled( 0, $this->tm->settings['notification']['completed'], false ),
),
'overdue' => array(
'value' => 1,
'checked' => checked( self::NOTIFY_IMMEDIATELY, $this->tm->settings['notification']['overdue'], false ),
),
'overdue_offset' => array(
'value' => $this->tm->settings['notification']['overdue_offset'],
'disabled' => disabled( 0, $this->tm->settings['notification']['overdue'], false ),
),
),
);
}
public function remove_scheduled_summary_email() {
wp_clear_scheduled_hook( WPML_TM_Jobs_Summary_Report_Hooks::EVENT_HOOK );
}
}