Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
63.89% |
23 / 36 |
|
60.00% |
6 / 10 |
CRAP | |
0.00% |
0 / 1 |
RecordingCrud | |
63.89% |
23 / 36 |
|
60.00% |
6 / 10 |
14.71 | |
0.00% |
0 / 1 |
getTable | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getClassColumnsPrefix | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getColumns | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
instanceFactory | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
deserializeRow | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
serializeFields | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
listByVoiceOf | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
listByManuscriptPrompt | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getByVoiceOfAndManuscriptPrompt | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getByAudioFileWikiPageIdentity | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\WikispeechSpeechDataCollector\Crud\Rdbms; |
4 | |
5 | /** |
6 | * @file |
7 | * @ingroup Extensions |
8 | * @license GPL-2.0-or-later |
9 | */ |
10 | |
11 | use MediaWiki\WikispeechSpeechDataCollector\Domain\Persistent; |
12 | use MediaWiki\WikispeechSpeechDataCollector\Domain\Recording; |
13 | |
14 | /** |
15 | * @since 0.1.0 |
16 | */ |
17 | class RecordingCrud extends AbstractUuidRdbmsCrud { |
18 | |
19 | /** @var string Name of table in database. */ |
20 | public const TABLE = self::TABLES_PREFIX . 'recording'; |
21 | |
22 | /** |
23 | * @return string Name of database table representing this class. |
24 | */ |
25 | protected function getTable(): string { |
26 | return self::TABLE; |
27 | } |
28 | |
29 | private const CLASS_COLUMNS_PREFIX = self::COLUMNS_PREFIX . 'r_'; |
30 | |
31 | /** |
32 | * @return string COLUMNS_PREFIX . 'class prefix' . '_' |
33 | */ |
34 | protected function getClassColumnsPrefix(): string { |
35 | return self::CLASS_COLUMNS_PREFIX; |
36 | } |
37 | |
38 | private const COLUMN_RECORDED = self::CLASS_COLUMNS_PREFIX . 'recorded'; |
39 | private const COLUMN_VOICE_OF = self::CLASS_COLUMNS_PREFIX . 'voice_of'; |
40 | private const COLUMN_SPOKEN_DIALECT = self::CLASS_COLUMNS_PREFIX . 'spoken_dialect'; |
41 | private const COLUMN_MANUSCRIPT_PROMPT = self::CLASS_COLUMNS_PREFIX . 'manuscript_prompt'; |
42 | private const COLUMN_AUDIO_FILE_WIKI_PAGE_IDENTITY = |
43 | self::CLASS_COLUMNS_PREFIX . 'audio_file_wiki_page_identity'; |
44 | |
45 | /** |
46 | * @return string[] Columns in table required to deserialize an instance, identity excluded. |
47 | */ |
48 | protected function getColumns(): array { |
49 | return [ |
50 | self::COLUMN_RECORDED, |
51 | self::COLUMN_VOICE_OF, |
52 | self::COLUMN_SPOKEN_DIALECT, |
53 | self::COLUMN_MANUSCRIPT_PROMPT, |
54 | self::COLUMN_AUDIO_FILE_WIKI_PAGE_IDENTITY |
55 | ]; |
56 | } |
57 | |
58 | public function instanceFactory(): Persistent { |
59 | return new Recording(); |
60 | } |
61 | |
62 | /** |
63 | * @param Recording $instance |
64 | * @param array $row |
65 | */ |
66 | protected function deserializeRow( |
67 | $instance, |
68 | array $row |
69 | ): void { |
70 | $instance->setRecorded( $this->deserializeTimestamp( $row, self::COLUMN_RECORDED ) ); |
71 | $instance->setVoiceOf( $this->deserializeUuid( $row, self::COLUMN_VOICE_OF ) ); |
72 | $instance->setSpokenDialect( $this->deserializeUuid( $row, self::COLUMN_SPOKEN_DIALECT ) ); |
73 | $instance->setManuscriptPrompt( $this->deserializeUuid( $row, self::COLUMN_MANUSCRIPT_PROMPT ) ); |
74 | $instance->setAudioFileWikiPageIdentity( |
75 | $this->deserializeInt( $row, self::COLUMN_AUDIO_FILE_WIKI_PAGE_IDENTITY ) ); |
76 | } |
77 | |
78 | /** |
79 | * @param Recording $instance |
80 | * @return array |
81 | */ |
82 | protected function serializeFields( |
83 | $instance |
84 | ): array { |
85 | $array = []; |
86 | $array[ self::COLUMN_RECORDED ] = $instance->getRecorded()->getTimestamp( TS_MW ); |
87 | $array[ self::COLUMN_VOICE_OF ] = $instance->getVoiceOf(); |
88 | $array[ self::COLUMN_SPOKEN_DIALECT ] = $instance->getSpokenDialect(); |
89 | $array[ self::COLUMN_MANUSCRIPT_PROMPT ] = $instance->getManuscriptPrompt(); |
90 | $array[ self::COLUMN_AUDIO_FILE_WIKI_PAGE_IDENTITY ] = $instance->getAudioFileWikiPageIdentity(); |
91 | return $array; |
92 | } |
93 | |
94 | /** |
95 | * @param string $voiceOf |
96 | * @return Recording[]|null |
97 | */ |
98 | public function listByVoiceOf( |
99 | string $voiceOf |
100 | ): ?array { |
101 | // @phan-suppress-next-line PhanTypeMismatchReturn |
102 | return $this->listByConditions( [ |
103 | self::COLUMN_VOICE_OF => $voiceOf |
104 | ] ); |
105 | } |
106 | |
107 | /** |
108 | * @param string $manuscriptPrompt |
109 | * @return Recording[]|null |
110 | */ |
111 | public function listByManuscriptPrompt( |
112 | string $manuscriptPrompt |
113 | ): ?array { |
114 | // @phan-suppress-next-line PhanTypeMismatchReturn |
115 | return $this->listByConditions( [ |
116 | self::COLUMN_MANUSCRIPT_PROMPT => $manuscriptPrompt |
117 | ] ); |
118 | } |
119 | |
120 | /** |
121 | * @param string $voiceOf |
122 | * @param string $manuscriptPrompt |
123 | * @return Recording|null |
124 | */ |
125 | public function getByVoiceOfAndManuscriptPrompt( |
126 | string $voiceOf, |
127 | string $manuscriptPrompt |
128 | ): ?Persistent { |
129 | // @phan-suppress-next-line PhanTypeMismatchReturnSuperType |
130 | return $this->getByConditions( [ |
131 | self::COLUMN_VOICE_OF => $voiceOf, |
132 | self::COLUMN_MANUSCRIPT_PROMPT => $manuscriptPrompt, |
133 | ] ); |
134 | } |
135 | |
136 | /** |
137 | * @param int $audioFileWikiPageIdentity |
138 | * @return Recording|null |
139 | */ |
140 | public function getByAudioFileWikiPageIdentity( |
141 | int $audioFileWikiPageIdentity |
142 | ): ?Persistent { |
143 | // @phan-suppress-next-line PhanTypeMismatchReturnSuperType |
144 | return $this->getByConditions( [ |
145 | self::COLUMN_AUDIO_FILE_WIKI_PAGE_IDENTITY => $audioFileWikiPageIdentity |
146 | ] ); |
147 | } |
148 | } |