Documentation

Weight
in package

The Weight class provides static conversion functions for weights.

This class is used to properly convert weights between the format used in the database (grams, integer) and a format for displaying and editing in the user interface (string, with units).

Tags
copyright

CLOUDREXX CMS - CLOUDREXX AG

author

Reto Kohli reto.kohli@comvation.com

access

public

version
3.0.0
subpackage

module_shop

Table of Contents

Properties

$arrUnits  : array<string|int, mixed>
The weight units in an array

Methods

getWeight()  : int
Return the weight found in the string argument converted back to grams
getWeightString()  : string
Return a string with the weight converted from grams to an appropriate unit.

Properties

$arrUnits

The weight units in an array

private static array<string|int, mixed> $arrUnits = array( 'g', //$_ARRAYLANG['TXT_WEIGHT_UNIT_GRAM'], 'kg', //$_ARRAYLANG['TXT_WEIGHT_UNIT_KILOGRAM'], 't', )
Tags
static
access

private

Methods

getWeight()

Return the weight found in the string argument converted back to grams

public static getWeight(mixed $weightString) : int

Takes a string as created by and returns the value converted to grams, with the unit removed, as an integer value ready to be written to the database. The unit, if missing, defaults to 'g' (grams). If no float value is found at the beginning of the string, if it is out of range, or if the unit is set but unknown, 0 will be returned. Note that, as weights are stored as integers, they are rounded down to whole grams.

Parameters
$weightString : mixed
Tags
access

public

Return values
int

The weight in grams

getWeightString()

Return a string with the weight converted from grams to an appropriate unit.

public static getWeightString(int $grams) : string

The weight is converted, and the unit chosen as follows:

  • weight in [ 0 .. 1'000[ -> 0 .. 999 grams,
  • weight in [ 1'000 .. 1'000'000[ -> 0 .. 999.999 kilograms,
  • weight in [1'000'000 .. 1'000'000'000[ -> 0 .. 999.999 tonnes. If the weight argument is outside of the valid range as specified above, '' (the empty string) is returned.
Parameters
$grams : int

The weight in grams

Tags
static
access

public

Return values
string

The weight in another unit, or ''


        
On this page

Search results