Skip to content
Merged
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
63 changes: 44 additions & 19 deletions public/main/wiki/wiki.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1565,29 +1565,54 @@ public static function display_wiki_entry(
}
}

/** @var CWiki|null $first */
$first = $repo->createQueryBuilder('w')
// Resolve FIRST row in the right scope (session-aware)
$effectiveSid = (int) $ctx['sessionId'];

$firstQb = $repo->createQueryBuilder('w')
->andWhere('w.cId = :cid')->setParameter('cid', $ctx['courseId'])
->andWhere('w.reflink = :reflink')->setParameter('reflink', $pageKey)
->andWhere('COALESCE(w.groupId,0) = :gid')->setParameter('gid', (int)$ctx['groupId'])
->andWhere('COALESCE(w.groupId,0) = :gid')->setParameter('gid', (int) $ctx['groupId'])
->orderBy('w.version', 'ASC')
->setMaxResults(1)
->getQuery()->getOneOrNullResult();
->setMaxResults(1);

if ($effectiveSid > 0) {
$firstQb->andWhere('COALESCE(w.sessionId,0) = :sid')->setParameter('sid', $effectiveSid);
} else {
$firstQb->andWhere('COALESCE(w.sessionId,0) = 0');
}

/** @var CWiki|null $first */
$first = $firstQb->getQuery()->getOneOrNullResult();

// if we are in session and no session page exists, show base course wiki
if (!$first && $effectiveSid > 0) {
$effectiveSid = 0;

$first = $repo->createQueryBuilder('w')
->andWhere('w.cId = :cid')->setParameter('cid', $ctx['courseId'])
->andWhere('w.reflink = :reflink')->setParameter('reflink', $pageKey)
->andWhere('COALESCE(w.groupId,0) = :gid')->setParameter('gid', (int) $ctx['groupId'])
->andWhere('COALESCE(w.sessionId,0) = 0')
->orderBy('w.version', 'ASC')
->setMaxResults(1)
->getQuery()->getOneOrNullResult();
}

$keyVisibility = $first?->getVisibility();
$pageId = $first?->getPageId() ?? 0;

// When loading LAST version, use the same effective scope we used above
$last = null;
if ($pageId) {
$qb = $repo->createQueryBuilder('w')
->andWhere('w.cId = :cid')->setParameter('cid', $ctx['courseId'])
->andWhere('w.pageId = :pid')->setParameter('pid', $pageId)
->andWhere('COALESCE(w.groupId,0) = :gid')->setParameter('gid', (int)$ctx['groupId'])
->andWhere('COALESCE(w.groupId,0) = :gid')->setParameter('gid', (int) $ctx['groupId'])
->orderBy('w.version', 'DESC')
->setMaxResults(1);

if ($ctx['sessionId'] > 0) {
$qb->andWhere('COALESCE(w.sessionId,0) = :sid')->setParameter('sid', (int)$ctx['sessionId']);
if ($effectiveSid > 0) {
$qb->andWhere('COALESCE(w.sessionId,0) = :sid')->setParameter('sid', $effectiveSid);
} else {
$qb->andWhere('COALESCE(w.sessionId,0) = 0');
}
Expand Down Expand Up @@ -2876,13 +2901,13 @@ public function handleAction(string $action): void

// Simple icon map
$icons = [
'mactiveusers' => \Chamilo\CoreBundle\Enums\ActionIcon::STAR,
'mvisited' => \Chamilo\CoreBundle\Enums\ActionIcon::HISTORY,
'mostchanged' => \Chamilo\CoreBundle\Enums\ActionIcon::REFRESH,
'orphaned' => \Chamilo\CoreBundle\Enums\ActionIcon::LINKS,
'wanted' => \Chamilo\CoreBundle\Enums\ActionIcon::SEARCH,
'mostlinked' => \Chamilo\CoreBundle\Enums\ActionIcon::LINKS,
'statistics' => \Chamilo\CoreBundle\Enums\ActionIcon::INFORMATION,
'mactiveusers' => ActionIcon::STAR,
'mvisited' => ActionIcon::HISTORY,
'mostchanged' => ActionIcon::REFRESH,
'orphaned' => ActionIcon::LINKS,
'wanted' => ActionIcon::SEARCH,
'mostlinked' => ActionIcon::LINKS,
'statistics' => ActionIcon::INFORMATION,
];

if (!$wikiHdrCssInjected) {
Expand All @@ -2895,7 +2920,7 @@ public function handleAction(string $action): void
foreach ($items as $key => $label) {
$isActive = ($key === $activeKey);
$href = $url.'&action='.$key;
$icon = Display::getMdiIcon($icons[$key] ?? \Chamilo\CoreBundle\Enums\ActionIcon::VIEW_DETAILS,
$icon = Display::getMdiIcon($icons[$key] ?? ActionIcon::VIEW_DETAILS,
'mdi-inline', null, ICON_SIZE_SMALL, $label);
echo '<a class="pill'.($isActive ? ' active' : '').'" href="'.$href.'"'.
($isActive ? ' aria-current="page"' : '').'>'.$icon.'<span>'.api_htmlentities($label).'</span></a>';
Expand Down Expand Up @@ -5007,18 +5032,18 @@ public function getStatsTable(): void
<li class="breadcrumb-item">
<a href="'.
$this->url(['action'=>'showpage','title'=>'index']).'">'.
Display::getMdiIcon(\Chamilo\CoreBundle\Enums\ActionIcon::HOME, 'mdi-inline', null, ICON_SIZE_SMALL, get_lang('Home')).
Display::getMdiIcon(ActionIcon::HOME, 'mdi-inline', null, ICON_SIZE_SMALL, get_lang('Home')).
'<span>'.get_lang('Wiki').'</span>
</a>
</li>
<li class="breadcrumb-item active" aria-current="page">'.
Display::getMdiIcon(\Chamilo\CoreBundle\Enums\ActionIcon::VIEW_MORE, 'mdi-inline', null, ICON_SIZE_SMALL, get_lang('More')).
Display::getMdiIcon(ActionIcon::VIEW_MORE, 'mdi-inline', null, ICON_SIZE_SMALL, get_lang('More')).
'<span>'.get_lang('More').'</span>
</li>

<div class="breadcrumb-actions">
<a class="btn btn-default btn-xs" href="'.$this->url().'">'.
Display::getMdiIcon(\Chamilo\CoreBundle\Enums\ActionIcon::BACK, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Back')).
Display::getMdiIcon(ActionIcon::BACK, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Back')).
' '.get_lang('Back').'
</a>
</div>
Expand Down
130 changes: 66 additions & 64 deletions src/CourseBundle/Component/CourseCopy/CourseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -974,13 +974,34 @@ public function build_gradebook(
$em = Database::getManager();
$catRepo = $em->getRepository(GradebookCategory::class);

$criteria = ['course' => $courseEntity];
if ($sessionEntity) {
$criteria['session'] = $sessionEntity;
$qb = $catRepo->createQueryBuilder('cat')
->andWhere('cat.course = :course')
->setParameter('course', $courseEntity);

if ($sessionEntity instanceof SessionEntity) {
if ($this->withBaseContent) {
// Include base categories (session IS NULL) + session categories
$qb->andWhere(
$qb->expr()->orX(
'cat.session = :session',
'cat.session IS NULL'
)
)->setParameter('session', $sessionEntity);
} else {
// Only session-specific categories
$qb->andWhere('cat.session = :session')
->setParameter('session', $sessionEntity);
}
} else {
// No session context => base only
$qb->andWhere('cat.session IS NULL');
}

$qb->addOrderBy('cat.id', 'ASC');

/** @var GradebookCategory[] $cats */
$cats = $catRepo->findBy($criteria);
$cats = $qb->getQuery()->getResult();

if (!$cats) {
return;
}
Expand All @@ -999,74 +1020,55 @@ public function build_gradebook(
*
* @return array<string,mixed>
*/
private function serializeGradebookCategory(GradebookCategory $c): array
private function serializeGradebookCategory(GradebookCategory $cat): array
{
$arr = [
'id' => (int) $c->getId(),
'title' => (string) $c->getTitle(),
'description' => (string) ($c->getDescription() ?? ''),
'weight' => (float) $c->getWeight(),
'visible' => (bool) $c->getVisible(),
'locked' => (int) $c->getLocked(),
'parent_id' => $c->getParent() ? (int) $c->getParent()->getId() : 0,
'generate_certificates' => (bool) $c->getGenerateCertificates(),
'certificate_validity_period' => $c->getCertificateValidityPeriod(),
'is_requirement' => (bool) $c->getIsRequirement(),
'default_lowest_eval_exclude' => (bool) $c->getDefaultLowestEvalExclude(),
'minimum_to_validate' => $c->getMinimumToValidate(),
'gradebooks_to_validate_in_dependence' => $c->getGradeBooksToValidateInDependence(),
'allow_skills_by_subcategory' => $c->getAllowSkillsBySubcategory(),
// camelCase duplicates (future-proof)
'generateCertificates' => (bool) $c->getGenerateCertificates(),
'certificateValidityPeriod' => $c->getCertificateValidityPeriod(),
'isRequirement' => (bool) $c->getIsRequirement(),
'defaultLowestEvalExclude' => (bool) $c->getDefaultLowestEvalExclude(),
'minimumToValidate' => $c->getMinimumToValidate(),
'gradeBooksToValidateInDependence' => $c->getGradeBooksToValidateInDependence(),
'allowSkillsBySubcategory' => $c->getAllowSkillsBySubcategory(),
];
$em = Database::getManager();

$evalRepo = $em->getRepository(GradebookEvaluation::class);
$linkRepo = $em->getRepository(GradebookLink::class);

$id = method_exists($cat, 'getId') ? (int) $cat->getId() : 0;

if ($c->getGradeModel()) {
$arr['grade_model_id'] = (int) $c->getGradeModel()->getId();
}

// Evaluations
$arr['evaluations'] = [];
foreach ($c->getEvaluations() as $e) {
/** @var GradebookEvaluation $e */
$arr['evaluations'][] = [
'title' => (string) $e->getTitle(),
'description' => (string) ($e->getDescription() ?? ''),
'weight' => (float) $e->getWeight(),
'max' => (float) $e->getMax(),
'type' => (string) $e->getType(),
'visible' => (int) $e->getVisible(),
'locked' => (int) $e->getLocked(),
'best_score' => $e->getBestScore(),
'average_score' => $e->getAverageScore(),
'score_weight' => $e->getScoreWeight(),
'min_score' => $e->getMinScore(),
$parentId = 0;
if (method_exists($cat, 'getParent') && $cat->getParent()) {
$parentId = method_exists($cat->getParent(), 'getId') ? (int) $cat->getParent()->getId() : 0;
}

$evaluations = [];
foreach ($evalRepo->findBy(['category' => $cat]) as $e) {
$evaluations[] = [
'title' => method_exists($e, 'getTitle') ? (string) $e->getTitle() : 'Evaluation',
'description' => method_exists($e, 'getDescription') ? (string) $e->getDescription() : '',
'weight' => method_exists($e, 'getWeight') ? (float) $e->getWeight() : 0.0,
'max' => method_exists($e, 'getMax') ? (float) $e->getMax() : 100.0,
'type' => method_exists($e, 'getType') ? (string) $e->getType() : 'manual',
'visible' => method_exists($e, 'getVisible') ? (int) $e->getVisible() : 1,
'locked' => method_exists($e, 'getLocked') ? (int) $e->getLocked() : 0,
];
}

// Links
$arr['links'] = [];
foreach ($c->getLinks() as $l) {
/** @var GradebookLink $l */
$arr['links'][] = [
'type' => (int) $l->getType(),
'ref_id' => (int) $l->getRefId(),
'weight' => (float) $l->getWeight(),
'visible' => (int) $l->getVisible(),
'locked' => (int) $l->getLocked(),
'best_score' => $l->getBestScore(),
'average_score' => $l->getAverageScore(),
'score_weight' => $l->getScoreWeight(),
'min_score' => $l->getMinScore(),
$links = [];
foreach ($linkRepo->findBy(['category' => $cat]) as $l) {
$links[] = [
'type' => method_exists($l, 'getType') ? (int) $l->getType() : 0,
'ref_id' => method_exists($l, 'getRefId') ? (int) $l->getRefId() : 0,
'weight' => method_exists($l, 'getWeight') ? (float) $l->getWeight() : 0.0,
'visible' => method_exists($l, 'getVisible') ? (int) $l->getVisible() : 1,
'locked' => method_exists($l, 'getLocked') ? (int) $l->getLocked() : 0,
];
}

return $arr;
return [
'id' => $id,
'parent_id' => $parentId,
'title' => method_exists($cat, 'getTitle') ? (string) $cat->getTitle() : 'Category',
'description' => method_exists($cat, 'getDescription') ? (string) $cat->getDescription() : '',
'weight' => method_exists($cat, 'getWeight') ? (float) $cat->getWeight() : 0.0,
'visible' => method_exists($cat, 'getVisible') ? (bool) $cat->getVisible() : true,
'locked' => method_exists($cat, 'getLocked') ? (int) $cat->getLocked() : 0,
'evaluations' => $evaluations,
'links' => $links,
];
}

/**
Expand Down
Loading
Loading