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.

StopsBusiness.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. return new LuPaginatedDbo(count($dbos), $dbos);
  56. }
  57. }