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 / 9
CRAP
0.00% covered (danger)
0.00%
0 / 1
ImageRecommendationBaseTaskType
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 9
90
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 getSuggestionFilters
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getMaxTasksPerDay
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getMinimumCaptionCharacterLength
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 shouldOpenInEditMode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getDefaultEditSection
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getQualityGateIds
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getViewData
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 toJsonArray
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace GrowthExperiments\NewcomerTasks\TaskType;
4
5use MessageLocalizer;
6
7abstract class ImageRecommendationBaseTaskType extends TaskType {
8
9    /** @see ::getMaxTasksPerDay */
10    public const FIELD_MAX_TASKS_PER_DAY = 'maxTasksPerDay';
11    /** @see ::getMinimumCaptionCharacterLength */
12    public const FIELD_MINIMUM_CAPTION_CHARACTER_LENGTH = 'minimumCaptionCharacterLength';
13    /** @see ::getMinimumImageSize */
14    public const FIELD_MINIMUM_IMAGE_SIZE = 'minimumImageSize';
15
16    public const VALID_MEDIA_TYPES = [
17        MEDIATYPE_BITMAP,
18        MEDIATYPE_DRAWING
19    ];
20
21    public const DEFAULT_SETTINGS = [
22        self::FIELD_MAX_TASKS_PER_DAY => 25,
23        self::FIELD_MINIMUM_CAPTION_CHARACTER_LENGTH => 5,
24        self::FIELD_MINIMUM_IMAGE_SIZE => [
25            'width' => 100
26        ]
27    ];
28
29    /** @inheritDoc */
30    protected const IS_MACHINE_SUGGESTION = true;
31
32    /** @var int */
33    protected $maxTasksPerDay;
34    /** @var int */
35    protected $minimumCaptionCharacterLength;
36    /** @var array */
37    protected $minimumImageSize;
38
39    /**
40     * @inheritDoc
41     * @param array $settings A settings array matching ImageRecommendationTaskType::DEFAULT_SETTINGS
42     */
43    public function __construct(
44        $id,
45        $difficulty,
46        array $settings = [],
47        array $extraData = [],
48        array $excludedTemplates = [],
49        array $excludedCategories = []
50    ) {
51        parent::__construct( $id, $difficulty, $extraData, $excludedTemplates, $excludedCategories );
52        $settings += self::DEFAULT_SETTINGS;
53        $this->maxTasksPerDay = $settings[self::FIELD_MAX_TASKS_PER_DAY];
54        $this->minimumCaptionCharacterLength = $settings[self::FIELD_MINIMUM_CAPTION_CHARACTER_LENGTH];
55        $this->minimumImageSize = $settings[self::FIELD_MINIMUM_IMAGE_SIZE];
56    }
57
58    /**
59     * Return the filters to apply to the recommendation
60     *
61     * @return array an array with the following fields:
62     *   - minimumSize: an array [ 'width' => int ] containing the minimum width
63     *   - validMediaTypes: an array of valid media types (MEDIATYPE_* constants)
64     */
65    public function getSuggestionFilters(): array {
66        return [
67            'minimumSize' => $this->minimumImageSize,
68            'validMediaTypes' => self::VALID_MEDIA_TYPES
69        ];
70    }
71
72    /**
73     * The maximum number of image recommendation tasks that a user can perform each calendar day.
74     *
75     * @return int
76     */
77    public function getMaxTasksPerDay(): int {
78        return $this->maxTasksPerDay;
79    }
80
81    /**
82     * The minimum number of characters needed for a caption to be submittable.
83     *
84     * @return int
85     */
86    public function getMinimumCaptionCharacterLength(): int {
87        return $this->minimumCaptionCharacterLength;
88    }
89
90    /** @inheritDoc */
91    public function shouldOpenInEditMode(): bool {
92        return true;
93    }
94
95    /** @inheritDoc */
96    public function getDefaultEditSection(): string {
97        return 'all';
98    }
99
100    /** @inheritDoc */
101    public function getQualityGateIds(): array {
102        return [ 'dailyLimit' ];
103    }
104
105    /** @inheritDoc */
106    public function getViewData( MessageLocalizer $messageLocalizer ) {
107        return parent::getViewData( $messageLocalizer ) + [
108                'maxTasksPerDay' => $this->maxTasksPerDay,
109                'minimumCaptionCharacterLength' => $this->minimumCaptionCharacterLength,
110                'minimumImageSize' => $this->minimumImageSize,
111            ];
112    }
113
114    /** @inheritDoc */
115    protected function toJsonArray(): array {
116        return parent::toJsonArray() + [
117                'settings' => [
118                    'maxTasksPerDay' => $this->maxTasksPerDay,
119                    'minimumCaptionCharacterLength' => $this->minimumCaptionCharacterLength,
120                    'minimumImageSize' => $this->minimumImageSize,
121                ],
122            ];
123    }
124
125}