counters.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. require_once "doctrine/bootstrap.php";
  3. require_once "auth.php";
  4. //пример 461 3ЭС5К
  5. function GetCounters($projectId, $checkpointtype)
  6. {
  7. global $link;
  8. $cs = array();
  9. $str = "select spl.tid, spl.value,tt.name from (select t.id as tid, t.parent_id as id, ch.value from checkpoints as ch
  10. LEFT JOIN tasks AS t ON ch.parent_task_id = t.id
  11. LEFT JOIN projects_locotech AS pl ON t.input_id = pl.id
  12. WHERE pl.id = $projectId and ch.type = $checkpointtype ) as spl
  13. LEFT JOIN tasks AS ts ON spl.id = ts.id
  14. LEFT JOIN tasktypes AS tt ON ts.type = tt.id";
  15. $query1 = mysqli_query($link, $str);
  16. while ($res1 = mysqli_fetch_assoc($query1)) {
  17. $cs[] = $res1;
  18. }
  19. return $cs;
  20. }
  21. function GetCounterArray($loco_number, $loco_type)
  22. {
  23. global $entityManager;
  24. $retarr = array();
  25. //limit=1: последний проект по данному локомотиву
  26. $projs = $entityManager->getRepository('Project')->findBy(array('loco_number' => $loco_number, 'loco_type' => $loco_type),
  27. array('id' => 'DESC'), 1);
  28. foreach ($projs as $proj) {
  29. $sectionArr = array();
  30. $thrust = GetCounters($proj->id, 310);
  31. $recuperation = GetCounters($proj->id, 311);
  32. $i = 0;
  33. foreach ($thrust as $thr)
  34. {
  35. $task = Task::Find($thr['tid']);
  36. if ($task)
  37. {
  38. $section = $task->getSection();
  39. $sectionArr[] = $loco_number.$section->letter."/".$section->getSectionSubnumber();
  40. $sectionArr[] = $thr['value'];
  41. $sectionArr[] = $recuperation[$i]['value'];
  42. }
  43. $i++;
  44. }
  45. $retarr[] = $sectionArr;
  46. }
  47. //var_dump($retarr);
  48. return $retarr;
  49. }