From 2b2620c954d61e6ba0ca8bc2f33cef3c4f8233d8 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 24 Jul 2020 12:37:54 +0300 Subject: [PATCH] orm usage --- application/Espo/Core/Repositories/Event.php | 40 +++++++++----------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/application/Espo/Core/Repositories/Event.php b/application/Espo/Core/Repositories/Event.php index 3bbc72fb86..aa68561b50 100644 --- a/application/Espo/Core/Repositories/Event.php +++ b/application/Espo/Core/Repositories/Event.php @@ -235,33 +235,29 @@ class Event extends \Espo\Core\Repositories\Database implements } } - public function getEntityReminderList(Entity $entity) + public function getEntityReminderList(Entity $entity) : array { - $pdo = $this->getEntityManager()->getPDO(); - $reminderList = []; + $reminderDataList = []; - $sql = " - SELECT DISTINCT `seconds`, `type` - FROM `reminder` - WHERE - `entity_type` = ".$pdo->quote($entity->getEntityType())." AND - `entity_id` = ".$pdo->quote($entity->id)." AND - `deleted` = 0 - ORDER BY `seconds` ASC - "; + $reminderCollection = $this->getEntityManager()->getRepository('Reminder') + ->select(['seconds', 'type']) + ->where([ + 'entityType' => $entity->getEntityType(), + 'entityId' => $entity->id, + ]) + ->distinct() + ->order('seconds') + ->find(); - $sth = $pdo->prepare($sql); - $sth->execute(); - $rows = $sth->fetchAll(\PDO::FETCH_ASSOC); - - foreach ($rows as $row) { - $o = new \StdClass(); - $o->seconds = intval($row['seconds']); - $o->type = $row['type']; - $reminderList[] = $o; + foreach ($reminderCollection as $reminder) { + $o = (object) [ + 'seconds' => $reminder->get('seconds'), + 'type' => $reminder->get('type'), + ]; + $reminderDataList[] = $o; } - return $reminderList; + return $reminderDataList; } protected function convertDateTimeToDefaultTimezone($string)