Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10 mantis ilias 43110 #9129

Open
wants to merge 14 commits into
base: release_10
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function __construct(
global $DIC;

parent::__construct($a_xml_file);
$this->activequestion = null;
$this->spl_id = $a_spl_id;
$this->has_error = false;
$this->characterbuffer = "";
Expand Down Expand Up @@ -212,10 +213,15 @@ public function handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs)
case "online":
if ($this->spl_id > 0) {
$spl = new ilObjSurveyQuestionPool($this->spl_id, false);
$spl->setOnline($value);
$spl->setOfflineStatus(!$value);
$spl->saveToDb();
}
break;
case "label":
$spl = new ilObjSurveyQuestionPool($this->spl_id, false);
$spl->setTitle($value);
$spl->saveToDb();
break;
}
}
break;
Expand Down Expand Up @@ -285,17 +291,13 @@ public function handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs)
break;
}
if (strlen($type ?? "")) {
if (SurveyQuestion::_includeClass($type)) {
$this->activequestion = new $type();

// if no pool is given, question will reference survey
$q_obj_id = $this->spl_id;
if ($this->spl_id < 0) {
$q_obj_id = $this->survey->getId();
}

$this->activequestion->setObjId($q_obj_id);
$this->activequestion = new $type();
// if no pool is given, question will reference survey
$q_obj_id = $this->spl_id;
if ($this->spl_id < 0) {
$q_obj_id = $this->survey->getId();
}
$this->activequestion->setObjId($q_obj_id);
} else {
$this->activequestion = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,15 @@ public function getXmlRepresentation(
): string {
$spl = new ilObjSurveyQuestionPool($a_id, false);
$spl->loadFromDb();

$spl_exp = new ilSurveyQuestionpoolExport($spl, 'xml');
$spl_exp->buildExportFile();
return "";
return $spl->toXmlForExport();
}

public function getXmlExportTailDependencies(
string $a_entity,
string $a_target_release,
array $a_ids
): array {
$deps = [];
$dependencies = [];

// service settings
$deps[] = [
Expand All @@ -54,7 +51,19 @@ public function getXmlExportTailDependencies(
"ids" => $a_ids
];

return $deps;

$md_ids = [];
foreach ($a_ids as $spl_id) {
$md_ids[] = $spl_id . ":0:spl";
}
if ($md_ids !== []) {
$dependencies[] = [
"component" => "components/ILIAS/MetaData",
"entity" => "md",
"ids" => $md_ids
];
}
return $dependencies;
}

public function getValidSchemaVersions(string $a_entity): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,34 @@ public function importXmlRepresentation(
// Container import => test object already created
if ($new_id = $a_mapping->getMapping('components/ILIAS/Container', 'objs', $a_id)) {
$newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
} else { // case ii, non container
// Shouldn't happen
$GLOBALS['ilLog']->write(__METHOD__ . ': Called in non container mode');
return;
} else { // case ii, non container
$newObj = new ilObjSurveyQuestionPool();
$new_id = $newObj->create();
}

# Try legacy import
$xml_file = $this->getXmlFileName();

if (!file_exists($xml_file)) {
if (file_exists($xml_file)) {
$GLOBALS['ilLog']->write(__METHOD__ . ': Cannot find xml definition: ' . $xml_file);
return;
// import qti data
$newObj->importObject($xml_file);
}

// import qti data
$newObj->importObject($xml_file);
$import = new SurveyImportParser($new_id, "", true);
$import->setXMLContent($a_xml);
$import->startParsing();
$a_mapping->addMapping(
"components/ILIAS/SurveyQuestionPool",
"spl",
$a_id,
$newObj->getId()
);
$a_mapping->addMapping(
'components/ILIAS/MetaData',
'md',
$a_id . ':0:spl',
$newObj->getId() . ':0:spl'
);
}

protected function getXmlFileName(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public function buildExportFileXML(
$this->export_dir . "/" . $this->subdir . ".zip"
);

// remove created files
unlink($this->export_dir . "/" . $this->subdir . "/" . $this->filename);
rmdir($this->export_dir . "/" . $this->subdir);

$expLog->write(date("[y-m-d H:i:s] ") . "Finished Export");

return $this->export_dir . "/" . $this->subdir . ".zip";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function __construct(

$this->addMultiCommand('copy', $this->lng->txt('copy'));
$this->addMultiCommand('move', $this->lng->txt('move'));
$this->addMultiCommand('exportQuestion', $this->lng->txt('export'));
#$this->addMultiCommand('exportQuestion', $this->lng->txt('export'));
$this->addMultiCommand('deleteQuestions', $this->lng->txt('delete'));

if (count($clip_questions) > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,36 @@ public function toXML(?array $questions): string
return $xml;
}

public function toXmlForExport(): string
{
$questions = $this->getQuestions();
$a_xml_writer = new ilXmlWriter();
$attrs = array(
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
"xsi:noNamespaceSchemaLocation" => "https://www.ilias.de/download/xsd/ilias_survey_4_2.xsd"
);
$a_xml_writer->xmlStartTag("surveyobject", $attrs);
$attrs = array(
"id" => "qpl_" . $this->getId(),
"label" => $this->getTitle()
);
$a_xml_writer->xmlStartTag("surveyquestions", $attrs);
$a_xml_writer->xmlElement("dummy", null, "dummy");
$a_xml_writer->xmlEndTag("surveyquestions");
$a_xml_writer->xmlEndTag("surveyobject");
$xml = $a_xml_writer->xmlDumpMem(false);
$questionxml = "";
foreach ($questions as $key => $value) {
$questiontype = $this->getQuestiontype($value);
SurveyQuestion::_includeClass($questiontype);
$question = new $questiontype();
$question->loadFromDb($value);
$questionxml .= $question->toXML(false);
}
$xml = str_replace("<dummy>dummy</dummy>", $questionxml, $xml);
return $xml;
}

public function getQuestions(): array
{
$ilDB = $this->db;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
*
*********************************************************************/

use ILIAS\Filesystem\Stream\Streams;
use ILIAS\Filesystem\Util\Archive\Archives as ILIASArchives;
use ILIAS\SurveyQuestionPool\Editing\EditingGUIRequest;
use ILIAS\Refinery\Factory as RefineryFactory;
use ILIAS\HTTP\Services as HTTPServices;

/**
* Class ilObjSurveyQuestionPoolGUI
Expand All @@ -29,6 +33,7 @@
* @ilCtrl_Calls ilObjSurveyQuestionPoolGUI: ilObjectMetaDataGUI, ilPermissionGUI, ilObjectCopyGUI
* @ilCtrl_Calls ilObjSurveyQuestionPoolGUI: ilCommonActionDispatcherGUI
* @ilCtrl_Calls ilObjSurveyQuestionPoolGUI: ILIAS\SurveyQuestionPool\Settings\SettingsGUI
* @ilCtrl_Calls ilObjSurveyQuestionPoolGUI: ilExportGUI
*/
class ilObjSurveyQuestionPoolGUI extends ilObjectGUI implements ilCtrlBaseClassInterface
{
Expand All @@ -39,6 +44,9 @@ class ilObjSurveyQuestionPoolGUI extends ilObjectGUI implements ilCtrlBaseClassI
protected ilNavigationHistory $nav_history;
protected ilHelpGUI $help;
protected ilLogger $log;
protected RefineryFactory $refinery;
protected HTTPServices $http;
protected ILIASArchives $archives;
public string $defaultscript;

public function __construct()
Expand All @@ -48,7 +56,9 @@ public function __construct()
$this->nav_history = $DIC["ilNavigationHistory"];
$this->toolbar = $DIC->toolbar();
$this->help = $DIC["ilHelp"];

$this->refinery = $DIC->refinery();
$this->http = $DIC->http();
$this->archives = $DIC->archives();
$this->edit_request = $DIC->surveyQuestionPool()
->internal()
->gui()
Expand Down Expand Up @@ -143,6 +153,11 @@ public function executeCommand(): void
$this->ctrl->forwardCommand($gui);
break;

case strtolower(ilExportGUI::class):
$export = new ilExportGUI($this, $this->object);
$this->ctrl->forwardCommand($export);
break;

case "":
$cmd .= "Object";
$this->$cmd();
Expand Down Expand Up @@ -226,6 +241,18 @@ public function exportQuestionObject(): void
}
}

public function exportQuestionExportTabObject(): void
{
$qids = $this->http->wrapper()->query()->retrieve(
"qid",
$this->refinery->custom()->transformation(function (string $value) {
$value = urldecode($value);
return explode(',', $value);
})
);
$this->createExportFileObject($qids);
}

/**
* Creates a confirmation form to delete questions from the question pool
*/
Expand Down Expand Up @@ -405,11 +432,12 @@ public function questionsObject(): void
)->submit()->toToolbar();

$ilToolbar->addSeparator();

/*
$this->gui->button(
$this->lng->txt("import"),
"importQuestions"
)->submit()->toToolbar();
*/
}

$table_gui = new ilSurveyQuestionsTableGUI($this, 'questions', $this->checkPermissionBool('write'));
Expand Down Expand Up @@ -444,27 +472,8 @@ protected function afterSave(ilObject $new_object): void
*/
public function exportObject(): void
{
$ilToolbar = $this->toolbar;

$this->tabs_gui->activateTab("export");
$ilToolbar->addButton(
$this->lng->txt('create_export_file'),
$this->ctrl->getLinkTarget($this, 'createExportFile')
);

$table_gui = new ilSurveyQuestionPoolExportTableGUI($this, 'export');
$export_dir = $this->object->getExportDirectory();
$export_files = $this->object->getExportFiles($export_dir);
$data = array();
foreach ($export_files as $exp_file) {
$file_arr = explode("__", $exp_file);
$data[] = array('file' => $exp_file,
'date' => ilDatePresentation::formatDate(new ilDateTime($file_arr[0], IL_CAL_UNIX)),
'size' => filesize($export_dir . "/" . $exp_file)
);
}
$table_gui->setData($data);
$this->tpl->setContent($table_gui->getHTML());
$export = new ilExportGUI($this, $this->object);
$export->listExportFiles();
}

/**
Expand Down Expand Up @@ -556,29 +565,6 @@ public function deleteExportFileObject(): void
$this->ctrl->redirect($this, "export");
}

protected function importFile(string $file_to_import, string $path_to_uploaded_file_in_temp_dir): void
{
$tpl = $this->tpl;

$newObj = new ilObjSurveyQuestionPool();
$newObj->setTitle("dummy");
$newObj->create(true);
$this->putObjectInTree($newObj);

// import qti data
$newObj->importObject($file_to_import);

if ($path_to_uploaded_file_in_temp_dir !== ''
&& $this->temp_file_system->hasDir($path_to_uploaded_file_in_temp_dir)) {
$this->temp_file_system->deleteDir($path_to_uploaded_file_in_temp_dir);
}

$this->deleteUploadedImportFile($path_to_uploaded_file_in_temp_dir);
$this->tpl->setOnScreenMessage('success', $this->lng->txt("object_imported"), true);
ilUtil::redirect("ilias.php?ref_id=" . $newObj->getRefId() .
"&baseClass=ilObjSurveyQuestionPoolGUI");
}

/**
* create new question
*/
Expand Down Expand Up @@ -646,6 +632,35 @@ public function infoScreenForward(): void
$this->ctrl->forwardCommand($info);
}

protected function importFile(string $file_to_import, string $path_to_uploaded_file_in_temp_dir): void
{
$unzip = $this->archives->unzip(Streams::ofResource(fopen($file_to_import, 'r')));
# If export contains a manifest xml use standard import
if (in_array(basename($file_to_import, ".zip") . DIRECTORY_SEPARATOR . "manifest.xml", iterator_to_array($unzip->getFiles()))) {
parent::importFile($file_to_import, $path_to_uploaded_file_in_temp_dir);
return;
}
$tpl = $this->tpl;

$newObj = new ilObjSurveyQuestionPool();
$newObj->setTitle("dummy");
$newObj->create(true);
$this->putObjectInTree($newObj);

// import qti data
$newObj->importObject($file_to_import);

if ($path_to_uploaded_file_in_temp_dir !== ''
&& $this->temp_file_system->hasDir($path_to_uploaded_file_in_temp_dir)) {
$this->temp_file_system->deleteDir($path_to_uploaded_file_in_temp_dir);
}

$this->deleteUploadedImportFile($path_to_uploaded_file_in_temp_dir);
$this->tpl->setOnScreenMessage('success', $this->lng->txt("object_imported"), true);
ilUtil::redirect("ilias.php?ref_id=" . $newObj->getRefId() .
"&baseClass=ilObjSurveyQuestionPoolGUI");
}

protected function addLocatorItems(): void
{
$ilLocator = $this->locator;
Expand Down