-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
273 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
components/ILIAS/DataCollection/classes/Fields/Copy/class.ilDclCopyFieldModel.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
* | ||
*********************************************************************/ | ||
|
||
class ilDclCopyFieldModel extends ilDclBaseFieldModel | ||
{ | ||
public function getRecordQueryFilterObject( | ||
$filter_value = "", | ||
?ilDclBaseFieldModel $sort_field = null | ||
): ?ilDclRecordQueryObject { | ||
$join_str | ||
= "INNER JOIN il_dcl_record_field AS filter_record_field_{$this->getId()} ON (filter_record_field_{$this->getId()}.record_id = record.id AND filter_record_field_{$this->getId()}.field_id = " | ||
. $this->db->quote($this->getId(), 'integer') . ") "; | ||
$join_str .= "INNER JOIN il_dcl_stloc{$this->getStorageLocation()}_value AS filter_stloc_{$this->getId()} ON (filter_stloc_{$this->getId()}.record_field_id = filter_record_field_{$this->getId()}.id AND filter_stloc_{$this->getId()}.value LIKE " | ||
. $this->db->quote("%$filter_value%", 'text') . ") "; | ||
|
||
$sql_obj = new ilDclRecordQueryObject(); | ||
$sql_obj->setJoinStatement($join_str); | ||
|
||
return $sql_obj; | ||
} | ||
|
||
public function getValidFieldProperties(): array | ||
{ | ||
return [ | ||
ilDclBaseFieldModel::PROP_REFERENCE, | ||
ilDclBaseFieldModel::PROP_N_REFERENCE | ||
]; | ||
} | ||
} |
134 changes: 134 additions & 0 deletions
134
components/ILIAS/DataCollection/classes/Fields/Copy/class.ilDclCopyFieldRepresentation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
* | ||
*********************************************************************/ | ||
|
||
class ilDclCopyFieldRepresentation extends ilDclBaseFieldRepresentation | ||
{ | ||
private const VALID_TYPES = [ | ||
ilDclDatatype::INPUTFORMAT_TEXT, | ||
ilDclDatatype::INPUTFORMAT_NUMBER, | ||
ilDclDatatype::INPUTFORMAT_BOOLEAN, | ||
ilDclDatatype::INPUTFORMAT_DATETIME, | ||
]; | ||
|
||
/** | ||
* @return ilSelectInputGUI|ilMultiSelectInputGUI | ||
*/ | ||
public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): ilFormPropertyGUI | ||
{ | ||
if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) { | ||
$input = new ilMultiSelectInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId()); | ||
} else { | ||
$input = new ilSelectInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId()); | ||
} | ||
|
||
$this->setupInputField($input, $this->getField()); | ||
|
||
$options = []; | ||
if (!$this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) { | ||
$options[''] = $this->lng->txt('dcl_please_select'); | ||
} | ||
|
||
$value = null; | ||
$copy_id = $this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE); | ||
$copy_field = ilDclCache::getFieldCache($copy_id); | ||
if ($copy_field->getTableId() !== 0) { | ||
$copy_table = ilDclCache::getTableCache($copy_field->getTableId()); | ||
foreach ($copy_table->getRecords() as $record) { | ||
$option = $record->getRecordField($copy_field->getId())->getPlainText(); | ||
if (!in_array($option, $options)) { | ||
$options[$option] = $option; | ||
} | ||
} | ||
} else { | ||
$input->setAlert($this->lng->txt('dcl_origin_not_found')); | ||
} | ||
|
||
if ($record_id !== null) { | ||
$value = ilDclCache::getRecordCache($record_id)->getRecordFieldValue($this->getField()->getId()); | ||
if ($value !== '' && !array_key_exists($value, $options)) { | ||
$options[$value] = $value . ' ' . $this->lng->txt('dcl_deprecated_copy'); | ||
} | ||
} | ||
|
||
$input->setOptions($options); | ||
|
||
return $input; | ||
} | ||
|
||
public function addFilterInputFieldToTable(ilTable2GUI $table) | ||
{ | ||
$input = $table->addFilterItemByMetaType( | ||
"filter_" . $this->getField()->getId(), | ||
ilTable2GUI::FILTER_TEXT, | ||
false, | ||
$this->getField()->getId() | ||
); | ||
$input->setSubmitFormOnEnter(true); | ||
|
||
$this->setupFilterInputField($input); | ||
|
||
return $this->getFilterInputFieldValue($input); | ||
} | ||
|
||
public function passThroughFilter(ilDclBaseRecordModel $record, $filter): bool | ||
{ | ||
$pass = parent::passThroughFilter($record, $filter); | ||
|
||
$value = $record->getRecordFieldValue($this->getField()->getId()); | ||
if (!$filter || strpos(strtolower($value), strtolower($filter)) !== false) { | ||
$pass = true; | ||
} | ||
|
||
return $pass; | ||
} | ||
|
||
protected function buildFieldCreationInput(ilObjDataCollection $dcl, string $mode = 'create'): ilRadioOption | ||
{ | ||
$datetype_title = $this->getField()->getDatatype()->getTitle(); | ||
if ($datetype_title === 'copy') { | ||
$datetype_title = 'copy_field'; | ||
} | ||
$opt = new ilRadioOption($this->lng->txt('dcl_' . $datetype_title), $this->getField()->getDatatypeId()); | ||
$opt->setInfo($this->lng->txt('dcl_' . $datetype_title . '_desc')); | ||
|
||
$options = []; | ||
$tables = $dcl->getTables(); | ||
foreach ($tables as $table) { | ||
foreach ($table->getRecordFields() as $field) { | ||
if (in_array($field->getDatatypeId(), self::VALID_TYPES)) { | ||
$options[$field->getId()] = $table->getTitle() . ' -> ' . $field->getTitle(); | ||
} | ||
} | ||
} | ||
|
||
$prop_table_selection = new ilSelectInputGUI( | ||
$this->lng->txt('dcl_copy_title'), | ||
'prop_' . ilDclBaseFieldModel::PROP_REFERENCE | ||
); | ||
$prop_table_selection->setOptions($options); | ||
$opt->addSubItem($prop_table_selection); | ||
|
||
$prop_multi_select = new ilDclCheckboxInputGUI( | ||
$this->lng->txt('dcl_multiple_selection'), | ||
'prop_' . ilDclBaseFieldModel::PROP_N_REFERENCE | ||
); | ||
$opt->addSubItem($prop_multi_select); | ||
|
||
return $opt; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
components/ILIAS/DataCollection/classes/Fields/Copy/class.ilDclCopyRecordFieldModel.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
* | ||
*********************************************************************/ | ||
|
||
class ilDclCopyRecordFieldModel extends ilDclBaseRecordFieldModel | ||
{ | ||
public function deserializeData($value) | ||
{ | ||
return (string) $value; | ||
} | ||
|
||
public function setValueFromForm(ilPropertyFormGUI $form): void | ||
{ | ||
$value = $form->getInput('field_' . $this->getField()->getId()); | ||
if (is_array($value)) { | ||
$value = implode(', ', $value); | ||
} | ||
$this->setValue($value); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
components/ILIAS/DataCollection/classes/Fields/Copy/class.ilDclCopyRecordRepresentation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
* | ||
*********************************************************************/ | ||
|
||
class ilDclCopyRecordRepresentation extends ilDclBaseRecordRepresentation | ||
{ | ||
public function parseFormInput($value) | ||
{ | ||
if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) { | ||
$value = [$value]; | ||
} | ||
|
||
return parent::parseFormInput($value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters