public function getSummary()
 {
     $txt = '';
     if ($this->groupHistoryModel->getIsNew()) {
         $txt .= 'New! ' . "\n";
     }
     if ($this->groupHistoryModel->isAnyChangeFlagsUnknown()) {
         $txt .= $this->groupHistoryModel->getDescription();
     } else {
         if ($this->groupHistoryModel->getTitleChanged()) {
             $txt .= 'Title Changed. ' . "\n";
         }
         if ($this->groupHistoryModel->getDescriptionChanged()) {
             $txt .= 'Description Changed. ' . "\n";
         }
         if ($this->groupHistoryModel->getUrlChanged()) {
             $txt .= 'URL Changed. ' . "\n";
         }
         if ($this->groupHistoryModel->getTwitterUsernameChanged()) {
             $txt .= 'Twitter Changed. ' . "\n";
         }
         if ($this->groupHistoryModel->getIsDeletedChanged()) {
             $txt .= 'Deleted Changed: ' . ($this->groupHistoryModel->getIsDeleted() ? "Deleted" : "Restored") . "\n\n";
         }
     }
     return $txt;
 }
 function testIntegration1()
 {
     \TimeSource::mock(2014, 1, 1, 12, 0, 0);
     $user = new UserAccountModel();
     $user->setEmail("*****@*****.**");
     $user->setUsername("test");
     $user->setPassword("password");
     $userRepo = new UserAccountRepository();
     $userRepo->create($user);
     $site = new SiteModel();
     $site->setTitle("Test");
     $site->setSlug("test");
     $siteRepo = new SiteRepository();
     $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting());
     ## Create group
     \TimeSource::mock(2014, 1, 1, 13, 0, 0);
     $group = new GroupModel();
     $group->setTitle("test");
     $group->setDescription("test test");
     $group->setUrl("http://www.group.com");
     $groupRepo = new GroupRepository();
     $groupRepo->create($group, $site, $user);
     ## Edit group
     \TimeSource::mock(2014, 1, 1, 14, 0, 0);
     $group = $groupRepo->loadById($group->getId());
     $group->setTwitterUsername("testy");
     $groupRepo->edit($group, $user);
     ## Now save changed flags on these .....
     $groupHistoryRepo = new GroupHistoryRepository();
     $stat = $this->app['db']->prepare("SELECT * FROM group_history");
     $stat->execute();
     while ($data = $stat->fetch()) {
         $groupHistory = new GroupHistoryModel();
         $groupHistory->setFromDataBaseRow($data);
         $groupHistoryRepo->ensureChangedFlagsAreSet($groupHistory);
     }
     ## Now load and check
     $historyRepo = new HistoryRepositoryBuilder();
     $historyRepo->setGroup($group);
     $historyRepo->setIncludeEventHistory(false);
     $historyRepo->setIncludeVenueHistory(false);
     $historyRepo->setIncludeGroupHistory(true);
     $histories = $historyRepo->fetchAll();
     $this->assertEquals(2, count($histories));
     #the edit
     $this->assertEquals(FALSE, $histories[0]->getTitleChanged());
     $this->assertEquals(false, $histories[0]->getDescriptionChanged());
     $this->assertEquals(false, $histories[0]->getUrlChanged());
     $this->assertEquals(true, $histories[0]->getTwitterUsernameChanged());
     $this->assertEquals(false, $histories[0]->getIsDeletedChanged());
     #the create
     $this->assertEquals(true, $histories[1]->getTitleChanged());
     $this->assertEquals(true, $histories[1]->getDescriptionChanged());
     $this->assertEquals(true, $histories[1]->getUrlChanged());
     $this->assertEquals(false, $histories[1]->getTwitterUsernameChanged());
     $this->assertEquals(false, $histories[1]->getIsDeletedChanged());
 }
 protected function run()
 {
     $groupHistoryRepo = new GroupHistoryRepository();
     $stat = $this->app['db']->prepare("SELECT * FROM group_history");
     $stat->execute();
     $count = 0;
     while ($data = $stat->fetch()) {
         $groupHistory = new GroupHistoryModel();
         $groupHistory->setFromDataBaseRow($data);
         $groupHistoryRepo->ensureChangedFlagsAreSet($groupHistory);
         ++$count;
     }
     return array('result' => 'ok', 'count' => $count);
 }
 function testSetChangedFlagsFromLast3()
 {
     $lastHistory = new GroupHistoryModel();
     $lastHistory->setFromDataBaseRow(array('group_id' => 1, 'title' => 'Cat', 'description' => 'no dogs allowed', 'user_account_id' => 1, 'created_at' => '2014-02-01 10:00:00', 'url' => 'http://www.groupwithnoname.com', 'twitter_username' => 'noname', 'is_deleted' => 0, 'title_changed' => 0, 'description_changed' => 0, 'url_changed' => 0, 'twitter_username_changed' => 0, 'is_deleted_changed' => 0));
     $groupHistory = new GroupHistoryModel();
     $groupHistory->setFromDataBaseRow(array('group_id' => 1, 'title' => 'Cat', 'description' => 'no dogs allowed', 'user_account_id' => 1, 'created_at' => '2014-02-01 10:00:00', 'url' => 'http://www.groupwithnoname.com', 'twitter_username' => 'noname', 'is_deleted' => 1, 'title_changed' => 0, 'description_changed' => 0, 'url_changed' => 0, 'twitter_username_changed' => 0, 'is_deleted_changed' => 0));
     $groupHistory->setChangedFlagsFromLast($lastHistory);
     $this->assertEquals(false, $groupHistory->getTitleChanged());
     $this->assertEquals(false, $groupHistory->getDescriptionChanged());
     $this->assertEquals(false, $groupHistory->getUrlChanged());
     $this->assertEquals(false, $groupHistory->getTwitterUsernameChanged());
     $this->assertEquals(true, $groupHistory->getIsDeletedChanged());
     $this->assertEquals(false, $groupHistory->getIsNew());
 }
 public function ensureChangedFlagsAreSet(GroupHistoryModel $groupHistory)
 {
     global $DB;
     // do we already have them?
     if (!$groupHistory->isAnyChangeFlagsUnknown()) {
         return;
     }
     // load last.
     $stat = $DB->prepare("SELECT * FROM group_history WHERE group_id = :id AND created_at < :at " . "ORDER BY created_at DESC");
     $stat->execute(array('id' => $groupHistory->getId(), 'at' => $groupHistory->getCreatedAt()->format("Y-m-d H:i:s")));
     if ($stat->rowCount() == 0) {
         $groupHistory->setChangedFlagsFromNothing();
     } else {
         while ($groupHistory->isAnyChangeFlagsUnknown() && ($lastHistoryData = $stat->fetch())) {
             $lastHistory = new GroupHistoryModel();
             $lastHistory->setFromDataBaseRow($lastHistoryData);
             $groupHistory->setChangedFlagsFromLast($lastHistory);
         }
     }
     // Save back to DB
     $sqlFields = array();
     $sqlParams = array('id' => $groupHistory->getId(), 'created_at' => $groupHistory->getCreatedAt()->format("Y-m-d H:i:s"), 'is_new' => $groupHistory->getIsNew() ? 1 : 0);
     if ($groupHistory->getTitleChangedKnown()) {
         $sqlFields[] = " title_changed = :title_changed ";
         $sqlParams['title_changed'] = $groupHistory->getTitleChanged() ? 1 : -1;
     }
     if ($groupHistory->getDescriptionChangedKnown()) {
         $sqlFields[] = " description_changed = :description_changed ";
         $sqlParams['description_changed'] = $groupHistory->getDescriptionChanged() ? 1 : -1;
     }
     if ($groupHistory->getUrlChangedKnown()) {
         $sqlFields[] = " url_changed = :url_changed ";
         $sqlParams['url_changed'] = $groupHistory->getUrlChanged() ? 1 : -1;
     }
     if ($groupHistory->getTwitterUsernameChangedKnown()) {
         $sqlFields[] = " twitter_username_changed = :twitter_username_changed ";
         $sqlParams['twitter_username_changed'] = $groupHistory->getTwitterUsernameChanged() ? 1 : -1;
     }
     if ($groupHistory->getIsDuplicateOfIdChangedKnown()) {
         $sqlFields[] = " is_duplicate_of_id_changed  = :is_duplicate_of_id_changed ";
         $sqlParams['is_duplicate_of_id_changed'] = $groupHistory->getIsDuplicateOfIdChangedKnown() ? 1 : -1;
     }
     if ($groupHistory->getIsDeletedChangedKnown()) {
         $sqlFields[] = " is_deleted_changed = :is_deleted_changed ";
         $sqlParams['is_deleted_changed'] = $groupHistory->getIsDeletedChanged() ? 1 : -1;
     }
     $statUpdate = $DB->prepare("UPDATE group_history SET " . " is_new = :is_new, " . implode(" , ", $sqlFields) . " WHERE group_id = :id AND created_at = :created_at");
     $statUpdate->execute($sqlParams);
 }
 public function fetchAll()
 {
     global $DB, $app;
     $results = array();
     /////////////////////////// Events History
     if ($this->historyRepositoryBuilderConfig->getIncludeEventHistory()) {
         $where = array();
         $joins = array();
         $params = array();
         if ($this->historyRepositoryBuilderConfig->getEvent()) {
             $where[] = 'event_information.id=:event';
             $params['event'] = $this->historyRepositoryBuilderConfig->getEvent()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getGroup()) {
             // We use a seperate table here so if event is in 2 groups and we select events in 1 group that isn't the main group only,
             // the normal event_in_group table still shows the main group.
             $joins[] = " JOIN event_in_group AS event_in_group_select ON event_in_group_select.event_id = event_information.id " . "AND event_in_group_select.removed_at IS NULL AND event_in_group_select.group_id = :group_id ";
             $params['group_id'] = $this->historyRepositoryBuilderConfig->getGroup()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getSite()) {
             $where[] = 'event_information.site_id =:site';
             $params['site'] = $this->historyRepositoryBuilderConfig->getSite()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getVenue()) {
             $where[] = 'event_information.venue_id = :venue';
             $params['venue'] = $this->historyRepositoryBuilderConfig->getVenue()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getSince()) {
             $where[] = ' event_history.created_at >= :since ';
             $params['since'] = $this->historyRepositoryBuilderConfig->getSince()->format("Y-m-d H:i:s");
         }
         if ($this->historyRepositoryBuilderConfig->getNotUser()) {
             $where[] = 'event_history.user_account_id != :userid ';
             $params['userid'] = $this->historyRepositoryBuilderConfig->getNotUser()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getApi2app()) {
             $where[] = 'event_history.api2_application_id  = :api2app';
             $params['api2app'] = $this->historyRepositoryBuilderConfig->getApi2app()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getArea()) {
             $areaids = array($this->historyRepositoryBuilderConfig->getArea()->getId());
             $this->statAreas = $DB->prepare("SELECT area_id FROM cached_area_has_parent WHERE has_parent_area_id=:id");
             $this->statAreas->execute(array('id' => $this->historyRepositoryBuilderConfig->getArea()->getId()));
             while ($d = $this->statAreas->fetch()) {
                 $areaids[] = $d['area_id'];
             }
             $joins[] = " LEFT JOIN venue_information ON  event_information.venue_id = venue_information.id ";
             $where[] = ' (event_information.area_id IN (' . implode(",", $areaids) . ')  OR venue_information.area_id IN (' . implode(",", $areaids) . ') ) ';
         }
         if ($this->historyRepositoryBuilderConfig->getVenueVirtualOnly()) {
             // we check both on an OR, that way we get both
             // a) events that were not virtual and became virtual, we get their full history
             // b) events that were virtual and now aren't, we get some of their history
             $where[] = " ( event_information.is_virtual = '1' OR event_history.is_virtual = '1' )";
         }
         $sql = "SELECT event_history.*, group_information.title AS group_title,  group_information.id AS group_id,  event_information.slug AS event_slug, user_account_information.username AS user_account_username FROM event_history " . " LEFT JOIN user_account_information ON user_account_information.id = event_history.user_account_id " . " LEFT JOIN event_information ON event_information.id = event_history.event_id " . " LEFT JOIN event_in_group ON event_in_group.event_id = event_information.id AND event_in_group.removed_at IS NULL AND event_in_group.is_main_group = '1' " . " LEFT JOIN group_information ON group_information.id = event_in_group.group_id " . implode(" ", $joins) . ($where ? " WHERE " . implode(" AND ", $where) : "") . " ORDER BY event_history.created_at DESC LIMIT " . $this->historyRepositoryBuilderConfig->getLimit();
         //var_dump($sql); var_dump($params);
         $stat = $DB->prepare($sql);
         $stat->execute($params);
         while ($data = $stat->fetch()) {
             $eventHistory = new EventHistoryModel();
             $eventHistory->setFromDataBaseRow($data);
             $results[] = $eventHistory;
         }
     }
     /////////////////////////// Group History
     if ($this->historyRepositoryBuilderConfig->getIncludeGroupHistory()) {
         $where = array();
         $params = array();
         if ($this->historyRepositoryBuilderConfig->getEvent() && $this->historyRepositoryBuilderConfig->getEvent()->getGroupId()) {
             $where[] = 'group_information.id=:group';
             $params['group'] = $this->historyRepositoryBuilderConfig->getEvent()->getGroupId();
         } else {
             if ($this->historyRepositoryBuilderConfig->getGroup()) {
                 $where[] = 'group_information.id =:group';
                 $params['group'] = $this->historyRepositoryBuilderConfig->getGroup()->getId();
             }
         }
         if ($this->historyRepositoryBuilderConfig->getSite()) {
             $where[] = 'group_information.site_id =:site';
             $params['site'] = $this->historyRepositoryBuilderConfig->getSite()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getSince()) {
             $where[] = ' group_history.created_at >= :since ';
             $params['since'] = $this->historyRepositoryBuilderConfig->getSince()->format("Y-m-d H:i:s");
         }
         if ($this->historyRepositoryBuilderConfig->getNotUser()) {
             $where[] = 'group_history.user_account_id != :userid ';
             $params['userid'] = $this->historyRepositoryBuilderConfig->getNotUser()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getApi2app()) {
             $where[] = 'group_history.api2_application_id  = :api2app';
             $params['api2app'] = $this->historyRepositoryBuilderConfig->getApi2app()->getId();
         }
         $sql = "SELECT group_history.*, group_information.slug AS group_slug, user_account_information.username AS user_account_username FROM group_history " . " LEFT JOIN user_account_information ON user_account_information.id = group_history.user_account_id " . " LEFT JOIN group_information ON group_information.id = group_history.group_id " . ($where ? " WHERE " . implode(" AND ", $where) : "") . " ORDER BY group_history.created_at DESC LIMIT " . $this->historyRepositoryBuilderConfig->getLimit();
         //var_dump($sql); var_dump($params);
         $stat = $DB->prepare($sql);
         $stat->execute($params);
         while ($data = $stat->fetch()) {
             $groupHistory = new GroupHistoryModel();
             $groupHistory->setFromDataBaseRow($data);
             $results[] = $groupHistory;
         }
     }
     /////////////////////////// Venue History
     if ($this->historyRepositoryBuilderConfig->getIncludeVenueHistory()) {
         $where = array();
         $params = array();
         if ($this->historyRepositoryBuilderConfig->getEvent() && $this->historyRepositoryBuilderConfig->getEvent()->getVenueId()) {
             $where[] = 'venue_information.id=:venue';
             $params['venue'] = $this->historyRepositoryBuilderConfig->getEvent()->getVenueId();
         } else {
             if ($this->historyRepositoryBuilderConfig->getVenue()) {
                 $where[] = 'venue_information.id=:venue';
                 $params['venue'] = $this->historyRepositoryBuilderConfig->getVenue()->getId();
             }
         }
         if ($this->historyRepositoryBuilderConfig->getSite()) {
             $where[] = 'venue_information.site_id =:site';
             $params['site'] = $this->historyRepositoryBuilderConfig->getSite()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getSince()) {
             $where[] = ' venue_history.created_at >= :since ';
             $params['since'] = $this->historyRepositoryBuilderConfig->getSince()->format("Y-m-d H:i:s");
         }
         if ($this->historyRepositoryBuilderConfig->getNotUser()) {
             $where[] = 'venue_history.user_account_id != :userid ';
             $params['userid'] = $this->historyRepositoryBuilderConfig->getNotUser()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getApi2app()) {
             $where[] = 'venue_history.api2_application_id  = :api2app';
             $params['api2app'] = $this->historyRepositoryBuilderConfig->getApi2app()->getId();
         }
         $sql = "SELECT venue_history.*, venue_information.slug AS venue_slug, user_account_information.username AS user_account_username FROM venue_history " . " LEFT JOIN user_account_information ON user_account_information.id = venue_history.user_account_id " . " LEFT JOIN venue_information ON venue_information.id = venue_history.venue_id " . ($where ? " WHERE " . implode(" AND ", $where) : "") . " ORDER BY venue_history.created_at DESC LIMIT " . $this->historyRepositoryBuilderConfig->getLimit();
         //var_dump($sql); var_dump($params);
         $stat = $DB->prepare($sql);
         $stat->execute($params);
         while ($data = $stat->fetch()) {
             $venueHistory = new VenueHistoryModel();
             $venueHistory->setFromDataBaseRow($data);
             $results[] = $venueHistory;
         }
     }
     /////////////////////////// Area History
     if ($this->historyRepositoryBuilderConfig->getIncludeAreaHistory()) {
         $where = array();
         $params = array();
         $joins = array();
         if ($this->historyRepositoryBuilderConfig->getArea()) {
             // Will this produce dupes? No evidence so far but there was a note in EventRepositoryBuilder that said so.
             $joins[] = " LEFT JOIN cached_area_has_parent ON cached_area_has_parent.area_id = area_information.id ";
             $where[] = ' (area_information.id =:area OR cached_area_has_parent.has_parent_area_id =:area )';
             $params['area'] = $this->historyRepositoryBuilderConfig->getArea()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getSite()) {
             $where[] = 'area_information.site_id =:site';
             $params['site'] = $this->historyRepositoryBuilderConfig->getSite()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getSince()) {
             $where[] = ' area_history.created_at >= :since ';
             $params['since'] = $this->historyRepositoryBuilderConfig->getSince()->format("Y-m-d H:i:s");
         }
         if ($this->historyRepositoryBuilderConfig->getNotUser()) {
             $where[] = 'area_history.user_account_id != :userid ';
             $params['userid'] = $this->historyRepositoryBuilderConfig->getNotUser()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getApi2app()) {
             $where[] = 'area_history.api2_application_id  = :api2app';
             $params['api2app'] = $this->historyRepositoryBuilderConfig->getApi2app()->getId();
         }
         $sql = "SELECT area_history.*, area_information.slug AS area_slug, user_account_information.username AS user_account_username FROM area_history " . " LEFT JOIN user_account_information ON user_account_information.id = area_history.user_account_id " . " LEFT JOIN area_information ON area_information.id = area_history.area_id " . implode(" ", $joins) . ($where ? " WHERE " . implode(" AND ", $where) : "") . " ORDER BY area_history.created_at DESC LIMIT " . $this->historyRepositoryBuilderConfig->getLimit();
         //var_dump($sql); var_dump($params);
         $stat = $DB->prepare($sql);
         $stat->execute($params);
         while ($data = $stat->fetch()) {
             $areaHistory = new AreaHistoryModel();
             $areaHistory->setFromDataBaseRow($data);
             $results[] = $areaHistory;
         }
     }
     /////////////////////////// Tags History
     if ($this->historyRepositoryBuilderConfig->getIncludeTagHistory()) {
         $where = array();
         $params = array();
         if ($this->historyRepositoryBuilderConfig->getSite()) {
             $where[] = 'tag_information.site_id =:site';
             $params['site'] = $this->historyRepositoryBuilderConfig->getSite()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getSince()) {
             $where[] = ' tag_history.created_at >= :since ';
             $params['since'] = $this->historyRepositoryBuilderConfig->getSince()->format("Y-m-d H:i:s");
         }
         if ($this->historyRepositoryBuilderConfig->getNotUser()) {
             $where[] = 'tag_history.user_account_id != :userid ';
             $params['userid'] = $this->historyRepositoryBuilderConfig->getNotUser()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getApi2app()) {
             $where[] = 'tag_history.api2_application_id  = :api2app';
             $params['api2app'] = $this->historyRepositoryBuilderConfig->getApi2app()->getId();
         }
         $sql = "SELECT tag_history.*, tag_information.slug AS tag_slug, user_account_information.username AS user_account_username FROM tag_history " . " LEFT JOIN user_account_information ON user_account_information.id = tag_history.user_account_id " . " LEFT JOIN tag_information ON tag_information.id = tag_history.tag_id " . ($where ? " WHERE " . implode(" AND ", $where) : "") . " ORDER BY tag_history.created_at DESC LIMIT " . $this->historyRepositoryBuilderConfig->getLimit();
         //var_dump($sql); var_dump($params);
         $stat = $DB->prepare($sql);
         $stat->execute($params);
         while ($data = $stat->fetch()) {
             $tagHistory = new TagHistoryModel();
             $tagHistory->setFromDataBaseRow($data);
             $results[] = $tagHistory;
         }
     }
     /////////////////////////// Import URL History
     if ($this->historyRepositoryBuilderConfig->getIncludeImportURLHistory()) {
         $where = array();
         $params = array();
         if ($this->historyRepositoryBuilderConfig->getSite()) {
             $where[] = 'import_url_information.site_id =:site';
             $params['site'] = $this->historyRepositoryBuilderConfig->getSite()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getGroup()) {
             $where[] = 'import_url_information.group_id =:group';
             $params['group'] = $this->historyRepositoryBuilderConfig->getGroup()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getSince()) {
             $where[] = ' import_url_history.created_at >= :since ';
             $params['since'] = $this->historyRepositoryBuilderConfig->getSince()->format("Y-m-d H:i:s");
         }
         if ($this->historyRepositoryBuilderConfig->getNotUser()) {
             $where[] = 'import_url_history.user_account_id != :userid ';
             $params['userid'] = $this->historyRepositoryBuilderConfig->getNotUser()->getId();
         }
         if ($this->historyRepositoryBuilderConfig->getApi2app()) {
             $where[] = 'import_url_history.api2_application_id  = :api2app';
             $params['api2app'] = $this->historyRepositoryBuilderConfig->getApi2app()->getId();
         }
         $sql = "SELECT import_url_history.*, import_url_information.slug AS import_url_slug, " . "user_account_information.username AS user_account_username " . " FROM import_url_history " . " LEFT JOIN user_account_information ON user_account_information.id = import_url_history.user_account_id " . " LEFT JOIN import_url_information ON import_url_information.id = import_url_history.import_url_id " . ($where ? " WHERE " . implode(" AND ", $where) : "") . " ORDER BY import_url_history.created_at DESC LIMIT " . $this->historyRepositoryBuilderConfig->getLimit();
         //var_dump($sql); var_dump($params);
         $stat = $DB->prepare($sql);
         $stat->execute($params);
         while ($data = $stat->fetch()) {
             $tagHistory = new ImportURLHistoryModel();
             $tagHistory->setFromDataBaseRow($data);
             $results[] = $tagHistory;
         }
     }
     ////////////////////// Others!
     foreach ($app['extensions']->getExtensions() as $ext) {
         $results = array_merge($results, $ext->getHistoryRepositoryBuilderData($this->historyRepositoryBuilderConfig));
     }
     ////////////////////// Finally sort & truncate
     $usort = function ($a, $b) {
         if ($a->getCreatedAtTimeStamp() == $b->getCreatedAtTimeStamp()) {
             return 0;
         } else {
             if ($a->getCreatedAtTimeStamp() > $b->getCreatedAtTimeStamp()) {
                 return -1;
             } else {
                 return 1;
             }
         }
     };
     usort($results, $usort);
     array_slice($results, 0, $this->historyRepositoryBuilderConfig->getLimit());
     return $results;
 }