/**
  * Insert object to database
  */
 public function insert()
 {
     $Route = $this->newRouteObject();
     $Trackdata = $this->newTrackdataObject();
     $Swimdata = $this->newSwimObject();
     if ($Route->name() != '' || $Route->hasPositionData() || $Route->hasElevations()) {
         $InserterRoute = new Runalyze\Model\Route\Inserter(DB::getInstance(), $Route);
         $InserterRoute->setAccountID(SessionAccountHandler::getId());
         $InserterRoute->insert();
         $this->forceToSet('routeid', $InserterRoute->insertedID());
         if ($this->getElevation() == 0) {
             $this->setElevation($Route->elevation());
         }
     }
     $Activity = $this->newActivityObject();
     $InserterActivity = new Runalyze\Model\Activity\Inserter(DB::getInstance(), $Activity);
     $InserterActivity->setAccountID(SessionAccountHandler::getId());
     $InserterActivity->setRoute($Route);
     $InserterActivity->setTrackdata($Trackdata);
     $InserterActivity->setSwimdata($Swimdata);
     $InserterActivity->insert();
     $this->id = $InserterActivity->insertedID();
     if ($this->hasArrayTime() || $this->hasArrayDistance() || $this->hasArrayHeartrate()) {
         $Trackdata->set(Runalyze\Model\Trackdata\Object::ACTIVITYID, $this->id());
         $InserterTrack = new Runalyze\Model\Trackdata\Inserter(DB::getInstance(), $Trackdata);
         $InserterTrack->setAccountID(SessionAccountHandler::getId());
         $InserterTrack->insert();
     }
     if ($this->hasArrayStroke() || $this->hasArrayStrokeType()) {
         $Swimdata->set(Runalyze\Model\Swimdata\Object::ACTIVITYID, $this->id());
         $InserterSwim = new Runalyze\Model\Swimdata\Inserter(DB::getInstance(), $Swimdata);
         $InserterSwim->setAccountID(SessionAccountHandler::getId());
         $InserterSwim->insert();
     }
     if ($this->hasArrayHRV()) {
         $HRV = $this->newHRVObject();
         $HRV->set(Runalyze\Model\HRV\Object::ACTIVITYID, $this->id());
         $InserterHRV = new Runalyze\Model\HRV\Inserter(DB::getInstance(), $HRV);
         $InserterHRV->setAccountID(SessionAccountHandler::getId());
         $InserterHRV->insert();
     }
 }
Esempio n. 2
0
 /**
  * Insert object to database
  */
 public function insert()
 {
     $DB = DB::getInstance();
     $AccountID = SessionAccountHandler::getId();
     $Route = $this->newRouteObject();
     $Trackdata = $this->newTrackdataObject();
     $Swimdata = $this->newSwimObject();
     if ($Route->name() != '' || $Route->hasPositionData() || $Route->hasElevations()) {
         $InserterRoute = new Runalyze\Model\Route\Inserter($DB, $Route);
         $InserterRoute->setAccountID($AccountID);
         $InserterRoute->insert();
         $this->forceToSet('routeid', $InserterRoute->insertedID());
         if ($this->getElevation() == 0) {
             $this->setElevation($Route->elevation());
         }
     }
     $Activity = $this->newActivityObject();
     $InserterActivity = new Runalyze\Model\Activity\Inserter($DB, $Activity);
     $InserterActivity->setAccountID($AccountID);
     $InserterActivity->setRoute($Route);
     $InserterActivity->setTrackdata($Trackdata);
     $InserterActivity->setSwimdata($Swimdata);
     if ($this->get('importer-equipment') != []) {
         $InserterActivity->setEquipmentIDs($this->get('importer-equipment'));
     } else {
         $InserterActivity->setEquipmentIDs(TrainingFormular::readEquipmentFromPost($Activity->sportid()));
     }
     $InserterActivity->setTagIDs(TrainingFormular::readTagFromPost());
     $InserterActivity->insert();
     $this->id = $InserterActivity->insertedID();
     if ($this->hasArrayTime() || $this->hasArrayDistance() || $this->hasArrayHeartrate()) {
         $Trackdata->set(Runalyze\Model\Trackdata\Entity::ACTIVITYID, $this->id());
         $InserterTrack = new Runalyze\Model\Trackdata\Inserter($DB, $Trackdata);
         $InserterTrack->setAccountID($AccountID);
         $InserterTrack->insert();
     }
     if ($this->hasArrayStroke() || $this->hasArrayStrokeType()) {
         $Swimdata->set(Runalyze\Model\Swimdata\Entity::ACTIVITYID, $this->id());
         $InserterSwim = new Runalyze\Model\Swimdata\Inserter($DB, $Swimdata);
         $InserterSwim->setAccountID($AccountID);
         $InserterSwim->insert();
     }
     if ($this->hasArrayHRV()) {
         $HRV = $this->newHRVObject();
         $HRV->set(Runalyze\Model\HRV\Entity::ACTIVITYID, $this->id());
         $InserterHRV = new Runalyze\Model\HRV\Inserter($DB, $HRV);
         $InserterHRV->setAccountID($AccountID);
         $InserterHRV->insert();
     }
 }