Skip to content
Snippets Groups Projects
Commit c91b3a34 authored by Peter Thienel's avatar Peter Thienel Committed by Jan-Hendrik Willms
Browse files

Resolve "Löschen eines Studienganges... I18N - Fehler"

Closes #555

Merge request studip/studip!269
parent 840e59f8
No related branches found
No related tags found
No related merge requests found
...@@ -13,12 +13,24 @@ ...@@ -13,12 +13,24 @@
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2 * @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP * @category Stud.IP
* @since 4.1 * @since 4.1
* *
*/ */
class I18NStringDatafield extends I18NString class I18NStringDatafield extends I18NString
{ {
/**
* Sets the metadata (database info object_id) of this i18n datafield.
*
* @param array $metadata Database info for object_id.
*/
public function setMetadata($metadata)
{
if (is_null($metadata['table'])) {
$this->metadata = $metadata;
}
}
/** /**
* Return an array containg the text in all additional languages. * Return an array containg the text in all additional languages.
* *
...@@ -32,7 +44,7 @@ class I18NStringDatafield extends I18NString ...@@ -32,7 +44,7 @@ class I18NStringDatafield extends I18NString
} }
return $this->lang; return $this->lang;
} }
/** /**
* Stores the i18n String manually in the database * Stores the i18n String manually in the database
* *
...@@ -44,10 +56,11 @@ class I18NStringDatafield extends I18NString ...@@ -44,10 +56,11 @@ class I18NStringDatafield extends I18NString
$object_id = $this->metadata['object_id']; $object_id = $this->metadata['object_id'];
/* Replace translations */ /* Replace translations */
$deleted = $db->execute("DELETE FROM `datafields_entries` " $deleted = $db->execute("DELETE FROM `datafields_entries` "
. "WHERE `datafield_id` = ? " . "WHERE `datafield_id` = ? "
. "AND `range_id` = ? " . "AND `range_id` = ? "
. "AND `sec_range_id` = ? " . "AND `sec_range_id` = ? "
. "AND `lang` <> ?", $object_id); . "AND `lang` <> ''",
[$object_id[0], $object_id[1], $object_id[2]]);
$i18nSQL = $db->prepare("INSERT INTO `datafields_entries` " $i18nSQL = $db->prepare("INSERT INTO `datafields_entries` "
. "(`datafield_id`, `range_id`, `sec_range_id`, `content`, `lang`) " . "(`datafield_id`, `range_id`, `sec_range_id`, `content`, `lang`) "
. "VALUES (?,?,?,?,?)"); . "VALUES (?,?,?,?,?)");
...@@ -59,10 +72,10 @@ class I18NStringDatafield extends I18NString ...@@ -59,10 +72,10 @@ class I18NStringDatafield extends I18NString
} }
} }
} }
/** /**
* Returns an I18NString object by given object_id, table and field. * Returns an I18NString object by given object_id, table and field.
* *
* @param string $object_id The id of the object with i18n fields. * @param string $object_id The id of the object with i18n fields.
* @param string $table The name of the table with the original values. * @param string $table The name of the table with the original values.
* @param string $field The name of the i18n field. * @param string $field The name of the i18n field.
...@@ -81,16 +94,15 @@ class I18NStringDatafield extends I18NString ...@@ -81,16 +94,15 @@ class I18NStringDatafield extends I18NString
. "AND `sec_range_id` = ? " . "AND `sec_range_id` = ? "
. "AND `lang` = ''", $object_id); . "AND `lang` = ''", $object_id);
} }
// var_dump($object_id, $base); exit;
$table = null; $table = null;
$field = null; $field = null;
return new self($base, self::fetchDataForField($object_id, $table, $field), return new self($base, self::fetchDataForField($object_id, $table, $field),
compact('object_id', 'table', 'field')); compact('object_id', 'table', 'field'));
} }
/** /**
* Retrieves all translations for one field. * Retrieves all translations for one field.
* *
* @param string $object_id The id of the object with i18n fields. * @param string $object_id The id of the object with i18n fields.
* @param string $table The name of the table with the original values. * @param string $table The name of the table with the original values.
* @param string $field The name oof the i18n field. * @param string $field The name oof the i18n field.
...@@ -106,11 +118,11 @@ class I18NStringDatafield extends I18NString ...@@ -106,11 +118,11 @@ class I18NStringDatafield extends I18NString
. "AND `sec_range_id` = ? " . "AND `sec_range_id` = ? "
. "AND `lang` <> ''", $object_id); . "AND `lang` <> ''", $object_id);
} }
/** /**
* This function is not used in the context of datafields, so it always * This function is not used in the context of datafields, so it always
* returns an empty array. * returns an empty array.
* *
* @param string $object_id The id of the object with i18n fields. * @param string $object_id The id of the object with i18n fields.
* @param string $table The name of the table with the original values. * @param string $table The name of the table with the original values.
* @return array An empty array. * @return array An empty array.
...@@ -119,11 +131,11 @@ class I18NStringDatafield extends I18NString ...@@ -119,11 +131,11 @@ class I18NStringDatafield extends I18NString
{ {
return []; return [];
} }
/** /**
* Removes all translations by given object id and table name. Accepts the * Removes all translations by given object id and table name. Accepts the
* language as third parameter to remove only translations to this language. * language as third parameter to remove only translations to this language.
* *
* @param string $object_id The id of the sorm object. * @param string $object_id The id of the sorm object.
* @param string $table The table name. * @param string $table The table name.
* @param string $lang Optional name of language. * @param string $lang Optional name of language.
...@@ -147,5 +159,5 @@ class I18NStringDatafield extends I18NString ...@@ -147,5 +159,5 @@ class I18NStringDatafield extends I18NString
. 'AND `table` = ?', . 'AND `table` = ?',
$object_id); $object_id);
} }
} }
\ No newline at end of file
...@@ -810,7 +810,7 @@ abstract class ModuleManagementModel extends SimpleORMap ...@@ -810,7 +810,7 @@ abstract class ModuleManagementModel extends SimpleORMap
* @return string The currently selected language. * @return string The currently selected language.
*/ */
public static final function getLanguage() public static final function getLanguage()
{ return 'DE'; {
$language = self::$language ?: $GLOBALS['MVV_LANGUAGES']['default']; $language = self::$language ?: $GLOBALS['MVV_LANGUAGES']['default'];
return $language; return $language;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment