<?php

Core::LoadPlugin('Attributes');
$end = date('Y-m-d', time() - 30 * 24 * 3600);
$table = 'markerAttributes';
$tableMetadata = AttributesTable::GetMetadata($table);
$field = 'sessionDate';
/* @var $db MapsDatabase */
$db = Core::LoadPlugin('Maps')->getDatabase();
$markers = $db->table(MapsDatabase::$MAPITEM);
$expiredEvents = json_decode('{
                "join":"join","table":"' . $table . '","set":"*","filters":[
                    {"join":"intersect","table":"' . $table . '","set":"*","filters":[
                        {"field":"' . $field . '","comparator":"lessThan","value":"' . $end . '","format":"date"}
                    ]}
                ]
            }');
$queryExpired = 'Select m.id as id, m.lid as lid FROM ' . $markers . '  as m, ' . AttributesFilter::JoinAttributeFilterObject($expiredEvents, 'm.id', 'm.type') . ' AND m.lid!=6';
$db->iterate($queryExpired, function ($row) use($field, $tableMetadata) {
    Core::Emit('custom.expire', array('mapitem' => $row->id));
});
$revivedEvents = json_decode('{
                "join":"join","table":"' . $table . '","set":"*","filters":[
                    {"join":"intersect","table":"' . $table . '","set":"*","filters":[
                        {"field":"' . $field . '","comparator":"greatorThanOrEqualTo","value":"' . $end . '","format":"date"}
                    ]}
                ]
            }');
$queryRevived = 'Select m.id as id, m.lid as lid FROM ' . $markers . '  as m, ' . AttributesFilter::JoinAttributeFilterObject($revivedEvents, 'm.id', 'm.type') . ' AND m.lid=6';
$db->iterate($queryRevived, function ($row) use($field, $tableMetadata) {
    Core::Emit('custom.revive', array('mapitem' => $row->id));
<?php

// decide whether to archive or unarchive
if (!empty($eventArgs)) {
    Core::LoadPlugin('Attributes');
    Core::LoadPlugin('Maps');
    $marker = MapController::LoadMapItem($eventArgs->mapitem);
    $tableMetadata = AttributesTable::GetMetadata('markerAttributes');
    $values = AttributesRecord::GetFields($marker->getId(), $marker->getType(), 'sessionDate', $tableMetadata);
    $sessionDate = $values['sessionDate'];
    $date = strtotime($sessionDate);
    $limit = time() - 30 * 24 * 3600;
    // Unarchive items without data, or within date range
    if (empty($sessionDate) || $date > $limit) {
        file_put_contents(__DIR__ . DS . '.custom.log', 'detect revive (' . $marker->getId() . ': ' . $sessionDate . ')' . "\n\n", FILE_APPEND);
        Core::Emit('custom.revive', $eventArgs);
    } else {
        file_put_contents(__DIR__ . DS . '.custom.log', 'detect expire (' . $marker->getId() . ': ' . $sessionDate . ')' . "\n\n", FILE_APPEND);
        Core::Emit('custom.expire', $eventArgs);
    }
}
div {
	height: 30px;
	background-color: aliceblue;
	margin: 0;
}

img {
	height: 30px;
	vertical-align: middle;
}
</style><?php 
foreach ($iconMap as $name => $icon) {
    echo '<div>' . $name . '=><img src="../' . $icon . '"/></div>';
}
echo "\n\n" . '   var iconSetMap=' . htmlspecialchars(json_encode($iconMap, JSON_PRETTY_PRINT)) . "\n\n";
$tableMetadata = AttributesTable::GetMetadata('newsAttributes');
EasyCsv::IterateRows_Assoc($csv, function ($row) use($tableMetadata, $iconMap) {
    $iconKey = trim($row['0']);
    $iconKey = str_replace('  ', ' ', $iconKey);
    $marker = MapController::GetFeatureWithName($row['Name']);
    if ($marker) {
        if (key_exists($iconKey, $iconMap)) {
            if ($marker->getIcon() != $iconMap[$iconKey]) {
                $marker->setIcon($iconMap[$iconKey]);
                // MapController::StoreMapFeature($marker);
            }
        } else {
            echo '<br/>missing key for: ' . $iconKey . ' | ' . $row['Name'] . '<br/></br/>';
        }
    } else {
        echo '<br/>missing marker for: ' . $row["Name"] . '<br/></br/>';
 public static function DefinedRegionsList()
 {
     $tableMetadata = AttributesTable::GetMetadata('siteData');
     $rgArray = array_map(function ($region) {
         return ucwords($region->section);
     }, AttributesField::GetDefinedList(AttributesField::GetMetadata('section', $tableMetadata)));
     return $rgArray;
 }