当前位置: 首页>>代码示例>>PHP>>正文


PHP Entity::getRelations方法代码示例

本文整理汇总了PHP中Espo\ORM\Entity::getRelations方法的典型用法代码示例。如果您正苦于以下问题:PHP Entity::getRelations方法的具体用法?PHP Entity::getRelations怎么用?PHP Entity::getRelations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Espo\ORM\Entity的用法示例。


在下文中一共展示了Entity::getRelations方法的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);
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:naushrambo,项目名称:espocrm,代码行数:87,代码来源:RDB.php

示例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();
//.........这里部分代码省略.........
开发者ID:disearth,项目名称:espocrm,代码行数:101,代码来源:RDB.php


注:本文中的Espo\ORM\Entity::getRelations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。