2017 © Pedro Peláez
 

modxevo-library-ddtools modxevo-library-ddtools

A library with various tools facilitating your work.

image

dd/modxevo-library-ddtools

A library with various tools facilitating your work.

  • Tuesday, June 26, 2018
  • by dd
  • Repository
  • 3 Watchers
  • 1 Stars
  • 101 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 33 Versions
  • 0 % Grown

The README.md

(MODX)EvolutionCMS.libraries.ddTools

A library with various tools facilitating your work., (*1)

Requires

Installation

Manually

  1. Create a new folder assets/libs/ddTools/.
  2. Extract the archive to the folder.

Using Composer

Just add dd/evolutioncms-libraries-ddtools to your composer.json., (*2)

ddTools version must be 0.14 or higher to use this method. If you use it, the compatibility with all your snippets, modules, etc. that use ddTools versions under 0.14 will be maintained., (*3)

Update using (MODX)EvolutionCMS.libraries.ddInstaller

Just run the following PHP code in your sources or Console:, (*4)

//Include (MODX)EvolutionCMS.libraries.ddInstaller
require_once(
    $modx->getConfig('base_path') .
    'assets/libs/ddInstaller/require.php'
);

//Update (MODX)EvolutionCMS.libraries.ddTools
\DDInstaller::install([
    'url' => 'https://github.com/DivanDesign/EvolutionCMS.libraries.ddTools',
    'type' => 'library'
]);
  • If ddTools is already exist on your site, ddInstaller will check it version and update it if needed.
  • If ddTools is not exist on your site, ddInstaller can't do anything because requires it for itself.

Parameters description

\ddTools::convertUrlToAbsolute($params)

Converts relative URLs to absolute., (*5)

The method tends to change URL as little as possible and just prepends required scheme and/or host (or sometimes nothing at all). All kinds of query parameters, hash, ports, etc. are not modified., (*6)

  • $params, (*7)

    • Desctription: Parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Required
  • $params->url, (*8)

    • Desctription: Source URL. Can be set as:
      • 'some/url' — relative
      • '/some/url' — relative starting with slash
      • 'example.com/some/url' — absolute starting with domain
      • '//example.com/some/url' — absolute starting with double slash
      • 'https://example.com/some/url' — absolute starting with scheme
    • Valid values: string
    • Required
  • $params->host, (*9)

    • Desctription: Host for the result URL.
    • Valid values: string
    • Default value: $_SERVER['HTTP_HOST']
  • $params->scheme, (*10)

    • Desctription: Scheme for the result URL.
    • Valid values: string
    • Default value: 'https' or 'http' depending on $_SERVER['HTTPS']

Returns

  • $result
    • Desctription: Source URL converted to absolute. Always contains scheme.
    • Valid values: string

\ddTools::getTpl($tpl = '')

The same as $modx->getTpl with some differences: * This method always returns string regardless of the parameter type. For example, $modx->getTpl(null) returns null, this method returns ''. * The parameter is optional. $modx->getTpl() throws an error, this method jsut returns ''. * $modx->getTpl('@CODE:') returns '@CODE:', this method returns ''., (*11)

  • $tpl
    • Desctription: Chunk name or inline template.
    • Valid values:
      • stringChunkName
      • string — use inline templates starting with @CODE:
    • Default value: ''

Returns

  • $result
    • Desctription: Required template.
    • Valid values: string

\ddTools::parseText($params)

Replaces placeholders in a text with required values. Like $modx->parseChunk, but takes a text and has some features., (*12)

  • $params, (*13)

    • Desctription: Parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Required
  • $params->text, (*14)

    • Desctription: String to parse.
    • Valid values: string
    • Required
  • $params->data, (*15)

    • Desctription: The array of additional data has to be replaced in $params->text.
      Nested objects and arrays are supported too:
      • {"someOne": "1", "someTwo": "test" } => [+someOne+], [+someTwo+].
      • {"some": {"a": "one", "b": "two"} } => [+some.a+], [+some.b+].
      • {"some": ["one", "two"] } => [+some.0+], [+some.1+].
    • Valid values:
      • arrayAssociative
      • stdClass
      • stringJsonObject — as JSON
      • stringHjsonObject — as HJSON
      • stringQueryFormatted — as Query string
    • Default value: []
  • $params->data->{$key}, (*16)

    • Valid values: Key is placeholder name, value is value.
      • string
      • array
      • object
    • Required
  • $params->placeholderPrefix, (*17)

    • Desctription: Placeholders prefix.
    • Valid values: string
    • Default value: '[+'
  • $params->placeholderSuffix, (*18)

    • Desctription: Placeholders suffix.
    • Valid values: string
    • Default value: '+]'
  • $params->removeEmptyPlaceholders, (*19)

    • Desctription: Do you need to remove empty placeholders?
    • Valid values: boolean
    • Default value: false
  • $params->mergeAll, (*20)

    • Desctription: Additional parsing of document fields, settings, chunks.
    • Valid values: boolean
    • Default value: true

Returns

  • $result
    • Desctription: Parsed text.
    • Valid values: string

\ddTools::verifyRenamedParams($params)

The method checks an array for deprecated parameters and writes warning messages into the MODX event log. It returns an associative array, in which the correct parameter names are the keys and the parameter values are the values. You can use the exctract function to turn the array into variables of the current symbol table., (*21)

  • $params, (*22)

    • Desctription: Parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Required
  • $params->params, (*23)

    • Desctription: The associative array of the parameters of a snippet, in which the parameter names are the keys and the parameter values are the values.
      You can directly pass here the $params variable if you call the method inside of a snippet.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Required
  • $params->compliance, (*24)

    • Desctription: An array (or object) of correspondence between new parameter names and old ones, in which the new names are the keys and the old names are the values.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Required
  • $params->compliance->{$newName}, (*25)

    • Desctription: The old name(s). Use a string for a single name or an array for multiple.
    • Valid values:
      • string
      • array
    • Required
  • $params->compliance->{$newName}[i], (*26)

    • Desctription: One of the old names.
    • Valid values: string
    • Required
  • $params->returnCorrectedOnly, (*27)

    • Desctription: Need to return only corrected parameters?
    • Valid values: boolean
    • Default value: true
  • $params->writeToLog, (*28)

    • Desctription: Write a warning message about deprecated parameters to the CMS event log.
    • Valid values: boolean
    • Default value: true

Returns

  • $result, (*29)

    • Desctription: An array or object, in which the correct parameter names are the keys and the parameter values are the values.
      Can contains all parameters or only corrected (see $params->returnCorrectedOnly).
    • Valid values:
      • arrayAssociative — if $params->params set as an array
      • stdClass — if $params->params set as an object
  • $result[$newName], (*30)

    • Desctription: A parameter value, in which the correct parameter name is the key and the parameter value is the value.
    • Valid values: mixed

\DDTools\FilesTools

\DDTools\FilesTools::modifyImage($params)

Modify your images: create thumbnails, crop, resize, fill background color or add watermark., (*31)

  • $params, (*32)

    • Desctription: Parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Required
  • $params->sourceFullPathName, (*33)

    • Desctription: Full file path of source image.
      You can pass a relative path too (e. g. assets/images/some.jpg), the method will automatically add base_path if needed.
    • Valid values: string
    • Required
  • $params->outputFullPathName, (*34)

    • Desctription: Full file path of result image.
      • You can pass a relative path too (e. g. assets/images/some.jpg), the method will automatically add base_path if needed.
      • The original image will be overwritten if this parameter is omitted.
    • Valid values: string
    • Default value: == $params->sourceFullPathName
  • $params->transformMode, (*35)

    • Desctription: Transform mode.
    • Valid values:
      • 'resize' — resize only, the image will be inscribed into the specified sizes with the same proportions
      • 'crop' — crop only
      • 'resizeAndCrop' — resize small side then crop big side to the specified value
      • 'resizeAndFill' — inscribe image into the specified sizes and fill empty space with the specified background (see $params->backgroundColor)
    • Default value: 'resize'
  • $params->width, (*36)

    • Desctription: Result image width.
      In pair width / height only one is required, omitted size will be calculated according to the image proportions.
    • Valid values: integer
    • Required
  • $params->height, (*37)

    • Desctription: Result image height.
      In pair width / height only one is required, omitted size will be calculated according to the image proportions.
    • Valid values: integer
    • Required
  • $params->allowEnlargement, (*38)

    • Desctription: Allow image enlargement when resizing.
    • Valid values: boolean
    • Default value: false
  • $params->backgroundColor, (*39)

    • Desctription: Result image background color in HEX (used only for $params->transformMode == 'resizeAndFill').
    • Valid values: string
    • Default value: FFFFFF
  • $params->allowEnlargement, (*40)

    • Desctription: Allow image enlargement when resizing.
    • Valid values: boolean
    • Default value: false
  • $params->quality, (*41)

    • Desctription: JPEG compression level.
    • Valid values: integer
    • Default value: 100
  • $params->watermarkImageFullPathName, (*42)

    • Desctription: Specify if you want to overlay your image with watermark.
      You can pass a relative path too (e. g. assets/images/some.jpg), the method will automatically add base_path if needed.
    • Valid values: string
    • Default value: —

\DDTools\ObjectTools

\DDTools\ObjectTools::isPropExists($params)

Checks if the object, class or array has a property / element. This is a “syntactic sugar” for checking an element in one way regardless of the “object” type., (*43)

The first reason for creating this method is convenience to not thinking about type of “object” variables. Second, the different order of parameters in the native PHP functions makes us crazy., (*44)

  • $params, (*45)

    • Desctription: Parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Required
  • $params->object, (*46)

    • Desctription: Source object or array.
    • Valid values:
      • stdClass
      • array
    • Required
  • $params->propName, (*47)

    • Desctription: Object property name or array key.
    • Valid values:
      • string
      • integer
    • Required

\DDTools\ObjectTools::getPropValue($params)

Get the value of an object property or an array element in any nesting level in one way regardless of the “object” type., (*48)

  • $params, (*49)

    • Desctription: Parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Required
  • $params->object, (*50)

    • Desctription: Source object or array.
      It can be nested, and elements of all levels can be mix of objects and arrays (see Examples below).
    • Valid values:
      • stdClass
      • array
    • Required
  • $params->propName, (*51)

    • Desctription: Object property name or array key.
      You can also use '.' to get nested properties. Several examples (see also full Examples below):
      • somePlainProp — get first-level property
      • someObjectProp.secondLevelProp — get property of the someObjectProp object|array
      • someArrayProp.0.thirdLevelProp — get property of the zero element of the someArrayProp array
    • Valid values:
      • string
      • integer
    • Required
Returns
  • $result
    • Desctription: Value of an object property or an array element.
    • Valid values:
      • mixed
      • NULL — if property not exists

\DDTools\ObjectTools::convertType($params)

Converts an object type. Arrays, JSON and Query string objects are also supported., (*52)

  • $params, (*53)

    • Desctription: Parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Required
  • $params->object, (*54)

    • Desctription: Input object | array | encoded string.
    • Valid values:
      • stdClass
      • array
      • stringJsonObjectJSON object
      • stringJsonArrayJSON array
      • stringHjsonObjectHJSON object
      • stringHjsonArrayHJSON array
      • stringQueryFormattedQuery string
    • Required
  • $params->type, (*55)

    • Desctription: Type of resulting object.
      Values are case insensitive (the following names are equal: 'stringjsonauto', 'stringJsonAuto', 'STRINGJSONAUTO', etc).
    • Valid values:
      • 'objectAuto' — stdClass or array depends on input object
      • 'objectStdClass'stdClass
      • 'objectArray'array
      • 'stringJsonAuto'stringJsonObject or stringJsonArray depends on input object
      • 'stringJsonObject'
      • 'stringJsonArray'
      • 'stringQueryFormatted'
      • 'stringHtmlAttrs' — HTML attributes string (e. g. width='100' height='50'), boolean values will be converted to 0 or 1 (e. g. data-is-loaded='1'), objects/arrays will be converted to JSON string (e. g. data-user-data='{"firstName": "Elon", "lastName": "Musk"}')
    • Default value: 'objectAuto'
Returns
  • $result
    • Desctription: Result type depends on $params->type.
    • Valid values:
      • stdClass
      • array
      • stringJsonObject
      • stringJsonArray

\DDTools\ObjectTools::extend($params)

Merge the contents of two or more objects or arrays together into the first one., (*56)

  • $params, (*57)

    • Desctription: Parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Required
  • $params->objects, (*58)

    • Desctription: Objects or arrays to merge. Moreover, objects can extend arrays and vice versa.
    • Valid values: array
    • Required
  • $params->objects[0], (*59)

    • Desctription: The object or array to extend. It will receive the new properties.
    • Valid values:
      • object
      • array
      • mixed — if passed something else, the new stdClass object will be created instead
    • Required
  • $params->objects[i], (*60)

    • Desctription: An object or array containing additional properties to merge in.
    • Valid values:
      • object
      • array
    • Required
  • $params->deep, (*61)

    • Desctription: If true, the merge becomes recursive (aka. deep copy).
    • Valid values: boolean
    • Default value: true
  • $params->overwriteWithEmpty, (*62)

    • Desctription: Overwrite fields with empty values (see examples below).
      The following values are considered to be empty:
      • '' — an empty string
      • [] — an empty array
      • (object) [] — an empty object
      • NULL
    • Valid values: boolean
    • Default value: true

\DDTools\ObjectTools::unfold($params)

Converts a multidimensional array/object into an one-dimensional one joining the keys with $params->keySeparator. For example, it can be helpful while using placeholders like [+size.width+]., (*63)

  • $params, (*64)

    • Desctription: Parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Required
  • $params->object, (*65)

    • Desctription: An object/array to convert.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Required
  • $params->keySeparator, (*66)

    • Desctription: Separator between nested keys in the result object/array.
    • Valid values: string
    • Default value: '.'
  • $params->keyPrefix, (*67)

    • Desctription: Prefix of the keys of an object/array (it's an internal varible, but can be used if required).
    • Valid values: string
    • Default value: ''
Returns
  • $result
    • Desctription: Unfolded object/array. Type of results depends on $params->object.
    • Valid values:
      • stdClass
      • array

\DDTools\ObjectCollection

Class representing a collection of some objects or arrays., (*68)

\DDTools\ObjectCollection::__construct($params)

  • $params, (*69)

    • Desctription: Parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Default value: —
  • $params->items, (*70)

    • Desctription: An array of items.
      You can avoid this parameter to create an empty collection and set items later.
    • Valid values:
      • array — can be indexed or associative, keys will not be used
      • object — also can be set as an object for better convenience, only property values will be used
      • stringJsonObjectJSON object
      • stringJsonArrayJSON array
      • stringHjsonObjectHJSON object
      • stringHjsonArrayHJSON array
      • stringQueryFormattedQuery string
    • Default value: —
  • $params->items[$itemIndex], (*71)

    • Desctription: An item.
    • Valid values:
      • array — indexed arrays are supported as well as associative
      • object
    • Required
  • $params->itemType, (*72)

    • Desctription: Allows to convert item type. If set, each item of $params->items will be converted to needed type.
      Values are case insensitive (the following names are equal: 'objectstdclass', 'objectStdClass', 'OBJECTSTDCLASS', etc).
    • Valid values:
      • 'objectStdClass'
      • 'objectArray'
      • null — do not convert type of items, use them as is
    • Default value: null

\DDTools\ObjectCollection::setItems($params)

Sets new collection items. Existing items will be removed., (*73)

Has the same parameters as \DDTools\ObjectCollection::__construct($params)., (*74)

\DDTools\ObjectCollection::addItems($params)

Appends items onto the end of collection., (*75)

Has the same parameters as \DDTools\ObjectCollection::__construct($params)., (*76)

\DDTools\ObjectCollection::getItems($params)

Gets an array of required collection items., (*77)

  • $params, (*78)

    • Desctription: Parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Default value: —
  • $params->filter, (*79)

    • Desctription: Filter clause for item properties.
      • Thus, ' "gender" == "female" || "gender" == "male" && "firstName" != "Bill" && "lastName" ' returns:
        • All items with the gender property equal to 'female'.
        • All items:
          • with the gender property equal to 'male' and
          • with the firstName property not equal to 'Bill' and
          • with the lastName property is exist with any value.
      • Quoted property names and values are optional, this is valid too: ' gender == female || gender == male && firstName != Bill && lastName '
      • Single quotes are also supported as double quotes: " gender == 'a' || gender == 'b' && firstName != 'Bill' && lastName "
      • Spaces, tabs and line breaks are optional, this is valid too: gender==female||gender==male&&firstName!=Bill&&lastName.
    • Valid values: stringSeparated
    • Default value: '' (without filtration)
  • $params->limit, (*80)

    • Desctription: Maximum number of items to return.
    • Valid values:
      • integer
      • 0 — all matching items
    • Default value: 0
  • $params->propAsResultKey, (*81)

    • Desctription: Item property, which value will be an item key in result array instead of an item index.
      For example, it can be useful if items have an ID property or something like that.
    • Valid values:
      • string
      • null — result array will be indexed
    • Default value: null
  • $params->propAsResultValue, (*82)

    • Desctription: Item property, which value will be an item value in result array instead of an item object.
    • Valid values:
      • string
      • null — result array values will item objects
    • Default value: null
Returns
  • $result, (*83)

    • Desctription: An array of items.
    • Valid values:
      • arrayIndexed
      • arrayAssociative — item property values will be used as result keys if $params->propAsResultKey is set
  • $result[$itemIndex|$itemFieldValue], (*84)

    • Desctription: An item object or item property value if specified in $params->propAsResultValue.
    • Valid values: mixed

\DDTools\ObjectCollection::getOneItem($params)

Gets required item., (*85)

  • $params, (*86)

    • Desctription: Parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Default value: —
  • $params->filter, (*87)

    • Desctription: Filter clause for item properties. The same parameter as \DDTools\ObjectCollection::getItems($params).
    • Valid values: stringSeparated
    • Default value: '' (first found item will be returned)
  • $params->notFoundResult, (*88)

    • Desctription: What will be returned when no items found.
    • Valid values: mixed
    • Default value: null

\DDTools\ObjectCollection::count()

Counts all items., (*89)

\DDTools\ObjectCollection::convertItemsType($params)

Converts type of needed items in collection., (*90)

  • $params, (*91)

    • Desctription: Parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Default value: —
  • $params->itemType, (*92)

    • Desctription: Result item type.
      Values are case insensitive (the following names are equal: 'objectstdclass', 'objectStdClass', 'OBJECTSTDCLASS', etc).
    • Valid values:
      • 'objectStdClass'
      • 'objectArray'
    • Required
  • $params->filter, (*93)

    • Desctription: Filter clause for item properties. The same parameter as \DDTools\ObjectCollection::getItems($params).
    • Valid values: stringSeparated
    • Default value: '' (all items will be converted)

\DDTools\ObjectCollection::updateItems($params)

Undates properties of existing items with new values., (*94)

  • $params, (*95)

    • Desctription: Parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Required
  • $params->data, (*96)

    • Desctription: New item data. Existing item will be extended by this data, it means:
      • Type of existing item will not be changed.
      • All given property values will overwrite existing.
      • Non-existing given properties will be created.
      • Existing properties that absent in $params->data will remain as is.
    • Valid values:
      • array
      • object
    • Required
  • $params->filter, (*97)

    • Desctription: Filter clause for item properties. The same parameter as \DDTools\ObjectCollection::getItems($params).
    • Valid values: stringSeparated
    • Default value: '' (any items will be updated)
  • $params->limit, (*98)

    • Desctription: Maximum number of items can be updated.
    • Valid values:
      • integer
      • 0 — all matching items
    • Default value: 0

\DDTools\ObjectCollection::deleteItems($params)

Deletes required items from collection., (*99)

  • $params, (*100)

    • Desctription: Parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Default value: —
  • $params->filter, (*101)

    • Desctription: Filter clause for item properties. The same parameter as \DDTools\ObjectCollection::getItems($params).
    • Valid values: stringSeparated
    • Default value: '' (any items will be deleted)
  • $params->limit, (*102)

    • Desctription: Maximum number of items can be deleted.
    • Valid values:
      • integer
      • 0 — all matching items
    • Default value: 0

\DDTools\ObjectCollection::toJSON(), \DDTools\ObjectCollection::__toString()

Gets an JSON-array of all collection items., (*103)

Returns
  • $result
    • Desctription: An JSON-array of items.
    • Valid values: stringJsonArray

\DDTools\ObjectCollection::setOneItemData (protected)

Sets data of an item object. All setting of an item data inside the class must be use this method. It's convenient to override this method in child classes if items are not plain objects., (*104)

  • $params, (*105)

    • Desctription: Parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Required
  • $params->itemIndex, (*106)

    • Desctription: Item index which data will be set.
    • Valid values: integer
    • Required
  • $params->itemData, (*107)

    • Desctription: New item data.
    • Valid values:
      • array — indexed arrays are supported as well as associative
      • object
    • Required

\DDTools\ObjectCollection::getOneItemData (protected)

Returns data of an item object. All getting of an item data inside the class must use this method. It's convenient to override this method in child classes if items are not plain objects., (*108)

  • $params, (*109)

    • Desctription: Parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Required
  • $params->itemObject, (*110)

    • Desctription: An item object which data will be returned.
    • Valid values:
      • array — indexed arrays are supported as well as associative
      • object
    • Required
Returns
  • $result
    • Desctription: Data of an item object.
    • Valid values:
      • array
      • object

\DDTools\Base\Base

Simple abstract class with some small methods facilitating your work. It is convenient to inherit your classes from this., (*111)

You can see an example of how it works in the (MODX)EvolutionCMS.snippets.ddGetDocumentField code., (*112)

\DDTools\Base\Base::setExistingProps($props)

Sets existing object properties., (*113)

  • $props, (*114)

    • Desctription: The object properties.
      • The method sets all existing properties: public, private or protected — it doesn't matter, exactly what you pass will be set.
      • No problem if If some properties are not exist, the method just skip them without errors.
    • Valid values:
      • arrayAssociative
      • object
      • It can also be set as an object-like string:
    • Required
  • $props->{$propName}, (*115)

    • Desctription: Key is the property name, value is the property value.
    • Valid values: mixed
    • Required

\DDTools\Base\Base::toArray()

Returns all properties of this object as an associative array independent of their visibility., (*116)

Returns
  • $result, (*117)

    • Desctription: An associative array representation of this object.
      The method returns all existing properties: public, private and protected.
    • Valid values: arrayAssociative
  • $result[$propName], (*118)

    • Desctription: The key is the object field name and the value is the object field value.
    • Valid values: mixed

\DDTools\Base\Base::toJSON()

Returns all properties of this object as an JSON string independent of their visibility., (*119)

Returns
  • $result, (*120)

    • Desctription: An JSON string representation of this object.
      The method returns all existing properties: public, private and protected.
    • Valid values:
      • stringJsonObject
      • stringJsonArray — if $this->toArray returns indexed array
  • $result->{$propName}, (*121)

    • Desctription: The key is the object field name and the value is the object field value.
    • Valid values: mixed

\DDTools\Base\Base::__toString()

The same as \DDTools\Base\Base::toJSON()., (*122)

\DDTools\Base\AncestorTrait

Simple trait for ancestors with some small methods facilitating your work., (*123)

You can see an example of how it works in the (MODX)EvolutionCMS.snippets.ddGetDocumentField code., (*124)

\DDTools\Base\AncestorTrait::createChildInstance($params)

  • $params, (*125)

    • Desctription: Parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Required
  • $params->name, (*126)

    • Desctription: Class name.
    • Valid values: string
    • Required
  • $params->params, (*127)

    • Desctription: Params to be passed to object constructor.
    • Valid values:
      • stdClass
      • arrayAssociative
    • Default value: []
  • $params->parentDir, (*128)

    • Desctription: Directory of the parent file (e. g. __DIR__).
    • Valid values: string
    • Default value: — (dirname of a class that uses this trait)
  • $params->capitalizeName, (*129)

    • Desctription: Need to capitalize child name?
    • Valid values: boolean
    • Default value: true
Returns
  • $result
    • Desctription: The new object instance.
    • Valid values: object

\DDTools\Snippet

Abstract class for snippets., (*130)

Properties

  • \DDTools\Snippet::$name, (*131)

    • Desctription: Snippet name (e. g. ddGetDocuments).
      Will be set from namespace in \DDTools\Snippet::__construct($params).
      You can use it inside child classes: $this->name.
    • Valid values: string
    • Visibility: protected
  • \DDTools\Snippet::$version, (*132)

    • Desctription: Snippet version.
      You must define it in your child class declaration.
    • Valid values: string
    • Visibility: protected
  • \DDTools\Snippet::$paths, (*133)

    • Desctription: Snippet paths.
      Will be set in \DDTools\Snippet::__construct($params).
    • Valid values: stdClass
    • Visibility: protected
  • \DDTools\Snippet::$paths->snippet, (*134)

    • Desctription: Full path to the snippet folder.
    • Valid values: string
  • \DDTools\Snippet::$paths->src, (*135)

    • Desctription: Ful path to the src folder.
    • Valid values: string
  • \DDTools\Snippet::$params, (*136)

    • Desctription: Snippet params.
      Will be set in \DDTools\Snippet::__construct($params).
      You can define default values of parameters as associative array in this field of your child class (e. g. protected $params = ['someParameter' => 'valueByDefault'];);.
    • Valid values: stdClass
    • Visibility: protected
  • \DDTools\Snippet::$params->{$paramName}, (*137)

    • Desctription: Key is parameter name, value is value.
    • Valid values: mixed
  • \DDTools\Snippet::$paramsTypes, (*138)

    • Desctription: Overwrite in child classes if you want to convert some parameters types.
      Parameters types will be converted respectively with this field in \DDTools\Snippet::prepareParams.
    • Valid values: arrayAssociative
    • Visibility: protected
  • \DDTools\Snippet::$paramsTypes[$paramName], (*139)

    • Desctription: The parameter type.
      Values are case insensitive (the following names are equal: 'stringjsonauto', 'stringJsonAuto', 'STRINGJSONAUTO', etc).
    • Valid values:
      • 'integer'
      • 'boolean'
      • 'objectAuto'
      • 'objectStdClass'
      • 'objectArray'
      • 'stringJsonAuto'
      • 'stringJsonObject'
      • 'stringJsonArray'
    • Visibility: protected
  • \DDTools\Snippet::$renamedParamsCompliance, (*140)

    • Desctription: Overwrite in child classes if you want to rename some parameters with backward compatibility (see $params->compliance of \ddTools::verifyRenamedParams).
    • Valid values: arrayAssociative
    • Visibility: protected

\DDTools\Snippet::__construct($params)

  • $params, (*141)

    • Desctription: Snippet parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
      • stringJsonObject
      • stringQueryFormatted
    • Default value: []
  • $params->{$paramName}, (*142)

    • Desctription: Key is parameter name, value is value.
    • Valid values: mixed
    • Required

\DDTools\Snippet::run()

Abstract method for main snippet action., (*143)

You must define it in your child class declaration., (*144)

\DDTools\Snippet::runSnippet($params)

Static method for easy running needed snippet using only it's name and parameters (if needed)., (*145)

  • $params, (*146)

    • Desctription: Snippet parameters, the pass-by-name style is used.
    • Valid values:
      • stdClass
      • arrayAssociative
      • stringJsonObject
      • stringQueryFormatted
    • Required
  • $params->name, (*147)

    • Desctription: The name of the snippet you want to run (e. g. ddGetDocuments).
    • Valid values: string
    • Required
  • $params->params, (*148)

    • Desctription: Parameters that will be passed to the snippet constructor.
    • Valid values:
      • stdClass
      • arrayAssociative
      • stringJsonObject
      • stringQueryFormatted
    • Default value: —
  • $params->params->{$paramName}, (*149)

    • Desctription: Key is parameter name, value is value.
    • Valid values: mixed
    • Required

Examples

\ddTools::convertUrlToAbsolute($params): Convert relative URLs to absolute

$params->url can be set in various ways for more convenience:, (*150)

//Relative
$url = 'some/page?q=42#hash';
//Relative starting with slash
$url = '/some/page?q=42#hash';
//Absolute starting with domain
$url = 'example.com/some/page?q=42#hash';
//Absolute starting with double slash
$url = '//example.com/some/page?q=42#hash';
//Absolute starting with scheme
$url = 'https://example.com/some/page?q=42#hash';
\ddTools::convertUrlToAbsolute([
    'url' => $url,
    //The parameter is optional and is used here just for clarity. By default it will be equal to domain of your site.
    'host' => 'example.com'
]);

Returns this with any of the above URLs:, (*151)

'https://example.com/some/page?q=42#hash'

Verify renamed snippet params (\ddTools::verifyRenamedParams($params))

Suppose we have the snippet ddSendFeedback with the getEmail and getId parameters. Over time, we decided to rename the parameters as docField and docId respectively (as it happened in version 1.9). And we want to save backward compatibility, the snippet must work with the old names and send message to the MODX event log., (*152)

//Include (MODX)EvolutionCMS.libraries.ddTools
require_once(
    $modx->getConfig('base_path') .
    'assets/libs/ddTools/modx.ddtools.class.php'
);

//Backward compatibility
extract(\ddTools::verifyRenamedParams([
    //We called the method inside of a snippet, so its parameters are contained in the `$params` variable (MODX feature)
    'params' => $params,
    'compliance' => [
        //The new name => The old name
        'docField' => 'getEmail',
        'docId' => 'getId'
    ]
]));

Below we can use $docField and $docId and not to worry. The method will check everything and will send a message to the MODX event log., (*153)

After some time we decided to rename the parameters again as email_docField и email_docId. Nothing wrong, the method can works with multiple old names, just pass an array:, (*154)

extract(\ddTools::verifyRenamedParams([
    //We called the method inside of a snippet, so its parameters are contained in the `$params` variable (MODX feature)
    'params' => $params,
    'compliance' => [
        //The new name => The old names
        'email_docField' => [
            'docField',
            'getEmail'
        ],
        'email_docId' => [
            'docId',
            'getId'
        ]
    ],
    //Also you can prevent writing to the CMS event log if you want
    'writeToLog' => false
]));

\ddTools::parseText($params)

Basic example

\ddTools::parseText([
    'text' => '
        <article>
            <h1>[+title+]</h1>
            [+text+]
            <p>[+authorFirstName+] [+authorLastName+], [+date+].</p>
        </article>
    ',
    'data' => [
        'title' => 'Bethink Yourselves!',
        'text' => '<p>Question your loyalty to your country and government and strive for a more just and peaceful society.</p>',
        'authorFirstName' => 'Leo',
        'authorLastName' => 'Tolstoy',
        'date' => '1904'
    ]
]);

Returns:, (*155)

<article>
    <h1>Bethink Yourselves!</h1>
    <p>Question your loyalty to your country and government and strive for a more just and peaceful society.</p>
    <p>Leo Tolstoy, 1904.</p>
</article>

Nested objects in $params->data

\ddTools::parseText([
    //Data can have a complex nested structure
    'data' => [
        'title' => 'Bethink Yourselves!',
        'text' => '<p>Question your actions and consider the morality behind them.</p>',
        //Note that this is not a string, but that's okay
        'meta' => [
            //Moreover, any depth is supported
            'author' => [
                'firstName' => 'Leo',
                'lastName' => 'Tolstoy',
            ],
            'date' => '1904'
        ]
    ],
    //For nested data you can use placeholders like '[+meta.date+]' for getting a property
    //Or like '[+meta+]' to get whole object as JSON
    'text' => '
        <article data-meta=\'[+meta+]\'>
            <h1>[+title+]</h1>
            [+text+]
            <p>[+meta.author.firstName+] [+meta.author.lastName+], [+meta.date+].</p>
        </article>
    '
]);

Returns:, (*156)

<article data-meta='{"author":{"firstName":"Leo","lastName":"Tolstoy"},"date":"1904"}'>
    <h1>Bethink Yourselves!</h1>
    <p>Question your actions and consider the morality behind them.</p>
    <p>Leo Tolstoy, 1904.</p>
</article>

\DDTools\ObjectTools

\DDTools\ObjectTools::convertType($params)

Convert a JSON or Query encoded string to an array

For example, some snippet supports 2 formats in one of parameters: JSON or Query string. Users use the format that is convenient to them and we support both. Just call this method and don't care about it., (*157)

//We can pass string in JSON format
\DDTools\ObjectTools::convertType([
    'object' => '{
        "pagetitle": "Test title",
        "published": "0"
    }',
    'type' => 'objectArray'
]);

//Or Query string
\DDTools\ObjectTools::convertType([
    'object' => 'pagetitle=Test title&published=0',
    'type' => 'objectArray'
]);

Both calls return:, (*158)

[
    'pagetitle' => 'Test title',
    'published' => '0'
];
Convert a Query encoded string to a JSON object string
\DDTools\ObjectTools::convertType([
    'object' => 'firstName=Hans&lastName=Zimmer',
    'type' => 'stringJsonAuto'
]);

Returns:, (*159)

{
    "firstName": "Hans",
    "lastName": "Zimmer"
}
Convert a JSON object to a JSON array
\DDTools\ObjectTools::convertType([
    'object' => '{
        "firstName": "Ramin",
        "lastName": "Djawadi"
    }',
    'type' => 'stringJsonArray'
]);

Returns:, (*160)

[
    "Ramin",
    "Djawadi"
]
Convert a HJSON encoded string to an object
\DDTools\ObjectTools::convertType([
    'object' => "{
        //This is HJSON, not JSON, so we can use comments insides
        keys: and values can be specified without quotes,
        multilineValues:
            '''
            Write multiline strings with proper whitespace handling.
            Starts and ends with triple quotes.
            A simple syntax and easy to read.
            '''
    }",
    'type' => 'objectStdClass'
]);

Returns:, (*161)

stdClass::__set_state(array(
   'keys' => 'and values can be specified without quotes,',
   'multilineValues' => 'Write multiline strings with proper whitespace handling.
Starts and ends with triple quotes.
A simple syntax and easy to read.',
))
Convert an associative array to a string of HTML attributes
\DDTools\ObjectTools::convertType([
    'object' => [
        'data-name' => 'KINO',
        //Will be converted to 1
        'data-is-active' => true,
        //Will be converted to JSON array
        'data-members' => [
            'Viktor Tsoi',
            'Yuri Kasparyan',
            'Aleksei Rybin',
            'Igor Tikhomirov',
            'Aleksandr Titov',
            'Georgy Guryanov',
            'Oleg Valinsky',
        ],
    ],
    'type' => 'stringHtmlAttrs'
]);

Returns:, (*162)

data-name='KINO' data-is-active='1' data-members='["Viktor Tsoi","Yuri Kasparyan","Aleksei Rybin","Igor Tikhomirov","Aleksandr Titov","Georgy Guryanov","Oleg Valinsky"]'

\DDTools\ObjectTools::extend($params)

Merge two objects, modifying the first
var_export(\DDTools\ObjectTools::extend([
    'objects' => [
        (object) [
            'cat' => 'mew',
            'dog' => (object) [
                'name' => 'Floyd',
                'weight' => 6
            ],
            'rabbit' => 42
        ],
        (object) [
            'dog' => (object) [
                'weight' => 10
            ],
            'bird' => 0
        ]
    ]
]));

Returns:, (*163)

stdClass::__set_state(array(
    'cat' => 'mew',
    'dog' => stdClass::__set_state(array(
        'name' => 'Floyd',
        'weight' => 10,
    )),
    'rabbit' => 42,
    'bird' => 0,
))
Also you can extend arrays
var_export(\DDTools\ObjectTools::extend([
    'objects' => [
        [
            'cat' => 'mew',
            'dog' => [
                'name' => 'Floyd',
                'weight' => 6
            ],
            'rabbit' => 42
        ],
        [
            'dog' => (object) [
                'weight' => 10
            ],
            'bird' => 0
        ]
    ]
]));

Returns:, (*164)

array(
    'cat' => 'mew',
    'dog' => array(
        'name' => 'Floyd',
        'weight' => 10,
    ),
    'rabbit' => 42,
    'bird' => 0,
)
Moreover, objects can extend arrays and vice versa
var_export(\DDTools\ObjectTools::extend([
    'objects' => [
        [
            'name' => 'jokes',
            'countries' => (object) [
                'usa' => 'democracy',
                'china' => 'chinese democracy'
            ],
        ],
        (object) [
            'countries' => [
                'china' => 'democracy too'
            ]
        ]
    ]
]));

Returns:, (*165)

//The object expanded the source array
array(
    'name' => 'jokes',
    //The array expanded the source object
    'countries' => stdClass::__set_state(
        'usa' => 'democracy',
        'china' => 'democracy too',
    )),
)
Don't overwrite fields with empty values ($params->overwriteWithEmpty == false)

By default, empty field values (e. g. '') are treated as other values and will replace non-empty ones., (*166)

var_export(\DDTools\ObjectTools::extend([
    'objects' => [
        (object) [
            'firstName' => 'John',
            'lastName' => 'Tesla',
            'discipline' => 'Electrical engineering'
        ],
        (object) [
            'firstName' => 'Nikola',
            'lastName' => ''
        ]
    ]
]));

Returns:, (*167)

stdClass::__set_state(array(
    'firstName' => 'Nikola',
    'lastName' => '',
    'discipline' => 'Electrical engineering'
))

Empty lastName from the second object replaced non-empty lastName from the first., (*168)

If you want to ignore empty values, just use $params->overwriteWithEmpty == false:, (*169)

var_export(\DDTools\ObjectTools::extend([
    'objects' => [
        (object) [
            'firstName' => 'John',
            'lastName' => 'Tesla',
            'discipline' => 'Electrical engineering'
        ],
        (object) [
            'firstName' => 'Nikola',
            'lastName' => ''
        ]
    ],
    'overwriteWithEmpty' => false
]));

Returns:, (*170)

stdClass::__set_state(array(
    'firstName' => 'Nikola',
    'lastName' => 'Tesla',
    'discipline' => 'Electrical engineering'
))

\DDTools\ObjectTools::unfold($params)

Unfold an object
var_export(\DDTools\ObjectTools::unfold([
    'object' => (object) [
        'name' => 'Elon Musk',
        'address' => (object) [
            'line1' => '3500 Deer Creek Road',
            'city' => 'Palo Alto',
            'state' => 'California',
            'country' => 'United States'
        ]
    ]
]));

Returns:, (*171)

stdClass::__set_state(array (
    'name' => 'Elon Musk',
    'address.line1' => '3500 Deer Creek Road',
    'address.city' => 'Palo Alto',
    'address.state' => 'California',
    'address.country' => 'United States'
))
Unfold an array
var_export(\DDTools\ObjectTools::unfold([
    'object' => [
        'a' => 'a val',
        'b' => [
            'b1' => 'b1 val',
            'b2' => [
                'b21' => 'b21 val',
                'b22' => 'b22 val'
            ]
        ],
        'c' => 'c val'
    ]
]));

Returns:, (*172)

array (
    'a' => 'a val',
    'b.b1' => 'b1 val',
    'b.b2.b21' => 'b21 val',
    'b.b2.b22' => 'b22 val',
    'c' => 'c val'
)
Use custom key separator
var_export(\DDTools\ObjectTools::unfold([
    'object' => [
        'name' => 'Elon Musk',
        'parents' => [
            'mother' => 'Maye Musk',
            'father' => 'Errol Musk'
        ]
    ],
    'keySeparator' => '_'
]));

Returns:, (*173)

stdClass::__set_state(array (
    'name' => 'Elon Musk',
    'parents_mother' => 'Maye Musk',
    'parents_father' => 'Errol Musk'
))

\DDTools\ObjectTools::isPropExists($params)

Checks if the object, class or array has a property / element using the same syntax., (*174)

You can pass an object:, (*175)

var_export(\DDTools\ObjectTools::isPropExists([
    'object' => (object) [
        'firstName' => 'John',
        'lastName' => 'Lennon'
    ],
    'propName' => 'firstName'
]));

Or an array:, (*176)

var_export(\DDTools\ObjectTools::isPropExists([
    'object' => [
        'firstName' => 'Paul',
        'lastName' => 'McCartney'
    ],
    'propName' => 'firstName'
]));

Both calls return true., (*177)

\DDTools\ObjectTools::getPropValue($params)

Get the value of an object property or an array element using the same syntax

You can pass an object:, (*178)

var_export(\DDTools\ObjectTools::getPropValue([
    'object' => (object) [
        'name' => 'Floyd',
        'weight' => 7
    ],
    'propName' => 'name'
]));

Or an array:, (*179)

var_export(\DDTools\ObjectTools::getPropValue([
    'object' => [
        'name' => 'Floyd',
        'weight' => 7
    ],
    'propName' => 'name'
]));

Both calls return 'Floyd'., (*180)

Get the value of an object property or an array element in any nesting level

Source object can be nested, and elements of all levels can be mix of objects and arrays., (*181)

//For example let the first level be stdClass
$sourceObject = (object) [
    //Let the second level be an indexed array
    'PinkFloyd' => [
        //Let the third level be an associative array
        [
            'name' => 'Syd Barrett',
            'role' => 'lead and rhythm guitars, vocals'
        ],
        [
            'name' => 'David Gilmour',
            'role' => 'lead and rhythm guitars, vocals, bass, keyboards, synthesisers'
        ],
        //Let Roger be a little bit special ;)
        (object) [
            'name' => 'Roger Waters',
            'role' => 'bass, vocals, rhythm guitar, synthesisers'
        ],
        [
            'name' => 'Richard Wright',
            'role' => 'keyboards, piano, organ, synthesisers, vocals'
        ],
        [
            'name' => 'Nick Mason',
            'role' => 'drums, percussion'
        ]
    ]
];
Get a first-level property

There's nothing special, just look at this example for the full picture., (*182)

var_export(\DDTools\ObjectTools::getPropValue([
    'object' => $sourceObject,
    'propName' => 'PinkFloyd'
]));

Returns:, (*183)

array (
    0 => array (
        'name' => 'Syd Barrett',
        'role' => 'lead and rhythm guitars, vocals',
    ),
    1 => array (
        'name' => 'David Gilmour',
        'role' => 'lead and rhythm guitars, vocals, bass, keyboards, synthesisers',
    ),
    2 => stdClass::__set_state(array(
         'name' => 'Roger Waters',
         'role' => 'bass, vocals, rhythm guitar, synthesisers',
    )),
    3 => array (
        'name' => 'Richard Wright',
        'role' => 'keyboards, piano, organ, synthesisers, vocals',
    ),
    4 => array (
        'name' => 'Nick Mason',
        'role' => 'drums, percussion',
    ),
)
Get a second-level property

Let's make it a little more interesting: let's get the 4th element of the second-level indexed array., (*184)

var_export(\DDTools\ObjectTools::getPropValue([
    'object' => $sourceObject,
    'propName' => 'PinkFloyd.4'
]));

Returns:, (*185)

array (
    'name' => 'Nick Mason',
    'role' => 'drums, percussion',
)
Get a third-level property

Any level of nesting is supported., (*186)

No matter what type of element is used in any nesting level, the method will work fine. So let's get Roger's name. As you remember, he is stdClass as opposed to the other members who are associative arrays., (*187)

var_export(\DDTools\ObjectTools::getPropValue([
    'object' => $sourceObject,
    'propName' => 'PinkFloyd.2.name'
]));

Returns:, (*188)

'Roger Waters'
Of course, it works fine with single-level objects that contain '.' in their property names
var_export(\DDTools\ObjectTools::getPropValue([
    'object' => [
        '1973.03.01' => 'The Dark Side of the Moon',
        '1975.09.12' => 'Wish You Were Here'
    ],
    'propName' => '1975.09.12'
]));

Returns:, (*189)

'Wish You Were Here'

\DDTools\ObjectCollection

Create a collection with items

$collection = new \DDTools\ObjectCollection([
    'items' => [
        [
            'name' => 'Mary Teresa',
            'isHuman' => 1,
            'gender' => 'female',
            'nobelPeacePrize' => 1,
            'religion' => 'Catholicism'
        ],
        [
            'name' => 'Mahatma Gandhi',
            'isHuman' => 1,
            'gender' => 'male',
            'nobelPeacePrize' => 0
        ],
        [
            'name' => 'Tenzin Gyatso',
            'isHuman' => 1,
            'gender' => 'male',
            'nobelPeacePrize' => 1,
            'religion' => 'Tibetan Buddhism'
        ],
        [
            'name' => 'ICAN',
            'isHuman' => 0,
            'nobelPeacePrize' => 1
        ]
    ]
]);

Set items as a JSON string

$collection->setItems([
    'items' => '[
        {
            "name": "Mary Teresa",
            "isHuman": 1,
            "gender": "female",
            "nobelPeacePrize": 1,
            "religion": "Catholicism"
        },
        {
            "name": "Mahatma Gandhi",
            "isHuman": 1,
            "gender": "male",
            "nobelPeacePrize": 0
        },
        {
            "name": "Tenzin Gyatso",
            "isHuman": 1,
            "gender": "male",
            "nobelPeacePrize": 1,
            "religion": "Tibetan Buddhism"
        },
        {
            "name": "ICAN",
            "isHuman": 0,
            "nobelPeacePrize": 1
        }
    ]'
]);

\DDTools\ObjectCollection::getItems($params)

Get an array of items using filter ($params->filter)
Filter by existence of a property
$collection->getItems([
    'filter' => 'religion'
]);

Returns:, (*190)

array(
    0 => array(
        'name' => 'Mary Teresa',
        'isHuman' => 1,
        'gender' => 'female',
        'nobelPeacePrize' => 1,
        'religion' => 'Catholicism'
    ),
    1 => array(
        'name' => 'Tenzin Gyatso',
        'isHuman' => 1,
        'gender' => 'male',
        'nobelPeacePrize' => 1,
        'religion' => 'Tibetan Buddhism'
    )
)
Filter by a property value
$collection->getItems([
    'filter' => 'gender==male'
]);

Returns:, (*191)

array(
    0 => array(
        'name' => 'Mahatma Gandhi',
        'isHuman' => 1,
        'gender' => 'male',
        'nobelPeacePrize' => 0
    ),
    1 => array(
        'name' => 'Tenzin Gyatso',
        'isHuman' => 1,
        'gender' => 'male',
        'nobelPeacePrize' => 1,
        'religion' => 'Tibetan Buddhism'
    )
)
Filter using several conditions
$collection->getItems([
    //Spaces, tabs and line breaks are also allowed and do not matter
    'filter' => '
        gender == female ||
        nobelPeacePrize == 1 && isHuman == 0
    '
]);

Returns:, (*192)

array(
    //gender == female
    0 => array(
        'name' => 'Mary Teresa',
        'isHuman' => 1,
        'gender' => 'female',
        'nobelPeacePrize' => 1,
        'religion' => 'Catholicism'
    ),
    //nobelPeacePrize == 1 && isHuman == 0
    1 => array(
        'name' => 'ICAN',
        'isHuman' => 0,
        'nobelPeacePrize' => 1
    ),
)
Get an associative array of items using a property value as a result key
$collection->getItems([
    'propAsResultKey' => 'name'
]);

Returns:, (*193)

array(
    'Mary Teresa' => array(
        'name' => 'Mary Teresa',
        'isHuman' => 1,
        'gender' => 'female',
        'nobelPeacePrize' => 1,
        'religion' => 'Catholicism'
    ),
    'Mahatma Gandhi' => array(
        'name' => 'Mahatma Gandhi',
        'isHuman' => 1,
        'gender' => 'male',
        'nobelPeacePrize' => 0
    ),
    'Tenzin Gyatso' => array(
        'name' => 'Tenzin Gyatso',
        'isHuman' => 1,
        'gender' => 'male',
        'nobelPeacePrize' => 1,
        'religion' => 'Tibetan Buddhism'
    ),
    'ICAN' => array(
        'name' => 'ICAN',
        'isHuman' => 0,
        'nobelPeacePrize' => 1
    )
)
Get a one-dimensional array of item property values
$collection->getItems([
    'propAsResultKey' => 'name',
    'propAsResultValue' => 'isHuman'
]);

Returns:, (*194)

array(
    'Mary Teresa' => 1,
    'Mahatma Gandhi' => 1,
    'Tenzin Gyatso' => 1,
    'ICAN' => 0
)

\DDTools\ObjectCollection::getOneItem($params)

$collection->getOneItem([
    'filter' => 'name == Mahatma Gandhi'
]);

Returns:, (*195)

array(
    'name' => 'Mahatma Gandhi',
    'isHuman' => 1,
    'gender' => 'male',
    'nobelPeacePrize' => 0
)
Custom results when no items found
$collection->getOneItem([
    'filter' => 'name == European Union',
    notFoundResult' => [
        'name' => 'Default item',
        'nobelPeacePrize' => 0
    ]
]);

Returns:, (*196)

array(
    'name' => 'Default item',
    'nobelPeacePrize' => 0
)

\DDTools\ObjectCollection::convertItemsType($params)

$collection->convertItemsType([
    'filter' => 'gender==male',
    'itemType' => 'objectStdClass'
]);

$collection->getItems();

Returns:, (*197)

array(
    0 => array(
        'name' => 'Mary Teresa',
        'isHuman' => 1,
        'gender' => 'female',
        'nobelPeacePrize' => 1,
        'religion' => 'Catholicism'
    ),
    1 => stdClass::__set_state(array(
        'name' => 'Mahatma Gandhi',
        'isHuman' => 1,
        'gender' => 'male',
        'nobelPeacePrize' => 0
    )),
    2 => stdClass::__set_state(array(
        'name' => 'Tenzin Gyatso',
        'isHuman' => 1,
        'gender' => 'male',
        'nobelPeacePrize' => 1,
        'religion' => 'Tibetan Buddhism'
    )),
    3 => array(
        'name' => 'ICAN',
        'isHuman' => 0,
        'nobelPeacePrize' => 1
    )
)

\DDTools\ObjectCollection::updateItems($params)

$collection->updateItems([
    'filter' => 'name==Mahatma Gandhi',
    'data' => [
        'nobelPeacePrize' => 1,
        'birthday' => '2 October 1869'
    ]
]);

$collection->getItems(
    'filter' => 'name==Mahatma Gandhi'
);

Returns:, (*198)

array(
    0 => stdClass::__set_state(array(
        //Existing properties that absent in `$params->data` have remained as is
        'name' => 'Mahatma Gandhi',
        'isHuman' => 1,
        'gender' => 'male',
        //Given property values have overwritten the existing ones
        'nobelPeacePrize' => 1,
        //Non-existing properties have been created
        'birthday' => '2 October 1869'
    ))
)

\DDTools\ObjectCollection::deleteItems($params)

$collection->updateItems([
    'filter' => 'isHuman==1',
    'limit' => 2
]);

$collection->getItems();

Returns:, (*199)

array(
    //2 humans have been deleted, 1 have remained
    0 => stdClass::__set_state(array(
        'name' => 'Tenzin Gyatso',
        'isHuman' => 1,
        'gender' => 'male',
        'nobelPeacePrize' => 1,
        'religion' => 'Tibetan Buddhism'
    )),
    1 => array(
        'name' => 'ICAN',
        'isHuman' => 0,
        'nobelPeacePrize' => 1
    )
)

, (*200)

The Versions

26/06 2018

dev-master

9999999-dev http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

26/06 2018

dev-develop

dev-develop http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

26/06 2018

v0.23

0.23.0.0 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

17/06 2018

v0.22

0.22.0.0 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

09/12 2017

v0.21

0.21.0.0 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

06/07 2017

v0.20

0.20.0.0 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

28/05 2017

v0.19

0.19.0.0 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

13/02 2017

v0.18

0.18.0.0 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

10/01 2017

v0.17

0.17.0.0 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

16/12 2016

v0.16.2

0.16.2.0 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

01/11 2016

v0.16.1

0.16.1.0 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

29/10 2016

v0.16

0.16.0.0 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

17/06 2016

v0.15.4

0.15.4.0 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

12/01 2016

v0.15.3

0.15.3.0 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

12/01 2016

v0.15.3-alpha1

0.15.3.0-alpha1 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

11/01 2016

v0.15.2

0.15.2.0 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

11/01 2016

v0.15.2-alpha1

0.15.2.0-alpha1 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

29/12 2015

v0.15.1

0.15.1.0 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

25/12 2015

v0.15

0.15.0.0 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

25/12 2015

v0.15-alpha10

0.15.0.0-alpha10 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

25/12 2015

v0.15-alpha9

0.15.0.0-alpha9 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

25/12 2015

v0.15-alpha8

0.15.0.0-alpha8 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

24/12 2015

v0.15-alpha7

0.15.0.0-alpha7 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

24/12 2015

v0.15-alpha6

0.15.0.0-alpha6 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

24/12 2015

v0.15-alpha5

0.15.0.0-alpha5 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

23/12 2015

v0.15-alpha4

0.15.0.0-alpha4 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

19/12 2015

v0.15-alpha3

0.15.0.0-alpha3 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

19/12 2015

v0.15-alpha2

0.15.0.0-alpha2 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

19/12 2015

v0.15-alpha1

0.15.0.0-alpha1 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

13/12 2015

v0.14.3

0.14.3.0 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

05/11 2015

v0.14.2

0.14.2.0 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

02/11 2015

v0.14.1

0.14.1.0 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools

04/10 2015

v0.14

0.14.0.0 http://code.divandesign.biz/modx/ddtools

A library with various tools facilitating your work.

  Sources   Download

MIT

The Requires

 

modx modx evolution modx evo ddtools