Skip to content

Commit

Permalink
Improvement when fetching template strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
srobotta committed Dec 5, 2024
1 parent 415cc10 commit 2599294
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion classes/repository/instance_repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private static function get_strings(string $type, int $subratingid, int $instanc
static $sortedstrings = [];
$typeid = localized_string_type::str2id($type);

if ($instanceid > 0) {
if ($instanceid > 0 || localized_string_type::is_template_type($type)) {
$strings = self::get_strings_for_instance($instanceid);
if (array_key_exists($typeid, $strings) && array_key_exists($subratingid, $strings[$typeid])) {
return $strings[$typeid][$subratingid];
Expand Down
19 changes: 19 additions & 0 deletions classes/repository/model/localized_string_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,23 @@ public static function id2str(int $id):string {
}
return $constants[$id - 1];
}

/**
* Return whether a type is a template type.
*
* @param string $type
* @return bool
*/
public static function is_template_type(string $type): bool {
return in_array($type, [
self::TEMPLATE_CRITERION,
self::TEMPLATE_CATEGORY_HEADER,
self::TEMPLATE_SUBRATING_TITLE,
self::TEMPLATE_SUBRATING_DESCRIPTION,
self::TEMPLATE_SUBRATING_VERY_NEGATIVE,
self::TEMPLATE_SUBRATING_NEGATIVE,
self::TEMPLATE_SUBRATING_POSITIVE,
self::TEMPLATE_SUBRATING_VERY_POSITIVE,
]);
}
}

0 comments on commit 2599294

Please sign in to comment.