AuditableBehavior::_getModelData PHP Method

_getModelData() protected method

Retrieves the entire set model data contained to the primary object and any/all HABTM associated data that has been configured with the behavior. Additionally, for the HABTM data, all we care about is the IDs, so the data will be reduced to an indexed array of those IDs.
protected _getModelData ( Model $Model ) : array | false
$Model Model The model that uses the behavior.
return array | false The model data or false.
    protected function _getModelData(Model $Model)
    {
        // Turn cacheQueries off for model provided.
        $Model->cacheQueries = false;
        $this->_unsetVirtualFieldsTemporarily($Model);
        // Retrieve the model data along with its appropriate HABTM model data.
        $data = $Model->find('first', array('contain' => !empty($this->settings[$Model->alias]['habtm']) ? array_values($this->settings[$Model->alias]['habtm']) : array(), 'conditions' => array($Model->alias . '.' . $Model->primaryKey => $Model->id)));
        // If we are using a SoftDelete behavior, $data will return empty after a delete.
        if (empty($data)) {
            return false;
        }
        $auditData = array($Model->alias => isset($data[$Model->alias]) ? $data[$Model->alias] : array());
        foreach ($this->settings[$Model->alias]['habtm'] as $habtmModel) {
            if (array_key_exists($habtmModel, $Model->hasAndBelongsToMany) && isset($data[$habtmModel])) {
                $habtmIds = Hash::combine($data[$habtmModel], '{n}.id', '{n}.id');
                // Grab just the ID values and sort those.
                $habtmIds = array_values($habtmIds);
                sort($habtmIds);
                $auditData[$Model->alias][$habtmModel] = implode(',', $habtmIds);
            }
        }
        $this->_restoreVirtualFields($Model);
        return $auditData[$Model->alias];
    }