\Orpheus\Publisher\PermanentObjectPermanentObject

The permanent object class

Manage a permanent object using the SQL Adapter.

Summary

Methods
Properties
Constants
selfInit()
set2Array()
setTo()
__construct()
__destruct()
__get()
__set()
__isset()
__toString()
id()
uid()
update()
getUpdateOperation()
onValidUpdate()
extractUpdateQuery()
getDeleteOperation()
runForUpdate()
onEdit()
onValidateInput()
onSaved()
save()
checkIntegrity()
remove()
free()
reload()
isDeleted()
isValid()
markAsDeleted()
getValue()
setValue()
equals()
logEvent()
fillLogEvent()
getLogEvent()
object()
isFieldEditable()
get()
load()
cacheObjects()
getCacheStats()
delete()
clearDeletedInstances()
clearInstances()
clearAllInstances()
escapeIdentifier()
ei()
formatValue()
fv()
formatValueList()
create()
getCreateOperation()
onValidCreate()
extractCreateQuery()
createAndGet()
completeFields()
getFields()
getClass()
getTable()
getIDField()
getDomain()
getValidator()
runForObject()
applyToObject()
checkUserInput()
checkForObject()
testUserInput()
getClassData()
getSQLAdapter()
init()
throwException()
throwNotFound()
text()
_text()
reportException()
No public properties found
No constants found
addModFields()
listModifiedFields()
clearModifiedFields()
checkCache()
parseFieldValue()
formatFieldValue()
$IDFIELD
$instances
$table
$DBInstance
$fields
$validator
$domain
$editableFields
$modFields
$data
$isDeleted
$onSavedInProgress
$knownClassData
N/A
No private methods found
No private properties found
N/A

Properties

$IDFIELD

$IDFIELD : string

The ID field

Type

string

$instances

$instances : array

Cache of all object instances

Type

array

$table

$table : string

The table

Type

string

$DBInstance

$DBInstance : string

DB instance

Use only to get SQL Adapter

Type

string

$fields

$fields : array

The fields of this object

Type

array

$validator

$validator : array

The validator The default one is an array system.

Type

array

$domain

$domain : string

The domain of this class Used as default for translations.

Type

string

$editableFields

$editableFields : array

Editable fields

Type

array

$modFields

$modFields : array

Currently modified fields

Type

array

$data

$data : array

The object's data

Type

array

$isDeleted

$isDeleted : boolean

Is this object deleted ?

Type

boolean

$onSavedInProgress

$onSavedInProgress : boolean

Is this object called onSaved ? It prevents recursive calls

Type

boolean

$knownClassData

$knownClassData : array

Store data about known classes

Type

array

Methods

selfInit()

selfInit() 

Internal static initialization

set2Array()

set2Array(array  $array) : array

Get the object as array

Parameters

array $array

Returns

array —

The resulting array

setTo()

setTo(array  $array) 

Insert this object in the given array using its ID as key

Parameters

array $array

__construct()

__construct(  $data) 

Constructor

Parameters

$data

An array of the object's data to construct

__destruct()

__destruct() 

Destructor

If something was modified, it saves the new data.

__get()

__get(string  $name) : \Orpheus\Publisher\PermanentObject\The

Magic getter

Parameters

string $name

Name of the property to get

Returns

\Orpheus\Publisher\PermanentObject\The —

value of field $name

Get the value of field $name. 'all' returns all fields.

__set()

__set(  $name,   $value) 

Magic setter

Parameters

$name

Name of the property to set

$value

New value of the property

Sets the value of field $name.

__isset()

__isset(  $name) 

Magic isset

Parameters

$name

Name of the property to check is set

Checks if the field $name is set.

__toString()

__toString() : \Orpheus\Publisher\PermanentObject\The

Magic toString

Returns

\Orpheus\Publisher\PermanentObject\The —

string value of the object.

The object's value when casting to string.

id()

id() : \Orpheus\Publisher\PermanentObject\The

Get this permanent object's ID

Returns

\Orpheus\Publisher\PermanentObject\The —

id of this object.

Get this object ID according to the IDFIELD attribute.

uid()

uid() : \Orpheus\Publisher\PermanentObject\The

Get this permanent object's unique ID

Returns

\Orpheus\Publisher\PermanentObject\The —

uid of this object.

Get this object ID according to the table and id.

update()

update(array  $input, array<mixed,string>  $fields, boolean  $noEmptyWarning = true, \Orpheus\Publisher\PermanentObject\&int  $errCount, \Orpheus\Publisher\PermanentObject\&int  $successCount) : \Orpheus\Publisher\PermanentObject\1

Update this permanent object from input data array

Parameters

array $input

The input data we will check and extract, used by children

array<mixed,string> $fields

The array of fields to check

boolean $noEmptyWarning

True to do not report warning for empty data (instead return 0). Default value is true.

\Orpheus\Publisher\PermanentObject\&int $errCount

Output parameter for the number of occurred errors validating fields.

\Orpheus\Publisher\PermanentObject\&int $successCount

Output parameter for the number of successes updating fields.

Returns

\Orpheus\Publisher\PermanentObject\1 —

in case of success, else 0.

getUpdateOperation()

getUpdateOperation(array  $input, array<mixed,string>  $fields) : \Orpheus\Publisher\Transaction\UpdateTransactionOperation

Get the update operation

Parameters

array $input

The input data we will check and extract, used by children

array<mixed,string> $fields

The array of fields to check

Returns

\Orpheus\Publisher\Transaction\UpdateTransactionOperation

onValidUpdate()

onValidUpdate(array  $input, integer  $newErrors) : boolean

Callback when validating update

Parameters

array $input
integer $newErrors

Returns

boolean

extractUpdateQuery()

extractUpdateQuery(array  $input, \Orpheus\Publisher\PermanentObject\PermanentObject  $object) : array

Extract an update query from this object

Parameters

array $input
\Orpheus\Publisher\PermanentObject\PermanentObject $object

Returns

array

runForUpdate()

runForUpdate(  $data,   $oldData) 

Run for Update

Parameters

$data

the new data

$oldData

the old data

onValidateInput()

onValidateInput(array  $input, array  $fields, \Orpheus\Publisher\PermanentObject\PermanentObject  $object) 

Callback when validating input

Parameters

array $input
array $fields
\Orpheus\Publisher\PermanentObject\PermanentObject $object

save()

save() : boolean

Save this permanent object

Returns

boolean —

True in case of success

If some fields was modified, it saves these fields using the SQL Adapter.

checkIntegrity()

checkIntegrity() 

Check object integrity & validity

remove()

remove() : integer

What do you think it does ?

Returns

integer

free()

free() : boolean

Free the object (remove)

Returns

boolean

reload()

reload(string  $field = null) : boolean

Reload fields from database

Parameters

string $field

The field to reload, default is null (all fields).

Returns

boolean —

True if done

Update the current object's fields from database. If $field is not set, it reloads only one field else all fields. Also it removes the reloaded fields from the modified ones list.

isDeleted()

isDeleted() : boolean

Check if this object is deleted

Returns

boolean —

True if this object is deleted

Checks if this object is known as deleted.

isValid()

isValid() : boolean

Check if this object is valid

Returns

boolean —

True if this object is valid

Check if this object is not deleted. May be used for others cases.

markAsDeleted()

markAsDeleted() 

Mark this object as deleted

getValue()

getValue(  $key = null) : mixed

Get one value or all values

Parameters

$key

Name of the field to get.

Returns

mixed —

Get the value of field $key or all data values if $key is null.

setValue()

setValue(string  $key, mixed  $value) : \Orpheus\Publisher\PermanentObject\PermanentObject

Set the value of a field

Parameters

string $key

Name of the field to set

mixed $value

New value of the field

Returns

\Orpheus\Publisher\PermanentObject\PermanentObject

Set the field $key with the new $value.

equals()

equals(object  $o) : boolean

Verify equality with another object

Parameters

object $o

The object to compare.

Returns

boolean —

True if this object represents the same data, else False.

Compare the class and the ID field value of the 2 objects.

logEvent()

logEvent(string  $event, integer  $time = null, string  $ipAdd = null) 

Log an event

Parameters

string $event

The event to log in this object

integer $time

A specified time to use for logging event

string $ipAdd

A specified IP Adress to use for logging event

fillLogEvent()

fillLogEvent(array  $array, string  $event) 

Add an $event log in this $array

Parameters

array $array
string $event

getLogEvent()

getLogEvent(string  $event, integer  $time = null, string  $ipAdd = null) 

Get the log of an event

Parameters

string $event

The event to log in this object

integer $time

A specified time to use for logging event

string $ipAdd

A specified IP Adress to use for logging event

isFieldEditable()

isFieldEditable(string  $fieldname) : boolean

Test if $fieldname is editable

Parameters

string $fieldname

Returns

boolean

get()

get(array  $options = NULL) : \Orpheus\SQLRequest\SQLSelectRequest|static|array<mixed,static>

Get some permanent objects

Parameters

array $options

The options used to get the permanents object

Returns

\Orpheus\SQLRequest\SQLSelectRequest|static|array<mixed,static> —

An array of array containing object's data

load()

load(mixed|array<mixed,mixed>  $in, boolean  $nullable = true, boolean  $usingCache = true) : \Orpheus\Publisher\PermanentObject\PermanentObject

Load a permanent object

Parameters

mixed|array<mixed,mixed> $in

The object ID to load or a valid array of the object's data

boolean $nullable

True to silent errors row and return null

boolean $usingCache

True to cache load and set cache, false to not cache

Returns

\Orpheus\Publisher\PermanentObject\PermanentObject

The object

cacheObjects()

cacheObjects(array  $objects) : array

Cache an array of objects

Parameters

array $objects

Returns

array

delete()

delete(integer  $in) : integer

Delete a permanent object

Parameters

integer $in

The object ID to delete or the delete array.

Returns

integer —

The number of deleted rows.

clearDeletedInstances()

clearDeletedInstances() 

Remove deleted instances from cache

clearInstances()

clearInstances() 

Remove deleted instances

clearAllInstances()

clearAllInstances() 

Remove all instances

escapeIdentifier()

escapeIdentifier(string  $identifier = null) : string

Escape identifier through instance

Parameters

string $identifier

The identifier to escape. Default is table name.

Returns

string —

The escaped identifier

ei()

ei(string  $identifier = null) : string

Escape identifier through instance

Parameters

string $identifier

The identifier to escape. Default is table name.

Returns

string —

The escaped identifier

formatValue()

formatValue(scalar  $value) : string

Escape value through instance

Parameters

scalar $value

The value to format

Returns

string —

The formatted $Value

fv()

fv(scalar  $value) : string

Escape value through instance

Parameters

scalar $value

The value to format

Returns

string —

The formatted $Value

formatValueList()

formatValueList(array  $list) : string

Escape values through instance and return as list string

Parameters

array $list

The list of values

Returns

string —

The formatted list string

create()

create(array  $input = array(), array  $fields = null, integer  $errCount) : integer

Create a new permanent object

Parameters

array $input

The input data we will check, extract and create the new object.

array $fields

The array of fields to check. Default value is null.

integer $errCount

Output parameter to get the number of found errors. Default value is 0

Returns

integer —

The ID of the new permanent object.

getCreateOperation()

getCreateOperation(array  $input, array<mixed,string>  $fields) : \Orpheus\Publisher\Transaction\CreateTransactionOperation

Get the create operation

Parameters

array $input

The input data we will check and extract, used by children

array<mixed,string> $fields

The array of fields to check

Returns

\Orpheus\Publisher\Transaction\CreateTransactionOperation

onValidCreate()

onValidCreate(array  $input, integer  $newErrors) : boolean

Callback when validating create

Parameters

array $input
integer $newErrors

Returns

boolean

extractCreateQuery()

extractCreateQuery(array  $input) : array

Extract a create query from this class

Parameters

array $input

Returns

array

createAndGet()

createAndGet(array  $input = array(), array|null  $fields = null, integer  $errCount) : \Orpheus\Publisher\PermanentObject\PermanentObject

Create a new permanent object

Parameters

array $input

The input data we will check, extract and create the new object.

array|null $fields

The array of fields to check. Default value is null.

integer $errCount

Output parameter to get the number of found errors. Default value is 0

Returns

\Orpheus\Publisher\PermanentObject\PermanentObject

The new permanent object

completeFields()

completeFields(array  $data) : array

Complete missing fields

Parameters

array $data

The data array to complete.

Returns

array —

The completed data array.

Complete an array of data of an object of this class by setting missing fields with empty string.

getFields()

getFields() : array

Get known fields

Returns

array

getClass()

getClass() : string

Get the name of this class

Returns

string —

The name of this class.

getTable()

getTable() : \Orpheus\Publisher\PermanentObject\The

Get the table of this class

Returns

\Orpheus\Publisher\PermanentObject\The —

table of this class.

getIDField()

getIDField() : \Orpheus\Publisher\PermanentObject\The

Get the ID field name of this class

Returns

\Orpheus\Publisher\PermanentObject\The —

ID field of this class.

getDomain()

getDomain() : \Orpheus\Publisher\PermanentObject\The

Get the domain of this class

Returns

\Orpheus\Publisher\PermanentObject\The —

domain of this class.

Get the domain of this class, can be guessed from $table or specified in $domain.

getValidator()

getValidator() : \Orpheus\Publisher\PermanentObject\The

Get the validator of this class

Returns

\Orpheus\Publisher\PermanentObject\The —

validator of this class.

Get the validator of this class.

runForObject()

runForObject(  $data) 

Run for object

Parameters

$data

The new data to process.

applyToObject()

applyToObject(  $data,   $id) 

Apply for new object

Parameters

$data

The new data to process.

$id

The ID of the new object.

checkUserInput()

checkUserInput(array  $input, array<mixed,string>  $fields = null, \Orpheus\Publisher\PermanentObject\PermanentObject  $ref = null, integer  $errCount) : \Orpheus\Publisher\PermanentObject\The

Check user input

Parameters

array $input

The user input data to check.

array<mixed,string> $fields

The array of fields to check. Default value is null.

\Orpheus\Publisher\PermanentObject\PermanentObject $ref

The referenced object (update only). Default value is null.

integer $errCount

The resulting error count, as pointer. Output parameter.

Returns

\Orpheus\Publisher\PermanentObject\The —

valid data.

Check if the class could generate a valid object from $input. The method could modify the user input to fix them but it must return the data. The data are passed through the validator, for different cases:

  • If empty, this function return an empty array.
  • If an array, it uses an field => checkMethod association.

checkForObject()

checkForObject(  $data,   $ref = null) 

Check for object

Parameters

$data

The new data to process.

$ref

The referenced object (update only). Default value is null.

testUserInput()

testUserInput(  $input,   $fields = null,   $ref = null,   $errCount) 

Test user input

Parameters

$input

The new data to process.

$fields

The array of fields to check. Default value is null.

$ref

The referenced object (update only). Default value is null.

$errCount

The resulting error count, as pointer. Output parameter.

getClassData()

getClassData(array  $classData = null) : array

Get all gathered data about this class

Parameters

array $classData

Returns

array

init()

init(string  $isFinal = true) 

Initialize the class

Parameters

string $isFinal

Call this function only once after declaring it

throwException()

throwException(string  $message) 

Throw an UserException

Parameters

string $message

the text message, may be a translation string

throwNotFound()

throwNotFound(string  $message = null) 

Throw a NotFoundException

Parameters

string $message

the text message, may be a translation string

text()

text(string  $text, array|string  $values = array()) : string

Translate text according to the object domain

Parameters

string $text

The text to translate

array|string $values

The values array to replace in text. Could be used as second parameter.

Returns

string —

The translated text

_text()

_text(\Orpheus\Publisher\PermanentObject\sting  $text, array|string  $values = array()) 

Translate text according to the object domain

Parameters

\Orpheus\Publisher\PermanentObject\sting $text

The text to translate

array|string $values

The values array to replace in text. Could be used as second parameter.

reportException()

reportException(  $e) 

Report an UserException

Parameters

$e

the UserException

addModFields()

addModFields(  $field) 

Mark the field as modified

Parameters

$field

The field to mark as modified.

Adds the $field to the modified fields array.

listModifiedFields()

listModifiedFields() : array<mixed,string>

List all modified fields

Returns

array<mixed,string>

clearModifiedFields()

clearModifiedFields() 

Clear modified fields

parseFieldValue()

parseFieldValue(string  $name, string  $value) : string

Parse the value from SQL scalar to PHP type

Parameters

string $name

The field name to parse

string $value

The field value to parse

Returns

string —

The parse $value

formatFieldValue()

formatFieldValue(string  $name, mixed  $value) : string

Format the value

Parameters

string $name

The field name to format

mixed $value

The field value to format

Returns

string —

The formatted $Value