Newer
Older
require_once "abstract.ilQuestionSetPoolConditionGUI.php";
/**
* Class ilQuestionSetPoolInitialConditionGUI
*
* Date: 21.11.13
* Time: 14:15
* @author Thomas Joußen <tjoussen@databay.de>
*/
class ilQuestionSetPoolInitialConditionGUI extends ilQuestionSetPoolConditionGUI
/**
* @var array $feedback_types needed for tiny-mce
*/
protected $feedback_types = array(
0 => array('post_var' => 'true_feedback', 'obj_type' => 'itf'),
2 => array('post_var' => 'false_feedback', 'obj_type' => 'iff'));
iljQueryUtil::initjQuery();
ilYuiUtil::initPanel();
ilYuiUtil::initOverlay();
$this->tpl->addJavascript('./Services/UIComponent/Overlay/js/ilOverlay.js');
$this->tpl->addJavaScript("./Services/JavaScript/js/Basic.js");
$this->bindModelToForm($model);
$template = new ilTemplate("tpl.il_xqsp_condition.html", true, true, "Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool");
$this->renderQuestionInfo($model, $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());
}
$model = $this->loadModel();
$this->initForm($model);
if($this->form->checkInput())
{
$model->bindForm($this->form);
$isValid = ilQuestionSetPoolConditionValidator::isValid(
$model->getInitialCondition(),
$model,
$model->getPath()->getNodes()->getData(),
$this->plugin
);
if($isValid)
$this->copyTemporaryMobs($model);
$this->deleteUnusedMobs($model);
ilUtil::sendSuccess($this->plugin->txt("msg_obj_modified"), true);
$this->redirect(
tjoussen
committed
$this->getAfterUpdateRedirectCmd(),
$this->getAfterUpdateRedirectParams($model)
);
}
}
$this->form->setValuesByPost();
$template = new ilTemplate("tpl.il_xqsp_condition.html", true, true, "Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool");
$this->renderQuestionInfo($model, $template);
$template->setVariable("FORM", $this->form->getHTML());
$template->setVariable("INFO", ilQuestionSetPoolInfoBox::render($this->plugin));
$this->tpl->setContent($template->get());
public function remove()
{
$model = $this->loadModel();
$model->read();
$model->setInitialCondition(null);
$model->update();
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 ilQuestionSetPoolNode
*/
protected function loadModel()
{
$id = (isset($_GET['node_id']))? (int)$_GET['node_id'] : (int)$_POST['id'];
tjoussen
committed
$model = new ilQuestionSetPoolNode($id);
$model->read();
return $model;
}
/**
* Initialize the PropertyFormGUI for this controller
{
$this->form = new ilPropertyFormGUI();
$this->form->setName('condition_form');
$this->plugin->txt("edit_initial_condition_title"),
$model->getPath()->getSet()->getTitle(),
$model->getPath()->getTitle(),
$model->getIndex()
));
$node_id = new ilHiddenInputGUI("id");
$node_id->setRequired(true);
$initial_condition = new ilConditionInputGUI($this->plugin->txt("initial_condition"), "initial_condition");
$initial_condition->setRequired(false);
$this->form->addItem($node_id);
$this->form->addItem($initial_condition);
$true_feedback = new ilTextAreaInputGUI($this->plugin->txt('true_feedback'), 'true_feedback');
$true_feedback->setUseRte(TRUE);
$true_feedback->addPlugin("latex");
$true_feedback->addButton("latex");
$true_feedback->setRTESupport($model->getId(), 'x_itf:html', 'assessment');
$true_feedback->setRteTagSet('full');
$this->form->addItem($true_feedback);
$false_feedback = new ilTextAreaInputGUI($this->plugin->txt('false_feedback'), 'false_feedback');
$false_feedback->setUseRte(TRUE);
$false_feedback->addPlugin("latex");
$false_feedback->addButton("latex");
$false_feedback->setRTESupport($model->getId(), 'x_iff:html', 'assessment');
$false_feedback->setInfo($this->plugin->txt('false_feedback_info'));
$false_feedback->setRteTagSet('full');
$this->form->addItem($false_feedback);
$this->ctrl->setParameter($this->controller, "path_id", $model->getPath()->getId());
$this->ctrl->setParameter($this->controller, "set_id", $model->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->form->addCommandButton("ilQuestionSetPoolInitialConditionGUI.update", $this->plugin->txt("save"));
$this->form->addCommandButton("ilQuestionSetPoolNodesGUI.listNodes", $this->plugin->txt("cancel"));
}
/**
* Get the redirect action after an update was successful
* @return string
*/
protected function getAfterUpdateRedirectCmd()
{
return "ilQuestionSetPoolNodesGUI.listNodes";
tjoussen
committed
* @param $model
*
tjoussen
committed
protected function getAfterUpdateRedirectParams($model)
tjoussen
committed
"set_id" => $model->getPath()->getSet()->getId(),
"path_id" => $model->getPath()->getId()
}
/**
* Returns the current tab name
* return string
*/
protected function getCurrentTab()
{
return "content";
}
/**
* @return array
*/
protected function getRequirements()
{
return array(
"providers/class.ilParserQuestionProvider.php",
"utils/abstract.ilQuestionSetPoolInfoBox.php",
"utils/abstract.ilQuestionSetPoolConditionValidator.php",
"utils/class.ilConditionInputGUI.php"
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
268
269
270
271
272
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', $model->getId());
}
}
}
protected function deleteUnusedMobs($model)
{
foreach($this->feedback_types as $type)
{
$oldMediaObjects = ilObjMediaObject::_getMobsOfObject('x_'.$type['obj_type'].':html', $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', $model->getId());
$mob_obj = new ilObjMediaObject($oldMob);
$mob_obj->delete();
}
}
}
}
}