1<?php
2
3/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once "Services/Object/classes/class.ilObjectListGUI.php";
6
7/**
8 * Class ilObjCourseListGUI
9 *
10 * @author Alex Killing <alex.killing@gmx.de>
11 * $Id$
12 *
13 * @ingroup ModulesCourse
14 */
15class ilObjCourseListGUI extends ilObjectListGUI
16{
17    /**
18     * @var \ilCertificateObjectsForUserPreloader
19     */
20    private $certificatePreloader;
21
22    /**
23    * initialisation
24    */
25    public function init()
26    {
27        $this->static_link_enabled = true;
28        $this->delete_enabled = true;
29        $this->cut_enabled = true;
30        $this->copy_enabled = true;
31        $this->subscribe_enabled = true;
32        $this->link_enabled = false;
33        $this->info_screen_enabled = true;
34        $this->type = "crs";
35        $this->gui_class_name = "ilobjcoursegui";
36
37        $this->substitutions = ilAdvancedMDSubstitution::_getInstanceByObjectType($this->type);
38        if ($this->substitutions->isActive()) {
39            $this->substitutions_enabled = true;
40        }
41
42        // general commands array
43        $this->commands = ilObjCourseAccess::_getCommands();
44    }
45
46    /**
47     * @inheritdoc
48     */
49    public function initItem($a_ref_id, $a_obj_id, $type, $a_title = "", $a_description = "")
50    {
51        parent::initItem($a_ref_id, $a_obj_id, $type, $a_title, $a_description);
52
53        $this->conditions_ok = ilConditionHandler::_checkAllConditionsOfTarget($a_ref_id, $this->obj_id);
54    }
55
56    /**
57     * @return \ilCertificateObjectsForUserPreloader
58     */
59    protected function getCertificatePreloader() : \ilCertificateObjectsForUserPreloader
60    {
61        if (null === $this->certificatePreloader) {
62            $repository = new ilUserCertificateRepository();
63            $this->certificatePreloader = new ilCertificateObjectsForUserPreloader($repository);
64        }
65
66        return $this->certificatePreloader;
67    }
68
69    /**
70    * Get item properties
71    *
72    * @return	array		array of property arrays:
73    *						"alert" (boolean) => display as an alert property (usually in red)
74    *						"property" (string) => property name
75    *						"value" (string) => property value
76    */
77    public function getProperties()
78    {
79        global $DIC;
80
81        $lng = $DIC['lng'];
82        $ilUser = $DIC['ilUser'];
83
84        $props = parent::getProperties();
85
86        // check activation
87        if (
88            !ilObjCourseAccess::_isActivated($this->obj_id) &&
89            !ilObject::lookupOfflineStatus($this->obj_id)
90        ) {
91            $showRegistrationInfo = false;
92            $props[] = array(
93                "alert" => true,
94                "property" => $lng->txt("status"),
95                "value" => $lng->txt("offline")
96            );
97        }
98
99        // blocked
100        include_once 'Modules/Course/classes/class.ilCourseParticipant.php';
101        $members = ilCourseParticipant::_getInstanceByObjId($this->obj_id, $ilUser->getId());
102        if ($members->isBlocked($ilUser->getId()) and $members->isAssigned($ilUser->getId())) {
103            $props[] = array("alert" => true, "property" => $lng->txt("member_status"),
104                "value" => $lng->txt("crs_status_blocked"));
105        }
106
107        // pending subscription
108        include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
109        if (ilCourseParticipants::_isSubscriber($this->obj_id, $ilUser->getId())) {
110            $props[] = array("alert" => true, "property" => $lng->txt("member_status"),
111                "value" => $lng->txt("crs_status_pending"));
112        }
113
114        include_once './Modules/Course/classes/class.ilObjCourseAccess.php';
115        $info = ilObjCourseAccess::lookupRegistrationInfo($this->obj_id);
116        if ($info['reg_info_list_prop']) {
117            $props[] = array(
118                'alert' => false,
119                'newline' => true,
120                'property' => $info['reg_info_list_prop']['property'],
121                'value' => $info['reg_info_list_prop']['value']
122            );
123        }
124        if ($info['reg_info_list_prop_limit']) {
125            $props[] = array(
126                'alert' => false,
127                'newline' => false,
128                'property' => $info['reg_info_list_prop_limit']['property'],
129                'propertyNameVisible' => strlen($info['reg_info_list_prop_limit']['property']) ? true : false,
130                'value' => $info['reg_info_list_prop_limit']['value']
131            );
132        }
133
134        // waiting list
135        include_once './Modules/Course/classes/class.ilCourseWaitingList.php';
136        if (ilCourseWaitingList::_isOnList($ilUser->getId(), $this->obj_id)) {
137            $props[] = array(
138                "alert" => true,
139                "property" => $lng->txt('member_status'),
140                "value" => $lng->txt('on_waiting_list')
141            );
142        }
143
144        // course period
145        $info = ilObjCourseAccess::lookupPeriodInfo($this->obj_id);
146        if (is_array($info)) {
147            $props[] = array(
148                'alert' => false,
149                'newline' => true,
150                'property' => $info['property'],
151                'value' => $info['value']
152            );
153        }
154
155        // check for certificates
156        $hasCertificate = $this->getCertificatePreloader()->isPreloaded($ilUser->getId(), $this->obj_id);
157        if (true === $hasCertificate) {
158            $lng->loadLanguageModule('certificate');
159            $cmd_link = "ilias.php?baseClass=ilRepositoryGUI&ref_id=" . $this->ref_id . "&cmd=deliverCertificate";
160            $props[] = [
161                'alert' => false,
162                'property' => $lng->txt('certificate'),
163                'value' => $DIC->ui()->renderer()->render(
164                    $DIC->ui()->factory()->link()->standard($lng->txt('download_certificate'), $cmd_link)
165                )
166            ];
167        }
168
169        // booking information
170        $repo = ilObjCourseAccess::getBookingInfoRepo();
171        $book_info = new ilBookingInfoListItemPropertiesAdapter($repo);
172        $props = $book_info->appendProperties($this->obj_id, $props);
173
174        return $props;
175    }
176
177
178    /**
179     * Workaround for course titles (linked if join or read permission is granted)
180     * @param type $a_permission
181     * @param type $a_cmd
182     * @param type $a_ref_id
183     * @param type $a_type
184     * @param type $a_obj_id
185     * @return type
186     */
187    public function checkCommandAccess($a_permission, $a_cmd, $a_ref_id, $a_type, $a_obj_id = "")
188    {
189        // Only check cmd access for cmd 'register' and 'unregister'
190        if ($a_cmd != 'view' and $a_cmd != 'leave' and $a_cmd != 'join') {
191            $a_cmd = '';
192        }
193
194        if ($a_permission == 'crs_linked') {
195            return
196                parent::checkCommandAccess('read', $a_cmd, $a_ref_id, $a_type, $a_obj_id) ||
197                parent::checkCommandAccess('join', $a_cmd, $a_ref_id, $a_type, $a_obj_id);
198        }
199        return parent::checkCommandAccess($a_permission, $a_cmd, $a_ref_id, $a_type, $a_obj_id);
200    }
201} // END class.ilObjCategoryGUI
202