public function logMotorCoachTransaction($data) { $this->logger->info('Service MotorCoachTransactionHandler logMotorCoachTransaction()'); $motorCoaches = $this->motorCoachManager->getBySlug(strtolower($data['coachName'])); if (sizeof($motorCoaches) > 0) { $motorCoach = $motorCoaches[0]; $trans = new MotorCoachTransaction(); $trans->setMotorCoachName($data['coachName']); $trans->setMotorCoach($motorCoach); $trans->setMotorCoachType($motorCoach->getType()); $trans->setGpsTime(new \DateTime($data['gpsTime'], new \DateTimeZone('Africa/Johannesburg'))); $trans->setLatitude($data['lat']); $trans->setLongitude($data['long']); $trans->setGpsSpeed($data['gpsSpeed']); $trans->setLineVoltage($data['lineVoltage']); $trans->setMAOutputVoltage($data['Supply100']); $trans->setSpeedo($data['speedo']); $trans->setBrakeVacuum($data['breakValve']); $trans->setBoggie1Current($data['boggieCurrent1']); $trans->setBoggie2Current($data['boggieCurrent2']); $trans->setShaftEncoder1Speed($data['shaftEncode1']); $trans->setShaftEncoder2Speed($data['shaftEncode2']); $trans->setShaftEncoder3Speed($data['shaftEncode3']); $trans->setShaftEncoder4Speed($data['shaftEncode4']); $trans->setStatus($this->sm->online()); $conditionalRules = $this->applyRules($data); $trans->setCondition($conditionalRules); $trans->setErrorMessage($this->errorMessage); $train = $motorCoach->getTrain(); if ($train) { $trans->setTrainName($train->getUnit()); $trans->setTrain($train); $trans->setTrainType($train->getType()); $train->setStatus($this->sm->online()); $train->setCondition($conditionalRules); $this->em->persist($train); } $motorCoach->setErrorData($this->errorMessage); $motorCoach->setCondition($conditionalRules); $motorCoach->setStatus($this->sm->online()); $this->em->persist($trans); $this->em->persist($motorCoach); $this->em->flush(); //Publish event to socket server $this->publishFeed($trans); return; } else { //create new motor coach $motorCoach = new MotorCoach(); $motorCoach->setUnit($data['coachName']); $motorCoach->setStatus($this->sm->offline()); $motorCoach->setCondition($this->conditionManager->unknown()); $this->em->persist($motorCoach); $this->em->flush(); } }
/** * Create motor coach * * @param MotorCoach $motorCoach * @return MotorCoach */ public function create(\MlankaTech\AppBundle\Entity\MotorCoach $motorCoach) { $this->logger->info("Service MotorCoachManager create()"); $motorCoach->setStatus($this->sm->notAllocated()); $motorCoach->setCondition($this->conditionManager->unknown()); if ($this->getCurrentUser()) { $motorCoach->setCreatedBy($this->getCurrentUser()); } else { $motorCoach->setCreatedBy(NULL); } $this->em->persist($motorCoach); $this->em->flush(); return $motorCoach; }