1<?php
2
3/**
4 * Class ilDclTableViewTableGUI
5 *
6 * @author  Theodor Truffer <tt@studer-raimann.ch>
7 * @ingroup ModulesDataCollection
8 *
9 *
10 */
11class ilDclTableViewTableGUI extends ilTable2GUI
12{
13
14    /**
15     * @var ilCtrl
16     */
17    protected $ctrl;
18    /**
19     * @var ilDclTable
20     */
21    protected $table;
22    /**
23     * @var ilDclTableViewGUI
24     */
25    protected $parent_obj;
26
27
28    /**
29     * ilDclTableViewTableGUI constructor.
30     *
31     * @param ilDclTableViewGUI $a_parent_obj
32     * @param string            $a_parent_cmd
33     * @param ilDclTable        $table
34     */
35    public function __construct(ilDclTableViewGUI $a_parent_obj, $a_parent_cmd, ilDclTable $table)
36    {
37        global $DIC;
38        $lng = $DIC['lng'];
39        $ilCtrl = $DIC['ilCtrl'];
40        parent::__construct($a_parent_obj, $a_parent_cmd);
41
42        $this->parent_obj = $a_parent_obj;
43        $this->table = $table;
44        $this->ctrl = $ilCtrl;
45        $this->lng = $lng;
46
47        $this->setExternalSegmentation(true);
48        $this->setExternalSorting(true);
49
50        if ($this->parent_obj instanceof ilDclTableViewGUI) {
51            $ilCtrl->setParameterByClass('ildcltableviewgui', 'table_id', $table->getId());
52            $this->setFormAction($ilCtrl->getFormActionByClass('ildcltableviewgui'));
53            $this->addMultiCommand('confirmDeleteTableviews', $lng->txt('dcl_delete_views'));
54            $this->addCommandButton('saveTableViewOrder', $lng->txt('dcl_save_order'));
55
56            $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
57            $this->setFormName('tableview_list');
58
59            $this->addColumn('', '', '1', true);
60            $this->addColumn($lng->txt('dcl_order'), null, '30px');
61
62            $this->setRowTemplate('tpl.tableview_list_row.html', 'Modules/DataCollection');
63            $this->setData($this->table->getTableViews());
64        } elseif ($this->parent_obj instanceof ilDclDetailedViewGUI) {
65            $this->setRowTemplate('tpl.detailview_list_row.html', 'Modules/DataCollection');
66            $this->setData($this->table->getVisibleTableViews($this->parent_obj->parent_obj->ref_id, true));
67        }
68
69        $this->addColumn($lng->txt('title'), null, 'auto');
70        $this->addColumn($lng->txt('description'), null, 'auto');
71        $this->addColumn($lng->txt('actions'), null, '30px');
72
73        $this->setTopCommands(true);
74        $this->setEnableHeader(true);
75        $this->setShowRowsSelector(false);
76        $this->setShowTemplates(false);
77        $this->setEnableHeader(true);
78        $this->setEnableTitle(true);
79        $this->setDefaultOrderDirection('asc');
80        $this->setLimit(0);
81
82        $this->setId('dcl_tableviews');
83        $this->setTitle($lng->txt("dcl_tableviews_table"));
84        $this->setStyle('table', $this->getStyle('table') . ' ' . 'dcl_record_list');
85    }
86
87
88    /**
89     * @param ilDclTableView $a_set
90     */
91    public function fillRow($a_set)
92    {
93        if ($this->parent_obj instanceof ilDclTableViewGUI) {
94            $this->tpl->setVariable("ID", $a_set->getId());
95            $this->tpl->setVariable("ORDER_NAME", "order[{$a_set->getId()}]");
96            $this->tpl->setVariable("ORDER_VALUE", $a_set->getOrder());
97        }
98        $this->tpl->setVariable("TITLE", $a_set->getTitle());
99        $this->ctrl->setParameterByClass('ilDclTableViewEditGUI', 'tableview_id', $a_set->getId());
100        $this->tpl->setVariable("TITLE_LINK", $this->ctrl->getLinkTargetByClass('ilDclTableViewEditGUI'));
101        $this->tpl->setVariable("DESCRIPTION", $a_set->getDescription());
102        $this->tpl->setVariable('ACTIONS', $this->buildAction($a_set->getId()));
103    }
104
105
106    /**
107     * build either actions menu or view button
108     *
109     * @param $id
110     *
111     * @return string
112     */
113    protected function buildAction($id)
114    {
115        if ($this->parent_obj instanceof ilDclTableViewGUI) {
116            $alist = new ilAdvancedSelectionListGUI();
117            $alist->setId($id);
118            $alist->setListTitle($this->lng->txt('actions'));
119            $this->ctrl->setParameterByClass('ildcltableviewgui', 'tableview_id', $id);
120            $this->ctrl->setParameterByClass('ilDclDetailedViewDefinitionGUI', 'tableview_id', $id);
121            $alist->addItem($this->lng->txt('settings'), '', $this->ctrl->getLinkTargetByClass('ildcltablevieweditgui', 'editGeneralSettings'));
122            $alist->addItem($this->lng->txt('dcl_list_visibility_and_filter'), '', $this->ctrl->getLinkTargetByClass('ildcltablevieweditgui', 'editFieldSettings'));
123            $alist->addItem($this->lng->txt('dcl_detailed_view'), '', $this->ctrl->getLinkTargetByClass(array('ildcltablevieweditgui', 'ilDclDetailedViewDefinitionGUI'), 'edit'));
124            $alist->addItem($this->lng->txt('delete'), '', $this->ctrl->getLinkTargetByClass('ildcltablevieweditgui', 'confirmDelete'));
125
126            return $alist->getHTML();
127        } elseif ($this->parent_obj instanceof ilDclDetailedViewGUI) {
128            $button = ilDclLinkButton::getInstance();
129            $this->ctrl->setParameterByClass('ilDclDetailedViewGUI', 'tableview_id', $id);
130            $this->ctrl->saveParameterByClass('ilDclDetailedViewGUI', 'record_id');
131            $button->setUrl($this->ctrl->getLinkTargetByClass('ilDclDetailedViewGUI', 'renderRecord'));
132            $button->setCaption('view');
133
134            return $button->getToolbarHTML();
135        }
136    }
137}
138