public function listAction() { if ($this->request->isAjax()) { $id = (int) (new \Validate())->getPost('id'); if ($id == 0) { $this->end(404); } $this->end((new \Train())->delTrain($id, $this->session->get('id'))); } //当前页码 $page_id = (int) $this->request->getQuery('page'); $page_id = $page_id < 1 ? 1 : $page_id; //省份code $pro_code = (int) $this->request->getQuery('pro_code'); //城市code $city_code = (int) $this->request->getQuery('city_code'); //区县code $area_code = (int) $this->request->getQuery('area_code'); //关键字 $keyword = preg_replace('/[^\\da-z\\x{4e00}-\\x{9fa5}]/iu', '', mb_substr($this->request->getQuery('keyword'), 0, 10, 'utf-8')); //关键字长度小于10,并且只能是字符数字中文 //每页显示条数 $limit = 20; //省市区县 $site = new \Site(); $provinces = $site->getProvince(); //省 $cities = $site->getCity($pro_code); //城市 $areas = $site->getArea($city_code); //区县 //查询数据 $train = new \Train(); //获取分类 $category = $train->getCategory(); $list = $train->getList($page_id, $limit, $pro_code, $city_code, $keyword); //数据 $page_html = $this->pageHtml($list['page']); //分页html //加载js $this->assets->addJs('backend/mt/train-list.js'); $this->view->setVars(['pro_code' => $pro_code, 'city_code' => $city_code, 'area_code' => $area_code, 'category' => $category, 'keyword' => $keyword, 'provinces' => $provinces, 'cities' => $cities, 'areas' => $areas, 'list' => $list['list'], 'page_html' => $page_html]); }
/** * shows the Search box */ static function showSearchBox() { ?> <div class="panel panel-primary"> <div class="panel-heading" data-toggle="collapse" aria-expanded="false" aria-controls="searchForm" role="tab"> <h3 class="panel-title"><a data-toggle="collapse" href="#searchForm" aria-expanded="false" aria-controls="searchForm"><?php echo Lang::l_("By route information:"); ?> </a></h3> </div> <div class="panel-body collapse" id="searchForm"> <form method="get" id="searchform" class=".form-horizontal"> <div class="form-group"> <label for="ref" class="col-sm-2 control-label"><?php echo Lang::l_("Line"); ?> :</label> <div class="col-sm-10"> <input type="text" name="ref" id="ref" class="form-control"> </div> </div> <div class="form-group"> <label for="operator" class="col-sm-2 control-label"><?php echo Lang::l_("Operator"); ?> :</label> <div class="col-sm-10"> <input type="text" name="operator" id="operator" class="form-control"> </div> </div> <div class="form-group"> <label for="network" class="col-sm-2 control-label"><?php echo Lang::l_("Network"); ?> :</label> <div class="col-sm-10"> <input type="text" name="network" id="network" class="form-control"> </div> </div> <div class="form-group"> <label for="from" class="col-sm-2 control-label"><?php echo Lang::l_("Origin"); ?> :</label> <div class="col-sm-10"> <input type="text" name="from" id="from" class="form-control"> </div> </div> <div class="form-group"> <label for="to" class="col-sm-2 control-label"><?php echo Lang::l_("Destination"); ?> :</label> <div class="col-sm-10"> <input type="text" name="to" id="to" class="form-control"> </div> </div> <div class="form-group"> <label for="trainsearch" class="col-sm-2 control-label"><?php echo Lang::l_('Train'); ?> :</label> <div class="col-sm-10"> <?php echo Train::changeTrain("", "", "trainsearch"); ?> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default"><?php echo Lang::l_("Search route"); ?> </button> </div> </div> </form> </div> </div> <?php }
/** * @group non-cacheable */ public function testEagerLoadWithNonNullableColumnsGeneratesInnerJoinOnOwningSide() { $waggon = new Waggon(); // It should have a train $train = new Train(new TrainOwner("Alexander")); $train->addWaggon($waggon); $this->_em->persist($train); $this->_em->flush(); $this->_em->clear(); $waggon = $this->_em->find(get_class($waggon), $waggon->id); // The last query is the eager loading of the owner of the train $this->assertSQLEquals("SELECT t0.id AS id_1, t0.name AS name_2, t3.id AS id_4, t3.driver_id AS driver_id_5, t3.owner_id AS owner_id_6 FROM TrainOwner t0 LEFT JOIN Train t3 ON t3.owner_id = t0.id WHERE t0.id IN (?)", $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['sql']); // The one before is the fetching of the waggon and train $this->assertSQLEquals("SELECT t0.id AS id_1, t0.train_id AS train_id_2, t3.id AS id_4, t3.driver_id AS driver_id_5, t3.owner_id AS owner_id_6 FROM Waggon t0 INNER JOIN Train t3 ON t0.train_id = t3.id WHERE t0.id = ?", $this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery - 1]['sql']); }
<?php include "Transport.php"; include "Car.php"; include "Plane.php"; include "Ship.php"; include "Train.php"; include "Bike.php"; $car = new Car(); $car->go(); $plane = new Plane(); $plane->go(); $train = new Train(); $train->go(); $car = new Ship(); $car->go(); $bike = new Bike(); $bike->go();
/** * sorts the accbrake array and deletes impossible accelerations/brakes * @param unknown $accbrake_array * @return number */ function sort_accbrake($accbrake_array) { //sort array after the start points of the accelerations and brakes foreach ($accbrake_array as $key => $row) { $start[$key] = $row[0]; $stop[$key] = $row[1]; $vstart[$key] = $row[2]; $vstop[$key] = $row[3]; $type[$key] = $row[4]; } array_multisort($start, SORT_ASC, $accbrake_array); //go through array $j = 0; for ($i = 0; isset($accbrake_array[$i + 1]); $i++) { //train breaks without accelerating before (next speed is bigger than current speed) if ($accbrake_array[$i + 1][2] > $accbrake_array[$i][3]) { //Special case: train is stopped if ($accbrake_array[$i][3] == 0) { //TODO: do we need to do anything here? } else { //set start speed of next one to end speed of current $accbrake_array[$i + 1][2] = $accbrake_array[$i][3]; } } //train accelerates without breaking after (next speed is smaller than current speed) if ($accbrake_array[$i + 1][2] < $accbrake_array[$i][3] && $accbrake_array[$i][4] == "acc" && $accbrake_array[$i + 1][4] == "brake") { //skip acceleration and delete array if possible if ($accbrake_array[$i][2] == $accbrake_array[$i + 1][2]) { $accbrake_array[$i][0] = 0; $accbrake_array[$i][1] = 0; $accbrake_array[$i][2] = 0; $accbrake_array[$i][3] = 0; } elseif ($accbrake_array[$i][2] < $accbrake_array[$i + 1][2]) { $acceleration = $this->train->acceleration($this->train->mass_empty, $this->train->torque, $this->train->power, 200, $accbrake_array[$i][2], $accbrake_array[$i + 1][2]); $way_acc = ($accbrake_array[$i + 1][2] * $accbrake_array[$i + 1][2] - $accbrake_array[$i][2] * $accbrake_array[$i][2]) / (2 * $acceleration); $accbrake_array[$i][0] = $accbrake_array[$i][0]; $accbrake_array[$i][1] = $accbrake_array[$i][0] + $way_acc; $accbrake_array[$i][2] = $accbrake_array[$i][2]; $accbrake_array[$i][3] = $accbrake_array[$i + 1][2]; } else { log_error("WARNING: Train accelerates without breaking after. Relation ID: " . $this->id . " | Maxspeed array position: " . $i); } } //two accelerations with different in-between speeds and no braking (next speed is smaller than current speed) if ($accbrake_array[$i + 1][2] < $accbrake_array[$i][3] && $accbrake_array[$i][4] == "acc" && $accbrake_array[$i + 1][4] == "acc") { //set maxspeed of first acceleration to lower speed $accbrake_array[$i][3] = $accbrake_array[$i + 1][2]; echo "-" . $accbrake_array[$i][1] . "|" . $accbrake_array[$i][2] . "|" . $accbrake_array[$i][3]; } //two brakings with different in-between speeds and no acceleration (next speed is smaller than current speed) if ($accbrake_array[$i + 1][2] < $accbrake_array[$i][3] && $accbrake_array[$i][4] == "brake" && $accbrake_array[$i + 1][4] == "brake") { //calculate new braking: $way_brake = ($accbrake_array[$i][2] * $accbrake_array[$i][2] - $accbrake_array[$i + 1][3] * $accbrake_array[$i + 1][3]) / (2 * $this->train->brake); $accbrake_array[$i][0] = $accbrake_array[$i + 1][1] - $way_brake; $accbrake_array[$i][1] = $accbrake_array[$i + 1][1]; $accbrake_array[$i][2] = $accbrake_array[$i][2]; $accbrake_array[$i][3] = $accbrake_array[$i + 1][3]; $accbrake_array[$i + 1][0] = 0; $accbrake_array[$i + 1][1] = 0; $accbrake_array[$i + 1][2] = 0; $accbrake_array[$i + 1][3] = 0; } //Operation B is within Operation A if ($accbrake_array[$i + 1][0] > $accbrake_array[$i][0] && $accbrake_array[$i + 1][1] < $accbrake_array[$i][1]) { //delete operation B $accbrake_array[$i + 1][0] = 0; $accbrake_array[$i + 1][1] = 0; $accbrake_array[$i + 1][2] = 0; $accbrake_array[$i + 1][3] = 0; } //two operations overlap if ($accbrake_array[$i + 1][0] < $accbrake_array[$i][1]) { //accelerating before braking if ($accbrake_array[$i + 1][4] == "brake" && $accbrake_array[$i][4] == "acc") { //brake speed is same as acceleration speed if ($accbrake_array[$i + 1][3] == $accbrake_array[$i][3]) { //do not brake $accbrake_array[$i + 1][1] = $accbrake_array[$i + 1][0] = $accbrake_array[$i][1]; $accbrake_array[$i + 1][2] = $accbrake_array[$i + 1][3]; } elseif ($accbrake_array[$i + 1][3] > $accbrake_array[$i][2]) { //only accelerate to braking speed $accbrake_array[$i][3] = $accbrake_array[$i + 1][3]; $accbrake_array[$i][1] = $accbrake_array[$i + 1][0] = ($accbrake_array[$i + 1][1] + $accbrake_array[$i][0]) / 2; $accbrake_array[$i + 1][2] = $accbrake_array[$i][3]; } elseif ($accbrake_array[$i + 1][3] < $accbrake_array[$i][2] && $accbrake_array[$i + 1][3] != $accbrake_array[$i + 1][2]) { //do not accelerate $accbrake_array[$i][1] = $accbrake_array[$i][0]; $accbrake_array[$i][3] = $accbrake_array[$i][2]; //recalculate braking way $accbrake_array[$i + 1][0] = $accbrake_array[$i + 1][1] - $this->ReCalculateS1($accbrake_array[$i + 1][1] - $accbrake_array[$i + 1][0], $accbrake_array[$i + 1][3] - $accbrake_array[$i][2], $accbrake_array[$i + 1][3] - $accbrake_array[$i + 1][2]); //new maxspeed value $accbrake_array[$i + 1][2] = $accbrake_array[$i][2]; } elseif ($accbrake_array[$i + 1][3] == $accbrake_array[$i][2]) { //Special case: train is stopped -> must be accelerated to move if ($accbrake_array[$i][2] == 0) { if ($accbrake_array[$i][3] != 0 && $accbrake_array[$i + 1][2] != 0) { //calculate new acceleration speed while ($accbrake_array[$i + 1][0] < $accbrake_array[$i][1]) { //set speed to 80% $newSpeed = 0.8 * $accbrake_array[$i][3]; //recalculate acceleration $accbrake_array[$i][1] = $accbrake_array[$i][0] + $this->ReCalculateS1($accbrake_array[$i][1] - $accbrake_array[$i][0], $newSpeed, $accbrake_array[$i][3]); $accbrake_array[$i][3] = $newSpeed; //recalculate braking $accbrake_array[$i + 1][0] = $accbrake_array[$i + 1][1] - $this->ReCalculateS1($accbrake_array[$i + 1][1] - $accbrake_array[$i + 1][0], $newSpeed, $accbrake_array[$i + 1][2]); $accbrake_array[$i + 1][2] = $newSpeed; } } } else { //do not brake or accelerate //delete braking $accbrake_array[$i + 1][0] = 0; $accbrake_array[$i + 1][1] = 0; $accbrake_array[$i + 1][2] = 0; $accbrake_array[$i + 1][3] = 0; //delete acceleration $accbrake_array[$i][0] = $accbrake_array[$i][1]; $accbrake_array[$i][3] = $accbrake_array[$i][2]; } } } //crossing operations if ($accbrake_array[$i + 1][4] == "brake" && $accbrake_array[$i][4] == "brake") { //delete braking $accbrake_array[$i + 1][0] = $accbrake_array[$i][1]; $accbrake_array[$i + 1][1] = $accbrake_array[$i][1]; $accbrake_array[$i + 1][2] = $accbrake_array[$i][3]; $accbrake_array[$i + 1][3] = $accbrake_array[$i][3]; } } } return $accbrake_array; }
/** OSMTrainRouteAnalysis Copyright © 2014-2015 sb12 osm.mapper999@gmail.com This file is part of OSMTrainRouteAnalysis. OSMTrainRouteAnalysis is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ $id = $_GET["id"]; $train = $_GET["train"]; $route = $_GET["route"]; $service = $_GET["service"]; // load settings include "../functions/settings.php"; // load needed functions include "../functions/lang.php"; include "../functions/start.php"; include "../functions/train.php"; if (Train::setDefaultTrain($train, $id, $service, $route)) { echo "true"; } else { echo "false"; }
/** * generates form to upload route */ function uploadRoute() { ?> <div class="panel panel-primary"> <div class="panel-heading" data-toggle="collapse" aria-expanded="false" aria-controls="idForm" role="tab"> <h3 class="panel-title"><a data-toggle="collapse" href="#uploadForm" aria-expanded="false" aria-controls="uploadForm"><?php echo Lang::l_("By uploading an osm file:"); ?> </a></h3> </div> <div class="panel-body collapse" id="uploadForm"> <?php echo Lang::l_('This can be used to edit routes locally and upload them to the tool without entering data into OSM, e.g. for case studies.'); ?> <br> <?php echo Lang::l_('All osm files can be processed as long as they contain the relation itself and all relevant ways and nodes, e.g. you can edit a route in JOSM, save it locally and upload it.'); ?> <form action="index.php" method="post" id="osmid" class=".form-horizontal" enctype="multipart/form-data"> <div class="form-group"> <label for="id" class="col-sm-2 control-label"><?php echo Lang::l_('Route file'); ?> :</label> <div class="col-sm-10"> <input type="file" name="osmfile" id="osmfile" class="form-control" required> </div> </div> <div class="form-group"> <label for="id" class="col-sm-2 control-label"><?php echo Lang::l_('Relation ID'); ?> :</label> <div class="col-sm-10"> <input type="number" name="id" id="id" class="form-control" required> </div> </div> <div class="form-group"> <label for="train" class="col-sm-2 control-label"><?php echo Lang::l_('Train'); ?> :</label> <div class="col-sm-10"> <?php echo Train::changeTrain(); ?> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default"><?php echo Lang::l_("Upload route"); ?> </button> </div> </div> </form> </div> </div> <?php }
public function compareAction() { //判断是否是ajax请求 if ($this->request->isAjax()) { $validate = new \Validate(); $data['id1'] = (int) $validate->getPost('id1'); $data['id2'] = (int) $validate->getPost('id2'); if ($data['id1'] == 0) { $this->end(400); } $this->end(json_encode((new \Train())->getPrimary($data))); } $data['id1'] = (int) $this->request->getQuery('id1'); $data['id2'] = (int) $this->request->getQuery('id2'); if ($data['id1'] == 0 || $data['id2'] == 0) { $this->notFound(); } $train = new \Train(); $train1 = $train->getDetail($data['id1']); $train2 = $train->getDetail($data['id2']); $train1['url'] = "/train/detail_" . $train1["tra_id"] . ".html"; $train2['url'] = "/train/detail_" . $train2["tra_id"] . ".html"; if (empty($train1) || empty($train2)) { $this->notFound(); } $this->assets->addCss("fontend/css/school/compare.css"); $this->assets->addJs("fontend/js/school_compare.js"); $this->view->setVars(['train1' => $train1, 'train2' => $train2]); }
/** * generates form to choose route id and train */ function enterID() { ?> <div class="panel-group container-fluid" role="tablist"> <div class="panel panel-primary"> <div class="panel-heading"> <h2 class="panel-title"><?php echo Lang::l_('Choose Route'); ?> :</h2> </div> </div> <div class="panel panel-primary"> <div class="panel-heading" data-toggle="collapse" aria-expanded="false" aria-controls="idForm" role="tab"> <h3 class="panel-title"><a data-toggle="collapse" href="#idForm" aria-expanded="false" aria-controls="idForm"><?php echo Lang::l_("By the OpenStreetMap relation id:"); ?> </a></h3> </div> <div class="panel-body collapse" id="idForm"> <form action="index.php" method="get" id="osmid" class=".form-horizontal"> <div class="form-group"> <label for="id" class="col-sm-2 control-label"><?php echo Lang::l_('OpenStreetMap id'); ?> :</label> <div class="col-sm-10"> <input type="number" name="id" id="id" class="form-control" required> </div> </div> <div class="form-group"> <label for="train" class="col-sm-2 control-label"><?php echo Lang::l_('Train'); ?> :</label> <div class="col-sm-10"> <?php echo Train::changeTrain(); ?> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default"><?php echo Lang::l_("Load route"); ?> </button> </div> </div> </form> </div> </div> <?php Search::showSearchBox(); }
if ($default_allowed) { $mysql = connectToDB(); $query = "UPDATE `osm_train_details` SET train = '" . $mysql->real_escape_string($train) . "' WHERE `id` = '" . $mysql->real_escape_string($id) . "'"; if (@$mysql->query($query)) { return true; } else { log_error($mysql->error); return false; } } else { return false; } } /** * gets the default train for a route * @param number $id id of route * @return String ref of default train */ static function getDefaultTrain($id) { $mysql = connectToDB(); $query = "SELECT train FROM `osm_train_details` WHERE `id` = '" . $mysql->real_escape_string($id) . "'"; $result = @$mysql->query($query); while ($line = $result->fetch_array()) { return $line["train"]; } } } //define Train types Train::$train_type = array("highspeed" => Lang::l_('Highspeed train'), "long_distance" => Lang::l_('Long distance train'), "night" => Lang::l_('Night train'), "regional" => Lang::l_('Regional train'), "light_rail" => Lang::l_('Light rail'), "tram" => Lang::l_('Tram'), "subway" => Lang::l_('Subway'), "freight" => Lang::l_('Freight train'));
/** * <p>Adds new train into the GVD. If is the train already stored, new exception is thrown.</p> * * @param object Train New train object. * @throws ObjectAlreadyStoredEception Exception is thrown if the object is already stored. */ public function addTrain(Train $train) { if (!array_key_exists($train->getId(), $this->trains)) { $this->trains[$train->getId()] = $train; } else { throw new ObjectAlreadyStoredException($train); } }