public function LpSteps::getMeetingStep in Opigno Learning path 3.x
Same name and namespace in other branches
- 8 src/LpSteps.php \Drupal\opigno_learning_path\LpSteps::getMeetingStep()
Builds up a training live meeting step.
Parameters
int $group_id: Training group ID.
int $uid: User ID.
\Drupal\opigno_moxtra\MeetingInterface $meeting: Opigno Moxtra Meeting entity.
Return value
array Data array about step in a group for a user.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
File
- src/
LpSteps.php, line 255
Class
Namespace
Drupal\opigno_learning_pathCode
public function getMeetingStep($group_id, $uid, MeetingInterface $meeting) {
$id = $meeting
->id();
$key = "{$group_id}_{$uid}_{$id}";
$results =& drupal_static(__FUNCTION__);
if (!isset($results[$key])) {
/** @var \Drupal\opigno_group_manager\Entity\OpignoGroupManagedContent $content */
$content = current(OpignoGroupManagedContent::loadByProperties([
'group_id' => $group_id,
'group_content_type_id' => 'ContentTypeMeeting',
'entity_id' => $meeting
->id(),
]));
$entityTypeManager = \Drupal::entityTypeManager();
/** @var \Drupal\opigno_moxtra\MeetingResultInterface[] $meeting_results */
$meeting_results = $entityTypeManager
->getStorage('opigno_moxtra_meeting_result')
->loadByProperties([
'user_id' => $uid,
'meeting' => $meeting
->id(),
]);
$presence = 0;
if (!empty($meeting_results)) {
$presence = current($meeting_results)
->getStatus();
}
$scores = array_map(function ($result) {
/** @var \Drupal\opigno_moxtra\MeetingResultInterface $result */
return $result
->getScore();
}, $meeting_results);
if (!empty($scores)) {
$score = end($scores);
}
else {
$score = 0;
}
$start_date = $meeting
->getStartDate();
$end_date = $meeting
->getEndDate();
$start_timestamp = isset($start_date) ? DrupalDateTime::createFromFormat(DrupalDateTime::FORMAT, $start_date)
->getTimestamp() : 0;
$end_timestamp = isset($end_date) ? DrupalDateTime::createFromFormat(DrupalDateTime::FORMAT, $end_date)
->getTimestamp() : 0;
$description = !empty($start_timestamp) && !empty($end_timestamp) ? date('d/m/Y H:i', $start_timestamp) . ' - ' . date('H:i', $end_timestamp) . '<br />' : '';
$results[$key] = [
// OpignoGroupManagedContent id.
'cid' => $content
->id(),
// Entity id.
'id' => $meeting
->id(),
'name' => $meeting
->label(),
'description' => $description,
'typology' => 'Meeting',
'best score' => !empty($scores) ? max($scores) : 0,
'current attempt score' => $score,
'required score' => (int) $content
->getSuccessScoreMin(),
'attempts' => count($meeting_results),
'activities' => 0,
'time spent' => !empty($scores) ? $end_timestamp - $start_timestamp : 0,
'current attempt time' => !empty($scores) ? $end_timestamp - $start_timestamp : 0,
'completed on' => !empty($scores) ? $end_timestamp : 0,
'mandatory' => (int) $content
->isMandatory(),
'presence' => $presence,
];
}
return $results[$key];
}