public function testSiteCount() { include_once dirname(__DIR__) . '/lib/GeoliveHelper.php'; include_once dirname(__DIR__) . '/lib/AjaxRequest.php'; $access = array('public', 'special', 'site-planning'); $c = GeoliveHelper::CountSitesInAreas(array("Douglas Gardner"), $access); $this->assertEquals(22, $c); $count = 0; GeoliveHelper::QueriedSiteListInAreas(array("Douglas Gardner"), function ($i) use(&$count) { $count++; }, $access); $this->assertEquals(22, $count, GeoliveHelper::Database()->lastQuery()); }
$sitesArray[] = get_object_vars($row); }); } // die(Core::GetDatasource()->getQuery()); if (UrlVar('exportOutput') == 'kml') { // export kmz file, this requires writing // to a temprotary file, kmz is a zip file with // .kmz extensions $filename = tempnam(__DIR__, 'zip'); include_once 'lib/KmlWriter.php'; $kmlWriter = new KmlWriter(); $zip = new ZipArchive(); $zip->open($filename); // add kml file if (count($sitesArray) == 0) { throw new Exception('No sites in site list:' . json_encode($siteList) . ' or paddling areas: ' . json_encode($paArray) . ' -- ' . GeoliveHelper::Database()->lastQuery()); } $zip->addFromString('default.kml', $kmlWriter->writeKml($sitesArray)); // add each icon linked in kml foreach ($kmlWriter->getStyles() as $icon) { $fileicon = __DIR__ . DS . $icon; if (!file_exists($fileicon)) { throw new Exception("unable to find file: " . $fileicon); } if (filesize($fileicon) == 0) { throw new Exception("file appears to be empty: " . $fileicon); } $zip->addFile(__DIR__ . DS . $icon, $icon); } $zip->close(); header('Content-Type: application/kmz+zip;');
public static function QueriedSiteListInAreasInIdList($areas, $ids, $iteratorCallback) { $from = "FROM " . GeoliveHelper::AttributeTable() . " a inner join " . GeoliveHelper::MapitemTable() . " m on a.mapitem = m.id WHERE m.lid IN (" . implode(', ', array_map(function ($layer) { return $layer->getId(); }, self::VisibleLayers())) . ") AND m.id IN(" . implode(', ', array_map(function ($id) { return (int) $id; }, $ids)) . ")"; $paWhere = 'AND (' . implode(' OR ', array_map(function ($pa) { return 'lower(trim(a.paddlingArea)) = lower(trim(\'' . GeoliveHelper::Database()->escape($pa) . '\'))'; }, $areas)) . ')'; $query = "SELECT * {$from} {$paWhere} order by m.name"; self::Database()->iterate($query, $iteratorCallback); }