Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
277 changes: 172 additions & 105 deletions public/main/gradebook/lib/be/category.class.php

Large diffs are not rendered by default.

74 changes: 63 additions & 11 deletions public/main/inc/ajax/document.ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,35 @@
$course = api_get_course_entity();
$results = [];

$createDocument = function(string $path, string $filename, string $mimetype, int $filesize, bool $ifExists) use (
$repo, $em, $course, $directoryParentId, &$results
// --------- LP context (optional): auto-create LP items when uploading from LP builder ----------
$lpId = (int) ($_REQUEST['lp_id'] ?? ($_POST['lp_id'] ?? 0));
$lpAutoAdd = ((int) ($_REQUEST['lp_auto_add'] ?? ($_POST['lp_auto_add'] ?? 0))) === 1;

$oLP = null;
$lpItemsCreated = [];

if ($lpAutoAdd && $lpId > 0) {
$lp = Container::getLpRepository()->find($lpId);
if ($lp) {
$courseInfo = api_get_course_info();
$oLP = new learnpath($lp, $courseInfo, api_get_user_id());
}
}

$createDocument = function(
string $path,
string $filename,
string $mimetype,
int $filesize,
string $ifExists
) use (
$repo,
$em,
$course,
$directoryParentId,
&$results,
$oLP,
&$lpItemsCreated
) {
$qb = $em->createQueryBuilder()
->select('d')
Expand Down Expand Up @@ -153,12 +180,33 @@

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

// --------- If in LP mode, also create the LP item (c_lp_item) ----------
$createdLpItemId = 0;
if ($oLP) {
$lpItemRepo = Container::getLpItemRepository();
$root = $lpItemRepo->getRootItem($oLP->get_id());

$createdLpItemId = (int) $oLP->add_item(
$root, // parent
'', // previous
TOOL_DOCUMENT, // item type
(string) $doc->getIid(), // path = document iid
$doc->getTitle(),
'', // description
'' // prerequisites
);

$oLP->set_modified_on();
$lpItemsCreated[] = $createdLpItemId;
}

$results[] = [
'name' => api_htmlentities($doc->getTitle()),
'url' => $repo->getResourceFileUrl($doc),
'size' => format_file_size($filesize),
'type' => api_htmlentities($mimetype),
'result' => Display::return_icon('accept.png', get_lang('Uploaded.'))
'name' => api_htmlentities($doc->getTitle()),
'url' => $repo->getResourceFileUrl($doc),
'size' => format_file_size($filesize),
'type' => api_htmlentities($mimetype),
'result' => Display::return_icon('accept.png', get_lang('Uploaded.')),
'lp_item_id' => $createdLpItemId,
];
};

Expand All @@ -182,7 +230,7 @@
$f->getFilename(),
mime_content_type($f->getRealPath()),
$f->getSize(),
$ifExists
(string) $ifExists
);
}
}
Expand All @@ -194,13 +242,17 @@
$fileInfo['tmp_name'],
$fileInfo['name'],
$fileInfo['type'],
$fileInfo['size'],
$ifExists
(int) $fileInfo['size'],
(string) $ifExists
);
}

header('Content-Type: application/json');
echo json_encode(['files' => $results]);
echo json_encode([
'files' => $results,
'lp_refresh' => !empty($lpItemsCreated),
'lp_items_created' => $lpItemsCreated,
]);
exit;
}
exit;
4 changes: 3 additions & 1 deletion public/main/inc/lib/SkillModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ public function getUserSkillsTable(int $userId, int $courseId = 0, int $sessionI
$passed = isset($skills[(int) $data['id']]);
$transparency = '';
if (false === $passed) {
// @todo use a css class
$transparency = 'opacity: 0.4; filter: alpha(opacity=40);';
}

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

Expand Down Expand Up @@ -1413,7 +1415,7 @@ public function getCoursesBySkill($skillId)
* @param int $courseId Optional. The course id
* @param int $sessionId Optional. The session id
*
* @return bool Whether the user has the skill return true. Otherwise, return false
* @return bool Whether the user has the skill return true. Otherwise return false
*/
public function userHasSkill($userId, $skillId, $courseId = 0, $sessionId = 0)
{
Expand Down
31 changes: 16 additions & 15 deletions public/main/inc/lib/SkillRelUserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SkillRelUserModel extends Model
'acquired_skill_at',
'course_id',
'session_id',
'acquired_level',
'validation_status',
'argumentation',
'argumentation_author_id',
Expand Down Expand Up @@ -61,27 +62,27 @@ public function getUserSkills($userId, $courseId = 0, $sessionId = 0)
return [];
}

$userId = (int) $userId;
$courseId = (int) $courseId;
$sessionId = $sessionId ? (int) $sessionId : null;
$whereConditions = [
'user_id = ? ' => (int) $userId,
];
$sessionId = (int) $sessionId;

$sql = "SELECT skill_id FROM {$this->table} WHERE user_id = $userId";

if ($courseId > 0) {
$whereConditions['AND course_id = ? '] = $courseId;
$whereConditions['AND session_id = ?'] = $sessionId;
$sql .= " AND course_id = $courseId";

if ($sessionId > 0) {
// Skill linked to a specific session
$sql .= " AND session_id = $sessionId";
} else {
// Course-level skill, no session → match NULL
$sql .= " AND session_id IS NULL";
}
}

$result = Database::select(
'skill_id',
$this->table,
[
'where' => $whereConditions,
],
'all'
);
$result = Database::query($sql);

return $result;
return Database::store_result($result, 'ASSOC');
}

/**
Expand Down
Loading
Loading