Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiQueryContentTranslationCorpora
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 getAllowedParams
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Api module for querying Content Translation parallel corpora.
4 *
5 * @copyright See AUTHORS.txt
6 * @license GPL-2.0-or-later
7 */
8
9namespace ContentTranslation\ActionApi;
10
11use ApiQuery;
12use ApiQueryBase;
13use ContentTranslation\Manager\TranslationCorporaManager;
14use Wikimedia\ParamValidator\ParamValidator;
15
16/**
17 * Api module for querying Content Translation parallel corpora.
18 */
19class ApiQueryContentTranslationCorpora extends ApiQueryBase {
20    private TranslationCorporaManager $corporaManager;
21
22    public function __construct( ApiQuery $queryModule, $moduleName, TranslationCorporaManager $corporaManager ) {
23        parent::__construct( $queryModule, $moduleName );
24
25        $this->corporaManager = $corporaManager;
26    }
27
28    public function execute() {
29        $params = $this->extractRequestParams();
30        $result = $this->getResult();
31
32        $sections = $this->corporaManager->getFilteredCorporaUnits(
33            (int)$params['translationid'],
34            $params['types'],
35            $params['striphtml']
36        );
37        $result->addValue( [ 'query', $this->getModuleName() ], 'sections', $sections );
38    }
39
40    public function getAllowedParams() {
41        $params = [
42            'translationid' => [
43                ParamValidator::PARAM_TYPE => 'integer',
44                ParamValidator::PARAM_REQUIRED => true,
45            ],
46            'striphtml' => [
47                ParamValidator::PARAM_TYPE => 'boolean',
48                ParamValidator::PARAM_DEFAULT => false,
49            ],
50            'types' => [
51                ParamValidator::PARAM_TYPE => [ 'source', 'mt', 'user' ],
52                ParamValidator::PARAM_DEFAULT => 'source|mt|user',
53                ParamValidator::PARAM_ISMULTI => true,
54            ],
55        ];
56
57        return $params;
58    }
59}