1<?php
2/*
3        +-----------------------------------------------------------------------------+
4        | ILIAS open source                                                           |
5        +-----------------------------------------------------------------------------+
6        | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
7        |                                                                             |
8        | This program is free software; you can redistribute it and/or               |
9        | modify it under the terms of the GNU General Public License                 |
10        | as published by the Free Software Foundation; either version 2              |
11        | of the License, or (at your option) any later version.                      |
12        |                                                                             |
13        | This program is distributed in the hope that it will be useful,             |
14        | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
15        | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
16        | GNU General Public License for more details.                                |
17        |                                                                             |
18        | You should have received a copy of the GNU General Public License           |
19        | along with this program; if not, write to the Free Software                 |
20        | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
21        +-----------------------------------------------------------------------------+
22*/
23
24include_once('./Services/Table/classes/class.ilTable2GUI.php');
25
26/**
27 *
28 * @author Stefan Meyer <smeyer.ilias@gmx.de>
29 * @version $Id$
30 *
31 * @ingroup ModulesCourse
32 */
33class ilCourseEditParticipantsTableGUI extends ilTable2GUI
34{
35    public $container = null;
36
37    /**
38     * @var ilObject
39     */
40    protected $rep_object = null;
41
42    /**
43     * Holds the local roles of the course object.
44     * This variable is an associative array.
45     * - The key is the localized name of the role (for example
46     *   'Course Administrator')
47     * - The value is an associative array with the keys 'role_id' and
48     *   'title'.
49     */
50    private $localCourseRoles = null;
51
52    /**
53     * Constructor
54     *
55     * @access public
56     * @param object parent gui object
57     * @return void
58     */
59    public function __construct($a_parent_obj, $rep_object)
60    {
61        global $DIC;
62
63        $lng = $DIC['lng'];
64        $ilCtrl = $DIC['ilCtrl'];
65
66        $this->lng = $lng;
67        $this->lng->loadLanguageModule('crs');
68        $this->ctrl = $ilCtrl;
69
70        $this->container = $a_parent_obj;
71        $this->rep_object = $rep_object;
72
73        include_once('./Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
74        $this->privacy = ilPrivacySettings::_getInstance();
75
76        $this->participants = ilCourseParticipants::_getInstanceByObjId($this->rep_object->getId());
77
78        parent::__construct($a_parent_obj, 'editMembers');
79        $this->setFormName('participants');
80        $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
81
82        $this->addColumn($this->lng->txt('name'), 'name', '20%');
83        $this->addColumn($this->lng->txt('login'), 'login', '25%');
84
85        if ($this->privacy->enabledCourseAccessTimes()) {
86            $this->addColumn($this->lng->txt('last_access'), 'access_time');
87        }
88        $this->addColumn($this->lng->txt('crs_passed'), 'passed');
89        $this->addColumn($this->lng->txt('crs_blocked'), 'blocked');
90        // cognos-blu-patch: begin
91        $this->addColumn($this->lng->txt('crs_mem_contact'), 'contact');
92        // cognos-blu-patch: end
93        $this->addColumn($this->lng->txt('crs_notification'), 'notification');
94        $this->addColumn($this->lng->txt('objs_role'), 'roles');
95
96        $this->addCommandButton('updateParticipants', $this->lng->txt('save'));
97        $this->addCommandButton('participants', $this->lng->txt('cancel'));
98
99        $this->setRowTemplate("tpl.edit_participants_row.html", "Modules/Course");
100
101        $this->disable('sort');
102        $this->enable('header');
103        $this->enable('numinfo');
104        $this->disable('select_all');
105
106        // Performance improvement: We read the local course roles
107        // only once, instead of reading them for each row in method fillRow().
108        $this->localCourseRoles = array();
109        foreach ($this->rep_object->getLocalCourseRoles(false) as $title => $role_id) {
110            $this->localCourseRoles[ilObjRole::_getTranslation($title)] = array('role_id' => $role_id, 'title' => $title);
111        }
112    }
113
114    /**
115     * fill row
116     *
117     * @access public
118     * @param array usr_data
119     */
120    public function fillRow($a_set)
121    {
122        global $DIC;
123
124        $rbacsystem = $DIC['rbacsystem'];
125        $ilAccess = $DIC['ilAccess'];
126        $ilUser = $DIC['ilUser'];
127        $hasEditPermissionAccess =
128            (
129                $ilAccess->checkAccess('edit_permission', '', $this->rep_object->getRefId()) or
130                $this->participants->isAdmin($ilUser->getId())
131            );
132
133        $this->tpl->setVariable('VAL_ID', $a_set['usr_id']);
134        $this->tpl->setVariable('VAL_NAME', $a_set['lastname'] . ', ' . $a_set['firstname']);
135
136        $this->tpl->setVariable('VAL_LOGIN', $a_set['login']);
137
138        if ($this->privacy->enabledCourseAccessTimes()) {
139            $this->tpl->setVariable('VAL_ACCESS', $a_set['access_time']);
140        }
141        // cognos-blu-patch: begin
142        $this->tpl->setVariable('VAL_CONTACT_CHECKED', $a_set['contact'] ? 'checked="checked"' : '');
143        // cognos-blu-patch: end
144
145        $this->tpl->setVariable('VAL_NOTIFICATION_CHECKED', $a_set['notification'] ? 'checked="checked"' : '');
146        $this->tpl->setVariable('VAL_PASSED_CHECKED', $a_set['passed'] ? 'checked="checked"' : '');
147        $this->tpl->setVariable('VAL_BLOCKED_CHECKED', $a_set['blocked'] ? 'checked="checked"' : '');
148
149        $this->tpl->setVariable('NUM_ROLES', count($this->participants->getRoles()));
150
151        $assigned = $this->participants->getAssignedRoles($a_set['usr_id']);
152        foreach ($this->localCourseRoles as $localizedTitle => $roleData) {
153            if ($hasEditPermissionAccess || substr($roleData['title'], 0, 12) != 'il_crs_admin') {
154                $this->tpl->setCurrentBlock('roles');
155                $this->tpl->setVariable('ROLE_ID', $roleData['role_id']);
156                $this->tpl->setVariable('ROLE_NAME', $localizedTitle);
157
158                if (in_array($roleData['role_id'], $assigned)) {
159                    $this->tpl->setVariable('ROLE_CHECKED', 'selected="selected"');
160                }
161                $this->tpl->parseCurrentBlock();
162            }
163        }
164    }
165}
166