Línea 2113... |
Línea 2113... |
2113 |
if (!$request->isPost()) {
|
2113 |
if (!$request->isPost()) {
|
2114 |
return new JsonModel(['success' => false, 'data' => 'ERROR_INVALID_REQUEST']);
|
2114 |
return new JsonModel(['success' => false, 'data' => 'ERROR_INVALID_REQUEST']);
|
2115 |
}
|
2115 |
}
|
Línea 2116... |
Línea 2116... |
2116 |
|
2116 |
|
2117 |
$slide_uuid = $this->params()->fromRoute('slide_uuid');
|
- |
|
Línea 2118... |
Línea 2117... |
2118 |
$topic_uuid = $this->params()->fromRoute('topic_uuid');
|
2117 |
$slide_uuid = $this->params()->fromRoute('slide_uuid');
|
2119 |
|
2118 |
|
2120 |
if (empty($slide_uuid) || empty($topic_uuid)) {
|
2119 |
if (empty($slide_uuid) || empty($topic_uuid)) {
|
Línea 2141... |
Línea 2140... |
2141 |
$capsule = $capsuleMapper->fetchOneById($slide->capsule_id);
|
2140 |
$capsule = $capsuleMapper->fetchOneById($slide->capsule_id);
|
2142 |
if (!$capsule || !in_array($capsule->id, $accessGrantedIds->capsules)) {
|
2141 |
if (!$capsule || !in_array($capsule->id, $accessGrantedIds->capsules)) {
|
2143 |
return new JsonModel(['success' => false, 'data' => 'ERROR_CAPSULE_ACCESS_DENIED']);
|
2142 |
return new JsonModel(['success' => false, 'data' => 'ERROR_CAPSULE_ACCESS_DENIED']);
|
2144 |
}
|
2143 |
}
|
Línea 2145... |
Línea -... |
2145 |
|
- |
|
2146 |
// Obtener Tópico
|
- |
|
2147 |
$topicMapper = MicrolearningTopicMapper::getInstance($this->adapter);
|
- |
|
2148 |
$topic = $topicMapper->fetchOneByUuid($topic_uuid);
|
- |
|
2149 |
if (!$topic || !in_array($topic->id, $accessGrantedIds->topics)) {
|
- |
|
2150 |
return new JsonModel(['success' => false, 'data' => 'ERROR_TOPIC_ACCESS_DENIED']);
|
- |
|
2151 |
}
|
- |
|
2152 |
|
- |
|
2153 |
// Validar que la cápsula pertenece al tópico
|
2144 |
|
2154 |
$topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
|
2145 |
$topicCapsuleMapper = MicrolearningTopicCapsuleMapper::getInstance($this->adapter);
|
- |
|
2146 |
$relations = $topicCapsuleMapper->fetchAllByCapsuleId($capsule->id);
|
2155 |
$relation = $topicCapsuleMapper->fetchOneByTopicIdAndCapsuleId($topic->id, $capsule->id);
|
2147 |
|
2156 |
if (!$relation) {
|
2148 |
if (!$relations) {
|
2157 |
return new JsonModel(['success' => false, 'data' => 'ERROR_CAPSULE_DOES_NOT_BELONG_TO_TOPIC']);
|
2149 |
return new JsonModel(['success' => false, 'data' => 'ERROR_CAPSULE_DOES_NOT_BELONG_TO_TOPIC']);
|
Línea 2158... |
Línea 2150... |
2158 |
}
|
2150 |
}
|
2159 |
|
2151 |
|
2160 |
// Marcar slide como visto
|
2152 |
foreach ($relations as $relation) {
|
2161 |
$progressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
|
2153 |
$progressMapper = MicrolearningUserProgressMapper::getInstance($this->adapter);
|
2162 |
$progressMapper->markSlideViewed($user_id, $topic->id, $capsule->id, $slide->id);
|
2154 |
$progressMapper->markSlideViewed($user_id, $relation->topic_id, $relation->capsule_id, $slide->id);
|
2163 |
|
2155 |
|
2164 |
$data = 'LABEL_THE_USER_PROGRESS_FOR_THIS_SLIDE_HAS_BEEN_COMPLETED';
|
2156 |
$data = 'LABEL_THE_USER_PROGRESS_FOR_THIS_SLIDE_HAS_BEEN_COMPLETED';
|
2165 |
|
2157 |
|
2166 |
// Si vio todos los slides → marcar cápsula como completada
|
2158 |
// Si vio todos los slides → marcar cápsula como completada
|
2167 |
if ($progressMapper->hasViewedAllSlidesInCapsule($user_id, $capsule->id)) {
|
2159 |
if ($progressMapper->hasViewedAllSlidesInCapsule($user_id, $capsule->id)) {
|
2168 |
$progressMapper->markCapsuleCompleted($user_id, $topic->id, $capsule->id);
|
2160 |
$progressMapper->markCapsuleCompleted($user_id, $relation->topic_id, $relation->capsule_id);
|
2169 |
$data = 'LABEL_THE_USER_PROGRESS_FOR_THIS_CAPSULE_HAS_BEEN_COMPLETED';
|
2161 |
$data = 'LABEL_THE_USER_PROGRESS_FOR_THIS_CAPSULE_HAS_BEEN_COMPLETED';
|
2170 |
}
|
2162 |
}
|
2171 |
|
2163 |
|
2172 |
// Si completó todas las cápsulas del tópico → marcar tópico como completado
|
2164 |
// Si completó todas las cápsulas del tópico → marcar tópico como completado
|
2173 |
if ($progressMapper->hasCompletedAllCapsulesInTopic($user_id, $topic->id)) {
|
2165 |
if ($progressMapper->hasCompletedAllCapsulesInTopic($user_id, $relation->topic_id)) {
|
- |
|
2166 |
$progressMapper->markTopicCompleted($user_id, $relation->topic_id);
|
2174 |
$progressMapper->markTopicCompleted($user_id, $topic->id);
|
2167 |
$data = 'LABEL_THE_USER_PROGRESS_FOR_THIS_TOPIC_HAS_BEEN_COMPLETED';
|
Línea 2175... |
Línea 2168... |
2175 |
$data = 'LABEL_THE_USER_PROGRESS_FOR_THIS_TOPIC_HAS_BEEN_COMPLETED';
|
2168 |
}
|
2176 |
}
|
2169 |
}
|