|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* |
|
5
|
|
|
* @Project |
|
6
|
|
|
* @Copyright Djoudi |
|
7
|
|
|
* @Created 2018-02-13 |
|
8
|
|
|
* @Filename EditorAjaxRepogitory.php |
|
9
|
|
|
* @Description |
|
10
|
|
|
* |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Djoudi\LaravelH5p\Repositories; |
|
14
|
|
|
|
|
15
|
|
|
use DB; |
|
16
|
|
|
use Djoudi\LaravelH5p\Eloquents\H5pLibrariesHubCache; |
|
17
|
|
|
use H5PEditorAjaxInterface; |
|
18
|
|
|
use Illuminate\Support\Facades\Auth; |
|
19
|
|
|
|
|
20
|
|
|
class EditorAjaxRepository implements H5PEditorAjaxInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Gets recently used libraries for the current author. |
|
24
|
|
|
* |
|
25
|
|
|
* @return array machine names. The first element in the array is the |
|
26
|
|
|
* most recently used. |
|
27
|
|
|
*/ |
|
28
|
|
|
/* public function getAuthorsRecentlyUsedLibraries() { |
|
29
|
|
|
global $wpdb; |
|
30
|
|
|
$recently_used = array(); |
|
31
|
|
|
$result = $wpdb->get_results($wpdb->prepare( |
|
32
|
|
|
"SELECT library_name, max(created_at) AS max_created_at |
|
33
|
|
|
FROM {$wpdb->prefix}h5p_events |
|
34
|
|
|
WHERE type='content' AND sub_type = 'create' AND user_id = %d |
|
35
|
|
|
GROUP BY library_name |
|
36
|
|
|
ORDER BY max_created_at DESC", |
|
37
|
|
|
get_current_user_id() |
|
38
|
|
|
)); |
|
39
|
|
|
foreach ($result as $row) { |
|
40
|
|
|
$recently_used[] = $row->library_name; |
|
41
|
|
|
} |
|
42
|
|
|
return $recently_used; |
|
43
|
|
|
} |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getAuthorsRecentlyUsedLibraries() |
|
46
|
|
|
{ |
|
47
|
|
|
// Get latest version of local libraries |
|
48
|
|
|
$major_versions_sql = 'SELECT hl.name, |
|
49
|
|
|
MAX(hl.major_version) AS majorVersion |
|
50
|
|
|
FROM h5p_libraries hl |
|
51
|
|
|
WHERE hl.runnable = 1 |
|
52
|
|
|
GROUP BY hl.name'; |
|
53
|
|
|
|
|
54
|
|
|
$minor_versions_sql = "SELECT hl2.name, |
|
55
|
|
|
hl2.majorVersion, |
|
56
|
|
|
MAX(hl2.minorVersion) AS minorVersion |
|
57
|
|
|
FROM ({$major_versions_sql}) hl1 |
|
58
|
|
|
JOIN h5p_libraries hl2 |
|
59
|
|
|
ON hl1.name = hl2.name |
|
60
|
|
|
AND hl1.majorVersion = hl2.majorVersion |
|
61
|
|
|
GROUP BY hl2.name, hl2.majorVersion"; |
|
62
|
|
|
|
|
63
|
|
|
return DB::select("SELECT hl4.id, |
|
64
|
|
|
hl4.name AS machine_name, |
|
65
|
|
|
hl4.major_version, |
|
66
|
|
|
hl4.minor_version, |
|
67
|
|
|
hl4.patch_version, |
|
68
|
|
|
hl4.restricted, |
|
69
|
|
|
hl4.has_icon |
|
70
|
|
|
FROM ({$minor_versions_sql}) hl3 |
|
71
|
|
|
JOIN h5p_libraries hl4 |
|
72
|
|
|
ON hl3.name = hl4.name |
|
73
|
|
|
AND hl3.major_version = hl4.major_version |
|
74
|
|
|
AND hl3.minor_version = hl4.minor_version |
|
75
|
|
|
GROUP BY hl4.name, hl4.major_version, hl4.minor_version"); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function getContentTypeCache($machineName = null) |
|
79
|
|
|
{ |
|
80
|
|
|
$where = H5pLibrariesHubCache::select(); |
|
81
|
|
|
if ($machineName) { |
|
82
|
|
|
return $where->where('machine_name', $machineName)->pluck('id', 'is_recommended'); |
|
83
|
|
|
} else { |
|
84
|
|
|
return $where->where('machine_name', $machineName)->get(); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function getLatestLibraryVersions() |
|
89
|
|
|
{ |
|
90
|
|
|
$recently_used = []; |
|
91
|
|
|
$result = DB::table('h5p_events') |
|
92
|
|
|
->select([ |
|
93
|
|
|
'library_name', |
|
94
|
|
|
'max(created_at) AS max_created_at', |
|
95
|
|
|
]) |
|
96
|
|
|
->where('type', 'content') |
|
97
|
|
|
->where('sub_type', 'create') |
|
98
|
|
|
->where('user_id', Auth::id()) |
|
99
|
|
|
->groupBy('library_name') |
|
100
|
|
|
->orderBy('max_created_at', 'DESC') |
|
101
|
|
|
->get(); |
|
102
|
|
|
|
|
103
|
|
|
foreach ($result as $row) { |
|
104
|
|
|
$recently_used[] = $row->library_name; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
dd($recently_used); |
|
108
|
|
|
exit; |
|
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
return $recently_used; |
|
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function validateEditorToken($token) |
|
114
|
|
|
{ |
|
115
|
|
|
// return (Helpers::nonce($token) == 'h5p_editor_ajax'); |
|
116
|
|
|
return true; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function getTranslations($libraries, $language_code) |
|
120
|
|
|
{ |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.