StatusIcons.php
1.71 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
<?php
namespace WPML\TM\ATE;
use WPML\FP\Lst;
use WPML\FP\Obj;
use WPML\FP\Relation;
use WPML\LIB\WP\Hooks;
use WPML\TM\API\Jobs;
use function WPML\FP\spreadArgs;
class StatusIcons implements \IWPML_Backend_Action {
/** @var bool */
private $alreadyFound = false;
public function add_hooks() {
if (
(int) Obj::prop( 'ate_job_id', $_GET )
&& self::hasTranslatedStatusInAte()
) {
Hooks::onFilter( 'wpml_css_class_to_translation', PHP_INT_MAX, 5 )
->then( spreadArgs( [ $this, 'setSpinningIconOnPageList' ] ) );
Hooks::onFilter( 'wpml_tm_translation_queue_job_icon', 10, 2 )
->then( spreadArgs( [ $this, 'setSpinningIconInTranslationQueue' ] ) );
}
}
private static function hasTranslatedStatusInAte() {
return Lst::includes(
(int) Obj::prop( 'ate_status', $_GET ),
[ \WPML_TM_ATE_API::TRANSLATED, \WPML_TM_ATE_API::DELIVERING ]
);
}
public function setSpinningIconOnPageList( $default, $postId, $languageCode, $trid, $status ) {
if ( ICL_TM_COMPLETE === $status ) {
return $default;
}
if ( $this->alreadyFound ) {
return $default;
} else {
return $this->getIcon( $default, Jobs::getTridJob( $trid, $languageCode ) );
}
}
public function setSpinningIconInTranslationQueue( $default, $job ) {
return $this->getIcon( $default, $job );
}
public function getIcon( $default, $job ) {
if ( $job &&
(int) Obj::prop( 'editor_job_id', $job ) === (int) Obj::prop( 'ate_job_id', $_GET )
&& Relation::propEq( 'editor', \WPML_TM_Editors::ATE, $job )
&& Lst::includes( (int) Obj::prop( 'status', $job ), [ ICL_TM_WAITING_FOR_TRANSLATOR, ICL_TM_IN_PROGRESS ] )
) {
$this->alreadyFound = true;
return 'otgs-ico-refresh-spin';
} else {
return $default;
}
}
}