ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSurveySyncTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 2010 Leifos, GPL, see docs/LICENSE */
3 
4 include_once("./Services/Table/classes/class.ilTable2GUI.php");
5 
15 {
23  function __construct($a_parent_obj, $a_parent_cmd, SurveyQuestion $a_question)
24  {
25  global $ilCtrl, $lng;
26 
27  $this->question = $a_question;
28 
29  parent::__construct($a_parent_obj, $a_parent_cmd);
30 
31  $this->setId("il_svy_spl_sync");
32 
33  $this->setTitle($this->question->getTitle());
34  $this->setDescription($lng->txt("survey_sync_question_copies_info"));
35 
36  $this->addCommandButton("synccopies", $lng->txt("survey_sync_question_copies"));
37  $this->addCommandButton("cancelsync", $lng->txt("cancel"));
38 
39  // $this->setSelectAllCheckbox("id[]");
40  $this->addColumn("", "", 1);
41  $this->addColumn($lng->txt("title"), "");
42 
43  $this->setDefaultOrderField("title");
44  $this->setDefaultOrderDirection("asc");
45 
46  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
47  $this->setRowTemplate("tpl.il_svy_qpl_sync.html", "Modules/SurveyQuestionPool");
48 
49  $this->importData();
50  }
51 
55  protected function importData()
56  {
57  global $ilAccess, $lng;
58 
59  include_once "Modules/Survey/classes/class.ilObjSurvey.php";
60 
61  $table_data = array();
62  foreach($this->question->getCopyIds(true) as $survey_obj_id => $questions)
63  {
64  $survey_id = new ilObjSurvey($survey_obj_id, false);
65  $survey_id->loadFromDB();
66  $survey_id = $survey_id->getSurveyId();
67 
68  $ref_ids = ilObject::_getAllReferences($survey_obj_id);
69  $message = "";
70 
71  // check permissions for "parent" survey
72  $can_write = false;
73  if(!ilObjSurvey::_hasDatasets($survey_id))
74  {
75  foreach($ref_ids as $ref_id)
76  {
77  if($ilAccess->checkAccess("edit", "", $ref_id))
78  {
79  $can_write = true;
80  break;
81  }
82  }
83 
84  if(!$can_write)
85  {
86  $message = $lng->txt("survey_sync_insufficient_permissions");
87  }
88  }
89  else
90  {
91  $message = $lng->txt("survey_has_datasets_warning");
92  }
93 
94  $survey_title = ilObject::_lookupTitle($survey_obj_id);
95  $survey_path = $this->buildPath($ref_ids);
96 
97  foreach($questions as $question_id)
98  {
99  $title = SurveyQuestion::_getTitle($question_id);
100 
101  if(!$can_write)
102  {
103  $question_id = null;
104  }
105 
106  $table_data[] = array(
107  "id" => $question_id,
108  "title" => $title,
109  "path" => $survey_path,
110  "message" => $message
111  );
112  }
113  }
114 
115  $this->setData($table_data);
116  }
117 
123  protected function fillRow($a_set)
124  {
125  global $lng, $ilCtrl;
126 
127  $this->tpl->setVariable("TXT_PATH", $lng->txt("path"));
128 
129  if($a_set["message"])
130  {
131  $this->tpl->setCurrentBlock("message");
132  $this->tpl->setVariable("TXT_MESSAGE", $a_set["message"]);
133  $this->tpl->parseCurrentBlock();
134  }
135 
136  // question
137  if($a_set["id"])
138  {
139  $this->tpl->setCurrentBlock("checkbox");
140  $this->tpl->setVariable("ID", $a_set["id"]);
141  $this->tpl->parseCurrentBlock();
142  }
143 
144 
145  $this->tpl->setVariable("TITLE", $a_set["title"]);
146  $this->tpl->setVariable("VALUE_PATH", implode("<br />", $a_set["path"]));
147  }
148 
155  protected function buildPath($ref_ids)
156  {
157  global $tree, $ilCtrl;
158 
159  include_once './Services/Link/classes/class.ilLink.php';
160 
161  if(!count($ref_ids))
162  {
163  return false;
164  }
165  foreach($ref_ids as $ref_id)
166  {
167  $path = "...";
168 
169  $counter = 0;
170  $path_full = $tree->getPathFull($ref_id);
171  if(sizeof($path_full))
172  {
173  foreach($path_full as $data)
174  {
175  if(++$counter < (count($path_full)-1))
176  {
177  continue;
178  }
179  $path .= " &raquo; ";
180  if($ref_id != $data['ref_id'])
181  {
182  $path .= $data['title'];
183  }
184  else
185  {
186  $path .= ('<a target="_top" href="'.
187  ilLink::_getLink($data['ref_id'],$data['type']).'">'.
188  $data['title'].'</a>');
189  }
190  }
191  }
192 
193  $result[] = $path;
194  }
195  return $result;
196  }
197 }
198 
199 ?>