public function browseAction() { $table = $this->_helper->db->getTable(); $locationTable = $this->_helper->db->getTable('Location'); $params = $this->getAllParams(); $params['only_map_items'] = false; $limit = (int) get_option('geolocation_per_page'); $currentPage = $this->getParam('page', 1); // Only get pagination data for the "normal" page, only get // item/location data for the KML output. if ($this->_helper->contextSwitch->getCurrentContext() == 'kml') { $allItems = $table->findBy($params); $items = $table->findBy($params, $limit, $currentPage); $this->view->items = $items; $this->view->locations = $locationTable->findLocationByItemPublishers($items); _logFile(count($this->view->locations)); } else { $this->view->totalItems = $table->count($params); $this->view->params = $params; $pagination = array('page' => $currentPage, 'per_page' => $limit, 'total_results' => $this->view->totalItems); Zend_Registry::set('pagination', $pagination); } }
<?php /* Here is the styling for the balloon that appears on the map */ ?> <Style id="item-info-balloon"> <BalloonStyle> <text><![CDATA[ <div class="geolocation_balloon"> <div class="geolocation_balloon_title">$[namewithlink]</div> <p class="geolocation_balloon_description">$[Snippet]</p> </div> ]]></text> </BalloonStyle> </Style> <?php foreach ($locations as $location) { _logFile($location['nb']); ?> <Placemark> <name><![CDATA[<?php echo $location['text']; ?> ]]></name> <namewithlink><![CDATA[<?php echo $location['nb']; ?> ]]></namewithlink> <items><![CDATA[<?php echo $location['items']; ?> ]]></items> <Point>
/** * Returns a location (or array of locations) for an item (or array of items) * @param array|Item|int $item An item or item id, or an array of items or item ids * @param boolean $findOnlyOne Whether or not to return only one location if it exists for the item * @return array|Location A location or an array of locations **/ public function findLocationByItemPublishers($item, $findOnlyOne = false) { $db = get_db(); if ($item instanceof Item && !$item->exists()) { return array(); } else { if (is_array($item) && !count($item)) { return array(); } } $alias = $this->getTableAlias(); // Create a SELECT statement for the Location table $select = $db->select()->from(array($alias => $db->Location), array("{$alias}.*", "GROUP_CONCAT({$alias}.item_id) as items", "COUNT({$alias}.address) AS nb")); // Create a WHERE condition that will pull down all the location info if (is_array($item)) { $itemIds = array(); foreach ($item as $it) { $itemIds[] = (int) ($it instanceof Item ? $it->id : $it); } $select->where("{$alias}.item_id IN (?)", $itemIds); } else { $itemId = (int) ($item instanceof Item ? $item->id : $item); $select->where("{$alias}.item_id = ?", $itemId); } // If only a single location is request, return the first one found. if ($findOnlyOne) { $location = $this->fetchObject($select); return $location; } $select->joinLeft(array('element_texts' => 'omeka_element_texts'), "{$alias}.item_id = element_texts.record_id AND element_texts.element_id = 45", array('element_texts.text')); $select->group('address'); // Get the locations. $locations = $this->fetchObjects($select); // Return an associative array of locations where the key is the item_id of the location // Note: Since each item can only have one location, this makes sense to associate a single location with a single item_id. // However, if in the future, an item can have multiple locations, then we cannot just associate a single location with a single item_id; // Instead, in the future, we would have to associate an array of locations with a single item_id. $indexedLocations = array(); foreach ($locations as $k => $loc) { $indexedLocations[$loc['item_id']] = $loc; } _logFile($select); return $indexedLocations; }