本文整理汇总了PHP中Espo\ORM\Entity::setFetched方法的典型用法代码示例。如果您正苦于以下问题:PHP Entity::setFetched方法的具体用法?PHP Entity::setFetched怎么用?PHP Entity::setFetched使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Espo\ORM\Entity
的用法示例。
在下文中一共展示了Entity::setFetched方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleSpecifiedRelations
protected function handleSpecifiedRelations(Entity $entity)
{
$relationTypes = array($entity::HAS_MANY, $entity::MANY_MANY, $entity::HAS_CHILDREN);
foreach ($entity->getRelations() as $name => $defs) {
if (in_array($defs['type'], $relationTypes)) {
$fieldName = $name . 'Ids';
$columnsFieldsName = $name . 'Columns';
if ($entity->has($fieldName) || $entity->has($columnsFieldsName)) {
if ($this->getMetadata()->get("entityDefs." . $entity->getEntityType() . ".fields.{$name}.noSave")) {
continue;
}
if ($entity->has($fieldName)) {
$specifiedIds = $entity->get($fieldName);
} else {
$specifiedIds = array();
foreach ($entity->get($columnsFieldsName) as $id => $d) {
$specifiedIds[] = $id;
}
}
if (is_array($specifiedIds)) {
$toRemoveIds = array();
$existingIds = array();
$toUpdateIds = array();
$existingColumnsData = new \stdClass();
$defs = array();
$columns = $this->getMetadata()->get("entityDefs." . $entity->getEntityType() . ".fields.{$name}.columns");
if (!empty($columns)) {
$columnData = $entity->get($columnsFieldsName);
$defs['additionalColumns'] = $columns;
}
$foreignCollection = $entity->get($name, $defs);
if ($foreignCollection) {
foreach ($foreignCollection as $foreignEntity) {
$existingIds[] = $foreignEntity->id;
if (!empty($columns)) {
$data = new \stdClass();
foreach ($columns as $columnName => $columnField) {
$foreignId = $foreignEntity->id;
$data->{$columnName} = $foreignEntity->get($columnField);
}
$existingColumnsData->{$foreignId} = $data;
$entity->setFetched($columnsFieldsName, $existingColumnsData);
}
}
}
if ($entity->has($fieldName)) {
$entity->setFetched($fieldName, $existingIds);
}
if ($entity->has($columnsFieldsName) && !empty($columns)) {
$entity->setFetched($columnsFieldsName, $existingColumnsData);
}
foreach ($existingIds as $id) {
if (!in_array($id, $specifiedIds)) {
$toRemoveIds[] = $id;
} else {
if (!empty($columns)) {
foreach ($columns as $columnName => $columnField) {
if ($columnData->{$id}->{$columnName} != $existingColumnsData->{$id}->{$columnName}) {
$toUpdateIds[] = $id;
}
}
}
}
}
foreach ($specifiedIds as $id) {
if (!in_array($id, $existingIds)) {
$data = null;
if (!empty($columns) && isset($columnData->{$id})) {
$data = $columnData->{$id};
}
$this->relate($entity, $name, $id, $data);
}
}
foreach ($toRemoveIds as $id) {
$this->unrelate($entity, $name, $id);
}
if (!empty($columns)) {
foreach ($toUpdateIds as $id) {
$data = $columnData->{$id};
$this->updateRelation($entity, $name, $id, $data);
}
}
}
}
}
}
}
示例2: handleSpecifiedRelations
protected function handleSpecifiedRelations(Entity $entity)
{
$relationTypeList = [$entity::HAS_MANY, $entity::MANY_MANY, $entity::HAS_CHILDREN];
foreach ($entity->getRelations() as $name => $defs) {
if (in_array($defs['type'], $relationTypeList)) {
$fieldName = $name . 'Ids';
$columnsFieldsName = $name . 'Columns';
if ($entity->has($fieldName) || $entity->has($columnsFieldsName)) {
if ($this->getMetadata()->get("entityDefs." . $entity->getEntityType() . ".fields.{$name}.noSave")) {
continue;
}
if ($entity->has($fieldName)) {
$specifiedIds = $entity->get($fieldName);
} else {
$specifiedIds = array();
foreach ($entity->get($columnsFieldsName) as $id => $d) {
$specifiedIds[] = $id;
}
}
if (is_array($specifiedIds)) {
$toRemoveIds = array();
$existingIds = array();
$toUpdateIds = array();
$existingColumnsData = new \stdClass();
$defs = array();
$columns = $this->getMetadata()->get("entityDefs." . $entity->getEntityType() . ".fields.{$name}.columns");
if (!empty($columns)) {
$columnData = $entity->get($columnsFieldsName);
$defs['additionalColumns'] = $columns;
}
$foreignCollection = $entity->get($name, $defs);
if ($foreignCollection) {
foreach ($foreignCollection as $foreignEntity) {
$existingIds[] = $foreignEntity->id;
if (!empty($columns)) {
$data = new \stdClass();
foreach ($columns as $columnName => $columnField) {
$foreignId = $foreignEntity->id;
$data->{$columnName} = $foreignEntity->get($columnField);
}
$existingColumnsData->{$foreignId} = $data;
$entity->setFetched($columnsFieldsName, $existingColumnsData);
}
}
}
if ($entity->has($fieldName)) {
$entity->setFetched($fieldName, $existingIds);
}
if ($entity->has($columnsFieldsName) && !empty($columns)) {
$entity->setFetched($columnsFieldsName, $existingColumnsData);
}
foreach ($existingIds as $id) {
if (!in_array($id, $specifiedIds)) {
$toRemoveIds[] = $id;
} else {
if (!empty($columns)) {
foreach ($columns as $columnName => $columnField) {
if ($columnData->{$id}->{$columnName} != $existingColumnsData->{$id}->{$columnName}) {
$toUpdateIds[] = $id;
}
}
}
}
}
foreach ($specifiedIds as $id) {
if (!in_array($id, $existingIds)) {
$data = null;
if (!empty($columns) && isset($columnData->{$id})) {
$data = $columnData->{$id};
}
$this->relate($entity, $name, $id, $data);
}
}
foreach ($toRemoveIds as $id) {
$this->unrelate($entity, $name, $id);
}
if (!empty($columns)) {
foreach ($toUpdateIds as $id) {
$data = $columnData->{$id};
$this->updateRelation($entity, $name, $id, $data);
}
}
}
}
} else {
if ($defs['type'] === $entity::HAS_ONE) {
if (empty($defs['entity']) || empty($defs['foreignKey'])) {
return;
}
if ($this->getMetadata()->get("entityDefs." . $entity->getEntityType() . ".fields.{$name}.noSave")) {
continue;
}
$foreignEntityType = $defs['entity'];
$foreignKey = $defs['foreignKey'];
$idFieldName = $name . 'Id';
$nameFieldName = $name . 'Name';
if (!$entity->has($idFieldName)) {
return;
}
$where = array();
//.........这里部分代码省略.........