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* TableGUI for material assignments of course objectives
28*
29* @author Stefan Meyer <smeyer.ilias@gmx.de>
30* @version $Id$
31*
32* @ingroup ModulesCourse
33*/
34class ilCourseObjectiveMaterialAssignmentTableGUI extends ilTable2GUI
35{
36    private $objective = null;
37    private $objective_lm = null;
38
39    private $objective_id = 0;
40    private $course_obj;
41
42    /**
43     * Constructor
44     *
45     * @access public
46     * @param
47     * @return
48     */
49    public function __construct($a_parent_obj, $a_course_obj, $a_objective_id)
50    {
51        global $DIC;
52
53        $lng = $DIC['lng'];
54        $ilCtrl = $DIC['ilCtrl'];
55
56        $this->objective_id = $a_objective_id;
57        $this->course_obj = $a_course_obj;
58
59        $this->lng = $lng;
60        $this->lng->loadLanguageModule('crs');
61        $this->ctrl = $ilCtrl;
62
63        parent::__construct($a_parent_obj, 'materialAssignment');
64        $this->setFormName('assignments');
65        $this->addColumn('', 'f', "1");
66        $this->addColumn($this->lng->txt('type'), 'type', "1px");
67        $this->addColumn($this->lng->txt('title'), 'title', '99%');
68
69        $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
70        $this->setRowTemplate("tpl.crs_objective_list_materials_row.html", "Modules/Course");
71
72        $this->setDefaultOrderField('title');
73        $this->setLimit(200);
74
75        $this->setNoEntriesText($this->lng->txt('crs_no_objective_lms_found'));
76
77
78        $this->addCommandButton('updateMaterialAssignment', $this->lng->txt('crs_wiz_next'));
79
80        $this->initObjectiveAssignments();
81    }
82
83    /**
84     * fill row
85     *
86     * @access protected
87     * @param array row data
88     * @return
89     */
90    protected function fillRow($a_set)
91    {
92        foreach ($a_set['sub'] as $sub_data) {
93            // Indentation
94            for ($i = $sub_data['depth'];$i > 1;$i--) {
95                $this->tpl->touchBlock('begin_depth');
96                $this->tpl->touchBlock('end_depth');
97            }
98
99            $this->tpl->setCurrentBlock('chapter');
100            include_once('Modules/LearningModule/classes/class.ilLMObject.php');
101
102            if ($this->objective_lm->isChapterAssigned($a_set['id'], $sub_data['id'])) {
103                $this->tpl->setVariable('CHAP_CHECKED', 'checked="checked"');
104            }
105
106            $this->tpl->setVariable('CHAPTER_TITLE', ilLMObject::_lookupTitle($sub_data['id']));
107            $this->tpl->setVariable('CHAP_ID', $a_set['id'] . '_' . $sub_data['id']);
108            $this->tpl->setVariable('CHAP_TYPE_IMG', ilObject::_getIcon($sub_data['id'], "tiny", $sub_data['type']));
109            $this->tpl->setVariable('CHAP_TYPE_ALT', $this->lng->txt('obj_' . $sub_data['type']));
110            $this->tpl->parseCurrentBlock();
111        }
112        if (count($a_set['sub'])) {
113            $this->tpl->setVariable('TXT_CHAPTER', $this->lng->txt('objs_st'));
114        }
115
116        $this->tpl->setVariable('VAL_ID', $a_set['id']);
117
118        if ($this->objective_lm->isAssigned($a_set['id'])) {
119            $this->tpl->setVariable('VAL_CHECKED', 'checked="checked"');
120        }
121
122        $this->tpl->setVariable('ROW_TYPE_IMG', ilObject::_getIcon($a_set['obj_id'], "tiny", $a_set['type']));
123        $this->tpl->setVariable('ROW_TYPE_ALT', $this->lng->txt('obj_' . $a_set['type']));
124
125        $this->tpl->setVariable('VAL_TITLE', $a_set['title']);
126        if (strlen($a_set['description'])) {
127            $this->tpl->setVariable('VAL_DESC', $a_set['description']);
128        }
129    }
130
131    /**
132     * parse
133     *
134     * @access public
135     * @param array array of assignable nodes (tree node data)
136     * @return
137     */
138    public function parse($a_assignable)
139    {
140        global $DIC;
141
142        $objDefinition = $DIC['objDefinition'];
143
144        $materials = array();
145        foreach ($a_assignable as $node) {
146            // no side blocks here
147            if ($objDefinition->isSideBlock($node['type'])) {
148                continue;
149            }
150
151            $tmp_data = array();
152            $subobjects = array();
153
154            if ($node['type'] == 'lm') {
155                include_once('./Modules/LearningModule/classes/class.ilLMObject.php');
156
157
158                // Chapters and pages
159                foreach ($chapters = $this->getAllSubObjects($node['child']) as $chapter => $chapter_data) {
160                    $sub['title'] = ilLMObject::_lookupTitle($chapter);
161                    $sub['id'] = $chapter;
162                    $sub['depth'] = $chapter_data['depth'];
163                    $sub['type'] = $chapter_data['type'];
164
165                    $subobjects[] = $sub;
166                }
167            }
168
169            $tmp_data['sub'] = $subobjects;
170            $tmp_data['title'] = $node['title'];
171            $tmp_data['description'] = $node['description'];
172            $tmp_data['type'] = $node['type'];
173            $tmp_data['id'] = $node['child'];
174            $tmp_data['obj_id'] = $node['obj_id'];
175
176            $materials[] = $tmp_data;
177        }
178
179        $this->setData($materials);
180    }
181
182    /**
183     * get all subobject (structure and page objects) of a lm
184     *
185     * @access protected
186     * @return
187     */
188    protected function getAllSubObjects($a_ref_id)
189    {
190        $tree = new ilTree(ilObject::_lookupObjId($a_ref_id));
191        $tree->setTableNames('lm_tree', 'lm_data');
192        $tree->setTreeTablePK("lm_id");
193
194        foreach ($tree->getSubTree($tree->getNodeData($tree->getRootId())) as $node) {
195            if ($node['type'] == 'st' or $node['type'] == 'pg') {
196                $depth = $node['depth'] - 1;
197                $child = $node['child'];
198                $chapter[$child]['depth'] = $depth;
199                $chapter[$child]['type'] = $node['type'];
200            }
201        }
202        return $chapter ? $chapter : array();
203    }
204
205
206    /**
207     * init objective assignments
208     *
209     * @access protected
210     * @return
211     */
212    protected function initObjectiveAssignments()
213    {
214        include_once('./Modules/Course/classes/class.ilCourseObjective.php');
215        $this->objective = new ilCourseObjective($this->course_obj, $this->objective_id);
216
217        include_once './Modules/Course/classes/class.ilCourseObjectiveMaterials.php';
218        $this->objective_lm = new ilCourseObjectiveMaterials($this->objective_id);
219    }
220}
221