1<?php
2
3/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once './Services/Table/classes/class.ilTable2GUI.php';
6
7/**
8* Table presentation of conditions
9*
10* @author Stefan Meyer <smeyer.ilias@gmx.de>
11* @version $Id$
12*/
13class ilConditionHandlerTableGUI extends ilTable2GUI
14{
15    protected $enable_editing;
16
17    /**
18     * Constructor
19     * @param ilObjectGUI $a_parent_obj
20     * @param string $a_parent_cmd
21     * @param bool $a_enable_editing
22     */
23    public function __construct($a_parent_obj, $a_parent_cmd, $a_enable_editing = false)
24    {
25        $this->enable_editing = $a_enable_editing;
26
27        parent::__construct($a_parent_obj, $a_parent_cmd);
28
29        $this->initTable();
30    }
31
32    /**
33     * Fill row template
34     * @param array $a_row
35     */
36    public function fillRow($a_row)
37    {
38        global $DIC;
39
40        $ilCtrl = $DIC['ilCtrl'];
41
42        $this->tpl->setVariable('OBJ_SRC', $a_row['icon']);
43        $this->tpl->setVariable('OBJ_ALT', $a_row['icon_alt']);
44        $this->tpl->setVariable('OBJ_TITLE', $a_row['title']);
45        include_once './Services/Link/classes/class.ilLink.php';
46        $this->tpl->setVariable('OBJ_LINK', ilLink::_getLink($a_row['ref_id'], $a_row['type']));
47        $this->tpl->setVariable('OBJ_DESCRIPTION', $a_row['description']);
48        $this->tpl->setVariable('COND_ID', $a_row['id']);
49        $this->tpl->setVariable('OBJ_CONDITION', $a_row['condition']);
50
51        if (!$this->enable_editing) {
52            $this->tpl->setCurrentBlock("obligatory_static");
53            $this->tpl->setVariable('OBL_SRC', ilUtil::getImagePath($a_row['obligatory'] ? 'icon_ok.svg' : 'icon_not_ok.svg'));
54            $this->tpl->setVariable(
55                'OBL_ALT',
56                $this->lng->txt($a_row['obligatory'] ?
57                    'precondition_obligatory_alt' :
58                    'precondition_not_obligatory_alt')
59            );
60            $this->tpl->parseCurrentBlock();
61        } else {
62            $this->tpl->setCurrentBlock("obligatory_edit");
63            $this->tpl->setVariable('OBL_ID', $a_row['id']);
64            $this->tpl->setVariable('OBL_STATUS', $a_row['obligatory'] ? ' checked="checked"' : '');
65            $this->tpl->parseCurrentBlock();
66        }
67
68        $ilCtrl->setParameterByClass(get_class($this->getParentObject()), 'condition_id', $a_row['id']);
69        $this->tpl->setVariable('EDIT_LINK', $ilCtrl->getLinkTargetByClass(get_class($this->getParentObject()), 'edit'));
70        $this->tpl->setVariable('TXT_EDIT', $this->lng->txt('edit'));
71    }
72
73    /**
74     * Set and parse conditions
75     * @param array $a_conditions
76     */
77    public function setConditions($a_conditions)
78    {
79        foreach ((array) $a_conditions as $condition) {
80            if ($condition['trigger_type'] == 'crsg') {
81                continue;
82            }
83
84            $row['id'] = $condition['condition_id'];
85            $row['ref_id'] = $condition['trigger_ref_id'];
86            $row['type'] = $condition['trigger_type'];
87            $row['title'] = ilObject::_lookupTitle($condition['trigger_obj_id']);
88            $row['description'] = ilObject::_lookupDescription($condition['trigger_obj_id']);
89            $row['icon'] = ilObject::_getIcon($condition['trigger_obj_id']);
90            $row['icon_alt'] = $this->lng->txt('obj_' . $condition['trigger_type']);
91            $row['condition'] = $this->lng->txt('condition_' . $condition['operator']);
92            $row['obligatory'] = $condition['obligatory'];
93
94            $rows[] = $row;
95        }
96        $this->setData($rows);
97    }
98
99    /**
100     * Init Table
101     * @global ilCtrl
102     */
103    protected function initTable()
104    {
105        global $DIC;
106
107        $ilCtrl = $DIC['ilCtrl'];
108
109        $this->lng->loadLanguageModule('rbac');
110
111        $this->setRowTemplate('tpl.condition_handler_row.html', 'Services/AccessControl');
112
113        $this->setTitle($this->lng->txt('active_preconditions'));
114
115        $this->addColumn('', '', '1');
116        $this->addColumn($this->lng->txt('rbac_precondition_source'), 'title', '66%');
117        $this->addColumn($this->lng->txt('condition'), 'condition');
118        $this->addColumn($this->lng->txt('precondition_obligatory'), 'obligatory');
119        $this->addColumn($this->lng->txt('actions'));
120
121        $this->enable('select_all');
122        $this->setSelectAllCheckbox('conditions');
123
124        $this->setDefaultOrderField('title');
125        $this->setDefaultOrderDirection('asc');
126
127        $this->setFormAction($ilCtrl->getFormAction($this->getParentObject(), $this->getParentCmd()));
128        $this->addMultiCommand('askDelete', $this->lng->txt('delete'));
129
130        if ($this->enable_editing) {
131            $this->addCommandButton("saveObligatoryList", $this->lng->txt("rbac_precondition_save_obligatory"));
132        }
133    }
134}
135