lithium\data\Entity::modified()

public method

Gets the current state for a given field or, if no field is given, gets the array of fields modified on this entity.

Parameters

  • string The

    field name to check its state.

Returns

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.

Source

	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;
	}