Skip to content

Commit 563a8ab

Browse files
authored
Merge pull request #7119 from christianbeeznest/fide-23100
Gradebook: Fix LP final item certificate and skill issuance - refs BT#23100
2 parents b818d78 + b7f6499 commit 563a8ab

9 files changed

Lines changed: 874 additions & 233 deletions

File tree

public/main/gradebook/lib/be/category.class.php

Lines changed: 172 additions & 105 deletions
Large diffs are not rendered by default.

public/main/inc/ajax/document.ajax.php

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,35 @@
108108
$course = api_get_course_entity();
109109
$results = [];
110110

111-
$createDocument = function(string $path, string $filename, string $mimetype, int $filesize, bool $ifExists) use (
112-
$repo, $em, $course, $directoryParentId, &$results
111+
// --------- LP context (optional): auto-create LP items when uploading from LP builder ----------
112+
$lpId = (int) ($_REQUEST['lp_id'] ?? ($_POST['lp_id'] ?? 0));
113+
$lpAutoAdd = ((int) ($_REQUEST['lp_auto_add'] ?? ($_POST['lp_auto_add'] ?? 0))) === 1;
114+
115+
$oLP = null;
116+
$lpItemsCreated = [];
117+
118+
if ($lpAutoAdd && $lpId > 0) {
119+
$lp = Container::getLpRepository()->find($lpId);
120+
if ($lp) {
121+
$courseInfo = api_get_course_info();
122+
$oLP = new learnpath($lp, $courseInfo, api_get_user_id());
123+
}
124+
}
125+
126+
$createDocument = function(
127+
string $path,
128+
string $filename,
129+
string $mimetype,
130+
int $filesize,
131+
string $ifExists
132+
) use (
133+
$repo,
134+
$em,
135+
$course,
136+
$directoryParentId,
137+
&$results,
138+
$oLP,
139+
&$lpItemsCreated
113140
) {
114141
$qb = $em->createQueryBuilder()
115142
->select('d')
@@ -153,12 +180,33 @@
153180

154181
$repo->addFileFromPath($doc, $filename, $path);
155182

183+
// --------- If in LP mode, also create the LP item (c_lp_item) ----------
184+
$createdLpItemId = 0;
185+
if ($oLP) {
186+
$lpItemRepo = Container::getLpItemRepository();
187+
$root = $lpItemRepo->getRootItem($oLP->get_id());
188+
189+
$createdLpItemId = (int) $oLP->add_item(
190+
$root, // parent
191+
'', // previous
192+
TOOL_DOCUMENT, // item type
193+
(string) $doc->getIid(), // path = document iid
194+
$doc->getTitle(),
195+
'', // description
196+
'' // prerequisites
197+
);
198+
199+
$oLP->set_modified_on();
200+
$lpItemsCreated[] = $createdLpItemId;
201+
}
202+
156203
$results[] = [
157-
'name' => api_htmlentities($doc->getTitle()),
158-
'url' => $repo->getResourceFileUrl($doc),
159-
'size' => format_file_size($filesize),
160-
'type' => api_htmlentities($mimetype),
161-
'result' => Display::return_icon('accept.png', get_lang('Uploaded.'))
204+
'name' => api_htmlentities($doc->getTitle()),
205+
'url' => $repo->getResourceFileUrl($doc),
206+
'size' => format_file_size($filesize),
207+
'type' => api_htmlentities($mimetype),
208+
'result' => Display::return_icon('accept.png', get_lang('Uploaded.')),
209+
'lp_item_id' => $createdLpItemId,
162210
];
163211
};
164212

@@ -182,7 +230,7 @@
182230
$f->getFilename(),
183231
mime_content_type($f->getRealPath()),
184232
$f->getSize(),
185-
$ifExists
233+
(string) $ifExists
186234
);
187235
}
188236
}
@@ -194,13 +242,17 @@
194242
$fileInfo['tmp_name'],
195243
$fileInfo['name'],
196244
$fileInfo['type'],
197-
$fileInfo['size'],
198-
$ifExists
245+
(int) $fileInfo['size'],
246+
(string) $ifExists
199247
);
200248
}
201249

202250
header('Content-Type: application/json');
203-
echo json_encode(['files' => $results]);
251+
echo json_encode([
252+
'files' => $results,
253+
'lp_refresh' => !empty($lpItemsCreated),
254+
'lp_items_created' => $lpItemsCreated,
255+
]);
204256
exit;
205257
}
206258
exit;

public/main/inc/lib/SkillModel.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@ public function getUserSkillsTable(int $userId, int $courseId = 0, int $sessionI
974974
$passed = isset($skills[(int) $data['id']]);
975975
$transparency = '';
976976
if (false === $passed) {
977+
// @todo use a css class
977978
$transparency = 'opacity: 0.4; filter: alpha(opacity=40);';
978979
}
979980

@@ -997,6 +998,7 @@ public function getUserSkillsTable(int $userId, int $courseId = 0, int $sessionI
997998
$passed = isset($skills[(int) $data['id']]);
998999
$transparency = '';
9991000
if (false === $passed) {
1001+
// @todo use a css class
10001002
$transparency = 'opacity: 0.4; filter: alpha(opacity=40);';
10011003
}
10021004

@@ -1413,7 +1415,7 @@ public function getCoursesBySkill($skillId)
14131415
* @param int $courseId Optional. The course id
14141416
* @param int $sessionId Optional. The session id
14151417
*
1416-
* @return bool Whether the user has the skill return true. Otherwise, return false
1418+
* @return bool Whether the user has the skill return true. Otherwise return false
14171419
*/
14181420
public function userHasSkill($userId, $skillId, $courseId = 0, $sessionId = 0)
14191421
{

public/main/inc/lib/SkillRelUserModel.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class SkillRelUserModel extends Model
1414
'acquired_skill_at',
1515
'course_id',
1616
'session_id',
17+
'acquired_level',
1718
'validation_status',
1819
'argumentation',
1920
'argumentation_author_id',
@@ -61,27 +62,27 @@ public function getUserSkills($userId, $courseId = 0, $sessionId = 0)
6162
return [];
6263
}
6364

65+
$userId = (int) $userId;
6466
$courseId = (int) $courseId;
65-
$sessionId = $sessionId ? (int) $sessionId : null;
66-
$whereConditions = [
67-
'user_id = ? ' => (int) $userId,
68-
];
67+
$sessionId = (int) $sessionId;
68+
69+
$sql = "SELECT skill_id FROM {$this->table} WHERE user_id = $userId";
6970

7071
if ($courseId > 0) {
71-
$whereConditions['AND course_id = ? '] = $courseId;
72-
$whereConditions['AND session_id = ?'] = $sessionId;
72+
$sql .= " AND course_id = $courseId";
73+
74+
if ($sessionId > 0) {
75+
// Skill linked to a specific session
76+
$sql .= " AND session_id = $sessionId";
77+
} else {
78+
// Course-level skill, no session → match NULL
79+
$sql .= " AND session_id IS NULL";
80+
}
7381
}
7482

75-
$result = Database::select(
76-
'skill_id',
77-
$this->table,
78-
[
79-
'where' => $whereConditions,
80-
],
81-
'all'
82-
);
83+
$result = Database::query($sql);
8384

84-
return $result;
85+
return Database::store_result($result, 'ASSOC');
8586
}
8687

8788
/**

0 commit comments

Comments
 (0)