@param EntityInterface $entity

@return array
331804
protected function getEntityDataArray(EntityInterface $entity)
    {
        $metadata = $this->getEntityMetadata();
        $array = [];
        
        foreach ($this->getHydrator()->extract($entity) as $sqlName => $value) {
            if ($sqlName !== $metadata->getIdentifier() && null !== $value) {
                $array[$metadata->getRawSQLName($metadata->getName($sqlName))] = $value;
            }
        }
        
        return $array;
    }
313830
public function supportsEntity(EntityInterface $entity): bool
    {
        foreach ($this->mappers as $mapper) {
            if ($mapper->supportsEntity($entity)) {
                return true;
            }
        }

        return false;
    }
124694
public function saveEntity(EntityInterface $entity)
    {
        $checkEntity = $this->getTable()->fetchEntityById($entity->getIdentifier());

        if ($checkEntity) {
            return $this->getTable()->updateEntity($entity);
        } else {
            return $this->getTable()->insertEntity($entity);
        }
    }
1063296
public function set(EntityInterface $entity)
    {
        $key = get_class($entity).'::'.$entity->getId();
        $this->getCache()->set($key, $entity);
        return $this;
    }
579597
public static function getRelationships(IEntity $entity): array
	{
		$return = [[], [], []];
		foreach ($entity->getMetadata()->getProperties() as $propertyMeta) {
			if ($propertyMeta->relationship === null) {
				continue;
			}

			$name = $propertyMeta->name;
			if (!$propertyMeta->relationship->cascade['remove']) {
				$return[2][$name] = $propertyMeta;
				continue;
			}

			$rawValue = $entity->getRawValue($name);
			if ($rawValue === null && $propertyMeta->isNullable) {
				continue;
			}

			$property = $entity->getProperty($name);
			if ($property instanceof IRelationshipContainer) {
				$value = $entity->getValue($name);
				if ($value) {
					if ($propertyMeta->relationship->type === Relationship::ONE_HAS_ONE && !$propertyMeta->relationship->isMain) {
						$return[0][$name] = $value;
					} else {
						$return[1][$name] = $value;
					}
				}

			} elseif ($property instanceof IRelationshipCollection) {
				$return[0][$name] = $entity->getValue($name);
			}
		}

		return $return;
	}
396942
protected function extractKeywordsFromKeywordableEntity(KeywordableInterface $entity)
    {
        $references = array();
        $keywords = $entity->getKeywords();

        foreach ($keywords as $keyword) {
            $references[] = $keyword->getId();
        }

        return $references;
    }
166444
public function entityByResult(string $entity): array
    {
        $result = array_get($this->response, "data.result", '');

        return array_get($this->response, "data.entities.$entity.$result", []);
    }
78573
protected function _getScope(EntityInterface $entity)
    {
        $scope = [];
        $config = $this->getConfig();

        // If scope are specified and data for all scope fields is not
        // provided we cannot calculate new order
        if ($config['scope']) {
            $scope = $entity->extract($config['scope']);
            if (count($scope) !== count($config['scope'])) {
                return false;
            }

            // Modify where clauses when NULL values are used
            foreach ($scope as $field => $value) {
                if (is_null($value)) {
                    $scope[$field . ' IS'] = $value;
                    unset($scope[$field]);
                }
            }
        }

        return $scope;
    }
717833
protected function _handleFiles(EntityInterface $entity) {
		$files = $this->getConfig('file');
		if (is_string($files)) {
			$files = [$files => $this->getConfig('defaults')];
		}

		$results = [];
		foreach ($files as $key => $file) {
			if (is_string($key)) {
				$field = $key;
				$options = $this->getConfig('defaults');
				$options += $file;
			}
			if (is_string($file)) {
				$field = $file;
				$options = $this->getConfig('defaults');
			}
			$results[$field] = $this->saveFile($entity->{$field}, $options);
		}

		return $results;
	}
642349
protected function getEntityTable($entity)
    {
        if (!$entity instanceof EntityInterface) {
            $entity = $this->getEntityClass($entity);
        }
        return $this->tablePrefix . $entity::getTable() . $this->tableSuffix;
    }
125538
public function attachEntityFields(EntityInterface $entity)
    {
        $_fields = [];
        foreach ($this->_attributesForEntity($entity) as $attr) {
            $field = $this->_prepareMockField($entity, $attr);
            if ($entity->has($field->get('name'))) {
                $this->_fetchPost($field);
            }

            $field->fieldAttached();
            $_fields[] = $field;
        }

        $entity->set('_fields', new FieldCollection($_fields));

        return $entity;
    }
384902
public function getVersions(EntityInterface $entity)
    {
        $primaryKey = (array)$this->_table->getPrimaryKey();

        $query = $this->_table->find('versions');
        $pkValue = $entity->extract($primaryKey);
        $conditions = [];
        foreach ($pkValue as $key => $value) {
            $field = current($query->aliasField($key));
            $conditions[$field] = $value;
        }
        $entities = $query->where($conditions)->all();

        if (empty($entities)) {
            return new Collection([]);
        }

        $entity = $entities->first();

        return $entity->get('_versions');
    }
129586
public function saveEvent(EntityInterface $entity): array
    {
        $response = [
            'status' => false,
            'errors' => [],
            'entity' => null,
        ];

        if ($entity instanceof EntityInterface) {
            $entity = $entity->toArray();
        }

        if (empty($entity['id'])) {
            unset($entity['id']);
        }

        $query = $this->find()
            ->where([
                //'source' => empty($entity['source']) ? null : $entity['source'],
                'source_id' => $entity['source_id'],
                'calendar_id' => $entity['calendar_id'],
            ]);

        $query->execute();

        /** @var EntityInterface $event */
        $event = (!$query->count()) ? $this->newEntity() : $query->first();
        $event = $this->patchEntity($event, $entity);

        $saved = $this->save($event);

        if ($saved) {
            $response['status'] = true;
            $response['entity'] = $saved;
        } else {
            $response['errors'] = $event->getErrors();
        }

        return $response;
    }
979662
private function getChildren(NodeInterface $node)
    {
        $result = [];
        foreach ($node->getNodes() as $child) {
            $result[$child->getIdentifier()] = $child;
        }

        return $result;
    }
586346
public function decodeItems(EntityInterface $entity) {
		$fields = $this->_getMappedFields();

		foreach ($fields as $map => $field) {
			$val = $entity->get($field);
			if ($this->isEncoded($val)) {
				$entity->set($map, $this->decoded);
			}
		}
	}
436537
public static function getListingFields(RepositoryInterface $table): array
    {
        // broadcast event to fetch display fields
        $event = new Event((string)EventName::MODEL_SEARCH_DISPLAY_FIELDS(), null, [
            'table' => $table
        ]);
        EventManager::instance()->dispatch($event);

        $result = (array)$event->result;

        if (empty($result)) {
            $result = static::getDefaultDisplayFields($table);
        }

        $result = array_diff($result, static::getSkippedDisplayFields($table, true));

        // reset numeric indexes
        return array_values($result);
    }
1287990
public function save(EntityInterface $entity)
    {
        $entity = $this->beforeSave($entity);

        $this->getEntityManager()->persist($entity);
        $this->getEntityManager()->flush($entity);

        $this->afterSave($entity);
    }