ILIAS  release_8 Revision v8.24
class.ilCertificateCourseLearningProgressEvaluation.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
31
32 public function __construct(
34 ?ilSetting $setting = null,
38 ) {
39 $this->templateRepository = $templateRepository;
40
41 if (null === $setting) {
42 $setting = new ilSetting('crs');
43 }
44 $this->setting = $setting;
45
46 if (null === $objectHelper) {
48 }
49 $this->objectHelper = $objectHelper;
50
51 if (null === $statusHelper) {
53 }
54 $this->statusHelper = $statusHelper;
55 if (null === $trackingHelper) {
57 }
58 $this->trackingHelper = $trackingHelper;
59 }
60
66 public function evaluate(int $refId, int $userId): array
67 {
68 $courseTemplates = $this->templateRepository
69 ->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(
70 $this->trackingHelper->enabledLearningProgress(),
71 $refId
72 );
73
74 $templatesOfCompletedCourses = [];
75 foreach ($courseTemplates as $courseTemplate) {
76 $courseObjectId = $courseTemplate->getObjId();
77
78 $subItems = $this->setting->get('cert_subitems_' . $courseObjectId);
79 if ($subItems === null) {
80 continue;
81 }
82 $subItems = json_decode($subItems, true, 512, JSON_THROW_ON_ERROR);
83 if (!is_array($subItems)) {
84 continue;
85 }
86
87 $subitem_obj_ids = [];
88 foreach ($subItems as $subItemRefId) {
89 $subitem_obj_ids[$subItemRefId] = $this->objectHelper->lookupObjId((int) $subItemRefId);
90 }
91
92 if (in_array($refId, $subItems)) {
93 $completed = true;
94
95 // check if all subitems are completed now
96 foreach ($subitem_obj_ids as $subitem_ref_id => $subitem_id) {
97 $status = $this->statusHelper->lookUpStatus($subitem_id, $userId);
98
100 $completed = false;
101 break;
102 }
103 }
104
105 if (true === $completed) {
106 $templatesOfCompletedCourses[] = $courseTemplate;
107 }
108 }
109 }
110
111 return $templatesOfCompletedCourses;
112 }
113}
__construct(ilCertificateTemplateRepository $templateRepository, ?ilSetting $setting=null, ?ilCertificateObjectHelper $objectHelper=null, ?ilCertificateLPStatusHelper $statusHelper=null, ?ilCertificateObjUserTrackingHelper $trackingHelper=null)
const LP_STATUS_COMPLETED_NUM
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$refId
Definition: xapitoken.php:58