From b1e62ecb20ac149dbc6a2ff8d8ecc5857458f5ae Mon Sep 17 00:00:00 2001 From: yuri Date: Mon, 23 Feb 2015 17:05:00 +0200 Subject: [PATCH] add getEntityType into entity --- application/Espo/Core/Utils/EntityManager.php | 1 + .../Espo/Modules/Crm/Entities/CaseObj.php | 4 ++-- application/Espo/ORM/Entity.php | 17 +++++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/application/Espo/Core/Utils/EntityManager.php b/application/Espo/Core/Utils/EntityManager.php index f9c237bd9c..6602a47a53 100644 --- a/application/Espo/Core/Utils/EntityManager.php +++ b/application/Espo/Core/Utils/EntityManager.php @@ -81,6 +81,7 @@ class EntityManager "namespace Espo\Custom\Entities;\n". "class {$normalizedName} extends \Espo\Core\Templates\Entities\\{$type}\n". "{\n". + " protected \$entityType = \"$name\";\n". "}\n"; $filePath = "custom/Espo/Custom/Entities/{$normalizedName}.php"; diff --git a/application/Espo/Modules/Crm/Entities/CaseObj.php b/application/Espo/Modules/Crm/Entities/CaseObj.php index ff5fef9ed5..5767560e42 100644 --- a/application/Espo/Modules/Crm/Entities/CaseObj.php +++ b/application/Espo/Modules/Crm/Entities/CaseObj.php @@ -18,13 +18,13 @@ * * You should have received a copy of the GNU General Public License * along with EspoCRM. If not, see http://www.gnu.org/licenses/. - ************************************************************************/ + ************************************************************************/ namespace Espo\Modules\Crm\Entities; class CaseObj extends \Espo\Core\ORM\Entity { - protected $entityName = 'Case'; + protected $entityType = 'Case'; } diff --git a/application/Espo/ORM/Entity.php b/application/Espo/ORM/Entity.php index c3a49c8d76..13ee6192d3 100644 --- a/application/Espo/ORM/Entity.php +++ b/application/Espo/ORM/Entity.php @@ -31,10 +31,10 @@ abstract class Entity implements IEntity private $isSaved = false; /** - * Entity name (entity type). + * Entity type. * @var string */ - protected $entityName; + protected $entityType; /** * @var array Defenition of fields. @@ -67,9 +67,9 @@ abstract class Entity implements IEntity public function __construct($defs = array(), EntityManager $entityManager = null) { - if (empty($this->entityName)) { + if (empty($this->entityType)) { $classNames = explode('\\', get_class($this)); - $this->entityName = end($classNames); + $this->entityType = end($classNames); } $this->entityManager = $entityManager; @@ -140,7 +140,7 @@ abstract class Entity implements IEntity } if (!empty($this->relations[$name])) { - $value = $this->entityManager->getRepository($this->entityName)->findRelated($this, $name, $params); + $value = $this->entityManager->getRepository($this->getEntityType())->findRelated($this, $name, $params); return $value; } @@ -240,7 +240,12 @@ abstract class Entity implements IEntity public function getEntityName() { - return $this->entityName; + return $this->getEntityType(); + } + + public function getEntityType() + { + return $this->entityType; } public function hasField($fieldName)