Passed
Push — 1.11.x ( e2d89c...378899 )
by
unknown
11:05
created

H5pImplementation::getContentHubMetadataChecked()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 0
c 1
b 1
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
// For licensing terms, see /license.txt
4
5
namespace Chamilo\PluginBundle\H5pImport\H5pImporter;
6
7
use Chamilo\PluginBundle\Entity\H5pImport\H5pImport;
8
use Chamilo\PluginBundle\Entity\H5pImport\H5pImportLibrary;
9
10
class H5pImplementation implements \H5PFrameworkInterface
11
{
12
    private $h5pImport;
13
    private $h5pImportLibraries;
14
15
    public function __construct(H5pImport $h5pImport)
16
    {
17
        $this->h5pImport = $h5pImport;
18
        $this->h5pImportLibraries = $h5pImport->getLibraries();
19
    }
20
21
    public function setContentHubMetadataChecked($time, $lang = 'en')
22
    {
23
        // TODO: Implement getPlatformInfo() method.
24
    }
25
26
    public function getContentHubMetadataChecked($lang = 'en')
27
    {
28
        // TODO: Implement getPlatformInfo() method.
29
    }
30
31
    public function getContentHubMetadataCache($lang = 'en')
32
    {
33
        // TODO: Implement getPlatformInfo() method.
34
    }
35
36
    public function replaceContentHubMetadataCache($metadata, $lang)
37
    {
38
        // TODO: Implement getPlatformInfo() method.
39
    }
40
41
    public function getPlatformInfo()
42
    {
43
        // TODO: Implement getPlatformInfo() method.
44
    }
45
46
    public function fetchExternalData($url, $data = null, $blocking = true, $stream = null, $fullData = false, $headers = Array(), $files = Array(), $method = 'POST')
47
    {
48
        // TODO: Implement fetchExternalData() method.
49
    }
50
51
    public function setLibraryTutorialUrl($machineName, $tutorialUrl)
52
    {
53
        // TODO: Implement setLibraryTutorialUrl() method.
54
    }
55
56
    public function setErrorMessage($message, $code = null)
57
    {
58
        // TODO: Implement setErrorMessage() method.
59
    }
60
61
    public function setInfoMessage($message)
62
    {
63
        // TODO: Implement setInfoMessage() method.
64
    }
65
66
    public function getMessages($type)
67
    {
68
        // TODO: Implement getMessages() method.
69
    }
70
71
    public function t($message, $replacements = [])
72
    {
73
        return get_lang($message);
74
    }
75
76
    public function getLibraryFileUrl($libraryFolderName, $fileName)
77
    {
78
        // TODO: Implement getLibraryFileUrl() method.
79
    }
80
81
    public function getUploadedH5pFolderPath()
82
    {
83
        // TODO: Implement getUploadedH5pFolderPath() method.
84
    }
85
86
    public function getUploadedH5pPath()
87
    {
88
        // TODO: Implement getUploadedH5pPath() method.
89
    }
90
91
    public function loadAddons()
92
    {
93
        $addons = [];
94
        $sql = "
95
                SELECT l1.machine_name, l1.major_version, l1.minor_version, l1.patch_version,
96
                      l1.iid, l1.preloaded_js, l1.preloaded_css
97
                FROM plugin_h5p_import_library AS l1
98
                LEFT JOIN plugin_h5p_import_library AS l2
99
                ON l1.machine_name = l2.machine_name AND
100
                    (l1.major_version < l2.major_version OR
101
                    (l1.major_version = l2.major_version AND
102
                    l1.minor_version < l2.minor_version))
103
                WHERE l2.machine_name IS null
104
        ";
105
106
        $result = \Database::query($sql);
107
        while ($row = \Database::fetch_array($result)) {
108
            $addons[] = \H5PCore::snakeToCamel($row);
109
        }
110
111
        return $addons;
112
    }
113
114
    public function getLibraryConfig($libraries = null)
115
    {
116
        // TODO: Implement getLibraryConfig() method.
117
    }
118
119
    public function loadLibraries()
120
    {
121
        // TODO: Implement loadLibraries() method.
122
    }
123
124
    public function getAdminUrl()
125
    {
126
        // TODO: Implement getAdminUrl() method.
127
    }
128
129
    public function getLibraryId($machineName, $majorVersion = null, $minorVersion = null)
130
    {
131
        // TODO: Implement getLibraryId() method.
132
    }
133
134
    public function getWhitelist($isLibrary, $defaultContentWhitelist, $defaultLibraryWhitelist)
135
    {
136
        // TODO: Implement getWhitelist() method.
137
    }
138
139
    public function isPatchedLibrary($library)
140
    {
141
        // TODO: Implement isPatchedLibrary() method.
142
    }
143
144
    public function isInDevMode()
145
    {
146
        // TODO: Implement isInDevMode() method.
147
    }
148
149
    public function mayUpdateLibraries()
150
    {
151
        // TODO: Implement mayUpdateLibraries() method.
152
    }
153
154
    public function saveLibraryData(&$libraryData, $new = true)
155
    {
156
        // TODO: Implement saveLibraryData() method.
157
    }
158
159
    public function insertContent($content, $contentMainId = null)
160
    {
161
        // TODO: Implement insertContent() method.
162
    }
163
164
    public function updateContent($content, $contentMainId = null)
165
    {
166
        // TODO: Implement updateContent() method.
167
    }
168
169
    public function resetContentUserData($contentId)
170
    {
171
        // TODO: Implement resetContentUserData() method.
172
    }
173
174
    public function saveLibraryDependencies($libraryId, $dependencies, $dependency_type)
175
    {
176
        // TODO: Implement saveLibraryDependencies() method.
177
    }
178
179
    public function copyLibraryUsage($contentId, $copyFromId, $contentMainId = null)
180
    {
181
        // TODO: Implement copyLibraryUsage() method.
182
    }
183
184
    public function deleteContentData($contentId)
185
    {
186
        // TODO: Implement deleteContentData() method.
187
    }
188
189
    public function deleteLibraryUsage($contentId)
190
    {
191
        // TODO: Implement deleteLibraryUsage() method.
192
    }
193
194
    public function saveLibraryUsage($contentId, $librariesInUse)
195
    {
196
        // TODO: Implement saveLibraryUsage() method.
197
    }
198
199
    public function getLibraryUsage($libraryId, $skipContent = false)
200
    {
201
        // TODO: Implement getLibraryUsage() method.
202
    }
203
204
    public function loadLibrary($machineName, $majorVersion, $minorVersion)
205
    {
206
        if ($this->h5pImportLibraries) {
207
            $foundLibrary = $this->h5pImportLibraries->filter(
208
                function (H5pImportLibrary $library) use ($machineName, $majorVersion, $minorVersion) {
209
                    return $library->getLibraryByMachineNameAndVersions($machineName, $majorVersion, $minorVersion);
210
                }
211
            )->first();
212
            if ($foundLibrary) {
213
                return [
214
                    'libraryId' => $foundLibrary->getIid(),
215
                    'title' => $foundLibrary->getTitle(),
216
                    'machineName' => $foundLibrary->getMachineName(),
217
                    'majorVersion' => $foundLibrary->getMajorVersion(),
218
                    'minorVersion' => $foundLibrary->getMinorVersion(),
219
                    'patchVersion' => $foundLibrary->getPatchVersion(),
220
                    'runnable' => $foundLibrary->getRunnable(),
221
                    'preloadedJs' => $foundLibrary->getPreloadedJsFormatted(),
222
                    'preloadedCss' => $foundLibrary->getPreloadedCssFormatted(),
223
                ];
224
            }
225
        }
226
227
        return false;
228
    }
229
230
    public function loadLibrarySemantics($machineName, $majorVersion, $minorVersion)
231
    {
232
        // TODO: Implement loadLibrarySemantics() method.
233
    }
234
235
    public function alterLibrarySemantics(&$semantics, $machineName, $majorVersion, $minorVersion)
236
    {
237
        // TODO: Implement alterLibrarySemantics() method.
238
    }
239
240
    public function deleteLibraryDependencies($libraryId)
241
    {
242
        // TODO: Implement deleteLibraryDependencies() method.
243
    }
244
245
    public function lockDependencyStorage()
246
    {
247
        // TODO: Implement lockDependencyStorage() method.
248
    }
249
250
    public function unlockDependencyStorage()
251
    {
252
        // TODO: Implement unlockDependencyStorage() method.
253
    }
254
255
    public function deleteLibrary($library)
256
    {
257
        // TODO: Implement deleteLibrary() method.
258
    }
259
260
    public function loadContent($id): array
261
    {
262
        $contentJson = H5pPackageTools::getJson($this->h5pImport->getPath().'/content.json');
263
        $h5pJson = H5pPackageTools::getJson($this->h5pImport->getPath().'/h5p.json');
264
265
        if ($contentJson && $h5pJson) {
266
            $params = json_encode($contentJson);
267
            $embedType = implode(',', $h5pJson->embedTypes);
268
            $title = $this->h5pImport->getName();
269
            $language = $h5pJson->language;
270
            $libraryId = $this->h5pImport->getMainLibrary()->getIid();
271
            $libraryName = $this->h5pImport->getMainLibrary()->getMachineName();
272
            $libraryMajorVersion = $this->h5pImport->getMainLibrary()->getMajorVersion();
273
            $libraryMinorVersion = $this->h5pImport->getMainLibrary()->getMinorVersion();
274
            $libraryEmbedTypes = $this->h5pImport->getMainLibrary()->getEmbedTypesFormatted();
275
276
            // Create the associative array with the loaded content information. Use the unique folder name as id.
277
            return [
278
                'contentId' => basename($this->h5pImport->getPath()),
279
                'params' => $params,
280
                'embedType' => $embedType,
281
                'title' => $title,
282
                'language' => $language,
283
                'libraryId' => $libraryId,
284
                'libraryName' => $libraryName,
285
                'libraryMajorVersion' => $libraryMajorVersion,
286
                'libraryMinorVersion' => $libraryMinorVersion,
287
                'libraryEmbedTypes' => $libraryEmbedTypes,
288
                'libraryFullscreen' => 0,
289
            ];
290
        }
291
292
        return [];
293
    }
294
295
    public function loadContentDependencies($id, $type = null): array
296
    {
297
        $h5pImportLibraries = $this->h5pImportLibraries;
298
        $dependencies = [];
299
300
        /** @var H5pImportLibrary|null $library */
301
        foreach ($h5pImportLibraries as $library) {
302
            $dependencies[] = [
303
                'libraryId' => $library->getIid(),
304
                'machineName' => $library->getMachineName(),
305
                'majorVersion' => $library->getMajorVersion(),
306
                'minorVersion' => $library->getMinorVersion(),
307
                'patchVersion' => $library->getPatchVersion(),
308
                'preloadedJs' => $library->getPreloadedJsFormatted(),
309
                'preloadedCss' => $library->getPreloadedCssFormatted(),
310
            ];
311
        }
312
313
        return $dependencies;
314
    }
315
316
    public function getOption($name, $default = null)
317
    {
318
        return api_get_course_plugin_setting('h5pimport', $name);
319
    }
320
321
    public function setOption($name, $value)
322
    {
323
        // TODO: Implement setOption() method.
324
    }
325
326
    public function updateContentFields($id, $fields)
327
    {
328
        // TODO: Implement updateContentFields() method.
329
    }
330
331
    public function clearFilteredParameters($library_ids)
332
    {
333
        // TODO: Implement clearFilteredParameters() method.
334
    }
335
336
    public function getNumNotFiltered()
337
    {
338
        // TODO: Implement getNumNotFiltered() method.
339
    }
340
341
    public function getNumContent($libraryId, $skip = null)
342
    {
343
        // TODO: Implement getNumContent() method.
344
    }
345
346
    public function isContentSlugAvailable($slug)
347
    {
348
        return true;
349
    }
350
351
    public function getLibraryStats($type)
352
    {
353
        // TODO: Implement getLibraryStats() method.
354
    }
355
356
    public function getNumAuthors()
357
    {
358
        // TODO: Implement getNumAuthors() method.
359
    }
360
361
    public function saveCachedAssets($key, $libraries)
362
    {
363
        // TODO: Implement saveCachedAssets() method.
364
    }
365
366
    public function deleteCachedAssets($library_id)
367
    {
368
        // TODO: Implement deleteCachedAssets() method.
369
    }
370
371
    public function getLibraryContentCount()
372
    {
373
        // TODO: Implement getLibraryContentCount() method.
374
    }
375
376
    public function afterExportCreated($content, $filename)
377
    {
378
        // TODO: Implement afterExportCreated() method.
379
    }
380
381
    public function hasPermission($permission, $id = null)
382
    {
383
        // TODO: Implement hasPermission() method.
384
    }
385
386
    public function replaceContentTypeCache($contentTypeCache)
387
    {
388
        // TODO: Implement replaceContentTypeCache() method.
389
    }
390
391
    public function libraryHasUpgrade($library)
392
    {
393
        // TODO: Implement libraryHasUpgrade() method.
394
    }
395
}
396