mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-09 20:49:30 +00:00
Added some more tests.
Also changed the behavior of some code to meet the expectation.
This commit is contained in:
parent
322778af68
commit
a97d016740
8 changed files with 523 additions and 12 deletions
|
|
@ -103,10 +103,9 @@ abstract class Attachment extends NamedDBElement
|
|||
*/
|
||||
public function isExternal() : bool
|
||||
{
|
||||
//return static::isUrl($this->getPath());
|
||||
//Treat all pathes without a filepath as external
|
||||
return (strpos($this->getPath(), '%MEDIA%') === false)
|
||||
&& (strpos($this->getPath(), '%BASE') === false);
|
||||
return (strpos($this->getPath(), '%MEDIA%') !== 0)
|
||||
&& (strpos($this->getPath(), '%BASE%') !== 0);
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
|
|
@ -118,11 +117,15 @@ abstract class Attachment extends NamedDBElement
|
|||
/**
|
||||
* Returns the extension of the file referenced via the attachment.
|
||||
* For a path like %BASE/path/foo.bar, bar will be returned.
|
||||
* @return string
|
||||
* If this attachment is external null is returned.
|
||||
* @return string|null The file extension in lower case.
|
||||
*/
|
||||
public function getExtension() : string
|
||||
public function getExtension() : ?string
|
||||
{
|
||||
return pathinfo($this->getPath(), PATHINFO_EXTENSION);
|
||||
if ($this->isExternal()) {
|
||||
return null;
|
||||
}
|
||||
return strtolower(pathinfo($this->getPath(), PATHINFO_EXTENSION));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -124,7 +124,11 @@ class AmountFormatter
|
|||
}
|
||||
|
||||
//Otherwise just output it
|
||||
$format_string = '%.' . $options['decimals'] . 'f ' . $options['unit'];
|
||||
if (!empty($options['unit'])) {
|
||||
$format_string = '%.' . $options['decimals'] . 'f ' . $options['unit'];
|
||||
} else { //Dont add space after number if no unit was specified
|
||||
$format_string = '%.' . $options['decimals'] . 'f';
|
||||
}
|
||||
return sprintf($format_string, $value);
|
||||
}
|
||||
}
|
||||
|
|
@ -58,12 +58,11 @@ class SIFormatter
|
|||
$prefixes_pos = ['' ,'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
|
||||
$prefixes_neg = ['' ,'m', 'μ', 'n', 'p', 'f', 'a', 'z', 'y'];
|
||||
|
||||
//Determine nearest prefix index.
|
||||
$nearest = (int) round(abs($magnitude) / 3);
|
||||
|
||||
if ($magnitude >= 0) {
|
||||
$nearest = (int) floor(abs($magnitude) / 3);
|
||||
$symbol = $prefixes_pos[$nearest];
|
||||
} else {
|
||||
$nearest = (int) round(abs($magnitude) / 3);
|
||||
$symbol = $prefixes_neg[$nearest];
|
||||
}
|
||||
|
||||
|
|
@ -105,7 +104,11 @@ class SIFormatter
|
|||
[$divisor, $symbol] = $this->getPrefixByMagnitude($this->getMagnitude($value));
|
||||
$value /= $divisor;
|
||||
//Build the format string, e.g.: %.2d km
|
||||
$format_string = '%.' . $decimals . 'f ' . $symbol . $unit;
|
||||
if ($unit !== '' || $symbol !== '') {
|
||||
$format_string = '%.' . $decimals . 'f ' . $symbol . $unit;
|
||||
} else {
|
||||
$format_string = '%.' . $decimals . 'f';
|
||||
}
|
||||
|
||||
return sprintf($format_string, $value);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue