class CUnits extends CommonDict (View source)

Class of dictionary type of thirdparty (used by imports)

Properties

DoliDB $db from  CommonDict
$error from  CommonDict
string[] $errors from  CommonDict
int $id from  CommonDict
?int $entity from  CommonDict
?string $code from  CommonDict
?string $label from  CommonDict
?int<0, 1> $active from  CommonDict
CUnits[] $records
$libelle
string $sortorder
string $short_label
string $unit_type
?int $scale

Methods

__construct($db)

Constructor

create($user, int<0, 1> $notrigger = 0)

Create object into database

fetch($id, string $code = '', $short_label = '', $unit_type = '')

Load object in memory from database

CUnits[]|int
fetchAll(string $sortorder = '', string $sortfield = '', int $limit = 0, int $offset = 0, string|array<string, mixed> $filter = '', string $filtermode = 'AND')

Load list of objects in memory from the database.

update($user = null, int<0, 1> $notrigger = 0)

Update object into database

delete(User $user, $notrigger = 0)

Delete object in database

int|string
getUnitFromCode(string $code, string $mode = 'code', string $unit_type = '')

Get unit from code

float
unitConverter(float $value, int $fk_unit, int $fk_new_unit = 0)

Unit converter

float|int
scaleOfUnitPow(int $id)

Get scale of unit factor

Details

__construct($db)

Constructor

@param DoliDB $db Database handler

Parameters

$db

create($user, int<0, 1> $notrigger = 0)

Create object into database

@param User $user User that create

Parameters

$user
int<0, 1> $notrigger

0=launch triggers after, 1=disable triggers @return int Return integer <0 if KO, Id of created object if OK

fetch($id, string $code = '', $short_label = '', $unit_type = '')

Load object in memory from database

@param int $id Id of CUnit object to fetch (rowid)

Parameters

$id
string $code

Code @param string $short_label Short Label ('g', 'kg', ...) @param string $unit_type Unit type ('size', 'surface', 'volume', 'weight', ...) @return int Return integer <0 if KO, >0 if OK

$short_label
$unit_type

CUnits[]|int fetchAll(string $sortorder = '', string $sortfield = '', int $limit = 0, int $offset = 0, string|array<string, mixed> $filter = '', string $filtermode = 'AND')

Load list of objects in memory from the database.

Parameters

string $sortorder

Sort Order

string $sortfield

Sort field

int $limit Limit
int $offset Offset
string|array<string, mixed> $filter

Filter USF

string $filtermode

Filter mode (AND or OR)

Return Value

CUnits[]|int

int <0 if KO, array of pages if OK

update($user = null, int<0, 1> $notrigger = 0)

Update object into database

@param User $user User that modify

Parameters

$user
int<0, 1> $notrigger

0=launch triggers after, 1=disable triggers @return int Return integer <0 if KO, >0 if OK

delete(User $user, $notrigger = 0)

Delete object in database

Parameters

User $user

User that delete @param int<0,1> $notrigger 0=launch triggers after, 1=disable triggers @return int Return integer <0 if KO, >0 if OK

$notrigger

int|string getUnitFromCode(string $code, string $mode = 'code', string $unit_type = '')

Get unit from code

Parameters

string $code

code of unit

string $mode

0= id , short_label=Use short label as value, code=use code

string $unit_type weight,size,surface,volume,qty,time...

Return Value

int|string

Return integer <0 if KO, Id of code if OK (or $code if $mode is different from '', 'short_label' or 'code')

float unitConverter(float $value, int $fk_unit, int $fk_new_unit = 0)

Unit converter

Parameters

float $value

value to convert

int $fk_unit

current unit id of value

int $fk_new_unit

the id of unit to convert in

Return Value

float

float|int scaleOfUnitPow(int $id)

Get scale of unit factor

Parameters

int $id

Id of unit in dictionary

Return Value

float|int

Scale of unit