From a656e2815782b0b1834df8a45f8d34183d4e95eb Mon Sep 17 00:00:00 2001 From: Ruben Date: Thu, 1 Sep 2016 16:33:00 +0100 Subject: [PATCH] Ad levels --- bin/generate_db.php | 90 ++++++++++-- cache/proxy/__CG__EmotionHeroModelsGame.php | 85 +++++++++++- cache/proxy/__CG__EmotionHeroModelsHit.php | 4 +- cache/proxy/__CG__EmotionHeroModelsLevel.php | 37 ++++- cache/proxy/__CG__EmotionHeroModelsTarget.php | 4 +- cache/proxy/__CG__EmotionHeroModelsUser.php | 11 ++ src/Models/Game.php | 71 ++++++++++ src/Models/GameRepository.php | 38 +++++ src/Models/Level.php | 42 +++++- src/Models/Target.php | 25 +++- src/Tools/Position.php | 130 ++++++++++++++++++ 11 files changed, 514 insertions(+), 23 deletions(-) create mode 100644 src/Tools/Position.php diff --git a/bin/generate_db.php b/bin/generate_db.php index de8c31c..4eb54e8 100644 --- a/bin/generate_db.php +++ b/bin/generate_db.php @@ -1,6 +1,8 @@ updateSchema($classes); +// ADD EMOTIONS -$emotions = ['anger','contempt','disgust', 'fear', 'joy','sadness','surprise']; -foreach($emotions as $emo) { - $emotion = new EmotionHero\Models\Emotion(); - $emotion->setName($emo); - $em->persist($emotion); +$emotions = []; +try { + $emos = ['anger','contempt','disgust', 'fear', 'joy','sadness','surprise']; + foreach($emos as $emo) { + $emotion = $em->getRepository(EmotionHero\Models\Emotion::class)->findOneBy(['name' => $emo]); + if(empty($emotion)) + { + $emotion = new EmotionHero\Models\Emotion(); + $emotion->setName($emo); + $em->persist($emotion); + } + $emotions[$emo] = $emotion; + + } + $em->flush(); +} catch (Exception $e) { + echo "\nEmotions Probably already inserted...\n"; } -$user = new EmotionHero\Models\User(); -$em->persist($user); +// TEST USER -$em->flush(); +if(empty($em->getRepository(EmotionHero\Models\User::class)->findOneBy([]))) { + $user = new EmotionHero\Models\User(); + $em->persist($user); -var_dump($user->getId()); \ No newline at end of file + $em->flush(); +} + +$lvl = new EmotionHero\Models\Level(); +$lvl->setId(1); +$lvl->setName("I am sooo ANGRY"); +$lvl->createTarget($emotions['anger'], 100, 1); +$lvl->createTarget($emotions['anger'], 100, 2); +$lvl->createTarget($emotions['anger'], 10, 3); +$lvl->createTarget($emotions['anger'], 20, 4); +$lvl->createTarget($emotions['anger'], 40, 5); +$lvl->createTarget($emotions['anger'], 70, 6); +$lvl->createTarget($emotions['anger'], 100, 7); +$em->persist($lvl); + + +$lvl = new EmotionHero\Models\Level(); +$lvl->setId(2); +$lvl->setName("Let's be joyfull!"); +$lvl->createTarget($emotions['joy'], 100, 1); +$lvl->createTarget($emotions['joy'], 100, 2); +$lvl->createTarget($emotions['joy'], 100, 4); +$lvl->createTarget($emotions['contempt'], 20, 4); +$lvl->createTarget($emotions['anger'], 100, 5); +$lvl->createTarget($emotions['joy'], 100, 7); +$lvl->createTarget($emotions['anger'], 100, 9); +$lvl->createTarget($emotions['joy'], 100, 11); +$lvl->createTarget($emotions['joy'], 70, 12); +$lvl->createTarget($emotions['joy'], 60, 13); +$lvl->createTarget($emotions['joy'], 30, 14); +$lvl->createTarget($emotions['joy'], 10, 14.5); +$lvl->createTarget($emotions['anger'], 100, 16); +$lvl->createTarget($emotions['joy'], 100, 17); +$lvl->createTarget($emotions['joy'], 100, 18); +$lvl->createTarget($emotions['joy'], 100, 19); +$lvl->createTarget($emotions['joy'], 100, 20); +$em->persist($lvl); + +$lvl = new EmotionHero\Models\Level(); +$lvl->setId(3); +$lvl->setName("What a surprise"); +$lvl->createTarget($emotions['surprise'], 20, 1); +$lvl->createTarget($emotions['surprise'], 50, 2); +$lvl->createTarget($emotions['surprise'], 80, 3); +$lvl->createTarget($emotions['surprise'], 100, 4); +$em->persist($lvl); + +$lvl = new EmotionHero\Models\Level(); +$lvl->setId(4); +$lvl->setName("Please, don't cry..."); +$lvl->createTarget($emotions['sadness'], 20, 1); +$lvl->createTarget($emotions['sadness'], 50, 2); +$lvl->createTarget($emotions['sadness'], 80, 3); +$lvl->createTarget($emotions['sadness'], 100, 4); +$em->persist($lvl); + +$em->flush(); diff --git a/cache/proxy/__CG__EmotionHeroModelsGame.php b/cache/proxy/__CG__EmotionHeroModelsGame.php index ebe1688..c4b2aed 100644 --- a/cache/proxy/__CG__EmotionHeroModelsGame.php +++ b/cache/proxy/__CG__EmotionHeroModelsGame.php @@ -64,10 +64,10 @@ class Game extends \EmotionHero\Models\Game implements \Doctrine\ORM\Proxy\Proxy public function __sleep() { if ($this->__isInitialized__) { - return ['__isInitialized__', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'id', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'user', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'level', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'hits', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'createdAt']; + return ['__isInitialized__', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'id', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'user', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'level', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'hits', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'score', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'createdAt']; } - return ['__isInitialized__', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'id', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'user', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'level', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'hits', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'createdAt']; + return ['__isInitialized__', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'id', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'user', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'level', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'hits', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'score', '' . "\0" . 'EmotionHero\\Models\\Game' . "\0" . 'createdAt']; } /** @@ -173,4 +173,85 @@ class Game extends \EmotionHero\Models\Game implements \Doctrine\ORM\Proxy\Proxy } + /** + * {@inheritDoc} + */ + public function getId() + { + if ($this->__isInitialized__ === false) { + return parent::getId(); + } + + + $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', []); + + return parent::getId(); + } + + /** + * {@inheritDoc} + */ + public function getUser() + { + + $this->__initializer__ && $this->__initializer__->__invoke($this, 'getUser', []); + + return parent::getUser(); + } + + /** + * {@inheritDoc} + */ + public function getLevel() + { + + $this->__initializer__ && $this->__initializer__->__invoke($this, 'getLevel', []); + + return parent::getLevel(); + } + + /** + * {@inheritDoc} + */ + public function getHits() + { + + $this->__initializer__ && $this->__initializer__->__invoke($this, 'getHits', []); + + return parent::getHits(); + } + + /** + * {@inheritDoc} + */ + public function getScore() + { + + $this->__initializer__ && $this->__initializer__->__invoke($this, 'getScore', []); + + return parent::getScore(); + } + + /** + * {@inheritDoc} + */ + public function getCreatedAt() + { + + $this->__initializer__ && $this->__initializer__->__invoke($this, 'getCreatedAt', []); + + return parent::getCreatedAt(); + } + + /** + * {@inheritDoc} + */ + public function getPosition() + { + + $this->__initializer__ && $this->__initializer__->__invoke($this, 'getPosition', []); + + return parent::getPosition(); + } + } diff --git a/cache/proxy/__CG__EmotionHeroModelsHit.php b/cache/proxy/__CG__EmotionHeroModelsHit.php index 17fd455..0b1b02e 100644 --- a/cache/proxy/__CG__EmotionHeroModelsHit.php +++ b/cache/proxy/__CG__EmotionHeroModelsHit.php @@ -64,10 +64,10 @@ class Hit extends \EmotionHero\Models\Hit implements \Doctrine\ORM\Proxy\Proxy public function __sleep() { if ($this->__isInitialized__) { - return ['__isInitialized__', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'id', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'target', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'game', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'score', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'emotion', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'hits']; + return ['__isInitialized__', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'id', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'target', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'game', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'score', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'emotion', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'hits', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'gender', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'glasses', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'roll', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'pitch', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'yaw', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'inter_ocular_distance', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'mouth_open', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'lip_press', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'brow_raise', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'nose_wrinkler', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'lip_depressor', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'brow_furrow', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'attention', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'smile', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'inner_brow_raiser', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'chin_raiser', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'smirk', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'lip_suck', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'upper_lip_raiser', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'lip_pucker', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'eye_closure', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'engagement', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'valence', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'anger', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'contempt', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'disgust', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'fear', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'joy', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'sadness', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'surprise', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_0x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_0y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_1x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_1y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_2x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_2y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_3x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_3y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_4x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_4y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_5x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_5y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_6x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_6y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_7x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_7y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_8x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_8y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_9x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_9y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_10x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_10y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_11x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_11y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_12x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_12y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_13x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_13y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_14x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_14y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_15x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_15y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_16x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_16y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_17x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_17y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_18x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_18y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_19x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_19y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_20x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_20y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_21x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_21y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_22x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_22y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_23x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_23y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_24x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_24y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_25x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_25y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_26x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_26y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_27x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_27y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_28x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_28y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_29x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_29y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_30x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_30y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_31x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_31y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_32x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_32y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_33x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_33y']; } - return ['__isInitialized__', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'id', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'target', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'game', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'score', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'emotion', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'hits']; + return ['__isInitialized__', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'id', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'target', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'game', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'score', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'emotion', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'hits', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'gender', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'glasses', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'roll', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'pitch', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'yaw', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'inter_ocular_distance', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'mouth_open', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'lip_press', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'brow_raise', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'nose_wrinkler', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'lip_depressor', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'brow_furrow', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'attention', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'smile', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'inner_brow_raiser', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'chin_raiser', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'smirk', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'lip_suck', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'upper_lip_raiser', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'lip_pucker', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'eye_closure', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'engagement', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'valence', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'anger', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'contempt', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'disgust', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'fear', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'joy', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'sadness', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'surprise', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_0x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_0y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_1x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_1y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_2x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_2y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_3x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_3y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_4x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_4y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_5x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_5y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_6x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_6y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_7x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_7y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_8x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_8y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_9x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_9y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_10x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_10y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_11x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_11y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_12x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_12y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_13x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_13y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_14x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_14y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_15x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_15y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_16x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_16y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_17x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_17y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_18x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_18y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_19x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_19y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_20x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_20y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_21x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_21y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_22x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_22y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_23x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_23y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_24x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_24y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_25x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_25y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_26x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_26y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_27x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_27y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_28x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_28y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_29x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_29y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_30x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_30y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_31x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_31y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_32x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_32y', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_33x', '' . "\0" . 'EmotionHero\\Models\\Hit' . "\0" . 'point_33y']; } /** diff --git a/cache/proxy/__CG__EmotionHeroModelsLevel.php b/cache/proxy/__CG__EmotionHeroModelsLevel.php index e6a1ab5..da18a53 100644 --- a/cache/proxy/__CG__EmotionHeroModelsLevel.php +++ b/cache/proxy/__CG__EmotionHeroModelsLevel.php @@ -64,10 +64,10 @@ class Level extends \EmotionHero\Models\Level implements \Doctrine\ORM\Proxy\Pro public function __sleep() { if ($this->__isInitialized__) { - return ['__isInitialized__', '' . "\0" . 'EmotionHero\\Models\\Level' . "\0" . 'id', '' . "\0" . 'EmotionHero\\Models\\Level' . "\0" . 'targets', '' . "\0" . 'EmotionHero\\Models\\Level' . "\0" . 'games']; + return ['__isInitialized__', '' . "\0" . 'EmotionHero\\Models\\Level' . "\0" . 'id', '' . "\0" . 'EmotionHero\\Models\\Level' . "\0" . 'name', '' . "\0" . 'EmotionHero\\Models\\Level' . "\0" . 'targets', '' . "\0" . 'EmotionHero\\Models\\Level' . "\0" . 'games']; } - return ['__isInitialized__', '' . "\0" . 'EmotionHero\\Models\\Level' . "\0" . 'id', '' . "\0" . 'EmotionHero\\Models\\Level' . "\0" . 'targets', '' . "\0" . 'EmotionHero\\Models\\Level' . "\0" . 'games']; + return ['__isInitialized__', '' . "\0" . 'EmotionHero\\Models\\Level' . "\0" . 'id', '' . "\0" . 'EmotionHero\\Models\\Level' . "\0" . 'name', '' . "\0" . 'EmotionHero\\Models\\Level' . "\0" . 'targets', '' . "\0" . 'EmotionHero\\Models\\Level' . "\0" . 'games']; } /** @@ -173,4 +173,37 @@ class Level extends \EmotionHero\Models\Level implements \Doctrine\ORM\Proxy\Pro } + /** + * {@inheritDoc} + */ + public function createTarget(\EmotionHero\Models\Emotion $emotion, float $score, float $time) + { + + $this->__initializer__ && $this->__initializer__->__invoke($this, 'createTarget', [$emotion, $score, $time]); + + return parent::createTarget($emotion, $score, $time); + } + + /** + * {@inheritDoc} + */ + public function setId($id) + { + + $this->__initializer__ && $this->__initializer__->__invoke($this, 'setId', [$id]); + + return parent::setId($id); + } + + /** + * {@inheritDoc} + */ + public function setName($name) + { + + $this->__initializer__ && $this->__initializer__->__invoke($this, 'setName', [$name]); + + return parent::setName($name); + } + } diff --git a/cache/proxy/__CG__EmotionHeroModelsTarget.php b/cache/proxy/__CG__EmotionHeroModelsTarget.php index 378d73d..b1767e4 100644 --- a/cache/proxy/__CG__EmotionHeroModelsTarget.php +++ b/cache/proxy/__CG__EmotionHeroModelsTarget.php @@ -64,10 +64,10 @@ class Target extends \EmotionHero\Models\Target implements \Doctrine\ORM\Proxy\P public function __sleep() { if ($this->__isInitialized__) { - return ['__isInitialized__', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'id', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'level', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'time', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'emotion', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'hits']; + return ['__isInitialized__', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'id', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'position', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'level', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'time', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'emotion', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'score', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'hits']; } - return ['__isInitialized__', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'id', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'level', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'time', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'emotion', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'hits']; + return ['__isInitialized__', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'id', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'position', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'level', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'time', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'emotion', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'score', '' . "\0" . 'EmotionHero\\Models\\Target' . "\0" . 'hits']; } /** diff --git a/cache/proxy/__CG__EmotionHeroModelsUser.php b/cache/proxy/__CG__EmotionHeroModelsUser.php index e87e82e..9ac76df 100644 --- a/cache/proxy/__CG__EmotionHeroModelsUser.php +++ b/cache/proxy/__CG__EmotionHeroModelsUser.php @@ -265,4 +265,15 @@ class User extends \EmotionHero\Models\User implements \Doctrine\ORM\Proxy\Proxy return parent::getId(); } + /** + * {@inheritDoc} + */ + public function getJwt() + { + + $this->__initializer__ && $this->__initializer__->__invoke($this, 'getJwt', []); + + return parent::getJwt(); + } + } diff --git a/src/Models/Game.php b/src/Models/Game.php index 87e4edc..6fe4289 100644 --- a/src/Models/Game.php +++ b/src/Models/Game.php @@ -6,6 +6,7 @@ use Doctrine\ORM\Mapping as ORM; use JMS\Serializer\Annotation as JMS; use Gedmo\Mapping\Annotation as Gedmo; use Doctrine\Common\Collections\ArrayCollection; +use EmotionHero\Application; /** * A Single play of a game: combines User, Level and time @@ -51,4 +52,74 @@ class Game * @ORM\Column(type="datetime") */ private $createdAt; + + /** + * Gets the value of id. + * + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * Gets the value of user. + * + * @return mixed + */ + public function getUser() + { + return $this->user; + } + + /** + * Gets the value of level. + * + * @return mixed + */ + public function getLevel() + { + return $this->level; + } + + /** + * Gets the value of hits. + * + * @return mixed + */ + public function getHits() + { + return $this->hits; + } + + /** + * Gets the value of score. + * + * @return mixed + */ + public function getScore() + { + return $this->score; + } + + /** + * Gets the value of createdAt. + * + * @return \DateTime $created + */ + public function getCreatedAt() + { + return $this->createdAt; + } + + /** + * @todo Em should not be fetched here. Quick fix for now... + * + * @JMS\VirtualProperty + * @return Position + */ + public function getPosition() { + return Application::getInstance()->getEm()->getRepository(static::class)->getPositionForGame($this); + } } diff --git a/src/Models/GameRepository.php b/src/Models/GameRepository.php index 7e52921..0df369a 100644 --- a/src/Models/GameRepository.php +++ b/src/Models/GameRepository.php @@ -2,8 +2,46 @@ namespace EmotionHero\Models; use Doctrine\ORM\EntityRepository; +use EmotionHero\Tools\Position; class GameRepository extends EntityRepository { + public function getPositionForGame(Game $game) { + $query = $this->_em->createQuery( + "SELECT COUNT(g.id) FROM ". Game::class ." g WHERE g.score < :score AND g.level = :level" + ) + ->setParameters([ + 'score' => $game->getScore(), + 'level' => $game->getLevel(), + ]); + $position = $query->getSingleScalarResult(); + $total = $this->getGameCountForLevel($game->getLevel()); + $highscore = $this->getHighscoreForLevel($game->getLevel()); + return new Position($position, $total, $game->getScore(), $highscore); + } + + public function getGameCountForLevel(Level $level) { + + $query = $this->_em->createQuery( + "SELECT COUNT(g.id) FROM ".Game::class." g WHERE g.level = :level" + ) + ->setParameters([ + 'level' => $game->getLevel(), + ]); + return $query->getSingleScalarResult(); + } + + /** + * @return float + */ + public function getHighscoreForLevel(Level $level) { + $query = $this->_em->createQuery( + "SELECT MAX(g.score) FROM ".Game::class." g WHERE g.level = :level" + ) + ->setParameters([ + 'level' => $game->getLevel(), + ]); + return $query->getSingleScalarResult(); + } } \ No newline at end of file diff --git a/src/Models/Level.php b/src/Models/Level.php index 0fdb21e..0bb372f 100644 --- a/src/Models/Level.php +++ b/src/Models/Level.php @@ -23,9 +23,15 @@ class Level */ private $id; + /** + * Name of the level + * @var string + */ + private $name; + /** - * @ORM\OneToMany(targetEntity="Target", mappedBy="level") + * @ORM\OneToMany(targetEntity="Target", mappedBy="level", cascade={"persist"}) */ private $targets; @@ -40,4 +46,38 @@ class Level $this->games = new ArrayCollection(); } + public function createTarget(Emotion $emotion, float $score, float $time) { + $pos = $this->targets->count()+1; + $target = new Target($this, $pos, $emotion, $score, $time); + $this->targets->set($pos, $target); + } + + + /** + * Sets the value of id. + * + * @param integer $id the id + * + * @return self + */ + public function setId($id) + { + $this->id = $id; + + return $this; + } + + /** + * Sets the Name of the level. + * + * @param string $name the name + * + * @return self + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } } diff --git a/src/Models/Target.php b/src/Models/Target.php index 08524c5..fc5e51c 100644 --- a/src/Models/Target.php +++ b/src/Models/Target.php @@ -9,7 +9,8 @@ use Doctrine\Common\Collections\ArrayCollection; /** * Users * - * @ORM\Table(name="targets") + * @ORM\Table(name="targets",uniqueConstraints={ + * }) * @ORM\Entity */ class Target @@ -23,9 +24,14 @@ class Target */ private $id; + /** + * Incremental position in level + * @var int + */ + private $position; /** - * @ORM\ManyToOne(targetEntity="Level", inversedBy="targets") + * @ORM\ManyToOne(targetEntity="Level", inversedBy="targets", cascade={"persist"}) * @ORM\JoinColumn(name="level_id", referencedColumnName="id", nullable=false) */ private $level; @@ -41,15 +47,24 @@ class Target */ private $emotion; + /** + * Required score + * @var int + */ + private $score; + /** * @ORM\OneToMany(targetEntity="Hit", mappedBy="target", fetch="EXTRA_LAZY") */ private $hits; - - - public function __construct() + public function __construct(Level $level, int $position, Emotion $emotion, int $score, float $time) { $this->hits = new ArrayCollection(); + $this->level = $level; + $this->emotion = $emotion; + $this->score = $score; + $this->time = $time; + $this->position = $position; } } diff --git a/src/Tools/Position.php b/src/Tools/Position.php new file mode 100644 index 0000000..d573cde --- /dev/null +++ b/src/Tools/Position.php @@ -0,0 +1,130 @@ +position = $position; + $this->total = $total; + $this->score = $score; + $this->highscore = $highscore; + } + + /** + * Gets the value of position. + * + * @return mixed + */ + public function getPosition() + { + return $this->position; + } + + /** + * Sets the value of position. + * + * @param mixed $position the position + * + * @return self + */ + public function setPosition($position) + { + $this->position = $position; + + return $this; + } + + /** + * Gets the value of total. + * + * @return mixed + */ + public function getTotal() + { + return $this->total; + } + + /** + * Sets the value of total. + * + * @param mixed $total the total + * + * @return self + */ + public function setTotal($total) + { + $this->total = $total; + + return $this; + } + + /** + * Gets the value of score. + * + * @return mixed + */ + public function getScore() + { + return $this->score; + } + + /** + * Sets the value of score. + * + * @param mixed $score the score + * + * @return self + */ + public function setScore($score) + { + $this->score = $score; + + return $this; + } + + /** + * Gets the value of highscore. + * + * @return mixed + */ + public function getHighscore() + { + return $this->highscore; + } + + /** + * Sets the value of highscore. + * + * @param mixed $highscore the highscore + * + * @return self + */ + public function setHighscore($highscore) + { + $this->highscore = $highscore; + + return $this; + } + + /** + * @JMS\VirtualProperty + * @return float + */ + public function getPercentage() { + return ($this->position / $this->total) * 100; + } +} \ No newline at end of file