api.emotionhero.com/bin/generate_db.php

124 lines
3.6 KiB
PHP

<?php
chdir(__DIR__);
// define('APPLICATION_ENV', 'development');
require_once __DIR__ . "/../bootstrap.php";
// Show table creation statements
// And (re)generate Proxies
$em = EmotionHero\Application::getInstance()->getEm();
var_dump($em->getConnection()->getDatabasePlatform()->getName());
// $serializer = JMS\Serializer\SerializerBuilder::create()->build();
$metadatas = $em->getMetadataFactory()->getAllMetadata();
// $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
$destPath = $em->getConfiguration()->getProxyDir();
$em->getProxyFactory()->generateProxyClasses($metadatas, $destPath);
$tool = new Doctrine\ORM\Tools\SchemaTool($em);
$classes = $metadatas;
// $classes = array(
// $em->getClassMetadata('EmotionHero\Models\Emotion'),
// );
// $tool->getCreateDatabaseSQL();
$queries = $tool->getCreateSchemaSQL($classes);
// $queries = $tool->getUpdateSchemaSql($classes);
foreach($queries as $sql){ echo "$sql;\n"; }
// updateSchema
$tool->updateSchema($classes);
die();
// ADD EMOTIONS
$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";
}
// TEST USER
if(empty($em->getRepository(EmotionHero\Models\User::class)->findOneBy([]))) {
$user = new EmotionHero\Models\User();
$em->persist($user);
$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();