示例#1
0
 public function testSimpleUpdate()
 {
     $Inserter = new Inserter($this->PDO);
     $Inserter->setAccountID(0);
     $Inserter->insert(new Object(array(Object::NAME => 'Route name', Object::DISTANCE => 3.14)));
     $Route = new Object($this->PDO->query('SELECT * FROM `' . PREFIX . 'route` WHERE `id`=' . $Inserter->insertedID())->fetch(PDO::FETCH_ASSOC));
     $Route->set(Object::DISTANCE, 0);
     $Changed = clone $Route;
     $Changed->set(Object::NAME, 'New route name');
     $Updater = new Updater($this->PDO, $Changed, $Route);
     $Updater->setAccountID(0);
     $Updater->update();
     $Result = new Object($this->PDO->query('SELECT * FROM `' . PREFIX . 'route` WHERE `id`=' . $Inserter->insertedID())->fetch(PDO::FETCH_ASSOC));
     $this->assertEquals('New route name', $Result->name());
     $this->assertEquals(3.14, $Result->distance());
 }
示例#2
0
 /**
  * Save changes for route
  */
 protected function saveChangesForRoute()
 {
     if (null === $this->Route || $this->OldRoute->isEmpty()) {
         return;
     }
     $this->Route->synchronize();
     if ($this->Route->isEmpty()) {
         $Deleter = new Model\Route\Deleter($this->PDO, $this->Route);
         $Deleter->setAccountID($this->AccountID);
         $Deleter->delete();
         $this->Route = null;
         $this->Activity->set(Entity::ROUTEID, 0);
         $this->Activity->set(Entity::ELEVATION, 0);
     } else {
         $Updater = new Model\Route\Updater($this->PDO, $this->Route, $this->OldRoute);
         $Updater->setAccountID($this->AccountID);
         $Updater->update();
     }
 }
use Runalyze\View\Activity\Linker;
use Runalyze\Data\Elevation\Correction\NoValidStrategyException;
$Frontend = new Frontend();
$Factory = Context::Factory();
$Activity = $Factory->activity(Request::sendId());
$ActivityOld = clone $Activity;
$Route = $Factory->route($Activity->get(Activity\Object::ROUTEID));
$RouteOld = clone $Route;
try {
    $Calculator = new Calculator($Route);
    $result = $Calculator->tryToCorrectElevation(Request::param('strategy'));
} catch (NoValidStrategyException $Exception) {
    $result = false;
}
if ($result) {
    $Calculator->calculateElevation();
    $Activity->set(Activity\Object::ELEVATION, $Route->elevation());
    $UpdaterRoute = new Route\Updater(DB::getInstance(), $Route, $RouteOld);
    $UpdaterRoute->setAccountID(SessionAccountHandler::getId());
    $UpdaterRoute->update();
    $UpdaterActivity = new Activity\Updater(DB::getInstance(), $Activity, $ActivityOld);
    $UpdaterActivity->setAccountID(SessionAccountHandler::getId());
    $UpdaterActivity->update();
    echo __('Elevation data has been corrected.');
    Ajax::setReloadFlag(Ajax::$RELOAD_DATABROWSER_AND_TRAINING);
    echo Ajax::getReloadCommand();
    echo Ajax::wrapJS('if($("#ajax").is(":visible") && $("#training").length)Runalyze.Overlay.load(\'' . Linker::EDITOR_URL . '?id=' . Request::sendId() . '\')');
    echo Ajax::wrapJS('if($("#ajax").is(":visible") && $("#gps-results").length)Runalyze.Overlay.load(\'' . Linker::ELEVATION_INFO_URL . '?id=' . Request::sendId() . '\')');
} else {
    echo __('Elevation data could not be retrieved.');
}