Options class

access public
package kocuj_internal_lib
inherited_from \KocujIL\V12a\Classes\ComponentObject

 Methods

Constructor

__construct(object $projectObj) : void
access public
inherited_from \KocujIL\V12a\Classes\ComponentObject::__construct()

Parameters

$projectObj

object

\KocujIL\V12a\Classes\Project object for current project

Constructor

__construct(object $projectObj) : void
Inherited
access public

Parameters

$projectObj

object

\KocujIL\V12a\Classes\Project object for current project

Add options container

addContainer(string $containerId, integer $optionAutoload = \KocujIL\V12a\Enums\OptionAutoload::YES, integer $containerType = \KocujIL\V12a\Enums\Project\Components\All\Options\ContainerType::SITE) : void
access public

Parameters

$containerId

string

Options container identifier; it must have maximum 16 characters

$optionAutoload

integer

Automatic loading of option or not; this argument is ignored if $containerType is set to \KocujIL\V12a\Enums\Project\Components\All\Options\ContainerType::WIDGET; must be one of the following constants from \KocujIL\V12a\Enums\OptionAutoload: NO (when option should not be automatically loaded) or YES (when option should be automatically loaded) - default: \KocujIL\V12a\Enums\OptionAutoload::YES

$containerType

integer

Options container type; must be one of the following constants from \KocujIL\V12a\Enums\Project\Components\All\Options\ContainerType: NETWORK_OR_SITE (for network - in multisite installation - or site - in standard installation - type), SITE (for site type), NETWORK (for network type), WIDGET (for widget type), DATA_SET_SITE (for data set table with options for site type) or DATA_SET_NETWORK (for data set table with options for network type) - default: \KocujIL\V12a\Enums\Project\Components\All\Options\ContainerType::SITE

Add new element for data set

addDataSetElement($containerId) : integer
access public

Parameters

$containerId

Returns

integerNew element identifier for data set

Add options container

addDefinition(string $containerId, string $optionId, string $type, string $defaultValue, string $label, integer $optionArray = \KocujIL\V12a\Enums\Project\Components\All\Options\OptionArray::NO, array $arraySettings = array(), array $dataSetSettings = array(), array $additional = array()) : void
todo disallow option id as "option_id" or "option_value"
todo add requirement that "global_foreignkeyforcontainer", "global_ordervalue" or "global_unique" can be set only when "global_searchkey" is set
todo add checking if "global_ordervalue" is only for one option in container
access public

Parameters

$containerId

string

Options container identifier

$optionId

string

Option identifier

$type

string

Option type

$defaultValue

string

Option default value

$label

string

Option label

$optionArray

integer

Option is array or standard; must be one of the following constants from \KocujIL\V12a\Enums\Project\Components\All\Options\OptionArray: NO (when it is standard option) or YES (when it is array option) - default: \KocujIL\V12a\Enums\Project\Components\All\Options\OptionArray::NO

$arraySettings

array

Array settings if $optionArray is set to \KocujIL\V12a\Enums\Project\Components\All\Options\OptionArray::YES - default: empty

$dataSetSettings

$additional

arrayarray

Data set settings for option; each options type can use different data set settings; there are the following data set settings which can be always used: "global_foreignkeyforcontainer" (string type; name of container for which this option is foreign key, so selected value can be only from available values in column "option_id" in the selected container; it works only if "global_searchkey" is set to true), "global_ordervalue" (bool type; if container is for data set and it is set to true, this value will be used for default ordering the elements list), "global_searchkey" (bool type; if container is for data set and it is set to true, there will be an additional column with option value for this definition), "global_unique" (bool type; if container is for data set and it is set to true, this field will be checked if its value is unique in data set; it works only if "global_searchkey" is set to true) - default: empty

Add options type

addType(string $optionType, array|string $callbackDefaultValue = NULL, array|string $callbackValidation = NULL, integer $typeLengthSupport = \KocujIL\V12a\Enums\Project\Components\All\Options\TypeLengthSupport::NO, integer $typeFormat = \KocujIL\V12a\Enums\Project\Components\All\Options\TypeFormat::TEXT) : void
access public

Parameters

$optionType

string

Options type

$callbackDefaultValue

arraystring

Callback function or method name for default value of option; can be global function or method from any class; if empty, no callback will be used - default: NULL

$callbackValidation

arraystring

Callback function or method name for validation of option; can be global function or method from any class; if empty, no callback will be used - default: NULL

$typeLengthSupport

integer

Minimum and maximum length is supported or not; must be one of the following constants from \KocujIL\V12a\Enums\Project\Components\All\Options\TypeLengthSupport: NO (when length limits are not supported) or YES (when length limits are supported) - default: \KocujIL\V12a\Enums\Project\Components\All\Options\TypeLengthSupport::NO

$typeFormat

integer

Format of value; must be one of the following constants from \KocujIL\V12a\Enums\Project\Components\All\Options\TypeFormat: TEXT (when format is text), NUMBER_INT (when format is int number) or NUMBER_FLOAT (when format is float number) - default: \KocujIL\V12a\Enums\Project\Components\All\Options\TypeFormat::TEXT

Check if options container exists

checkContainer(string $id) : boolean
access public

Parameters

$id

string

Options container identifier

Returns

booleanOptions container exists (true) or not (false)

Check data set element identifier

checkDataSetElementId(string $containerId, integer $dataSetElementId) : boolean
access public

Parameters

$containerId

string

Options container identifier

$dataSetElementId

integer

Data set element identifier

Returns

booleanElement identifier exists in data set (true) or not (false)

Check if option definition exists

checkDefinition(string $containerId, string $optionId) : boolean
access public

Parameters

$containerId

string

Options container identifier

$optionId

string

Option definition identifier

Returns

booleanOption definition exists (true) or not (false)

Check if options type exists

checkType(string $id) : boolean
access public

Parameters

$id

string

Options type identifier

Returns

booleanOptions type exists (true) or not (false)

Get all options values

getAllOptions(string $containerId, $dataSetElementId = 0) : array
access public

Parameters

$containerId

string

Option container identifier

$dataSetElementId

Returns

arrayOptions values

Get object of class type from component

getComponent(string $type, integer $projectCategory = \KocujIL\V12a\Enums\ProjectCategory::CORE, string $fragment = '') : object
Inherited
access public

Parameters

$type

string

Component type

$projectCategory

integer

Component category; must be one of the following constants from \KocujIL\V12a\Enums\ProjectCategory: CORE (for "core" category), ALL (for "all" category), FRONTEND (for "frontend" category) or BACKEND (for "backend" category) - default: \KocujIL\V12a\Enums\ProjectCategory::CORE

$fragment

string

Component fragment - default: empty

Returns

objectObject of class type from component

Get options container data by id

getContainer(string $id) : array | boolean
access public

Parameters

$id

string

Options container identifier

Returns

arraybooleanOptions container data or false if not exists; options container data have the following fields: "autoload" (bool type; if true, options container will be loaded automatically), "dbkey" (string type; database key for options container), "tablename" (string type; table name in database for data set options), "type" (int type; options container is automatic, for network or for site)

Get options containers data

getContainers() : array
access public

Returns

arrayOptions containers data; each options container data has the following fields: "autoload" (bool type; if true, options container will be loaded automatically), "dbkey" (string type; database key for options container), "tablename" (string type; table name in database for data set options), "type" (int type; options container is automatic, for network or for site)

Get elements from data set

getDataSetElements(string $containerId, array $searchValues = array(), string $orderBy = '', integer $order = \KocujIL\V12a\Enums\Project\Components\All\Options\Order::ASC, integer $count = 1, integer $from = 0) : array
access public

Parameters

$containerId

string

Option container identifier

$searchValues

array

If options are for data set, these are options keys and values by which data will be searched - default: empty

$orderBy

string

Option by which results will be sorted - default: empty

$order

integer

Order of sorting; must be one of the following constants from \KocujIL\V12a\Enums\Project\Components\All\Options\Order: ASC (when order is ascendand) or DESC (when order is descendant) - default: \KocujIL\V12a\Enums\Project\Components\All\Options\Order::ASC

$count

integer

How many elements should be returned; if it set to 0, all elements will be get - default: 1

$from

integer

From which element data should be returned - default: 0

Returns

arrayOptions values for each founded element

Get elements count for data set

getDataSetElementsCount(string $containerId, array $searchValues = array()) : array
access public

Parameters

$containerId

string

Option container identifier

$searchValues

array

If options are for data set, these are options keys and values by which data will be searched - default: empty

Returns

arrayOptions values for each founded element

Get option definition data by id

getDefinition(string $containerId, string $optionId) : array | boolean
access public

Parameters

$containerId

string

Options container identifier

$optionId

string

Option definition identifier

Returns

arraybooleanOption definition data or false if not exists; option definition data have the following fields: "additional" (array type; additional settings for option), "arraymode" (int type; set if option is standard or array), "arraysettings" (array type; settings for option if it is an array), "datasetsettings" (array type; data set settings for option), "defaultvalue" (string type; option default value), "label" (string type; option label), "type" (string type; option type)

Get options definitions data

getDefinitions(string $containerId) : array
access public

Parameters

$containerId

string

Options container identifier

Returns

arrayOptions definitions data; each option definition data has the following fields: "additional" (array type; additional settings for option), "arraymode" (int type; set if option is standard or array), "arraysettings" (array type; settings for option if it is an array), "datasetsettings" (array type; data set settings for option), "defaultvalue" (string type; option default value), "label" (string type; option label), "type" (string type; option type)

Get option value

getOption(string $containerId, string $optionId, integer $dataSetElementId = 0) : string
access public

Parameters

$containerId

string

Option container identifier

$optionId

string

Option identifier

$dataSetElementId

integer

Data set element identifier - default: 0

Returns

stringOption value

Get object of type \KocujIL\V12a\Classes\Project

getProjectObj() : object
Inherited
access public

Returns

objectObject of type \KocujIL\V12a\Classes\Project

Get object of class type for strings from component

getStrings(string $type, integer $projectCategory = \KocujIL\V12a\Enums\ProjectCategory::CORE) : object
Inherited
access public

Parameters

$type

string

Component type

$projectCategory

integer

Component category; must be one of the following constants from \KocujIL\V12a\Enums\ProjectCategory: CORE (for "core" category), ALL (for "all" category), FRONTEND (for "frontend" category) or BACKEND (for "backend" category) - default: \KocujIL\V12a\Enums\ProjectCategory::CORE

Returns

objectObject of class type for strings from component

Get options type data by id

getType(string $id) : array | boolean
access public

Parameters

$id

string

Options type identifier

Returns

arraybooleanOptions type data or false if not exists; options type data have the following fields: "defaultvalue" (array or string type; callback for default value of option), "format" (int type; information about format), "lengthsupport" (int type; information is minimum and maximum length is supported for this options type), "validation" (array or string type; callback for validation of option)

Get options types data

getTypes() : array
access public

Returns

arrayOptions types data; each options types data has the following fields: "defaultvalue" (array or string type; callback for default value of option), "format" (int type; information about format), "lengthsupport" (int type; information is minimum and maximum length is supported for this options type), "validation" (array or string type; callback for validation of option)

Load container for widget

loadContainerForWidget(string $containerId, array $options) : void
access public

Parameters

$containerId

string

Option container identifier

$options

array

Options

Remove all containers from database

removeAllContainersFromDb() : void
access public

Remove container

removeContainer(string $id) : void
access public

Parameters

$id

string

Container identifier

Remove container from database

removeContainerFromDb(string $containerId) : void
access public

Parameters

$containerId

string

Option container identifier

Remove data set element identifier

removeDataSetElement(string $containerId, integer $dataSetElementId) : void
todo when removing other elements with foreign key set to current container, do not remove entire cache for this container from memory, but only deleted elements
access public

Parameters

$containerId

string

Options container identifier

$dataSetElementId

integer

Data set element identifier

Remove option definition

removeDefinition(string $containerId, string $optionId) : void
access public

Parameters

$containerId

string

Options definition identifier

$optionId

string

Option identifier

Remove type

removeType(string $id) : void
access public

Parameters

$id

string

Type identifier

Set option value

setOption(string $containerId, string $optionId, string $optionValue, integer $dataSetElementId = 0) : boolean
access public

Parameters

$containerId

string

Option container identifier

$optionId

string

Option identifier

$optionValue

string

Option value

$dataSetElementId

integer

Data set element identifier - default: 0

Returns

booleanOptions has been set correctly (true) or not (false)

Set option value and return text with status

setOptionWithReturnedText(string $containerId, string $optionId, string $optionValue, $outputText, integer $dataSetElementId = 0) : boolean
access public

Parameters

$containerId

string

Option container identifier

$optionId

string

Option identifier

$optionValue

string

Option value

$outputText

$dataSetElementId

integer

Data set element identifier - default: 0

Returns

booleanOptions has been set correctly (true) or not (false)

Update all containers in database

updateAllContainersInDb() : void
access public

Update container in database; if it is data set, only loaded elements will be updated

updateContainerInDb(string $containerId) : void
access public

Parameters

$containerId

string

Option container identifier

Change container type to area

changeContainerTypeToArea(integer $containerType) : integer
access private

Parameters

$containerType

integer

Options container type; must be one of the following constants from \KocujIL\V12a\Enums\Project\Components\All\Options\ContainerType: NETWORK_OR_SITE (for network - in multisite installation - or site - in standard installation - type), SITE (for site type), NETWORK (for network type) or WIDGET (for widget type) - default: \KocujIL\V12a\Enums\Project\Components\All\Options\ContainerType::SITE

Returns

integerArea type

Change options based on options definitions

changeOptionsByDefinitions(string $containerId, boolean $force = false, integer $dataSetElementId = 0) : void
access private

Parameters

$containerId

string

Options container identifier

$force

boolean

Force changing options (true) or not (false)

$dataSetElementId

integer

Data set element identifier - default: 0

Get elements or elements count from data set

getDataSetElementsOrCount(boolean $getElements, string $containerId, array $searchValues = array(), string $orderBy = '', integer $order = \KocujIL\V12a\Enums\Project\Components\All\Options\Order::ASC, integer $count = 1, integer $from = 0) : array | integer
access private

Parameters

$getElements

boolean

Get element (true) or elements count (false)

$containerId

string

Option container identifier

$searchValues

array

If options are for data set, these are options keys and values by which data will be searched - default: empty

$orderBy

string

Option by which results will be sorted - default: empty

$order

integer

Order of sorting; must be one of the following constants from \KocujIL\V12a\Enums\Project\Components\All\Options\Order: ASC (when order is ascendand) or DESC (when order is descendant) - default: \KocujIL\V12a\Enums\Project\Components\All\Options\Order::ASC

$count

integer

How many elements should be returned; if it set to 0, all elements will be get - default: 1

$from

integer

From which element data should be returned - default: 0

Returns

arrayintegerOptions values for each founded element or elements count

Load options from database if needed

loadOptionsFromDbIfNeeded(string $containerId, integer $dataSetElementId = 0) : void
access private

Parameters

$containerId

string

Options container identifier

$dataSetElementId

integer

Data set element identifier - default: 0

Callback for option default value - checkbox

typeDefaultValueCheckbox(object $componentObj, string $defaultOptionValue, array $additional) : string
Static
access private

Parameters

$componentObj

object

Object with this component

$defaultOptionValue

string

Default option value

$additional

array

Additional settings for option

Returns

stringParsed default option value

Callback for option default value - integer or float

typeDefaultValueIntegerOrFloat(object $componentObj, string $defaultOptionValue, array $additional) : string
Static
access private

Parameters

$componentObj

object

Object with this component

$defaultOptionValue

string

Default option value

$additional

array

Additional settings for option; there are the following additional settings which can be used: "global_maxvalue" (int type; maximum value of number), "global_minvalue" (int type; minimal value of number)

Returns

stringParsed default option value

Callback for option validation - checkbox

typeValidationCheckbox(object $componentObj, string $containerId, string $optionId, integer $optionArray, string $optionValue, array $additional) : string
Static
access private

Parameters

$componentObj

object

Object with this component

$containerId

string

Option container identifier

$optionId

string

Option container identifier

$optionArray

integer

Option is array or standard; must be one of the following constants from \KocujIL\V12a\Enums\Project\Components\All\Options\OptionArray: NO (when it is standard option) or YES (when it is array option)

$optionValue

string

Option value

$additional

array

Additional settings for option

Returns

stringOutput text if there was an error or empty string if option value has been validated correctly

Callback for option validation - float

typeValidationFloat(object $componentObj, string $containerId, string $optionId, integer $optionArray, string $optionValue, array $additional) : string
Static
access private

Parameters

$componentObj

object

Object with this component

$containerId

string

Option container identifier

$optionId

string

Option container identifier

$optionArray

integer

Option is array or standard; must be one of the following constants from \KocujIL\V12a\Enums\Project\Components\All\Options\OptionArray: NO (when it is standard option) or YES (when it is array option)

$optionValue

string

Option value

$additional

array

Additional settings for option; there are the following additional settings which can be used: "maxvalue" (int type; maximum value of number), "minvalue" (int type; minimal value of number)

Returns

stringOutput text if there was an error or empty string if option value has been validated correctly

Option validation callback helper - integer or float

typeValidationHelperIntegerOrFloat(object $componentObj, string $containerId, string $optionId, integer $optionArray, string $optionValue, array $additional, boolean $mustBeInteger) : string
Static
access private

Parameters

$componentObj

object

Object with this component

$containerId

string

Option container identifier

$optionId

string

Option container identifier

$optionArray

integer

Option is array or standard; must be one of the following constants from \KocujIL\V12a\Enums\Project\Components\All\Options\OptionArray: NO (when it is standard option) or YES (when it is array option)

$optionValue

string

Option value

$additional

array

Additional settings for option; there are the following additional settings which can be used: "maxvalue" (int type; maximum value of number), "minvalue" (int type; minimal value of number)

$mustBeInteger

boolean

Value must be integer (true) or not (false)

Returns

stringOutput text if there was an error or empty string if option value has been validated correctly

Callback for option validation - integer

typeValidationInteger(object $componentObj, string $containerId, string $optionId, integer $optionArray, string $optionValue, array $additional) : string
Static
access private

Parameters

$componentObj

object

Object with this component

$containerId

string

Option container identifier

$optionId

string

Option container identifier

$optionArray

integer

Option is array or standard; must be one of the following constants from \KocujIL\V12a\Enums\Project\Components\All\Options\OptionArray: NO (when it is standard option) or YES (when it is array option)

$optionValue

string

Option value

$additional

array

Additional settings for option; there are the following additional settings which can be used: "maxvalue" (int type; maximum value of number), "minvalue" (int type; minimal value of number)

Returns

stringOutput text if there was an error or empty string if option value has been validated correctly

 Properties

 

Options containers

$containers : array

Default

array()
access private
 

Flag for data set table creation now

$dataSetTableCreatedNow : boolean

Default

false
access private
 

Options definitions

$definitions : array

Default

array()
access private
 

Options

$options : array

Default

array()
access private
 

\KocujIL\V12a\Classes\Project object for current project

$projectObj : object

Default

NULL
access private
 

Options types

$types : array

Default

array()
access private