// ######################################################### Get Data
$calendar->getEventRepositoryBuilder()->setIncludeAreaInformation(true);
$calData = $calendar->getData();
$childAreas = array();
if ($thisconfig->getBoolean('ListChildAreas', false)) {
    $areaRepoBuilder = new \repositories\builders\AreaRepositoryBuilder();
    $areaRepoBuilder->setSite($site);
    $areaRepoBuilder->setIncludeDeleted(false);
    if ($area) {
        $areaRepoBuilder->setParentArea($area);
    } else {
        $areaRepoBuilder->setNoParentArea(true);
    }
    $childAreas = array();
    $areaRepository = new AreaRepository();
    foreach ($areaRepoBuilder->fetchAll() as $area) {
        $areaRepository->updateFutureEventsCache($area);
        if ($thisconfig->getBoolean('ListChildAreasWithNoEvents', false) || $area->getCachedFutureEvents() > 0) {
            $childAreas[] = $area;
        }
    }
}
// ######################################################### Build Email Content, show user.
configureAppForSite($site);
$messageText = $app['twig']->render('email/sendSpecifiedEventsEmail.cli.txt.twig', array('data' => $calData, 'currentSite' => $site, 'currentTimeZone' => $thisconfig->get('TimeZone'), 'intro' => file_get_contents($configDataDir . '/' . $thisconfig->get('IntroTXTFile')), 'listChildAreas' => $thisconfig->getBoolean('ListChildAreas'), 'listChildAreasIntro' => $thisconfig->get('ListChildAreasIntro'), 'childAreas' => $childAreas));
$messageHTML = $app['twig']->render('email/sendSpecifiedEventsEmail.cli.html.twig', array('data' => $calData, 'currentSite' => $site, 'currentTimeZone' => $thisconfig->get('TimeZone'), 'intro' => file_get_contents($configDataDir . '/' . $thisconfig->get('IntroHTMLFile')), 'listChildAreas' => $thisconfig->getBoolean('ListChildAreas'), 'listChildAreasIntro' => $thisconfig->get('ListChildAreasIntro'), 'childAreas' => $childAreas));
if ($CONFIG->isDebug) {
    file_put_contents('/tmp/sendEventsEmail.txt', $messageText);
}
if ($CONFIG->isDebug) {
    file_put_contents('/tmp/sendEventsEmail.html', $messageHTML);
require_once (defined('COMPOSER_ROOT_DIR') ? COMPOSER_ROOT_DIR : APP_ROOT_DIR) . '/vendor/autoload.php';
require_once APP_ROOT_DIR . '/core/php/autoload.php';
require_once APP_ROOT_DIR . '/core/php/autoloadCLI.php';
/**
 *
 * @package com.meetyournextmp
 * @license Closed Source
 * @copyright (c) 2013-2015, JMB Technology Limited, http://jmbtechnology.co.uk/
 * @author James Baster <*****@*****.**>
 */
// AREAS
$parentAreas = array('England' => null, 'Scotland' => null, 'Wales' => null, 'Northern Ireland' => null);
$arb = new \repositories\builders\AreaRepositoryBuilder();
$arb->setNoParentArea(true);
$arb->setIncludeDeleted(false);
$arb->fetchAll();
foreach ($arb->fetchAll() as $area) {
    foreach ($parentAreas as $key => $value) {
        if ($area->getTitle() == $key) {
            $parentAreas[$key] = $area;
        }
    }
}
foreach ($parentAreas as $key => $value) {
    if (!$value) {
        die("No area for " . $key);
    }
}
// JSON
$file = $argv[1];
$data = json_decode(file_get_contents($file));