From 9a258f2aa5d8233bb8957a92280f50a43f7f4e8a Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Tue, 14 Jan 2014 12:01:49 +0200 Subject: [PATCH] order By Link field --- application/Espo/Core/SelectManager.php | 8 +++++++- application/Espo/Services/Record.php | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/application/Espo/Core/SelectManager.php b/application/Espo/Core/SelectManager.php index ef6d3e6cd4..c3191df50a 100644 --- a/application/Espo/Core/SelectManager.php +++ b/application/Espo/Core/SelectManager.php @@ -15,12 +15,15 @@ class SelectManager protected $entityManager; protected $entityName; + + protected $metadata; - public function __construct(ORM\EntityManager $entityManager, \Espo\Entities\User $user, Acl $acl) + public function __construct(ORM\EntityManager $entityManager, \Espo\Entities\User $user, Acl $acl, $metadata) { $this->entityManager = $entityManager; $this->user = $user; $this->acl = $acl; + $this->metadata = $metadata; } public function setEntityName($entityName) @@ -42,6 +45,9 @@ class SelectManager { if (!empty($params['sortBy'])) { $result['orderBy'] = $params['sortBy']; + if ($this->metadata->get("entityDefs.{$this->entityName}.fields." . $result['orderBy'] . ".type") == 'link') { + $result['orderBy'] .= 'Name'; + } } if (isset($params['asc'])) { if ($params['asc']) { diff --git a/application/Espo/Services/Record.php b/application/Espo/Services/Record.php index ab1f8adc50..c7e633092c 100644 --- a/application/Espo/Services/Record.php +++ b/application/Espo/Services/Record.php @@ -109,7 +109,7 @@ class Record extends \Espo\Core\Services\Base $className = '\\Espo\\Core\\SelectManager'; } - $selectManager = new $className($this->getEntityManager(), $this->getUser(), $this->getAcl()); + $selectManager = new $className($this->getEntityManager(), $this->getUser(), $this->getAcl(), $this->getMetadata()); $selectManager->setEntityName($entityName); return $selectManager;