コード例 #1
0
ファイル: TalkTest.php プロジェクト: cgrandval/opencfp
 protected function setUp()
 {
     $this->app = new Application(BASE_PATH, Environment::testing());
     $cfg = new \Spot\Config();
     $cfg->addConnection('sqlite', ['dbname' => 'sqlite::memory', 'driver' => 'pdo_sqlite']);
     $spot = new \Spot\Locator($cfg);
     $this->app['spot'] = $spot;
     $this->mapper = $spot->mapper(\OpenCFP\Domain\Entity\Talk::class);
     foreach ($this->entities as $entity) {
         $spot->mapper('OpenCFP\\Domain\\Entity\\' . $entity)->migrate();
     }
 }
コード例 #2
0
 /**
  * @param Generator $generator
  * @return array
  */
 public function guessColumnFormatters(Generator $generator)
 {
     $formatters = array();
     $nameGuesser = new Name($generator);
     $columnTypeGuesser = new ColumnTypeGuesser($generator);
     $fields = $this->mapper->fields();
     foreach ($fields as $fieldName => $field) {
         if ($field['primary'] === true) {
             continue;
         }
         if ($formatter = $nameGuesser->guessFormat($fieldName)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
         if ($formatter = $columnTypeGuesser->guessFormat($field)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
     }
     $entityName = $this->mapper->entity();
     $entity = $this->mapper->build([]);
     $relations = $entityName::relations($this->mapper, $entity);
     foreach ($relations as $relation) {
         // We don't need any other relation here.
         if ($relation instanceof BelongsTo) {
             $fieldName = $relation->localKey();
             $entityName = $relation->entityName();
             $field = $fields[$fieldName];
             $required = $field['required'];
             $locator = $this->locator;
             $formatters[$fieldName] = function ($inserted) use($required, $entityName, $locator) {
                 if (!empty($inserted[$entityName])) {
                     return $inserted[$entityName][mt_rand(0, count($inserted[$entityName]) - 1)]->getId();
                 } else {
                     if ($required && $this->useExistingData) {
                         // We did not add anything like this, but it's required,
                         // So let's find something existing in DB.
                         $mapper = $this->locator->mapper($entityName);
                         $records = $mapper->all()->limit(self::RELATED_FETCH_COUNT)->toArray();
                         if (empty($records)) {
                             return null;
                         }
                         $id = $records[mt_rand(0, count($records) - 1)]['id'];
                         return $id;
                     } else {
                         return null;
                     }
                 }
             };
         }
     }
     return $formatters;
 }
コード例 #3
0
ファイル: index.php プロジェクト: emmajane/helpmeabstract
 * Time: 9:46 PM
 */
use GuzzleHttp\Client;
use Spot\Config;
use Spot\Locator;
require_once __DIR__ . '/vendor/autoload.php';
Dotenv::load(__DIR__);
session_start();
$app = new \Slim\Slim(array('templates.path' => './views', 'debug' => true));
$loader = new Twig_Loader_Filesystem(__DIR__ . '/views');
$twig = new Twig_Environment($loader);
$cfg = new Config();
// MySQL
$cfg->addConnection('mysql', 'mysql://' . $_ENV['DATABASE_USER'] . ':' . $_ENV['DATABASE_PASSWORD'] . '@localhost/helpmeabstract');
$spot = new Locator($cfg);
$volunteerMapper = $spot->mapper('Kayladnls\\Entity\\Volunteer');
$proposalMapper = $spot->mapper('Kayladnls\\Entity\\Proposal');
$app->notFound(function () use($app) {
    $app->redirect('/error');
});
$app->get('/', function () use($twig, $volunteerMapper) {
    $volunteers = $volunteerMapper->getForHomePage();
    echo $twig->render('index.php', array('volunteers' => $volunteers));
});
$app->get('/volunteer', function () use($twig) {
    echo $twig->render('volunteer.php');
});
$app->post('/submitVolunteer', function () use($twig, $volunteerMapper) {
    $field_errors = $volunteerMapper->verifyFields();
    if (empty($field_errors)) {
        if ($volunteerMapper->findByEmail($_POST['email']) == 0) {