| Línea 521... |
Línea 521... |
| 521 |
if(!in_array($order_field,['name', 'added_on'] )) {
|
521 |
if(!in_array($order_field,['name', 'added_on'] )) {
|
| 522 |
$order_field = 'name';
|
522 |
$order_field = 'name';
|
| 523 |
}
|
523 |
}
|
| Línea 524... |
Línea 524... |
| 524 |
|
524 |
|
| 525 |
if(!in_array( $order_direction,['asc', 'desc'])) {
|
525 |
if(!in_array( $order_direction,['asc', 'desc'])) {
|
| 526 |
$order_direction = 'asc'; // Corregido: asignar a $order_direction
|
526 |
$order_direction = 'asc';
|
| Línea 527... |
Línea 527... |
| 527 |
}
|
527 |
}
|
| 528 |
|
528 |
|
| 529 |
$userProgressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
|
529 |
$userProgressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
|
| 530 |
$capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
|
530 |
$capsuleMapper = MicrolearningCapsuleMapper::getInstance($this->adapter);
|
| 531 |
$topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter); // Añadido
|
531 |
$topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter); // Añadido
|
| Línea 532... |
Línea 532... |
| 532 |
$topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
|
532 |
$topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
|
| Línea 533... |
Línea -... |
| 533 |
$capsuleCommentMapper = MicrolearningCapsuleCommentMapper::getInstance($this->adapter); // Reordenado
|
- |
|
| 534 |
|
533 |
$capsuleCommentMapper = MicrolearningCapsuleCommentMapper::getInstance($this->adapter); // Reordenado
|
| Línea 535... |
Línea 534... |
| 535 |
$accessGranted = $this->getAccessGranted();
|
534 |
|
| 536 |
|
535 |
$accessGranted = $this->getAccessGranted();
|
| Línea 537... |
Línea 536... |
| 537 |
// $topics = []; // Ya no es necesario cachear tópicos aquí
|
536 |
|
| 538 |
$capsulesData = []; // Renombrado
|
537 |
$capsulesData = [];
|
| 539 |
|
538 |
|
| 540 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
- |
|
| 541 |
$path = $storage->getPathMicrolearningCapsule();
|
539 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
| 542 |
|
- |
|
| 543 |
foreach($accessGranted->capsules as $capsule_id)
|
- |
|
| 544 |
{
|
- |
|
| 545 |
// 1. Verificar progreso (debe ser nulo para pendiente)
|
- |
|
| 546 |
$userProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule_id);
|
- |
|
| 547 |
if($userProgress) {
|
- |
|
| 548 |
continue;
|
540 |
$path = $storage->getPathMicrolearningCapsule();
|
| 549 |
}
|
541 |
|
| - |
|
542 |
foreach($accessGranted->topics as $topic_id)
|
| - |
|
543 |
{
|
| Línea 550... |
Línea 544... |
| 550 |
|
544 |
$topic = $topicMapper->fetchOne($topic_id);
|
| 551 |
// 2. Obtener detalles de la cápsula
|
545 |
if(!$topic) {
|
| 552 |
$capsule = $capsuleMapper->fetchOne($capsule_id);
|
546 |
continue;
|
| 553 |
if(!$capsule) { // Añadir verificación por si la cápsula no existe
|
547 |
}
|
| 554 |
continue;
|
548 |
|
| 555 |
}
|
- |
|
| 556 |
|
549 |
$capsules = $topicCapsuleMapper->fetchAllActiveByTopicId($topic_id) ?? [];
|
| - |
|
550 |
|
| 557 |
// 3. Filtrar por nombre
|
551 |
foreach($capsules as $capsule) {
|
| 558 |
if($name) {
|
552 |
$capsule = $capsuleMapper->fetchOne($capsule->capsule_id);
|
| 559 |
if(empty($name) || stripos($capsule->name, $name) === false) {
|
553 |
if(!$capsule) {
|
| - |
|
554 |
continue;
|
| 560 |
continue;
|
555 |
}
|
| 561 |
}
|
556 |
|
| 562 |
}
|
557 |
$userProgress = $userProgressMapper->fetchOneByUseridAndCapsuleId($currentUser->id, $capsule->id);
|
| 563 |
|
558 |
if($userProgress) {
|
| 564 |
// 4. Obtener Tópico asociado válido
|
- |
|
| 565 |
$topic = null;
|
559 |
continue;
|
| - |
|
560 |
}
|
| - |
|
561 |
|
| - |
|
562 |
if($name) {
|
| - |
|
563 |
if(empty($name) || stripos($capsule->name, $name) === false) {
|
| - |
|
564 |
continue;
|
| - |
|
565 |
}
|
| - |
|
566 |
}
|
| - |
|
567 |
|
| - |
|
568 |
$dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->id);
|
| - |
|
569 |
$link_slides = $topic->uuid ? $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic->uuid, 'capsule_id' => $capsule->uuid], ['force_canonical' => true]) : '';
|
| - |
|
570 |
|
| - |
|
571 |
array_push($capsulesData, [
|
| - |
|
572 |
'uuid' => $capsule->uuid,
|
| - |
|
573 |
'name' => $capsule->name ? $capsule->name : '',
|
| - |
|
574 |
'description' => $capsule->description ? $capsule->description : '',
|
| - |
|
575 |
'image' => $capsule->image ? $storage->getGenericImage($path, $capsule->uuid, $capsule->image) : '',
|
| - |
|
576 |
'link_comments' => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
|
| - |
|
577 |
'link_comment_add' => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
|
| 566 |
$topic_uuid_for_links = null;
|
578 |
'link_slides' => $link_slides,
|
| 567 |
$relation = $topicCapsuleMapper->fetchOneByCapsuleId($capsule->id);
|
- |
|
| 568 |
if ($relation && in_array($relation->topic_id, $accessGranted->topics)) {
|
- |
|
| 569 |
$topic = $topicMapper->fetchOne($relation->topic_id);
|
- |
|
| 570 |
if ($topic) {
|
- |
|
| 571 |
$topic_uuid_for_links = $topic->uuid;
|
- |
|
| 572 |
}
|
- |
|
| 573 |
}
|
- |
|
| 574 |
|
- |
|
| 575 |
// 5. Obtener datos de comentarios
|
- |
|
| 576 |
$dataCountAndRatingAverage = $capsuleCommentMapper->fetchCountAndRatingAverage($capsule->company_id, $capsule->id);
|
- |
|
| 577 |
|
- |
|
| 578 |
// 6. Construir enlace slides
|
- |
|
| 579 |
$link_slides = $topic_uuid_for_links ? $this->url()->fromRoute('microlearning/slides', ['topic_id' => $topic_uuid_for_links, 'capsule_id' => $capsule->uuid], ['force_canonical' => true]) : '';
|
- |
|
| 580 |
|
- |
|
| 581 |
// 7. Añadir al array de resultados
|
- |
|
| 582 |
array_push($capsulesData, [
|
- |
|
| 583 |
'uuid' => $capsule->uuid,
|
- |
|
| 584 |
'name' => $capsule->name ? $capsule->name : '',
|
- |
|
| 585 |
'description' => $capsule->description ? $capsule->description : '',
|
- |
|
| 586 |
'image' => $capsule->image ? $storage->getGenericImage($path, $capsule->uuid, $capsule->image) : '',
|
- |
|
| 587 |
'position' => $capsule->order,
|
- |
|
| 588 |
'link_comments' => $this->url()->fromRoute('microlearning/capsules-comments', ['capsule_id' => $capsule->uuid], ['force_canonical' => true]),
|
- |
|
| 589 |
'link_comment_add' => $this->url()->fromRoute('microlearning/capsules-comments/add', ['capsule_id' => $capsule->uuid],['force_canonical' => true]),
|
- |
|
| 590 |
'link_slides' => $link_slides, // Usar enlace construido
|
579 |
'total_comments' => strval($dataCountAndRatingAverage['total_comments']),
|
| Línea 591... |
Línea 580... |
| 591 |
'total_comments' => strval($dataCountAndRatingAverage['total_comments']),
|
580 |
'total_rating' => strval($dataCountAndRatingAverage['total_rating']),
|
| 592 |
'total_rating' => strval($dataCountAndRatingAverage['total_rating']),
|
- |
|
| 593 |
'progress' => 0,
|
581 |
'progress' => 0,
|
| 594 |
'added_on' => $capsule->added_on,
|
582 |
'added_on' => $capsule->added_on,
|
| 595 |
'updated_on' => $capsule->updated_on,
|
583 |
'updated_on' => $capsule->updated_on,
|
| 596 |
]);
|
584 |
]);
|
| 597 |
}
|
585 |
}
|
| Línea 628... |
Línea 616... |
| 628 |
|
616 |
|
| 629 |
// 9. Retornar
|
617 |
// 9. Retornar
|
| 630 |
return new JsonModel([
|
618 |
return new JsonModel([
|
| 631 |
'success' => true,
|
619 |
'success' => true,
|
| 632 |
'data' => $capsulesData
|
620 |
'data' => $capsulesData
|
| 633 |
]);
|
- |
|
| 634 |
|
- |
|
| 635 |
|
- |
|
| 636 |
|
621 |
]);
|
| Línea 637... |
Línea 622... |
| 637 |
}
|
622 |
}
|
| 638 |
|
623 |
|
| 639 |
return new JsonModel([
|
624 |
return new JsonModel([
|