ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilSurveySyncTableGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
11{
15 protected $access;
16
20 protected $tree;
21
29 public function __construct($a_parent_obj, $a_parent_cmd, SurveyQuestion $a_question)
30 {
31 global $DIC;
32
33 $this->ctrl = $DIC->ctrl();
34 $this->lng = $DIC->language();
35 $this->access = $DIC->access();
36 $this->tree = $DIC->repositoryTree();
37 $ilCtrl = $DIC->ctrl();
38 $lng = $DIC->language();
39
40 $this->question = $a_question;
41
42 parent::__construct($a_parent_obj, $a_parent_cmd);
43
44 $this->setId("il_svy_spl_sync");
45
46 $this->setTitle($this->question->getTitle());
47 $this->setDescription($lng->txt("survey_sync_question_copies_info"));
48
49 $this->addCommandButton("synccopies", $lng->txt("survey_sync_question_copies"));
50 $this->addCommandButton("cancelsync", $lng->txt("cancel"));
51
52 // $this->setSelectAllCheckbox("id[]");
53 $this->addColumn("", "", 1);
54 $this->addColumn($lng->txt("title"), "");
55
56 $this->setDefaultOrderField("title");
57 $this->setDefaultOrderDirection("asc");
58
59 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
60 $this->setRowTemplate("tpl.il_svy_qpl_sync.html", "Modules/SurveyQuestionPool");
61
62 $this->importData();
63 }
64
68 protected function importData()
69 {
70 $ilAccess = $this->access;
72
73 $table_data = array();
74 foreach ($this->question->getCopyIds(true) as $survey_obj_id => $questions) {
75 $survey_id = new ilObjSurvey($survey_obj_id, false);
76 $survey_id->loadFromDB();
77 $survey_id = $survey_id->getSurveyId();
78
79 $ref_ids = ilObject::_getAllReferences($survey_obj_id);
80 $message = "";
81
82 // check permissions for "parent" survey
83 $can_write = false;
84 if (!ilObjSurvey::_hasDatasets($survey_id)) {
85 foreach ($ref_ids as $ref_id) {
86 if ($ilAccess->checkAccess("edit", "", $ref_id)) {
87 $can_write = true;
88 break;
89 }
90 }
91
92 if (!$can_write) {
93 $message = $lng->txt("survey_sync_insufficient_permissions");
94 }
95 } else {
96 $message = $lng->txt("survey_has_datasets_warning");
97 }
98
99 $survey_title = ilObject::_lookupTitle($survey_obj_id);
100 $survey_path = $this->buildPath($ref_ids);
101
102 foreach ($questions as $question_id) {
103 $title = SurveyQuestion::_getTitle($question_id);
104
105 if (!$can_write) {
106 $question_id = null;
107 }
108
109 $table_data[] = array(
110 "id" => $question_id,
111 "title" => $title,
112 "path" => $survey_path,
113 "message" => $message
114 );
115 }
116 }
117
118 $this->setData($table_data);
119 }
120
126 protected function fillRow($a_set)
127 {
129 $ilCtrl = $this->ctrl;
130
131 $this->tpl->setVariable("TXT_PATH", $lng->txt("path"));
132
133 if ($a_set["message"]) {
134 $this->tpl->setCurrentBlock("message");
135 $this->tpl->setVariable("TXT_MESSAGE", $a_set["message"]);
136 $this->tpl->parseCurrentBlock();
137 }
138
139 // question
140 if ($a_set["id"]) {
141 $this->tpl->setCurrentBlock("checkbox");
142 $this->tpl->setVariable("ID", $a_set["id"]);
143 $this->tpl->parseCurrentBlock();
144 }
145
146
147 $this->tpl->setVariable("TITLE", $a_set["title"]);
148 $this->tpl->setVariable("VALUE_PATH", implode("<br />", $a_set["path"]));
149 }
150
157 protected function buildPath($ref_ids)
158 {
160 $ilCtrl = $this->ctrl;
161
162 if (!count($ref_ids)) {
163 return false;
164 }
165 foreach ($ref_ids as $ref_id) {
166 $path = "...";
167
168 $counter = 0;
169 $path_full = $tree->getPathFull($ref_id);
170 if (sizeof($path_full)) {
171 foreach ($path_full as $data) {
172 if (++$counter < (count($path_full) - 1)) {
173 continue;
174 }
175 $path .= " &raquo; ";
176 if ($ref_id != $data['ref_id']) {
177 $path .= $data['title'];
178 } else {
179 $path .= ('<a target="_top" href="' .
180 ilLink::_getLink($data['ref_id'], $data['type']) . '">' .
181 $data['title'] . '</a>');
182 }
183 }
184 }
185
186 $result[] = $path;
187 }
188 return $result;
189 }
190}
$result
An exception for terminatinating execution or to throw for unit testing.
Basic class for all survey question types.
static _getTitle($question_id)
Returns the question title of a question with a given id.
Class ilObjSurvey.
static _hasDatasets($survey_id)
static _lookupTitle($a_id)
lookup object title
static _getAllReferences($a_id)
get all reference ids of object
Survey sync table GUI class.
fillRow($a_set)
Fill table row.
buildPath($ref_ids)
Build path with deep-link.
__construct($a_parent_obj, $a_parent_cmd, SurveyQuestion $a_question)
Constructor.
importData()
Import data from DB.
Class ilTable2GUI.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
setData($a_data)
set table data @access public
setRowTemplate($a_template, $a_template_dir="")
Set row template.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setId($a_val)
Set id.
setDescription($a_val)
Set description.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$message
Definition: xapiexit.php:14