-
-
Save carambazza/53804469d3021601f1bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ChartsBundle\Controller; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
use Symfony\Component\HttpFoundation\Request; | |
use ChartsBundle\Entity\Activity; | |
use ChartsBundle\Form\Type\ActivityType; | |
use Symfony\Component\Form\Extension\Core\Type\TextType; | |
use Symfony\Component\Form\Extension\Core\Type\SubmitType; | |
use Symfony\Component\Form\Extension\Core\Type\FileType; | |
class DashboardController extends Controller | |
{ | |
public function indexAction(Request $request) | |
{ | |
$activity = new Activity(); | |
$form = $this->createForm(ActivityType::class, $activity); | |
$form->handleRequest($request); | |
// if ($form->isValid()) { | |
// | |
// $em = $this->getDoctrine()->getManager(); | |
// | |
// $activity->upload(); | |
// | |
// $em->persist($activity); | |
// $em->flush(); | |
// | |
// return $this->redirect($this->generateUrl('dashboard')); | |
// } | |
return $this->render('ChartsBundle:Dashboard:index.html.twig', array( | |
'form' => $form->createView(), 'activity' => $activity | |
)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ChartsBundle\Entity; | |
use Doctrine\Common\Collections\ArrayCollection; | |
/** | |
* Activity | |
*/ | |
class Activity | |
{ | |
/** | |
* @var int | |
*/ | |
private $id; | |
/** | |
* @var User | |
*/ | |
private $user; | |
/** | |
* @var Collection|Activity[] | |
*/ | |
private $activityRecords; | |
/** | |
* @var Collection|Activity[] | |
*/ | |
private $activityLaps; | |
/** | |
* @var Collection|Activity[] | |
*/ | |
private $activityUnits; | |
/** | |
* @var | |
*/ | |
private $activityFile; | |
/** | |
* @var string | |
*/ | |
private $name; | |
/** | |
* @var string | |
*/ | |
private $description; | |
/** | |
* @var \DateTime | |
*/ | |
private $timestamp; | |
/** | |
* @var \DateTime | |
*/ | |
private $startTime; | |
/** | |
* @var string | |
*/ | |
private $startPositionLat; | |
/** | |
* @var string | |
*/ | |
private $startPositionLong; | |
/** | |
* @var string | |
*/ | |
private $totalElapsedTime; | |
/** | |
* @var string | |
*/ | |
private $totalTimerTime; | |
/** | |
* @var string | |
*/ | |
private $totalDistance; | |
/** | |
* @var string | |
*/ | |
private $totalCycles; | |
/** | |
* @var string | |
*/ | |
private $necLat; | |
/** | |
* @var string | |
*/ | |
private $necLong; | |
/** | |
* @var string | |
*/ | |
private $swcLat; | |
/** | |
* @var string | |
*/ | |
private $swcLong; | |
/** | |
* @var string | |
*/ | |
private $totalWork; | |
/** | |
* @var string | |
*/ | |
private $messageIndex; | |
/** | |
* @var string | |
*/ | |
private $totalCalories; | |
/** | |
* @var string | |
*/ | |
private $totalFatCalories; | |
/** | |
* @var string | |
*/ | |
private $avgSpeed; | |
/** | |
* @var string | |
*/ | |
private $maxSpeed; | |
/** | |
* @var string | |
*/ | |
private $avgPower; | |
/** | |
* @var string | |
*/ | |
private $maxPower; | |
/** | |
* @var string | |
*/ | |
private $totalAscent; | |
/** | |
* @var string | |
*/ | |
private $totalDescent; | |
/** | |
* @var string | |
*/ | |
private $firstLapIndex; | |
/** | |
* @var string | |
*/ | |
private $numLaps; | |
/** | |
* @var string | |
*/ | |
private $normalizedPower; | |
/** | |
* @var string | |
*/ | |
private $trainingStressScore; | |
/** | |
* @var string | |
*/ | |
private $intensityFactor; | |
/** | |
* @var string | |
*/ | |
private $leftRightBalance; | |
/** | |
* @var string | |
*/ | |
private $thresholdPower; | |
/** | |
* @var string | |
*/ | |
private $event; | |
/** | |
* @var string | |
*/ | |
private $eventType; | |
/** | |
* @var string | |
*/ | |
private $sport; | |
/** | |
* @var string | |
*/ | |
private $subSport; | |
/** | |
* @var string | |
*/ | |
private $avgHeartRate; | |
/** | |
* @var string | |
*/ | |
private $maxHeartRate; | |
/** | |
* @var string | |
*/ | |
private $avgCadence; | |
/** | |
* @var string | |
*/ | |
private $maxCadence; | |
/** | |
* @var string | |
*/ | |
private $enhancedAvgSpeed; | |
/** | |
* @var string | |
*/ | |
private $enhancedMaxSpeed; | |
/** | |
* | |
*/ | |
public function __construct() | |
{ | |
$this->activityRecords = new ArrayCollection(); | |
$this->activityLaps = new ArrayCollection(); | |
$this->activityUnits = new ArrayCollection(); | |
} | |
/** | |
* Get id | |
* | |
* @return int | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* @return User | |
*/ | |
public function getUser() | |
{ | |
return $this->user; | |
} | |
/** | |
* @param User $user | |
*/ | |
public function setUser($user) | |
{ | |
$this->user = $user; | |
} | |
/** | |
* Set name | |
* | |
* @param string $name | |
* | |
* @return Activity | |
*/ | |
public function setName($name) | |
{ | |
$this->name = $name; | |
return $this; | |
} | |
/** | |
* Get name | |
* | |
* @return string | |
*/ | |
public function getName() | |
{ | |
return $this->name; | |
} | |
/** | |
* Set description | |
* | |
* @param string $description | |
* | |
* @return Activity | |
*/ | |
public function setDescription($description) | |
{ | |
$this->description = $description; | |
return $this; | |
} | |
/** | |
* Get description | |
* | |
* @return string | |
*/ | |
public function getDescription() | |
{ | |
return $this->description; | |
} | |
/** | |
* @return Activity[]|Collection | |
*/ | |
public function getActivityRecords() | |
{ | |
return $this->activityRecords; | |
} | |
/** | |
* @return Activity[]|Collection | |
*/ | |
public function getActivityLaps() | |
{ | |
return $this->activityLaps; | |
} | |
/** | |
* @return Activity[]|Collection | |
*/ | |
public function getActivityUnits() | |
{ | |
return $this->activityUnits; | |
} | |
/** | |
* @return \DateTime | |
*/ | |
public function getTimestamp() | |
{ | |
return $this->timestamp; | |
} | |
/** | |
* @param \DateTime $timestamp | |
*/ | |
public function setTimestamp($timestamp) | |
{ | |
$this->timestamp = $timestamp; | |
} | |
/** | |
* @return \DateTime | |
*/ | |
public function getStartTime() | |
{ | |
return $this->startTime; | |
} | |
/** | |
* @param \DateTime $startTime | |
*/ | |
public function setStartTime($startTime) | |
{ | |
$this->startTime = $startTime; | |
} | |
/** | |
* @return string | |
*/ | |
public function getStartPositionLat() | |
{ | |
return $this->startPositionLat; | |
} | |
/** | |
* @param string $startPositionLat | |
*/ | |
public function setStartPositionLat($startPositionLat) | |
{ | |
$this->startPositionLat = $startPositionLat; | |
} | |
/** | |
* @return string | |
*/ | |
public function getStartPositionLong() | |
{ | |
return $this->startPositionLong; | |
} | |
/** | |
* @param string $startPositionLong | |
*/ | |
public function setStartPositionLong($startPositionLong) | |
{ | |
$this->startPositionLong = $startPositionLong; | |
} | |
/** | |
* @return string | |
*/ | |
public function getTotalElapsedTime() | |
{ | |
return $this->totalElapsedTime; | |
} | |
/** | |
* @param string $totalElapsedTime | |
*/ | |
public function setTotalElapsedTime($totalElapsedTime) | |
{ | |
$this->totalElapsedTime = $totalElapsedTime; | |
} | |
/** | |
* @return string | |
*/ | |
public function getTotalTimerTime() | |
{ | |
return $this->totalTimerTime; | |
} | |
/** | |
* @param string $totalTimerTime | |
*/ | |
public function setTotalTimerTime($totalTimerTime) | |
{ | |
$this->totalTimerTime = $totalTimerTime; | |
} | |
/** | |
* @return string | |
*/ | |
public function getTotalDistance() | |
{ | |
return $this->totalDistance; | |
} | |
/** | |
* @param string $totalDistance | |
*/ | |
public function setTotalDistance($totalDistance) | |
{ | |
$this->totalDistance = $totalDistance; | |
} | |
/** | |
* @return string | |
*/ | |
public function getTotalCycles() | |
{ | |
return $this->totalCycles; | |
} | |
/** | |
* @param string $totalCycles | |
*/ | |
public function setTotalCycles($totalCycles) | |
{ | |
$this->totalCycles = $totalCycles; | |
} | |
/** | |
* @return string | |
*/ | |
public function getNecLat() | |
{ | |
return $this->necLat; | |
} | |
/** | |
* @param string $necLat | |
*/ | |
public function setNecLat($necLat) | |
{ | |
$this->necLat = $necLat; | |
} | |
/** | |
* @return string | |
*/ | |
public function getNecLong() | |
{ | |
return $this->necLong; | |
} | |
/** | |
* @param string $necLong | |
*/ | |
public function setNecLong($necLong) | |
{ | |
$this->necLong = $necLong; | |
} | |
/** | |
* @return string | |
*/ | |
public function getSwcLat() | |
{ | |
return $this->swcLat; | |
} | |
/** | |
* @param string $swcLat | |
*/ | |
public function setSwcLat($swcLat) | |
{ | |
$this->swcLat = $swcLat; | |
} | |
/** | |
* @return string | |
*/ | |
public function getSwcLong() | |
{ | |
return $this->swcLong; | |
} | |
/** | |
* @param string $swcLong | |
*/ | |
public function setSwcLong($swcLong) | |
{ | |
$this->swcLong = $swcLong; | |
} | |
/** | |
* @return string | |
*/ | |
public function getTotalWork() | |
{ | |
return $this->totalWork; | |
} | |
/** | |
* @param string $totalWork | |
*/ | |
public function setTotalWork($totalWork) | |
{ | |
$this->totalWork = $totalWork; | |
} | |
/** | |
* @return string | |
*/ | |
public function getMessageIndex() | |
{ | |
return $this->messageIndex; | |
} | |
/** | |
* @param string $messageIndex | |
*/ | |
public function setMessageIndex($messageIndex) | |
{ | |
$this->messageIndex = $messageIndex; | |
} | |
/** | |
* @return string | |
*/ | |
public function getTotalCalories() | |
{ | |
return $this->totalCalories; | |
} | |
/** | |
* @param string $totalCalories | |
*/ | |
public function setTotalCalories($totalCalories) | |
{ | |
$this->totalCalories = $totalCalories; | |
} | |
/** | |
* @return string | |
*/ | |
public function getTotalFatCalories() | |
{ | |
return $this->totalFatCalories; | |
} | |
/** | |
* @param string $totalFatCalories | |
*/ | |
public function setTotalFatCalories($totalFatCalories) | |
{ | |
$this->totalFatCalories = $totalFatCalories; | |
} | |
/** | |
* @return string | |
*/ | |
public function getAvgSpeed() | |
{ | |
return $this->avgSpeed; | |
} | |
/** | |
* @param string $avgSpeed | |
*/ | |
public function setAvgSpeed($avgSpeed) | |
{ | |
$this->avgSpeed = $avgSpeed; | |
} | |
/** | |
* @return string | |
*/ | |
public function getMaxSpeed() | |
{ | |
return $this->maxSpeed; | |
} | |
/** | |
* @param string $maxSpeed | |
*/ | |
public function setMaxSpeed($maxSpeed) | |
{ | |
$this->maxSpeed = $maxSpeed; | |
} | |
/** | |
* @return string | |
*/ | |
public function getAvgPower() | |
{ | |
return $this->avgPower; | |
} | |
/** | |
* @param string $avgPower | |
*/ | |
public function setAvgPower($avgPower) | |
{ | |
$this->avgPower = $avgPower; | |
} | |
/** | |
* @return string | |
*/ | |
public function getMaxPower() | |
{ | |
return $this->maxPower; | |
} | |
/** | |
* @param string $maxPower | |
*/ | |
public function setMaxPower($maxPower) | |
{ | |
$this->maxPower = $maxPower; | |
} | |
/** | |
* @return string | |
*/ | |
public function getTotalAscent() | |
{ | |
return $this->totalAscent; | |
} | |
/** | |
* @param string $totalAscent | |
*/ | |
public function setTotalAscent($totalAscent) | |
{ | |
$this->totalAscent = $totalAscent; | |
} | |
/** | |
* @return string | |
*/ | |
public function getTotalDescent() | |
{ | |
return $this->totalDescent; | |
} | |
/** | |
* @param string $totalDescent | |
*/ | |
public function setTotalDescent($totalDescent) | |
{ | |
$this->totalDescent = $totalDescent; | |
} | |
/** | |
* @return string | |
*/ | |
public function getFirstLapIndex() | |
{ | |
return $this->firstLapIndex; | |
} | |
/** | |
* @param string $firstLapIndex | |
*/ | |
public function setFirstLapIndex($firstLapIndex) | |
{ | |
$this->firstLapIndex = $firstLapIndex; | |
} | |
/** | |
* @return string | |
*/ | |
public function getNumLaps() | |
{ | |
return $this->numLaps; | |
} | |
/** | |
* @param string $numLaps | |
*/ | |
public function setNumLaps($numLaps) | |
{ | |
$this->numLaps = $numLaps; | |
} | |
/** | |
* @return string | |
*/ | |
public function getNormalizedPower() | |
{ | |
return $this->normalizedPower; | |
} | |
/** | |
* @param string $normalizedPower | |
*/ | |
public function setNormalizedPower($normalizedPower) | |
{ | |
$this->normalizedPower = $normalizedPower; | |
} | |
/** | |
* @return string | |
*/ | |
public function getTrainingStressScore() | |
{ | |
return $this->trainingStressScore; | |
} | |
/** | |
* @param string $trainingStressScore | |
*/ | |
public function setTrainingStressScore($trainingStressScore) | |
{ | |
$this->trainingStressScore = $trainingStressScore; | |
} | |
/** | |
* @return string | |
*/ | |
public function getIntensityFactor() | |
{ | |
return $this->intensityFactor; | |
} | |
/** | |
* @param string $intensityFactor | |
*/ | |
public function setIntensityFactor($intensityFactor) | |
{ | |
$this->intensityFactor = $intensityFactor; | |
} | |
/** | |
* @return string | |
*/ | |
public function getLeftRightBalance() | |
{ | |
return $this->leftRightBalance; | |
} | |
/** | |
* @param string $leftRightBalance | |
*/ | |
public function setLeftRightBalance($leftRightBalance) | |
{ | |
$this->leftRightBalance = $leftRightBalance; | |
} | |
/** | |
* @return string | |
*/ | |
public function getThresholdPower() | |
{ | |
return $this->thresholdPower; | |
} | |
/** | |
* @param string $thresholdPower | |
*/ | |
public function setThresholdPower($thresholdPower) | |
{ | |
$this->thresholdPower = $thresholdPower; | |
} | |
/** | |
* @return string | |
*/ | |
public function getEvent() | |
{ | |
return $this->event; | |
} | |
/** | |
* @param string $event | |
*/ | |
public function setEvent($event) | |
{ | |
$this->event = $event; | |
} | |
/** | |
* @return string | |
*/ | |
public function getEventType() | |
{ | |
return $this->eventType; | |
} | |
/** | |
* @param string $eventType | |
*/ | |
public function setEventType($eventType) | |
{ | |
$this->eventType = $eventType; | |
} | |
/** | |
* @return string | |
*/ | |
public function getSport() | |
{ | |
return $this->sport; | |
} | |
/** | |
* @param string $sport | |
*/ | |
public function setSport($sport) | |
{ | |
$this->sport = $sport; | |
} | |
/** | |
* @return string | |
*/ | |
public function getSubSport() | |
{ | |
return $this->subSport; | |
} | |
/** | |
* @param string $subSport | |
*/ | |
public function setSubSport($subSport) | |
{ | |
$this->subSport = $subSport; | |
} | |
/** | |
* @return string | |
*/ | |
public function getAvgHeartRate() | |
{ | |
return $this->avgHeartRate; | |
} | |
/** | |
* @param string $avgHeartRate | |
*/ | |
public function setAvgHeartRate($avgHeartRate) | |
{ | |
$this->avgHeartRate = $avgHeartRate; | |
} | |
/** | |
* @return string | |
*/ | |
public function getMaxHeartRate() | |
{ | |
return $this->maxHeartRate; | |
} | |
/** | |
* @param string $maxHeartRate | |
*/ | |
public function setMaxHeartRate($maxHeartRate) | |
{ | |
$this->maxHeartRate = $maxHeartRate; | |
} | |
/** | |
* @return string | |
*/ | |
public function getAvgCadence() | |
{ | |
return $this->avgCadence; | |
} | |
/** | |
* @param string $avgCadence | |
*/ | |
public function setAvgCadence($avgCadence) | |
{ | |
$this->avgCadence = $avgCadence; | |
} | |
/** | |
* @return string | |
*/ | |
public function getMaxCadence() | |
{ | |
return $this->maxCadence; | |
} | |
/** | |
* @param string $maxCadence | |
*/ | |
public function setMaxCadence($maxCadence) | |
{ | |
$this->maxCadence = $maxCadence; | |
} | |
/** | |
* @return string | |
*/ | |
public function getEnhancedAvgSpeed() | |
{ | |
return $this->enhancedAvgSpeed; | |
} | |
/** | |
* @param string $enhancedAvgSpeed | |
*/ | |
public function setEnhancedAvgSpeed($enhancedAvgSpeed) | |
{ | |
$this->enhancedAvgSpeed = $enhancedAvgSpeed; | |
} | |
/** | |
* @return string | |
*/ | |
public function getEnhancedMaxSpeed() | |
{ | |
return $this->enhancedMaxSpeed; | |
} | |
/** | |
* @param string $enhancedMaxSpeed | |
*/ | |
public function setEnhancedMaxSpeed($enhancedMaxSpeed) | |
{ | |
$this->enhancedMaxSpeed = $enhancedMaxSpeed; | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getActivityFile() | |
{ | |
return $this->activityFile; | |
} | |
/** | |
* @param mixed $activityFile | |
*/ | |
public function setActivityFile($activityFile) | |
{ | |
$this->activityFile = $activityFile; | |
} | |
/** | |
* @param $data | |
*/ | |
public function fromArray($data) | |
{ | |
foreach($data as $value) { | |
if(strlen($value[0]) <= 0) { | |
continue; | |
} | |
// $value[0] === FIELD | |
// $value[1] === VALUE | |
// $value[2] === UNIT | |
$method = 'set'.str_replace(' ', '', ucwords(str_replace('_', ' ', $value[0]))); | |
$cleanValue = $value[1]; | |
if ('timestamp' === $value[0] || 'start_time' === $value[0]) { | |
$cleanValue = $this->garminTimeStampConverter($value[1]); | |
} | |
if ('semicircles' === $value[2]) { | |
$cleanValue = $value[1] * (180 / pow(2,31)); | |
} | |
$callable = [$this, $method]; | |
if (true === is_callable($callable)) { | |
call_user_func_array($callable, [$cleanValue]); | |
} | |
} | |
} | |
/** | |
* @param $fitFileTimeStamp | |
* @return \DateTime | |
*/ | |
private function garminTimeStampConverter($fitFileTimeStamp) | |
{ | |
// fit file timestamp is UTC 00:00 Dec31 1989 | |
// https://www.thisisant.com/forum/viewthread/4051/#4670 | |
// need to add difference from 1970 - 1989 = 631062000 to fit timestamp | |
$garminUTC = new \DateTime('1989-12-31 00:00:00'); | |
$timeStamp = (int)$fitFileTimeStamp + (int)$garminUTC->getTimestamp(); | |
$d = date('Y-m-d H:i:s', $timeStamp); | |
$date = new \DateTime($d); | |
return $date; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ChartsBundle\Entity; | |
use ChartsBundle\Timestampable; | |
use Doctrine\ORM\Mapping as ORM; | |
use ChartsBundle\Uploadable; | |
use Symfony\Component\HttpFoundation\File\UploadedFile; | |
class ActivityFile implements Uploadable, Timestampable | |
{ | |
/** | |
* @var integer | |
*/ | |
private $id; | |
/** | |
* @var string | |
*/ | |
private $name; | |
/** | |
* @var string | |
*/ | |
private $path; | |
/** | |
* @var string | |
*/ | |
private $realPath; | |
/** | |
* @var File | |
*/ | |
private $file; | |
/** | |
* @var boolean | |
*/ | |
private $fetchedToDb; | |
/** | |
* @var \DateTime | |
*/ | |
private $createdAt; | |
/** | |
* @var \DateTime | |
*/ | |
private $updatedAt; | |
/** | |
* | |
*/ | |
public function __construct() | |
{ | |
$this->fetchedToDb = false; | |
} | |
/** | |
* @return integer | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* @return string | |
*/ | |
public function getName() | |
{ | |
return $this->name; | |
} | |
/** | |
* @return string | |
*/ | |
public function getPath() | |
{ | |
return $this->path; | |
} | |
/** | |
* @return UploadedFile | |
*/ | |
public function getFile() | |
{ | |
return $this->file; | |
} | |
/** | |
* @return string | |
*/ | |
public function getRealPath() | |
{ | |
return $this->realPath; | |
} | |
/** | |
* @param string $realPath | |
*/ | |
public function setRealPath($realPath) | |
{ | |
$this->realPath = $realPath; | |
} | |
/** | |
* @return boolean | |
*/ | |
public function isFetchedToDb() | |
{ | |
return $this->fetchedToDb; | |
} | |
/** | |
* @param boolean $fetchedToDb | |
*/ | |
public function setFetchedToDb($fetchedToDb) | |
{ | |
$this->fetchedToDb = $fetchedToDb; | |
} | |
/** | |
* @return \DateTime | |
*/ | |
public function getCreatedAt() | |
{ | |
return $this->createdAt; | |
} | |
/** | |
* @param \DateTime|null $createdAt | |
* @return $this | |
*/ | |
public function setCreatedAt(\DateTime $createdAt = null) | |
{ | |
$this->createdAt = $createdAt; | |
return $this; | |
} | |
/** | |
* @return \DateTime | |
*/ | |
public function getUpdatedAt() | |
{ | |
return $this->updatedAt; | |
} | |
/** | |
* @param \DateTime $updatedAt | |
* @return $this | |
*/ | |
public function setUpdatedAt(\DateTime $updatedAt = null) | |
{ | |
$this->updatedAt = $updatedAt; | |
return $this; | |
} | |
/** | |
* @param string $name | |
* @return ActivityFile | |
*/ | |
public function setName($name) | |
{ | |
$this->name = $name; | |
return $this; | |
} | |
/** | |
* @param string $path | |
* @return ActivityFile | |
*/ | |
public function setPath($path = null) | |
{ | |
$this->path = $path; | |
return $this; | |
} | |
/** | |
* @param UploadedFile $file | |
*/ | |
public function setFile(UploadedFile $file = null) | |
{ | |
$this->file = $file; | |
} | |
/** | |
* @return null|string | |
*/ | |
public function getAbsolutePath() | |
{ | |
return null === $this->path | |
? null | |
: $this->getUploadRootDir() . '/' . $this->path; | |
} | |
/** | |
* @return null|string | |
*/ | |
public function getWebPath() | |
{ | |
return null === $this->path | |
? null | |
: $this->getUploadDir() . '/' . $this->path; | |
} | |
/** | |
* @return string | |
*/ | |
protected function getUploadRootDir() | |
{ | |
// the absolute directory path where uploaded | |
// documents should be saved | |
return __DIR__ . '/../../../' . $this->getUploadDir(); | |
} | |
/** | |
* @return string | |
*/ | |
protected function getUploadDir() | |
{ | |
// get rid of the __DIR__ so it doesn't screw up | |
// when displaying uploaded doc/image in the view. | |
$date = new \DateTime('now'); | |
return 'uploads/fit_files/' . $this->getUser()->getId() . '/' . $date->format('Y-m'); | |
} | |
/** | |
* | |
*/ | |
public function upload() | |
{ | |
if (null === $this->getFile()) { | |
return; | |
} | |
if('fit' !== $this->getFile()->getClientOriginalExtension()) { | |
echo 'sorry, we can only handle .fit files'; | |
return; | |
} | |
$fileName = md5(uniqid()) . '.' . $this->getFile()->getClientOriginalName(); | |
$this->getFile()->move( | |
$this->getUploadRootDir(), | |
$fileName | |
); | |
$this->path = $fileName; | |
$this->name = $this->getFile()->getClientOriginalName(); | |
$this->setRealPath($this->getUploadDir() . '/' . $fileName); | |
// clean up the file property as you won't need it anymore | |
$this->file = null; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ChartsBundle\Entity; | |
use Doctrine\Common\Collections\ArrayCollection; | |
use FOS\UserBundle\Model\User as BaseUser; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* User | |
*/ | |
class User extends BaseUser | |
{ | |
/** | |
* @var int | |
*/ | |
protected $id; | |
/** | |
* @var | |
*/ | |
private $activities; | |
public function __construct() | |
{ | |
parent::__construct(); | |
$this->roles = array('ROLE_USER'); | |
$this->activities = new ArrayCollection(); | |
} | |
/** | |
* Get id | |
* | |
* @return int | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getActivities() | |
{ | |
return $this->activities; | |
} | |
/** | |
* @param mixed $activities | |
*/ | |
public function setActivities($activities) | |
{ | |
$this->activities = $activities; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ChartsBundle\Form\Type; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | |
use Symfony\Component\Form\Extension\Core\Type\FileType; | |
class ActivityFileType extends AbstractType | |
{ | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder | |
->add('file', FileType::class, | |
array( | |
"required" => TRUE, | |
"attr" => array( | |
//"accept" => "image/*", | |
"multiple" => true, | |
) | |
) | |
); | |
} | |
public function setDefaultOptions(OptionsResolverInterface $resolver) | |
{ | |
$resolver->setDefaults(array( | |
'data_class' => 'ChartsBundle\Entity\ActivityFile', | |
)); | |
} | |
public function getName() | |
{ | |
return 'activityFile'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ChartsBundle\Form\Type; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | |
use Symfony\Component\Form\Extension\Core\Type\TextType; | |
use Symfony\Component\Form\Extension\Core\Type\CollectionType; | |
use Symfony\Component\Form\Extension\Core\Type\SubmitType; | |
class ActivityType extends AbstractType | |
{ | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder | |
->add('name', TextType::class) | |
->add('description', TextType::class) | |
->add( | |
'activityFile', | |
CollectionType::class, | |
array( | |
'entry_type' => ActivityFileType::class, | |
'allow_add' => true, | |
'allow_delete' => true, | |
'by_reference' => false, | |
) | |
) | |
->add('save', SubmitType::class, array('label' => 'Upload .fit file')); | |
} | |
public function setDefaultOptions(OptionsResolverInterface $resolver) | |
{ | |
$resolver->setDefaults(array( | |
'data_class' => 'ChartsBundle\Entity\Activity', | |
)); | |
} | |
public function getName() | |
{ | |
return 'activity'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> | |
<entity repository-class="ChartsBundle\Repository\ActivityRepository" name="ChartsBundle\Entity\Activity"> | |
<id name="id" type="guid" column="id"> | |
<generator strategy="UUID"/> | |
</id> | |
<many-to-one field="user" target-entity="User" inversed-by="activities"> | |
<join-column name="user_id" referenced-column-name="id" /> | |
</many-to-one> | |
<one-to-many field="activityRecords" target-entity="ActivityRecord" mapped-by="activity"> | |
<cascade> | |
<cascade-remove /> | |
</cascade> | |
</one-to-many> | |
<one-to-many field="activityLaps" target-entity="ActivityLap" mapped-by="activity"> | |
<cascade> | |
<cascade-remove /> | |
</cascade> | |
</one-to-many> | |
<one-to-many field="activityUnits" target-entity="ActivityUnit" mapped-by="activity"> | |
<cascade> | |
<cascade-remove /> | |
</cascade> | |
</one-to-many> | |
<one-to-one field="activityFile" target-entity="ActivityFile"> | |
<join-column name="activity_file_id" referenced-column-name="id" /> | |
</one-to-one> | |
<field name="name" type="string" column="name" length="255" nullable="true"/> | |
<field name="description" type="text" column="description" nullable="true"/> | |
<field name="timestamp" type="datetime" column="timestamp" nullable="true"/> | |
<field name="startTime" type="datetime" column="start_time" nullable="true"/> | |
<field name="startPositionLat" type="decimal" column="start_position_lat" precision="10" scale="8" nullable="true"/> | |
<field name="startPositionLong" type="decimal" column="start_position_long" precision="11" scale="8" nullable="true"/> | |
<field name="totalElapsedTime" type="decimal" column="total_elapsed_time" precision="10" scale="2" nullable="true"/> | |
<field name="totalTimerTime" type="decimal" column="total_timer_time" precision="10" scale="2" nullable="true"/> | |
<field name="totalDistance" type="decimal" column="total_distance" precision="11" scale="2" nullable="true"/> | |
<field name="totalCycles" type="integer" column="total_cycles" nullable="true"/> | |
<field name="necLat" type="decimal" column="nec_lat" precision="10" scale="8" nullable="true"/> | |
<field name="necLong" type="decimal" column="nec_long" precision="11" scale="8" nullable="true"/> | |
<field name="swcLat" type="decimal" column="swc_lat" precision="10" scale="8" nullable="true"/> | |
<field name="swcLong" type="decimal" column="swc_long" precision="11" scale="8" nullable="true"/> | |
<field name="totalWork" type="integer" column="total_work" nullable="true"/> | |
<field name="messageIndex" type="integer" column="message_index" nullable="true"/> | |
<field name="totalCalories" type="integer" column="total_calories" nullable="true"/> | |
<field name="totalFatCalories" type="integer" column="total_fat_calories" nullable="true"/> | |
<field name="avgSpeed" type="decimal" column="avg_speed" precision="6" scale="2" nullable="true"/> | |
<field name="maxSpeed" type="decimal" column="max_speed" precision="6" scale="2" nullable="true"/> | |
<field name="avgPower" type="integer" column="avg_power" nullable="true"/> | |
<field name="maxPower" type="integer" column="max_power" nullable="true"/> | |
<field name="totalAscent" type="integer" column="total_ascent" nullable="true"/> | |
<field name="totalDescent" type="integer" column="total_descent" nullable="true"/> | |
<field name="firstLapIndex" type="integer" column="first_lap_index" nullable="true"/> | |
<field name="numLaps" type="smallint" column="num_laps" nullable="true"/> | |
<field name="normalizedPower" type="integer" column="normalized_power" nullable="true"/> | |
<field name="trainingStressScore" type="smallint" column="training_stress_score" nullable="true"/> | |
<field name="intensityFactor" type="decimal" column="intensity_factor" precision="3" scale="2" nullable="true"/> | |
<field name="leftRightBalance" type="smallint" column="left_right_balance" nullable="true"/> | |
<field name="thresholdPower" type="integer" column="threshold_power" nullable="true"/> | |
<field name="event" type="smallint" column="event" nullable="true"/> | |
<field name="eventType" type="smallint" column="event_type" nullable="true"/> | |
<field name="sport" type="smallint" column="sport" nullable="true"/> | |
<field name="subSport" type="smallint" column="sub_sport" nullable="true"/> | |
<field name="avgHeartRate" type="smallint" column="avg_heart_rate" nullable="true"/> | |
<field name="maxHeartRate" type="smallint" column="max_heart_rate" nullable="true"/> | |
<field name="avgCadence" type="smallint" column="avg_cadence" nullable="true"/> | |
<field name="maxCadence" type="smallint" column="max_cadence" nullable="true"/> | |
<field name="enhancedAvgSpeed" type="integer" column="enhanced_avg_speed" nullable="true"/> | |
<field name="enhancedMaxSpeed" type="integer" column="enhanced_max_speed" nullable="true"/> | |
</entity> | |
</doctrine-mapping> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> | |
<entity repository-class="ChartsBundle\Repository\ActivityFile" name="ChartsBundle\Entity\ActivityFile"> | |
<id name="id" type="guid" column="id"> | |
<generator strategy="UUID"/> | |
</id> | |
<field name="name" type="string" column="name" length="255"/> | |
<field name="path" type="string" column="path" length="255"/> | |
<field name="fetchedToDb" column="fetched_to_db" type="boolean"/> | |
<field name="realPath" type="string" column="real_path" length="255"/> | |
<field name="createdAt" type="datetime" column="created_at"/> | |
<field name="updatedAt" type="datetime" column="updated_at"/> | |
</entity> | |
</doctrine-mapping> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> | |
<entity repository-class="ChartsBundle\Repository\UserRepository" name="ChartsBundle\Entity\User" table="fos_user"> | |
<id name="id" type="guid" column="id"> | |
<generator strategy="UUID"/> | |
</id> | |
<one-to-many field="activities" target-entity="Activity" mapped-by="user"> | |
<cascade> | |
<cascade-persist/> | |
<cascade-remove /> | |
</cascade> | |
</one-to-many> | |
</entity> | |
</doctrine-mapping> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment