Newer
Older
<?php
require_once "abstract.ilQuestionSetPoolConditionGUI.php";
/**
* Class ilQuestionSetPoolJumpConditionGUI
*
* Date: 05.12.13
* Time: 09:20
* @author Thomas Joußen <tjoussen@databay.de>
*/
class ilQuestionSetPoolJumpConditionGUI extends ilQuestionSetPoolConditionGUI
{
/**
* @var array $feedback_types needed for tiny-mce
*/
protected $feedback_types = array(
0 => array('post_var' => 'true_feedback', 'obj_type' => 'tf'),
1 => array('post_var' => 'true_jump_feedback', 'obj_type' => 'tjf'),
2 => array('post_var' => 'false_feedback', 'obj_type' => 'ff'));
/**
* @var ilQuestionSetPoolJumpCondition
*/
protected $model;
public function edit()
{
iljQueryUtil::initjQuery();
ilYuiUtil::initPanel();
ilYuiUtil::initOverlay();
$this->tpl->addJavascript('./Services/UIComponent/Overlay/js/ilOverlay.js');
$this->tpl->addJavaScript("./Services/JavaScript/js/Basic.js");
$this->model = $this->loadModel();
$this->bindModelToForm($this->model);
ilUtil::sendInfo($this->plugin->txt("jump_condition_target_question"), true);
$template = new ilTemplate("tpl.il_xqsp_condition.html", true, true, "Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool");
$this->renderQuestionInfo($this->model->getNode(), $template);
$template->setVariable("FORM", $this->form->getHTML());
$template->setVariable("INFO", ilQuestionSetPoolInfoBox::render($this->plugin));
$button = ilLinkButton::getInstance();
$button->addCSSClass('toggle_feedback');
$button->setCaption($this->plugin->txt('hide_feedback_form_parts'), false);
$this->toolbar->addButtonInstance($button);
$template->setVariable("TXT_SHOW_FEEDBACK", $this->plugin->txt('show_feedback_form_parts'));
$template->setVariable("TXT_HIDE_FEEDBACK", $this->plugin->txt('hide_feedback_form_parts'));
$this->tpl->setContent($template->get());
}
public function update()
{
$this->model = $this->loadModel();
if($this->form->checkInput())
{
$this->model->bindForm($this->form);
$isValid = ilQuestionSetPoolConditionValidator::isValid(
$this->model->getJumpCondition(),
$this->model->getNode(),
$this->model->getNode()->getPath()->getNodes()->getData(),
$this->plugin
);
if($isValid)
{
$this->model->update();
$this->copyTemporaryMobs();
$this->deleteUnusedMobs();
$this->deleteTemporaryMobs();
ilUtil::sendSuccess($this->plugin->txt("msg_obj_modified"), true);
$this->redirect(
$this->getAfterUpdateRedirectCmd(),
$this->getAfterUpdateRedirectParams($this->model)
);
}
}
$this->form->setValuesByPost();
$template = new ilTemplate("tpl.il_xqsp_condition.html", true, true, "Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool");
$this->renderQuestionInfo($this->model->getNode(), $template);
$template->setVariable("FORM", $this->form->getHTML());
$template->setVariable("INFO", ilQuestionSetPoolInfoBox::render($this->plugin));
$this->tpl->setContent($template->get());
}
public function up()
{
$condition = $this->loadModel();
$data = $condition->getNode()->getJumpConditionList()->getData();
foreach($data as $key => $element)
{
if($element["id"] == $condition->getId())
{
$this->swap($condition, $data[$key-1]["id"]);
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
}
}
$this->redirect("ilQuestionSetPoolNodesGUI.listNodes", array(
"path_id" => $condition->getNode()->getPath()->getId(),
"set_id" => $condition->getNode()->getPath()->getSet()->getId()
));
}
public function down()
{
$condition = $this->loadModel();
$data = $condition->getNode()->getJumpConditionList()->getData();
foreach($data as $key => $element)
{
if($element["id"] == $condition->getId())
{
$this->swap($condition, $data[$key+1]["id"]);
break;
}
}
$this->redirect("ilQuestionSetPoolNodesGUI.listNodes", array(
"path_id" => $condition->getNode()->getPath()->getId(),
"set_id" => $condition->getNode()->getPath()->getSet()->getId()
));
}
/**
* @param ilQuestionSetPoolJumpCondition $condition
* @param $swap_condition_id
*/
protected function swap($condition, $swap_condition_id)
{
$swap_condition = new ilQuestionSetPoolJumpCondition();
$swap_condition->setId($swap_condition_id);
$swap_condition->read();
$sorting = $condition->getSorting();
$condition->setSorting($swap_condition->getSorting());
$swap_condition->setSorting($sorting);
$swap_condition->update();
$condition->update();
}
public function remove()
{
$model = $this->loadModel();
$model->remove();
ilUtil::sendSuccess($this->plugin->txt("msg_obj_modified"), true);
$this->redirect(
$this->getAfterUpdateRedirectCmd(),
$this->getAfterUpdateRedirectParams($model)
);
}
/**
* Loads and returns the Model for the controller gui
* @return ilQuestionSetPoolJumpCondition
*/
protected function loadModel()
{
$id = (isset($_GET['condition_id']))? (int)$_GET['condition_id'] : (int)$_POST['id'];
tjoussen
committed
$model = new ilQuestionSetPoolJumpCondition($id);
$model->read();
return $model;
}
/**
* Initialize the PropertyFormGUI for this controller
*/
$this->form = new ilPropertyFormGUI();
$this->form->setName('condition_form');
$this->form->setTitle(sprintf($this->plugin->txt("jump_condition_title"),
$model->getNode()->getPath()->getSet()->getTitle(),
$model->getNode()->getPath()->getTitle(),
$model->getNode()->getIndex()
));
$node_id = new ilHiddenInputGUI("node_fi");
$condition_id = new ilHiddenInputGUI("id");
$condition = new ilConditionInputGUI($this->plugin->txt("condition"), "jump_condition");
$condition->setRequired(false);
$questions = new ilSelectInputGUI($this->plugin->txt("target_question"), "question");
$questions->setRequired(true);
$questions->setOptions($this->getQuestions());
tjoussen
committed
$repititions = new ilNumberInputGUI($this->plugin->txt("repititions"), "repititions");
tjoussen
committed
$repititions->allowDecimals(false);
$repititions->setRequired(false);
$this->form->addItem($node_id);
$this->form->addItem($condition);
$this->form->addItem($questions);
tjoussen
committed
$this->form->addItem($repititions);
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
$true_feedback = new ilTextAreaInputGUI($this->plugin->txt('true_feedback'), 'true_feedback');
$true_feedback->setUseRte(TRUE);
$true_feedback->addPlugin("latex");
$true_feedback->addButton("latex");
if($_GET["condition_id"])
{
$true_feedback->setRTESupport($_GET["condition_id"], 'x_tf', 'assessment');
}
else
{
$true_feedback->setRTESupport($ilUser->getId(), 'x_tf~', 'assessment');
}
$true_feedback->setRteTagSet('full');
$this->form->addItem($true_feedback);
$true_jump_feedback = new ilTextAreaInputGUI($this->plugin->txt('true_jump_feedback'), 'true_jump_feedback');
$true_jump_feedback->setUseRte(TRUE);
$true_jump_feedback->addPlugin("latex");
$true_jump_feedback->addButton("latex");
if($_GET["condition_id"])
{
$true_jump_feedback->setRTESupport($_GET["condition_id"], 'x_tjf', 'assessment');
}
else
{
$true_jump_feedback->setRTESupport($ilUser->getId(), 'x_tjf~:html', 'assessment');
}
$true_jump_feedback->setRteTagSet('full');
$this->form->addItem($true_jump_feedback);
$false_feedback = new ilTextAreaInputGUI($this->plugin->txt('false_feedback'), 'false_feedback');
$false_feedback->setUseRte(TRUE);
$false_feedback->addPlugin("latex");
$false_feedback->addButton("latex");
if($_GET["condition_id"])
{
$false_feedback->setRTESupport($_GET["condition_id"], 'x_ff:html', 'assessment');
}
else
{
$false_feedback->setRTESupport($ilUser->getId(), 'x_ff~:html', 'assessment');
}
$false_feedback->setRteTagSet('full');
$this->form->addItem($false_feedback);
$this->ctrl->setParameter($this->controller, "condition_id", $_GET["condition_id"]);
$this->ctrl->setParameter($this->controller, "path_id", $model->getNode()->getPath()->getId());
$this->ctrl->setParameter($this->controller, "set_id", $model->getNode()->getPath()->getSet()->getId());
$this->form->setFormAction($this->ctrl->getFormAction($this->controller));
$this->ctrl->setParameter($this->controller, "path_id", "");
$this->ctrl->setParameter($this->controller, "set_id", "");
$this->ctrl->setParameter($this->controller, "condition_id", "");
$this->form->addCommandButton("ilQuestionSetPoolJumpConditionGUI.update", $this->plugin->txt("save"));
$this->form->addCommandButton("ilQuestionSetPoolNodesGUI.listNodes", $this->plugin->txt("cancel"));
}
protected function bindModelToForm(ilPluginModelInterface $model)
{
parent::bindModelToForm($model);
$item = $this->form->getItemByPostVar("node_fi");
$item->setValue($model->getNode()->getId());
$question_id = "-";
$question_id = $model->getQuestion()->getId();
$item = $this->form->getItemByPostVar("question");
$item->setValue($question_id);
}
/**
* @return array
*/
protected function getQuestions()
{
$questions = array();
$result = $ilDB->queryF(
"SELECT qs_qst.question_index, q.title, q.question_id
FROM rep_robj_xqsp_qs_qst qs_qst
INNER JOIN rep_robj_xqsp_node n ON n.question_fi = qs_qst.question_fi
INNER JOIN qpl_questions q ON q.question_id = qs_qst.question_fi
WHERE n.path_fi = %s AND n.node_index <= %s",
array("integer", "integer"),
array($this->model->getNode()->getPath()->getId(), $this->model->getNode()->getIndex())
);
while(($row = $ilDB->fetchAssoc($result)) != null)
{
$questions[$row["question_id"]] = "Q" . $row['question_index'] . " - " . $row["title"];
}
$questions["-"] = $this->plugin->txt("tst_termination");
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
return $questions;
}
/**
* Get the redirect action after an update was successful
* @return string
*/
protected function getAfterUpdateRedirectCmd()
{
return "ilQuestionSetPoolNodesGUI.listNodes";
}
/**
* @param $model
*
* @return array
*/
protected function getAfterUpdateRedirectParams($model)
{
return array(
"set_id" => $model->getNode()->getPath()->getSet()->getId(),
"path_id" => $model->getNode()->getPath()->getId()
);
}
/**
* Returns the current tab name
* return string
*/
protected function getCurrentTab()
{
return "content";
}
/**
* @return array
*/
protected function getRequirements()
{
return array(
"models/class.ilQuestionSetPoolJumpCondition.php",
"providers/class.ilParserQuestionProvider.php",
"utils/abstract.ilQuestionSetPoolInfoBox.php",
"utils/abstract.ilQuestionSetPoolConditionValidator.php",
"utils/class.ilConditionInputGUI.php"
);
}
/**
*
*/
protected function copyTemporaryMobs()
{
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
foreach($this->feedback_types as $type)
{
$mediaObjects = ilRTE::_getMediaObjects($this->form->getInput($type['post_var']), 0);
$myMediaObjects = ilObjMediaObject::_getMobsOfObject('x_'.$type['obj_type'].'~:html', $ilUser->getId());
foreach($mediaObjects as $mob)
{
foreach($myMediaObjects as $myMob)
{
if($mob == $myMob)
{
// change usage
ilObjMediaObject::_removeUsage($mob, 'x_'.$type['obj_type'].'~:html', $ilUser->getId());
break;
}
}
ilObjMediaObject::_saveUsage($mob, 'x_'.$type['obj_type'].':html', $this->model->getId());
}
}
}
/**
*
*/
protected function deleteUnusedMobs()
{
foreach($this->feedback_types as $type)
{
// remove usage of deleted media objects
include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
$oldMediaObjects = ilObjMediaObject::_getMobsOfObject('x_'.$type['obj_type'].':html', $this->model->getId());
$curMediaObjects = ilRTE::_getMediaObjects($this->form->getInput($type['post_var']), 0);
foreach($oldMediaObjects as $oldMob)
{
$found = false;
foreach($curMediaObjects as $curMob)
{
if($oldMob == $curMob)
{
$found = true;
break;
}
}
if(!$found)
{
if(ilObjMediaObject::_exists($oldMob))
{
ilObjMediaObject::_removeUsage($oldMob, 'x_' . $type['obj_type'].':html', $this->model->getId());
$mob_obj = new ilObjMediaObject($oldMob);
$mob_obj->delete();
}
}
}
}
}
/**
*
*/
protected function deleteTemporaryMobs()
{
try
{
include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php';
foreach($this->feedback_types as $type)
{
$mobs = ilObjMediaObject::_getMobsOfObject('x_'.$type['obj_type'].'~:html', $ilUser->getId());
foreach($mobs as $mob)
{
if(ilObjMediaObject::_exists($mob))
{
ilObjMediaObject::_removeUsage($mob, 'x_'.$type['obj_type'].'~:html', $ilUser->getId());
$mob_obj = new ilObjMediaObject($mob);
$mob_obj->delete();
}
}
}
}
catch(Exception $e)
{
}
}