class Data extends DatasetChild

This class allows the storage and retrieval of the attributes of a data item.

The Data object is where most of the information used by a simulator is stored:

  • User input
  • information from data sources
  • intermediate calculation data
  • information returned to the user.

The data item can have one of the following type:

  • date: a date stored in the d/m/Y format
  • boolean: the value of the data item can be true or false
  • number: a numeric data with decimal places
  • integer: a numeric value without decimal places.
  • text: a short text
  • textarea: a long text
  • money: a numeric data with decimal places. The value of the data will be displayed with the currency symbol
  • choice: the value of the data is chosen from a list of choices
  • multichoice: the values of the data are chosen from a list of choices
  • percent: a numeric data with decimal places. The display of the value of the data will be followed by the % symbol.
  • table: the data item has an associated Table object
  • department: a departement code
  • region: a region code
  • country: a country code

Constants

TYPES

Properties

protected Simulator $simulator from DatasetChild
protected int $id from DatasetChild
protected string $name from DatasetChild
protected string $label from DatasetChild
protected RichText $description from DatasetChild
protected bool $error from DatasetChild
protected array $errorMessages from DatasetChild
protected bool $warning from DatasetChild
protected array $warningMessages from DatasetChild
protected bool $used from DatasetChild
private string $type
private string $min
private string $unparsedMin
private string $max
private string $unparsedMax
private string $pattern
private string $default
private string $unit
private string $unparsedDefault
private int $round
private string $content
private string $source
private string $unparsedIndex
private string $index
private bool $memorize
private array $choices
private ChoiceSource $choiceSource
private Table $table
private mixed $value
private array $rulesDependency
private int $inputStepId

Methods

void
__construct(Simulator $simulator, int $id, string $name)

Constructor of class Data

getSimulator()

Returns the Simulator object that uses this dataset child

int
getId()

Returns the ID of this dataset child.

void
setId(int $id)

Sets the ID of this dataset child.

string
getName()

Returns the name of this dataset child.

void
setName(string $name)

Sets the name of this dataset child.

string
getLabel()

Returns the label of this dataset child.

void
setLabel(string $label)

Sets the label of this dataset child.

getDescription()

Returns the description of this dataset child.

void
setDescription(RichText $description)

Sets the description of this dataset child.

bool
isUsed()

Returns the state of use of this dataset child by the current simulation step

bool
getUsed()

Returns the state of use of this dataset child by the current simulation step

void
setUsed(bool $used)

Sets the state of use of this dataset child by the current simulation step

bool
isError()

Returns the error attribute of this dataset child

bool
getError()

Returns the error attribute of this dataset child

void
setError(bool $error)

Determines whether this dataset child has a issued error or not

array
getErrorMessages()

Returns the list of error messages.

void
setErrorMessages(array $errorMessages)

Sets the list of error messages.

void
addErrorMessage(string $errorMessage)

Adds a message to the list of error messages.

void
removeErrorMessage(int $index)

Removes a message from the list of error messages.

bool
isWarning()

Returns the warning attribute of this dataset child

bool
getWarning()

Returns the warning attribute of this dataset child

void
setWarning(bool $warning)

Determines whether this dataset child has a issued warning or not

array
getWarningMessages()

Returns the list of warning messages.

void
setWarningMessages(array $warningMessages)

Sets the list of warning messages.

void
addWarningMessage(string $warningMessage)

Adds a message to the list of warning messages.

void
removeWarningMessage(int $index)

Removes a message from the list of warning messages.

string
getClass()

Returns the class name of this dataset child. It's either "Data" or "DataGroup".

string
getType()

Returns the type of this data item

void
setType(string $type)

Sets the type of this data item

string
getMin()

Returns the minimum value of this data item

string
getPlainMin()

Returns the arithmetic expression used to calculate the minimum value of this data item where the ids (prefixed with #) of the data are replaced by their labels.

void
setMin(string $min)

Sets the minimum value of this data item

string
getUnparsedMin()

Returns the arithmetic expression used to calculate the minimum value of this data item.

void
setUnparsedMin(string $unparsedMin)

Sets the arithmetic expression used to calculate the minimum value of this data item.

string
getMax()

Returns the maximum value of this data item

string
getPlainMax()

Returns the arithmetic expression used to calculate the maximum value of this data item where the ids (prefixed with #) of the data are replaced by their labels.

void
setMax(string $max)

Sets the maximum value of this data item

string
getUnparsedMax()

Returns the arithmetic expression used to calculate the minimum value of this data item.

void
setUnparsedMax(string $unparsedMax)

Sets the arithmetic expression used to calculate the minimum value of this data item.

string
getPattern()

Returns the pattern of this data item.

void
setPattern(string $pattern)

Sets the pattern of this data item.

string
getDefault()

Returns the default value of this data item

string
getPlainDefault()

Returns the arithmetic expression used to calculate the default value of this data item where the ids (prefixed with #) of the data are replaced by their labels.

void
setDefault(string $default)

Sets the default value of this data item

string
getUnparsedDefault()

Returns the arithmetic expression used to calculate the default value of this data item.

void
setUnparsedDefault(string $unparsedDefault)

Sets the arithmetic expression used to calculate the default value of this data item.

string
getUnit()

Returns the unit (measurement) text of this data item.

void
setUnit(string $unit)

Sets the unit(measurement) text of this data item.

int|null
getRound()

Returns the number of decimal places for this data item.

void
setRound(int|null $round)

Sets the number of decimal places for this data item. The last digit of the value of the data will be rounded to the nearest integer.

string
getContent()

Returns the arithmetic expression used to calculate the current value of this data item.

string
getPlainContent()

Returns the arithmetic expression used to calculate the value of this data item where the ids (prefixed with #) of the data are replaced by their labels.

void
setContent(string $content)

Sets the arithmetic expression used to calculate the value of this data item.

string
getSource()

Returns the id of the source if this data item is filled with the result of a query on a data source

string
getPlainSource() deprecated

Returns the arithmetic expression used to calculate the id of the source where the ids (prefixed with #) of the data are replaced by their labels.

void
setSource(string $source)

Sets the id of the source if this data item is filled with the result of a query on a data source

string
getIndex()

Returns the key of the associative array of the result if this data item is filled with the result of a query on a data source

string
getPlainIndex()

Returns the arithmetic expression used to calculate the key of the associative array of the result if this data item is filled with the result of a query on a data source. The ids (prefixed with #) of the data are replaced by their labels.

void
setIndex(string $index)

Sets the key of the associative array of the result if this data item is filled with the result of a query on a data source

string
getUnparsedIndex()

Returns the arithmetic expression used to calculate the key of the associative array of the result if this data item is filled with the result of a query on a data source.

void
setUnparsedIndex(string $unparsedIndex)

Sets the arithmetic expression used to calculate the key of the associative array of the result if this data item is filled with the result of a query on a data source.

bool
isMemorize()

Retrieves the memorize attribute of this data item.

bool
getMemorize()

Returns the memorize attribute of this data item.

void
setMemorize(bool $memorize)

Determines whether the value of this data should be stored in a cookie in the user's browser or not.

array
getChoices()

Returns the list of Choice Objects of this data item.

string|array
getChoiceLabel()

Returns the label of the choice corresponding to the current value of this data item.

string|array
getChoiceLabelByValue(mixed $avalue)

Retrieves the label of a choice by its value from the list of choices associated with that data item.

void
setChoices(array $choices)

Sets the list of Choice Objects of this data item.

void
addChoice(ChoiceGroup|Choice $choice)

Adds a Choice object in the list of choices of this data item.

Choice|null
getChoiceById(int $id)

Retrieves a Choice object by its id in the list of choices of this data item.

getChoiceSource()

Returns the ChoiceSource object if the type of this data is "choice" or "multichoice" and the list of choices is made with the result of a query on a data source.

void
setChoiceSource(ChoiceSource $choiceSource)

Sets the ChoiceSource object if the type of this data is "choice" or "multichoice" and the list of choices is made with the result of a query on a data source.

getTable()

Returns the Table object associated with this data item if the type of this data is "table".

void
setTable(Table $table)

Returns the Table object associated with this data item if the type of this data is "table".

mixed
getValue()

Retrieves the current value of this data item

string
getPlainValue()

Returns the current value of this data item in a string

void
setValue(mixed $value)

Sets the current value of this data item

int
getInputStepId()

Retrieves the id of the step where the user enters the value of this data item

void
setInputStepId(int $inputStepId)

Sets the id of the step where the user enters the value of this data item

array
getRulesDependency()

Returns the list of business rules that use this data item

void
setRulesDependency(array $rulesDependency)

Sets the list of business rules that use this data item

void
addRuleDependency(int $ruleId)

Adds a business rule id to the list of business rules that use this data item

void
removeRuleDependency(int $index)

Removes a business rule id from the list of business rules that use this data item

bool
check()

Checks the value of this data item according to its type

string
replaceIdByDataLabel(array $matches)

Returns the label of the data item whose identifier is the first element of the given array. The argument is an array because this method is the callback function of a preg_replace_callback.

string
replaceByDataLabel(string $target)

Replaces all data id (prefixed with #) by its label in the given text

Details

at line 270
void __construct(Simulator $simulator, int $id, string $name)

Constructor of class Data

Parameters

Simulator $simulator The Simulator object that uses this dataset child.
int $id The ID of this dataset child.
string $name The name of this dataset child.

Return Value

void

in DatasetChild at line 144
Simulator getSimulator()

Returns the Simulator object that uses this dataset child

Return Value

Simulator The Simulator object

in DatasetChild at line 155
int getId()

Returns the ID of this dataset child.

Return Value

int The ID of this dataset child.

in DatasetChild at line 167
void setId(int $id)

Sets the ID of this dataset child.

Parameters

int $id The ID of this dataset child.

Return Value

void

in DatasetChild at line 178
string getName()

Returns the name of this dataset child.

Return Value

string The name of this dataset child.

in DatasetChild at line 190
void setName(string $name)

Sets the name of this dataset child.

Parameters

string $name The name of this dataset child.

Return Value

void

in DatasetChild at line 201
string getLabel()

Returns the label of this dataset child.

Return Value

string The label of this dataset child.

in DatasetChild at line 213
void setLabel(string $label)

Sets the label of this dataset child.

Parameters

string $label The label of this dataset child.

Return Value

void

in DatasetChild at line 224
RichText getDescription()

Returns the description of this dataset child.

Return Value

RichText The description of this dataset child.

in DatasetChild at line 236
void setDescription(RichText $description)

Sets the description of this dataset child.

Parameters

RichText $description The description of this dataset child.

Return Value

void

in DatasetChild at line 247
bool isUsed()

Returns the state of use of this dataset child by the current simulation step

Return Value

bool true if this dataset child is used (displayed) by the current simulation step, false otherwise

in DatasetChild at line 258
bool getUsed()

Returns the state of use of this dataset child by the current simulation step

Return Value

bool true if this dataset child is used (displayed) by the current simulation step, false otherwise

in DatasetChild at line 270
void setUsed(bool $used)

Sets the state of use of this dataset child by the current simulation step

Parameters

bool $used true if this dataset child is used (displayed) by the current simulation step, false otherwise

Return Value

void

in DatasetChild at line 281
bool isError()

Returns the error attribute of this dataset child

Return Value

bool true if an error was occured, false if not

in DatasetChild at line 292
bool getError()

Returns the error attribute of this dataset child

Return Value

bool true if an error was occured, false if not

in DatasetChild at line 304
void setError(bool $error)

Determines whether this dataset child has a issued error or not

Parameters

bool $error true if this dataset child has a issued error, false otherwise

Return Value

void

in DatasetChild at line 315
array getErrorMessages()

Returns the list of error messages.

Return Value

array The list of error messages

in DatasetChild at line 327
void setErrorMessages(array $errorMessages)

Sets the list of error messages.

Parameters

array $errorMessages The list of error messages

Return Value

void

in DatasetChild at line 339
void addErrorMessage(string $errorMessage)

Adds a message to the list of error messages.

Parameters

string $errorMessage The message to add

Return Value

void

in DatasetChild at line 353
void removeErrorMessage(int $index)

Removes a message from the list of error messages.

Parameters

int $index The index of the message in the list of error messages

Return Value

void

in DatasetChild at line 364
bool isWarning()

Returns the warning attribute of this dataset child

Return Value

bool true if an warning was issued, false if not

in DatasetChild at line 375
bool getWarning()

Returns the warning attribute of this dataset child

Return Value

bool true if an warning was issued, false if not

in DatasetChild at line 387
void setWarning(bool $warning)

Determines whether this dataset child has a issued warning or not

Parameters

bool $warning true if this dataset child has a issued warning, false otherwise

Return Value

void

in DatasetChild at line 398
array getWarningMessages()

Returns the list of warning messages.

Return Value

array The list of warning messages.

in DatasetChild at line 410
void setWarningMessages(array $warningMessages)

Sets the list of warning messages.

Parameters

array $warningMessages The list of warning messages.

Return Value

void

in DatasetChild at line 422
void addWarningMessage(string $warningMessage)

Adds a message to the list of warning messages.

Parameters

string $warningMessage The message to add.

Return Value

void

in DatasetChild at line 436
void removeWarningMessage(int $index)

Removes a message from the list of warning messages.

Parameters

int $index The index of the message in the list of warning messages

Return Value

void

in DatasetChild at line 447
string getClass()

Returns the class name of this dataset child. It's either "Data" or "DataGroup".

Return Value

string The class name

at line 281
string getType()

Returns the type of this data item

Return Value

string The type of this data item

at line 293
void setType(string $type)

Sets the type of this data item

Parameters

string $type The type of this data item

Return Value

void

at line 307
string getMin()

Returns the minimum value of this data item

Return Value

string The mimimum value

at line 318
string getPlainMin()

Returns the arithmetic expression used to calculate the minimum value of this data item where the ids (prefixed with #) of the data are replaced by their labels.

Return Value

string The arithmetic expression

at line 330
void setMin(string $min)

Sets the minimum value of this data item

Parameters

string $min The minimum value

Return Value

void

at line 341
string getUnparsedMin()

Returns the arithmetic expression used to calculate the minimum value of this data item.

Return Value

string The arithmetic expression

at line 353
void setUnparsedMin(string $unparsedMin)

Sets the arithmetic expression used to calculate the minimum value of this data item.

Parameters

string $unparsedMin The arithmetic expression

Return Value

void

at line 364
string getMax()

Returns the maximum value of this data item

Return Value

string The maximum value

at line 375
string getPlainMax()

Returns the arithmetic expression used to calculate the maximum value of this data item where the ids (prefixed with #) of the data are replaced by their labels.

Return Value

string The arithmetic expression

at line 387
void setMax(string $max)

Sets the maximum value of this data item

Parameters

string $max The maximum value

Return Value

void

at line 398
string getUnparsedMax()

Returns the arithmetic expression used to calculate the minimum value of this data item.

Return Value

string The arithmetic expression

at line 410
void setUnparsedMax(string $unparsedMax)

Sets the arithmetic expression used to calculate the minimum value of this data item.

Parameters

string $unparsedMax The arithmetic expression

Return Value

void

at line 421
string getPattern()

Returns the pattern of this data item.

Return Value

string The pattern

at line 433
void setPattern(string $pattern)

Sets the pattern of this data item.

Parameters

string $pattern The pattern

Return Value

void

at line 444
string getDefault()

Returns the default value of this data item

Return Value

string The default value

at line 455
string getPlainDefault()

Returns the arithmetic expression used to calculate the default value of this data item where the ids (prefixed with #) of the data are replaced by their labels.

Return Value

string The arithmetic expression

at line 467
void setDefault(string $default)

Sets the default value of this data item

Parameters

string $default The default value

Return Value

void

at line 478
string getUnparsedDefault()

Returns the arithmetic expression used to calculate the default value of this data item.

Return Value

string The arithmetic expression

at line 490
void setUnparsedDefault(string $unparsedDefault)

Sets the arithmetic expression used to calculate the default value of this data item.

Parameters

string $unparsedDefault The arithmetic expression

Return Value

void

at line 501
string getUnit()

Returns the unit (measurement) text of this data item.

Return Value

string The unit text

at line 513
void setUnit(string $unit)

Sets the unit(measurement) text of this data item.

Parameters

string $unit The unit text

Return Value

void

at line 526
int|null getRound()

Returns the number of decimal places for this data item.

Useless if this data is not of type "number", "money" or "percent".

Return Value

int|null The number of decimal places

at line 540
void setRound(int|null $round)

Sets the number of decimal places for this data item. The last digit of the value of the data will be rounded to the nearest integer.

Useless if this data is not of type "number", "money" or "percent".

Parameters

int|null $round The number of decimal places

Return Value

void

at line 551
string getContent()

Returns the arithmetic expression used to calculate the current value of this data item.

Return Value

string The arithmetic expression

at line 562
string getPlainContent()

Returns the arithmetic expression used to calculate the value of this data item where the ids (prefixed with #) of the data are replaced by their labels.

Return Value

string The arithmetic expression

at line 574
void setContent(string $content)

Sets the arithmetic expression used to calculate the value of this data item.

Parameters

string $content The arithmetic expression

Return Value

void

at line 585
string getSource()

Returns the id of the source if this data item is filled with the result of a query on a data source

Return Value

string The id of the source

at line 599
string getPlainSource() deprecated

deprecated

Returns the arithmetic expression used to calculate the id of the source where the ids (prefixed with #) of the data are replaced by their labels.

This function is no longer used.

Return Value

string The arithmetic expression

at line 611
void setSource(string $source)

Sets the id of the source if this data item is filled with the result of a query on a data source

Parameters

string $source The id of the source

Return Value

void

at line 622
string getIndex()

Returns the key of the associative array of the result if this data item is filled with the result of a query on a data source

Return Value

string The key of the associative array

at line 633
string getPlainIndex()

Returns the arithmetic expression used to calculate the key of the associative array of the result if this data item is filled with the result of a query on a data source. The ids (prefixed with #) of the data are replaced by their labels.

Return Value

string The arithmetic expression

at line 645
void setIndex(string $index)

Sets the key of the associative array of the result if this data item is filled with the result of a query on a data source

Parameters

string $index The key of the associative array

Return Value

void

at line 656
string getUnparsedIndex()

Returns the arithmetic expression used to calculate the key of the associative array of the result if this data item is filled with the result of a query on a data source.

Return Value

string The arithmetic expression

at line 668
void setUnparsedIndex(string $unparsedIndex)

Sets the arithmetic expression used to calculate the key of the associative array of the result if this data item is filled with the result of a query on a data source.

Parameters

string $unparsedIndex The arithmetic expression

Return Value

void

at line 681
bool isMemorize()

Retrieves the memorize attribute of this data item.

Indicates whether the value of this data should be saved in a cookie in the user's browser.

Return Value

bool The memorize attribute

at line 692
bool getMemorize()

Returns the memorize attribute of this data item.

Return Value

bool The memorize attribute

at line 704
void setMemorize(bool $memorize)

Determines whether the value of this data should be stored in a cookie in the user's browser or not.

Parameters

bool $memorize true if the value of this data should be stored in a cookie, false otherwise

Return Value

void

at line 717
array getChoices()

Returns the list of Choice Objects of this data item.

If the type of this data is "choice" or "multichoice", the list of choices allows the user to select the value of this data item.

Return Value

array The list of Choice Objects

at line 728
string|array getChoiceLabel()

Returns the label of the choice corresponding to the current value of this data item.

Return Value

string|array The label of the choice

at line 740
string|array getChoiceLabelByValue(mixed $avalue)

Retrieves the label of a choice by its value from the list of choices associated with that data item.

Parameters

mixed $avalue The value of the choice

Return Value

string|array The label of the choice

at line 796
void setChoices(array $choices)

Sets the list of Choice Objects of this data item.

If the type of this data is "choice" or "multichoice", the list of choices allows the user to select the value of this data item.

Parameters

array $choices The list of Choice Objects

Return Value

void

at line 808
void addChoice(ChoiceGroup|Choice $choice)

Adds a Choice object in the list of choices of this data item.

Parameters

ChoiceGroup|Choice $choice The Choice object

Return Value

void

at line 820
Choice|null getChoiceById(int $id)

Retrieves a Choice object by its id in the list of choices of this data item.

Parameters

int $id The id of the Choice object

Return Value

Choice|null The Choice object

at line 842
ChoiceSource|null getChoiceSource()

Returns the ChoiceSource object if the type of this data is "choice" or "multichoice" and the list of choices is made with the result of a query on a data source.

Return Value

ChoiceSource|null The ChoiceSource object

at line 854
void setChoiceSource(ChoiceSource $choiceSource)

Sets the ChoiceSource object if the type of this data is "choice" or "multichoice" and the list of choices is made with the result of a query on a data source.

Parameters

ChoiceSource $choiceSource The ChoiceSource object

Return Value

void

at line 865
Table getTable()

Returns the Table object associated with this data item if the type of this data is "table".

Return Value

Table The Table Object

at line 877
void setTable(Table $table)

Returns the Table object associated with this data item if the type of this data is "table".

Parameters

Table $table The Table Object

Return Value

void

at line 888
mixed getValue()

Retrieves the current value of this data item

Return Value

mixed The current value

at line 911
string getPlainValue()

Returns the current value of this data item in a string

Return Value

string The current value

at line 947
void setValue(mixed $value)

Sets the current value of this data item

Parameters

mixed $value The current value

Return Value

void

at line 991
int getInputStepId()

Retrieves the id of the step where the user enters the value of this data item

Returns -1 if the value is never entered by the user.

Return Value

int The id of the step

at line 1003
void setInputStepId(int $inputStepId)

Sets the id of the step where the user enters the value of this data item

Parameters

int $inputStepId The id of the step

Return Value

void

at line 1014
array getRulesDependency()

Returns the list of business rules that use this data item

Return Value

array The list of business rules

at line 1026
void setRulesDependency(array $rulesDependency)

Sets the list of business rules that use this data item

Parameters

array $rulesDependency The list of business rules

Return Value

void

at line 1038
void addRuleDependency(int $ruleId)

Adds a business rule id to the list of business rules that use this data item

Parameters

int $ruleId The id of the business rule.

Return Value

void

at line 1052
void removeRuleDependency(int $index)

Removes a business rule id from the list of business rules that use this data item

Parameters

int $index The index of the rule to remove

Return Value

void

at line 1063
bool check()

Checks the value of this data item according to its type

Return Value

bool false if there is an error, true otherwise

at line 1166
private string replaceIdByDataLabel(array $matches)

Returns the label of the data item whose identifier is the first element of the given array. The argument is an array because this method is the callback function of a preg_replace_callback.

If the data item is not found the given id prefixed by # is returned

Parameters

array $matches The first element is a data id

Return Value

string returned value : The label of the data

at line 1180
private string replaceByDataLabel(string $target)

Replaces all data id (prefixed with #) by its label in the given text

Parameters

string $target The text in which the data id are to be replaced

Return Value

string The text with data label