ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCertificateCourseLearningProgressEvaluation.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
8 {
13 
17  private $setting;
18 
22  private $objectHelper;
23 
27  private $statusHelper;
28 
32  private $trackingHelper;
33 
40  public function __construct(
42  ilSetting $setting = null,
46  ) {
47  $this->templateRepository = $templateRepository;
48 
49  if (null === $setting) {
50  $setting = new ilSetting('crs');
51  }
52  $this->setting = $setting;
53 
54  if (null === $objectHelper) {
56  }
57  $this->objectHelper = $objectHelper;
58 
59  if (null === $statusHelper) {
61  }
62  $this->statusHelper = $statusHelper;
63  if (null === $trackingHelper) {
65  }
66  $this->trackingHelper = $trackingHelper;
67  }
68 
74  public function evaluate(int $refId, int $userId) : array
75  {
76  $courseTemplates = $this->templateRepository->fetchActiveTemplatesByType('crs');
77 
78  $enabledGlobalLearningProgress = $this->trackingHelper->enabledLearningProgress();
79 
80  $templatesOfCompletedCourses = array();
81  foreach ($courseTemplates as $courseTemplate) {
82  $courseObjectId = $courseTemplate->getObjId();
83 
84  if ($enabledGlobalLearningProgress) {
85  $objectLearningProgressSettings = new ilLPObjSettings($courseObjectId);
86  $mode = $objectLearningProgressSettings->getMode();
87 
89  continue;
90  }
91  }
92 
93  $subItems = $this->setting->get('cert_subitems_' . $courseObjectId, false);
94 
95  if (false === $subItems || $subItems === null) {
96  continue;
97  }
98 
99  $subItems = json_decode($subItems);
100 
101  if (!is_array($subItems)) {
102  continue;
103  }
104 
105  $subitem_obj_ids = array();
106  foreach ($subItems as $subItemRefId) {
107  $subitem_obj_ids[$subItemRefId] = $this->objectHelper->lookupObjId((int) $subItemRefId);
108  }
109 
110  if (in_array($refId, $subItems)) {
111  $completed = true;
112 
113  // check if all subitems are completed now
114  foreach ($subitem_obj_ids as $subitem_ref_id => $subitem_id) {
115  $status = $this->statusHelper->lookUpStatus($subitem_id, $userId);
116 
117  if ($status != ilLPStatus::LP_STATUS_COMPLETED_NUM) {
118  $completed = false;
119  break;
120  }
121  }
122 
123  if (true === $completed) {
124  $templatesOfCompletedCourses[] = $courseTemplate;
125  }
126  }
127  }
128 
129  return $templatesOfCompletedCourses;
130  }
131 }
const LP_STATUS_COMPLETED_NUM
__construct(ilCertificateTemplateRepository $templateRepository, ilSetting $setting=null, ilCertificateObjectHelper $objectHelper=null, ilCertificateLPStatusHelper $statusHelper=null, ilCertificateObjUserTrackingHelper $trackingHelper=null)