Пример #1
0
 public function searchCampusMap($query)
 {
     $this->searchResults = array();
     foreach ($this->feeds as $id => $feedData) {
         $controller = MapDataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
         if ($controller->canSearch()) {
             try {
                 $results = $controller->search($query);
                 $this->resultCount += count($results);
                 $this->searchResults = array_merge($this->searchResults, $results);
             } catch (KurogoDataServerException $e) {
                 Kurogo::log(LOG_WARNING, 'encountered KurogoDataServerException for feed config: ' . print_r($feedData, true) . $e->getMessage(), 'maps');
             }
         }
     }
     return $this->searchResults;
 }
Пример #2
0
 public function searchCampusMap($query) {
     $this->searchResults = array();
 
 	foreach ($this->feeds as $id => $feedData) {
         $controller = MapDataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
         $controller->setCategory($id);
         $controller->setDebugMode($GLOBALS['siteConfig']->getVar('DATA_DEBUG'));
         
         if ($controller->canSearch()) {
             $results = $controller->search($query);
             $this->resultCount += count($results);
             $this->searchResults = array_merge($this->searchResults, $results);
         }
 	}
 	
 	return $this->searchResults;
 }
Пример #3
0
    private function getDataController($categoryPath, &$listItemPath) {
        if (!$this->feeds)
            $this->feeds = $this->loadFeedData();

        if ($categoryPath === NULL) {
            return MapDataController::factory('MapDataController', array(
                'JS_MAP_CLASS' => 'GoogleJSMap',
                'DEFAULT_ZOOM_LEVEL' => $this->getOptionalModuleVar('DEFAULT_ZOOM_LEVEL', 10)
                ));
        
        } else {
            $listItemPath = $categoryPath;
            if ($this->numGroups > 0) {
                if (count($categoryPath) < 2) {
                    $path = implode(MAP_CATEGORY_DELIMITER, $categoryPath);
                    throw new Exception("invalid category path $path for multiple feed groups");
                }
                $feedIndex = array_shift($listItemPath).MAP_CATEGORY_DELIMITER.array_shift($listItemPath);
            } else {
                $feedIndex = array_shift($listItemPath);
            }
            $feedData = $this->feeds[$feedIndex];
            $controller = MapDataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
            $controller->setCategory($feedIndex);
            $controller->setDebugMode(Kurogo::getSiteVar('DATA_DEBUG'));
            return $controller;
        }
    }
Пример #4
0
    public function initializeForCommand() {

        $this->feedGroups = $this->getFeedGroups();
        $this->numGroups = count($this->feedGroups);

        switch ($this->command) {
            case 'groups':

                $response = array(
                    'total' => $this->numGroups,
                    'returned' => $this->numGroups,
                    'displayField' => 'title',
                    'results' => $this->feedGroups,
                    );

                $this->setResponse($response);
                $this->setResponseVersion(1);
            
                break;
            case 'categories':
                $this->feedGroup = $this->getArg('group', null);
                if ($this->feedGroup !== NULL && !isset($this->feedGroups[$this->feedGroup])) {
                    $this->feedGroup = NULL;
                }

                $categories = array();
                $this->feeds = $this->loadFeedData();
                foreach ($this->feeds as $id => $feedData) {
                    if (isset($feedData['HIDDEN']) && $feedData['HIDDEN']) continue;
                    $controller = MapDataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
                    $controller->setCategory($id);
                    $category = array(
                        'id' => $controller->getCategory(),
                        'title' => $controller->getTitle(),
                        );
                    $category['subcategories'] = $controller->getAllCategoryNodes();
                    $categories[] = $category;
                }

                $this->setResponse($categories);
                $this->setResponseVersion(1);
            
                break;
            case 'places':
                $categoryPath = $this->getCategoriesAsArray();
                if ($categoryPath) {
                    $dataController = $this->getDataController($categoryPath, $listItemPath);
                    $listItems = $dataController->getListItems($listItemPath);
                    $places = array();
                    foreach ($listItems as $listItem) {
                        if ($listItem instanceof MapFeature) {
                            $places[] = arrayFromMapFeature($listItem);
                        }
                    }
                
                    $response = array(
                        'total' => count($places),
                        'returned' => count($places),
                        'displayField' => 'title',
                        'results' => $places,
                        );
                
                    $this->setResponse($response);
                    $this->setResponseVersion(1);
                }
                break;
            case 'search':
                $searchTerms = $this->getArg('q');
                if ($searchTerms) {
                    $this->feedGroup = $this->getArg('group', null);
                    if ($this->feedGroup !== NULL && !isset($this->feedGroups[$this->feedGroup])) {
                        $this->feedGroup = NULL;
                    }

                    $mapSearchClass = $GLOBALS['siteConfig']->getVar('MAP_SEARCH_CLASS');
                    if (!$this->feeds)
                        $this->feeds = $this->loadFeedData();
                    $mapSearch = new $mapSearchClass($this->feeds);
        
                    $searchResults = $mapSearch->searchCampusMap($searchTerms);
        
                    $places = array();
                    foreach ($searchResults as $result) {
                        $places[] = arrayFromMapFeature($result);
                    }

                    $response = array(
                        'total' => count($places),
                        'returned' => count($places),
                        'displayField' => 'title',
                        'results' => $places,
                        );
                
                    $this->setResponse($response);
                    $this->setResponseVersion(1);
                }

                break;

            // ajax calls
            case 'staticImageURL':
                $baseURL = $this->getArg('baseURL');
                $mapClass = $this->getArg('mapClass');
                $mapController = MapImageController::factory($mapClass, $baseURL);
                
                $projection = $this->getArg('projection');
                if ($projection) {
                    $mapController->setMapProjection($projection);
                }
                
                $width = $this->getArg('width');
                if ($width) {
                    $mapController->setImageWidth($width);
                }

                $height = $this->getArg('height');
                if ($height) {
                    $mapController->setImageHeight($height);
                }

                $bbox = $this->getArg('bbox', null);
                $lat = $this->getArg('lat');
                $lon = $this->getArg('lon');
                $zoom = $this->getArg('zoom');

                if ($bbox) {
                    $mapController->setBoundingBox($bbox);

                } else if ($lat && $lon && $zoom !== null) {
                    $mapController->setZoomLevel($zoom);
                    $mapController->setCenter(array('lat' => $lat, 'lon' => $lon));
                }
                
                $url = $mapController->getImageURL();
                
                $this->setResponse($url);
                $this->setResponseVersion(1);
            
                break;
            default:
                $this->invalidCommand();
                break;
        }
    }
Пример #5
0
 private function getDataController($category = null)
 {
     $feedData = $this->getCurrentFeed($category);
     if ($feedData) {
         $controller = MapDataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
     }
     if (!isset($controller)) {
         $controller = MapDataController::defaultDataController();
     }
     return $controller;
 }
Пример #6
0
 private function getDataController($currentCategory = null)
 {
     if (!$this->feeds) {
         $this->loadFeedData();
     }
     if ($currentCategory === null) {
         $drillPath = array();
         $category = $this->getArg('category');
         if (isset($this->feeds[$category])) {
             $currentCategory = $category;
         } else {
             // traces the parent categories that led the user to this category id
             $references = $this->getCategoryReferences();
             foreach ($references as $reference) {
                 if ($currentCategory) {
                     $drillPath[] = $reference;
                 } elseif (isset($this->feeds[$reference])) {
                     $currentCategory = $reference;
                 }
             }
             $drillPath[] = $category;
         }
     }
     $dataController = null;
     if ($feedData = $this->getCurrentFeed($currentCategory)) {
         $dataController = MapDataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
         if ($drillPath) {
             $dataController->addDisplayFilter('category', $drillPath);
         }
     }
     return $dataController;
 }
Пример #7
0
 public function searchCampusMap($query)
 {
     $controller = MapDataController::factory($this->feedData['CONTROLLER_CLASS'], $this->feedData);
     $this->searchResults = $controller->search($query);
     return $this->searchResults;
 }
Пример #8
0
 public function searchCampusMap($query) {
     $this->searchResults = array();
 
 	foreach ($this->feeds as $id => $feedData) {
         $controller = MapDataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
         $controller->setDebugMode($GLOBALS['siteConfig']->getVar('DATA_DEBUG'));
         
         if ($controller->canSearch()) {
             $results = $controller->search($query);
             $this->resultCount += count($results);
             foreach ($results as $index => $aResult) {
                 if (is_array($aResult)) {
                     foreach ($aResult as $featureID => $feature) {
                         $this->searchResults[] = array(
                             'title' => $feature->getTitle(),
                             'subtitle' => $feature->getSubtitle(),
                             'category' => $id,
                             'subcategory' => $index,
                             'index' => $featureID,
                         );
                     }
                 } else {
                     $this->searchResults[] = array(
                         'title' => $aResult->getTitle(),
                         'subtitle' => $aResult->getSubtitle(),
                         'category' => $id,
                         'index' => $index,
                         );
                 }
             }
         }
 	}
 	
 	return $this->searchResults;
 }
Пример #9
0
    public function initializeForCommand() {

        $this->feedGroups = $this->getFeedGroups();
        $this->numGroups = count($this->feedGroups);

        switch ($this->command) {
            case 'categories':
                $this->feedGroup = $this->getArg('group', null);
                if ($this->feedGroup !== NULL && !isset($this->feedGroups[$this->feedGroup])) {
                    $this->feedGroup = NULL;
                }

                $categories = array();
                $this->feeds = $this->loadFeedData();
                foreach ($this->feeds as $id => $feedData) {
                    if (isset($feedData['HIDDEN']) && $feedData['HIDDEN']) continue;
                    $controller = MapDataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
                    $controller->setCategory($id);
                    $category = array(
                        'id' => $controller->getCategory(),
                        'title' => $controller->getTitle(),
                        );
                    $category['subcategories'] = $controller->getAllCategoryNodes();
                    $categories[] = $category;
                }

                $this->setResponse($categories);
                $this->setResponseVersion(1);
            
                break;
            case 'places':
                $categoryPath = $this->getCategoriesAsArray();
                if ($categoryPath) {
                    $dataController = $this->getDataController($categoryPath, $listItemPath);
                    $listItems = $dataController->getListItems($listItemPath);
                    $places = array();
                    foreach ($listItems as $listItem) {
                        if ($listItem instanceof MapFeature) {
                            $aPlace = $this->arrayFromMapFeature($listItem);
                            $aPlace['category'] = $categoryPath;
                            $places[] = $aPlace;
                        }
                    }
                
                    $response = array(
                        'total' => count($places),
                        'returned' => count($places),
                        'displayField' => 'title',
                        'results' => $places,
                        );
                
                    $this->setResponse($response);
                    $this->setResponseVersion(1);
                }
                break;
            case 'search':
                $this->initializeForSearch();

                break;

            // ajax calls
            case 'staticImageURL':
                $baseURL = $this->getArg('baseURL');
                $mapClass = $this->getArg('mapClass');
                $mapController = MapImageController::factory($mapClass, $baseURL);
                
                $projection = $this->getArg('projection');
                if ($projection) {
                    $mapController->setMapProjection($projection);
                }
                
                $width = $this->getArg('width');
                if ($width) {
                    $mapController->setImageWidth($width);
                }

                $height = $this->getArg('height');
                if ($height) {
                    $mapController->setImageHeight($height);
                }

                $bbox = $this->getArg('bbox', null);
                $lat = $this->getArg('lat');
                $lon = $this->getArg('lon');
                $zoom = $this->getArg('zoom');

                if ($bbox) {
                    $mapController->setBoundingBox($bbox);

                } else if ($lat && $lon && $zoom !== null) {
                    $mapController->setZoomLevel($zoom);
                    $mapController->setCenter(array('lat' => $lat, 'lon' => $lon));
                }
                
                $url = $mapController->getImageURL();
                
                $this->setResponse($url);
                $this->setResponseVersion(1);
            
                break;

                case 'geocode':
                    $locationSearchTerms = $this->getArg('q');
                    
                    $geocodingDataControllerClass = $this->getOptionalModuleVar('GEOCODING_DATA_CONTROLLER_CLASS');
                    $geocodingDataParserClass = $this->getOptionalModuleVar('GEOCODING_DATA_PARSER_CLASS');
                    $geocoding_base_url = $this->getOptionalModuleVar('GEOCODING_BASE_URL');

                    $arguments = array('BASE_URL' => $geocoding_base_url,
                                  'CACHE_LIFETIME' => 86400,
                                  'PARSER_CLASS' => $geocodingDataParserClass);

                    $controller = DataController::factory($geocodingDataControllerClass, $arguments);
                    $controller->addCustomFilters($locationSearchTerms);
                    $response = $controller->getParsedData();

                    // checking for Geocoding service error
                    if ($response['errorCode'] == 0) {

                        unset($response['errorCode']);
                        unset($response['errorMessage']);
                        $this->setResponse($response);
                        $this->setResponseVersion(1);
                    }
                    else {
                        $kurogoError = new KurogoError($response['errorCode'], "Geocoding service Erroe", $response['errorMessage']);
                        $this->setResponseError($kurogoError);
                        $this->setResponseVersion(1);
                    }
                    break;
                    
            default:
                $this->invalidCommand();
                break;
        }
    }
Пример #10
0
 private function getDataController($index) {
     if ($index === NULL) {
         return MapDataController::factory('MapDataController', array(
             'JS_MAP_CLASS' => 'GoogleJSMap',
             'DEFAULT_ZOOM_LEVEL' => $this->getModuleVar('DEFAULT_ZOOM_LEVEL', 10)
             ));
     
     } else if (isset($this->feeds[$index])) {
         $feedData = $this->feeds[$index];
         $controller = MapDataController::factory($feedData['CONTROLLER_CLASS'], $feedData);
         $controller->setDebugMode($GLOBALS['siteConfig']->getVar('DATA_DEBUG'));
         return $controller;
     }
 }