mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-08-29 06:18:26 +02:00
Update AbstractParameter.php (#959)
* Update AbstractParameter.php Make lazy null conditionals explicit. Try to handle LaTeX special chars gracefully. Fixes #958 * Only escape the percentage sign, so that you can still use latex for units * Only escape previously unescaped percentage signs * simplify regex * Render the percentage sign correctly in units in the frontend. --------- Co-authored-by: Jan Böhmer <mail@jan-boehmer.de>
This commit is contained in:
parent
00a74ed96a
commit
2226b72d1c
3 changed files with 16 additions and 8 deletions
|
@ -217,7 +217,7 @@ abstract class AbstractParameter extends AbstractNamedDBElement implements Uniqu
|
|||
|
||||
$str = '';
|
||||
$bracket_opened = false;
|
||||
if ($this->value_typical) {
|
||||
if ($this->value_typical !== null) {
|
||||
$str .= $this->getValueTypicalWithUnit($latex_formatted);
|
||||
if ($this->value_min || $this->value_max) {
|
||||
$bracket_opened = true;
|
||||
|
@ -225,11 +225,11 @@ abstract class AbstractParameter extends AbstractNamedDBElement implements Uniqu
|
|||
}
|
||||
}
|
||||
|
||||
if ($this->value_max && $this->value_min) {
|
||||
if ($this->value_max !== null && $this->value_min !== null) {
|
||||
$str .= $this->getValueMinWithUnit($latex_formatted).' ... '.$this->getValueMaxWithUnit($latex_formatted);
|
||||
} elseif ($this->value_max) {
|
||||
} elseif ($this->value_max !== null) {
|
||||
$str .= 'max. '.$this->getValueMaxWithUnit($latex_formatted);
|
||||
} elseif ($this->value_min) {
|
||||
} elseif ($this->value_min !== null) {
|
||||
$str .= 'min. '.$this->getValueMinWithUnit($latex_formatted);
|
||||
}
|
||||
|
||||
|
@ -449,7 +449,10 @@ abstract class AbstractParameter extends AbstractNamedDBElement implements Uniqu
|
|||
if (!$with_latex) {
|
||||
$unit = $this->unit;
|
||||
} else {
|
||||
$unit = '$\mathrm{'.$this->unit.'}$';
|
||||
//Escape the percentage sign for convenience (as latex uses it as comment and it is often used in units)
|
||||
$escaped = preg_replace('/\\\\?%/', "\\\\%", $this->unit);
|
||||
|
||||
$unit = '$\mathrm{'.$escaped.'}$';
|
||||
}
|
||||
|
||||
return $str.' '.$unit;
|
||||
|
@ -457,7 +460,7 @@ abstract class AbstractParameter extends AbstractNamedDBElement implements Uniqu
|
|||
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the class of the element that is allowed to be associated with this attachment.
|
||||
* @return string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue