lithium\data\Entity::modified PHP Метод

modified() публичный Метод

Gets the current state for a given field or, if no field is given, gets the array of fields modified on this entity.
public modified ( $field = null ) : mixed
Результат mixed Returns `true` if a field is given and was updated, `false` otherwise and `null` if the field was not set at all. If no field is given returns an arra where the keys are entity field names, and the values are `true` for changed fields.
    public function modified($field = null)
    {
        if ($field) {
            if (!isset($this->_updated[$field]) && !isset($this->_data[$field])) {
                return null;
            }
            if (!array_key_exists($field, $this->_updated)) {
                return false;
            }
            $value = $this->_updated[$field];
            if (is_object($value) && method_exists($value, 'modified')) {
                $modified = $value->modified();
                return $modified === true || is_array($modified) && in_array(true, $modified, true);
            }
            $isSet = isset($this->_data[$field]);
            return !$isSet || $this->_data[$field] !== $this->_updated[$field];
        }
        $fields = array_fill_keys(array_keys($this->_data), false);
        foreach ($this->_updated as $field => $value) {
            if (is_object($value) && method_exists($value, 'modified')) {
                if (!isset($this->_data[$field])) {
                    $fields[$field] = true;
                    continue;
                }
                $modified = $value->modified();
                $fields[$field] = $modified === true || is_array($modified) && in_array(true, $modified, true);
            } else {
                $fields[$field] = !isset($fields[$field]) || $this->_data[$field] !== $this->_updated[$field];
            }
        }
        return $fields;
    }

Usage Example

Пример #1
0
 public function testModified()
 {
     $entity = new Entity();
     $this->assertEqual(array(), $entity->modified());
     $data = array('foo' => 'bar', 'baz' => 'dib');
     $entity->set($data);
     $this->assertEqual(array('foo' => true, 'baz' => true), $entity->modified());
 }
All Usage Examples Of lithium\data\Entity::modified