Example #1
0
/**
 * Get a cropped array of layer definitions for an exhibit.
 *
 * @param NeatlineExhibit $exhibit The exhibit.
 * @return array The layers.
 */
function nl_getLayersForExhibit($exhibit)
{
    $groups = nl_getLayers();
    $subset = array();
    // Explode the list of layer IDs in `spatial_layers` and merge the
    // `spatial_layer` slug into the array, which ensures that at least one
    // layer is included if `spatial_layers` is empty.
    $ids = nl_explode($exhibit->spatial_layers);
    $ids = array_merge($ids, array($exhibit->spatial_layer));
    // Walk the layer groups.
    foreach ($groups as $group => $layers) {
        // Include the layer if it is enabled in the exhihbit.
        foreach ($layers as $layer) {
            if (in_array($layer['id'], $ids)) {
                $subset[] = $layer;
            }
        }
    }
    return $subset;
}
Example #2
0
 /**
  * `nl_getLayers` should parse the JSON in the passed file.
  */
 public function testGetLayers()
 {
     $this->assertEquals(array('Group1' => array(array('title' => 'Layer 1', 'id' => 'Layer1', 'type' => 'Type1'), array('title' => 'Layer 2', 'id' => 'Layer2', 'type' => 'Type2')), 'Group2' => array(array('title' => 'Layer 3', 'id' => 'Layer3', 'type' => 'Type3'), array('title' => 'Layer 4', 'id' => 'Layer4', 'type' => 'Type4')), 'Group3' => array(array('title' => 'Layer 5', 'id' => 'Layer5', 'type' => 'Type5'), array('title' => 'Layer 6', 'id' => 'Layer6', 'type' => 'Type6'))), nl_getLayers());
 }