src/ORM/DataObject.php
public function getChangedFields($databaseFieldsOnly = false, $changeLevel = self::CHANGE_STRICT)
    {
        $changedFields = array();

        // Update the changed array with references to changed obj-fields
        foreach ($this->record as $k => $v) {
            // Prevents DBComposite infinite looping on isChanged
            if (is_array($databaseFieldsOnly) && !in_array($k, $databaseFieldsOnly)) {
                continue;
            }
            if (is_object($v) && method_exists($v, 'isChanged') && $v->isChanged()) {
                $this->changed[$k] = self::CHANGE_VALUE;
            }
        }

        // If change was forced, then derive change data from $this->record
        if ($this->changeForced && $changeLevel <= self::CHANGE_STRICT) {
            $changed = array_combine(
                array_keys($this->record),
                array_fill(0, count($this->record), self::CHANGE_STRICT)
            );
            // @todo Find better way to allow versioned to write a new version after forceChange
            unset($changed['Version']);
        } else {
            $changed = $this->changed;
        }

        if (is_array($databaseFieldsOnly)) {
            $fields = array_intersect_key($changed, array_flip($databaseFieldsOnly));
        } elseif ($databaseFieldsOnly) {
            $fieldsSpecs = static::getSchema()->fieldSpecs(static::class);
            $fields = array_intersect_key($changed, $fieldsSpecs);
        } else {
            $fields = $changed;
        }

        // Filter the list to those of a certain change level
        if ($changeLevel > self::CHANGE_STRICT) {
            if ($fields) {
                foreach ($fields as $name => $level) {
                    if ($level < $changeLevel) {
                        unset($fields[$name]);
                    }
                }
            }
        }

        if ($fields) {
            foreach ($fields as $name => $level) {
                $changedFields[$name] = array(
                    'before' => array_key_exists($name, $this->original) ? $this->original[$name] : null,
                    'after' => array_key_exists($name, $this->record) ? $this->record[$name] : null,
                    'level' => $level
                );
            }
        }

        return $changedFields;
    }
public function getChangedFields($databaseFieldsOnly = false, $changeLevel = self::CHANGE_STRICT)
    {
        $changedFields = array();

        // Update the changed array with references to changed obj-fields
        foreach ($this->record as $k => $v) {
            // Prevents DBComposite infinite looping on isChanged
            if (is_array($databaseFieldsOnly) && !in_array($k, $databaseFieldsOnly)) {
                continue;
            }
            if (is_object($v) && method_exists($v, 'isChanged') && $v->isChanged()) {
                $this->changed[$k] = self::CHANGE_VALUE;
            }
        }

        // If change was forced, then derive change data from $this->record
        if ($this->changeForced && $changeLevel <= self::CHANGE_STRICT) {
            $changed = array_combine(
                array_keys($this->record),
                array_fill(0, count($this->record), self::CHANGE_STRICT)
            );
            // @todo Find better way to allow versioned to write a new version after forceChange
            unset($changed['Version']);
        } else {
            $changed = $this->changed;
        }

        if (is_array($databaseFieldsOnly)) {
            $fields = array_intersect_key($changed, array_flip($databaseFieldsOnly));
        } elseif ($databaseFieldsOnly) {
            $fieldsSpecs = static::getSchema()->fieldSpecs(static::class);
            $fields = array_intersect_key($changed, $fieldsSpecs);
        } else {
            $fields = $changed;
        }

        // Filter the list to those of a certain change level
        if ($changeLevel > self::CHANGE_STRICT) {
            if ($fields) {
                foreach ($fields as $name => $level) {
                    if ($level < $changeLevel) {
                        unset($fields[$name]);
                    }
                }
            }
        }

        if ($fields) {
            foreach ($fields as $name => $level) {
                $changedFields[$name] = array(
                    'before' => array_key_exists($name, $this->original) ? $this->original[$name] : null,
                    'after' => array_key_exists($name, $this->record) ? $this->record[$name] : null,
                    'level' => $level
                );
            }
        }

        return $changedFields;
    }
public function getChangedFields ( $ databaseFieldsOnly = false , $ changeLevel = self :: CHANGE_STRICT ) { $ changedFields = array ( ) ; // Update the changed array with references to changed obj-fields foreach ( $ this -> record as $ k => $ v ) { // Prevents DBComposite infinite looping on isChanged if ( is_array ( $ databaseFieldsOnly ) && ! in_array ( $ k , $ databaseFieldsOnly ) ) { continue ; } if ( is_object ( $ v ) && method_exists ( $ v , 'isChanged' ) && $ v -> isChanged ( ) ) { $ this -> changed [ $ k ] = self :: CHANGE_VALUE ; } } // If change was forced, then derive change data from $this->record if ( $ this -> changeForced && $ changeLevel <= self :: CHANGE_STRICT ) { $ changed = array_combine ( array_keys ( $ this -> record ) , array_fill ( 0 , count ( $ this -> record ) , self :: CHANGE_STRICT ) ) ; // @todo Find better way to allow versioned to write a new version after forceChange unset ( $ changed [ 'Version' ] ) ; } else { $ changed = $ this -> changed ; } if ( is_array ( $ databaseFieldsOnly ) ) { $ fields = array_intersect_key ( $ changed , array_flip ( $ databaseFieldsOnly ) ) ; } elseif ( $ databaseFieldsOnly ) { $ fieldsSpecs = static :: getSchema ( ) -> fieldSpecs ( static :: class ) ; $ fields = array_intersect_key ( $ changed , $ fieldsSpecs ) ; } else { $ fields = $ changed ; } // Filter the list to those of a certain change level if ( $ changeLevel > self :: CHANGE_STRICT ) { if ( $ fields ) { foreach ( $ fields as $ name => $ level ) { if ( $ level < $ changeLevel ) { unset ( $ fields [ $ name ] ) ; } } } } if ( $ fields ) { foreach ( $ fields as $ name => $ level ) { $ changedFields [ $ name ] = array ( 'before' => array_key_exists ( $ name , $ this -> original ) ? $ this -> original [ $ name ] : null , 'after' => array_key_exists ( $ name , $ this -> record ) ? $ this -> record [ $ name ] : null , 'level' => $ level ) ; } } return $ changedFields ; }
Return the fields that have changed since the last write.

The change level affects what the functions defines as "changed":
- Level CHANGE_STRICT (integer 1) will return strict changes, even !== ones.
- Level CHANGE_VALUE (integer 2) is more lenient, it will only return real data changes,
for example a change from 0 to null would not be included.

Example return:
<code>
array(
'Title' = array('before' => 'Home', 'after' => 'Home-Changed', 'level' => DataObject::CHANGE_VALUE)
)
</code>

@param boolean|array $databaseFieldsOnly Filter to determine which fields to return. Set to true
to return all database fields, or an array for an explicit filter. false returns all fields.
@param int $changeLevel The strictness of what is defined as change. Defaults to strict
@return array
Return the fields that have changed since the last write .