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 * inititialize new item 48 * 49 * @param int $a_ref_id reference id 50 * @param int $a_obj_id object id 51 * @param string $a_title title 52 * @param string $a_description description 53 */ 54 public function initItem($a_ref_id, $a_obj_id, $a_title = "", $a_description = "") 55 { 56 parent::initItem($a_ref_id, $a_obj_id, $a_title, $a_description); 57 58 $this->conditions_ok = ilConditionHandler::_checkAllConditionsOfTarget($a_ref_id, $this->obj_id); 59 } 60 61 /** 62 * @return \ilCertificateObjectsForUserPreloader 63 */ 64 protected function getCertificatePreloader() : \ilCertificateObjectsForUserPreloader 65 { 66 if (null === $this->certificatePreloader) { 67 $repository = new ilUserCertificateRepository(); 68 $this->certificatePreloader = new ilCertificateObjectsForUserPreloader($repository); 69 } 70 71 return $this->certificatePreloader; 72 } 73 74 /** 75 * Get item properties 76 * 77 * @return array array of property arrays: 78 * "alert" (boolean) => display as an alert property (usually in red) 79 * "property" (string) => property name 80 * "value" (string) => property value 81 */ 82 public function getProperties() 83 { 84 global $DIC; 85 86 $lng = $DIC['lng']; 87 $ilUser = $DIC['ilUser']; 88 89 $props = parent::getProperties(); 90 91 // check activation 92 if ( 93 !ilObjCourseAccess::_isActivated($this->obj_id) && 94 !ilObject::lookupOfflineStatus($this->obj_id) 95 ) { 96 $showRegistrationInfo = false; 97 $props[] = array( 98 "alert" => true, 99 "property" => $lng->txt("status"), 100 "value" => $lng->txt("offline") 101 ); 102 } 103 104 // blocked 105 include_once 'Modules/Course/classes/class.ilCourseParticipant.php'; 106 $members = ilCourseParticipant::_getInstanceByObjId($this->obj_id, $ilUser->getId()); 107 if ($members->isBlocked($ilUser->getId()) and $members->isAssigned($ilUser->getId())) { 108 $props[] = array("alert" => true, "property" => $lng->txt("member_status"), 109 "value" => $lng->txt("crs_status_blocked")); 110 } 111 112 // pending subscription 113 include_once 'Modules/Course/classes/class.ilCourseParticipants.php'; 114 if (ilCourseParticipants::_isSubscriber($this->obj_id, $ilUser->getId())) { 115 $props[] = array("alert" => true, "property" => $lng->txt("member_status"), 116 "value" => $lng->txt("crs_status_pending")); 117 } 118 119 include_once './Modules/Course/classes/class.ilObjCourseAccess.php'; 120 $info = ilObjCourseAccess::lookupRegistrationInfo($this->obj_id); 121 if ($info['reg_info_list_prop']) { 122 $props[] = array( 123 'alert' => false, 124 'newline' => true, 125 'property' => $info['reg_info_list_prop']['property'], 126 'value' => $info['reg_info_list_prop']['value'] 127 ); 128 } 129 if ($info['reg_info_list_prop_limit']) { 130 $props[] = array( 131 'alert' => false, 132 'newline' => false, 133 'property' => $info['reg_info_list_prop_limit']['property'], 134 'propertyNameVisible' => strlen($info['reg_info_list_prop_limit']['property']) ? true : false, 135 'value' => $info['reg_info_list_prop_limit']['value'] 136 ); 137 } 138 139 // waiting list 140 include_once './Modules/Course/classes/class.ilCourseWaitingList.php'; 141 if (ilCourseWaitingList::_isOnList($ilUser->getId(), $this->obj_id)) { 142 $props[] = array( 143 "alert" => true, 144 "property" => $lng->txt('member_status'), 145 "value" => $lng->txt('on_waiting_list') 146 ); 147 } 148 149 // course period 150 $info = ilObjCourseAccess::lookupPeriodInfo($this->obj_id); 151 if (is_array($info)) { 152 $props[] = array( 153 'alert' => false, 154 'newline' => true, 155 'property' => $info['property'], 156 'value' => $info['value'] 157 ); 158 } 159 160 // check for certificates 161 $hasCertificate = $this->getCertificatePreloader()->isPreloaded($ilUser->getId(), $this->obj_id); 162 if (true === $hasCertificate) { 163 $lng->loadLanguageModule('certificate'); 164 $cmd_link = "ilias.php?baseClass=ilRepositoryGUI&ref_id=" . $this->ref_id . 165 "&cmd=deliverCertificate"; 166 $props[] = array("alert" => false, 167 "value" => '<a href="' . $cmd_link . '">' . $lng->txt("download_certificate") . '</a>'); 168 } 169 170 return $props; 171 } 172 173 174 /** 175 * Workaround for course titles (linked if join or read permission is granted) 176 * @param type $a_permission 177 * @param type $a_cmd 178 * @param type $a_ref_id 179 * @param type $a_type 180 * @param type $a_obj_id 181 * @return type 182 */ 183 public function checkCommandAccess($a_permission, $a_cmd, $a_ref_id, $a_type, $a_obj_id = "") 184 { 185 // Only check cmd access for cmd 'register' and 'unregister' 186 if ($a_cmd != 'view' and $a_cmd != 'leave' and $a_cmd != 'join') { 187 $a_cmd = ''; 188 } 189 190 if ($a_permission == 'crs_linked') { 191 return 192 parent::checkCommandAccess('read', $a_cmd, $a_ref_id, $a_type, $a_obj_id) || 193 parent::checkCommandAccess('join', $a_cmd, $a_ref_id, $a_type, $a_obj_id); 194 } 195 return parent::checkCommandAccess($a_permission, $a_cmd, $a_ref_id, $a_type, $a_obj_id); 196 } 197} // END class.ilObjCategoryGUI 198