You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: robin
  5. * Date: 9/30/16
  6. * Time: 8:58 PM
  7. */
  8. namespace App\Business;
  9. use App\DataAccess\StopsDataAccess;
  10. use App\Dbo\StopsDbo;
  11. use Luticate\Utils\Dbo\LuPaginatedDbo;
  12. class StopsBusiness
  13. {
  14. protected static function getDataAccess()
  15. {
  16. return new StopsDataAccess();
  17. }
  18. public static function getStopDboById(array $dbos, string $id)
  19. {
  20. /**
  21. * @var $dbos StopsDbo[]
  22. */
  23. foreach ($dbos as $dbo) {
  24. if ($dbo->getId() == $id) {
  25. return $dbo;
  26. }
  27. }
  28. return null;
  29. }
  30. public static function mergeStringArray(array $array1, array $array2)
  31. {
  32. foreach ($array2 as $e) {
  33. if (!in_array($e, $array1)) {
  34. $array1[] = $e;
  35. }
  36. }
  37. return $array1;
  38. }
  39. public static function getAll()
  40. {
  41. $config = MiscBusiness::getConfig();
  42. $dbos = [];
  43. foreach ($config["scheduleTypes"] as $scheduleType) {
  44. $scheduleDbos = static::getDataAccess()->getAll($scheduleType["resourceId"], $scheduleType["type"]);
  45. foreach ($scheduleDbos as $scheduleDbo) {
  46. $dbo = static::getStopDboById($dbos, $scheduleDbo->getId());
  47. if (is_null($dbo)) {
  48. $dbos[] = $scheduleDbo;
  49. }
  50. else {
  51. $dbo->setRoutes(static::mergeStringArray($dbo->getRoutes(), $dbo->getRoutes()));
  52. }
  53. }
  54. }
  55. usort($dbos, function ($dbo1, $dbo2)
  56. {
  57. /**
  58. * @var $dbo1 StopsDbo
  59. * @var $dbo2 StopsDbo
  60. */
  61. return intval($dbo1->getId()) > intval($dbo2->getId());
  62. });
  63. return new LuPaginatedDbo(count($dbos), $dbos);
  64. }
  65. }