Esempio n. 1
0
    private function getFeatureForMap($dataController, $categoryPath=array()) {
        if (isset($this->args['featureindex'])) { // this is a regular place
            $index = $this->args['featureindex'];
            $feature = $dataController->getFeature($index, $categoryPath);
                    
        } elseif (isset($this->args['group'])) { // this is a campus
            $campusData = $this->getDataForGroup($this->args['group']);
            $coordParts = explode(',', $campusData['center']);
            $center = array('lat' => $coordParts[0], 'lon' => $coordParts[1]);

            $feature = new EmptyMapFeature($center);
            // may get rid of these setters and only allow setting in the constructor
            $feature->setTitle($campusData['title']);
            $feature->setField('address', $campusData['address']);
            $feature->setDescription($campusData['description']);
            $feature->setIndex($this->args['campus']);
        } else {
            $center = array('lat' => 0, 'lon' => 0);
            $feature = new EmptyMapFeature($center);
        }
        return $feature;
    }
    protected function initializeForPage() {
        switch ($this->page) {
            case 'help':
                break;
            
            case 'index':
                $numCampuses = $GLOBALS['siteConfig']->getVar('CAMPUS_COUNT');
                if ($numCampuses > 1) {
                    $campusLinks = array();
                    for ($i = 0; $i < $numCampuses; $i++) {
                        $aCampus = $GLOBALS['siteConfig']->getSection('campus-'.$i);
                        $campusLinks[] = array(
                            'title' => $aCampus['title'],
                            'url' => $this->campusURL($i),
                            );
                    }
                    $this->assign('browseHint', 'Select a Location');
                    $this->assign('categories', $campusLinks);
                    $this->assign('searchTip', NULL);

                } else {
                    if (!$this->feeds)
                        $this->feeds = $this->loadFeedData();
                    
                    $this->assignCategoriesForCampus(NULL);
                    $this->assign('browseHint', 'Browse map by:');
                    $this->assign('searchTip', "You can search by any category shown in the 'Browse by' list below.");
                }
                
                $this->generateBookmarkLink();

                break;
            
            case 'bookmarks':
                $campuses = array();
                $places = array();

                foreach ($this->getBookmarks() as $aBookmark) {
                    if ($aBookmark) { // prevent counting empty string
                        $titles = $this->getTitleForBookmark($aBookmark);
                        $subtitle = count($titles) > 1 ? $titles[1] : null;
                        if ($this->bookmarkType($aBookmark) == 'campus') {
                            $campuses[] = array(
                                'title' => $titles[0],
                                'subtitle' => $subtitle,
                                'url' => $this->detailURLForBookmark($aBookmark),
                                );
                        } else {
                            $places[] = array(
                                'title' => $titles[0],
                                'subtitle' => $subtitle,
                                'url' => $this->detailURLForBookmark($aBookmark),
                                );
                        }                        
                    }
                }
                $this->assign('campuses', $campuses);
                $this->assign('places', $places);
            
                break;
            
            case 'campus':
                // this is like the index page for single-campus organizations
                if (!$this->feeds)
                    $this->feeds = $this->loadFeedData();
                
                $index = $this->args['campus'];
                $campus = $GLOBALS['siteConfig']->getSection('campus-'.$index);
                $title = $campus['title'];
                $id = $campus['id'];

                $this->assignCategoriesForCampus($id);
                $this->assign('browseHint', "Browse {$title} by:");

                $cookieID = http_build_query(array('campus' => $index));

                $this->generateBookmarkOptions($cookieID);

                $this->generateBookmarkLink();

                break;
            
            case 'search':
          
                if (isset($this->args['filter'])) {
                    $searchTerms = $this->args['filter'];

                    $mapSearchClass = $GLOBALS['siteConfig']->getVar('MAP_SEARCH_CLASS');
                    $mapSearch = new $mapSearchClass();
                    if (!$this->feeds)
                        $this->feeds = $this->loadFeedData();
                    $mapSearch->setFeedData($this->feeds);
        
                    $searchResults = $mapSearch->searchCampusMap($searchTerms);
        
                    if (count($searchResults) == 1) {
                        $this->redirectTo('detail', $mapSearch->getURLArgsForSearchResult($searchResults[0]));
                    } else {
                        $places = array();
                        foreach ($searchResults as $result) {
                            $title = $mapSearch->getTitleForSearchResult($result);
                            $subtitle = $mapSearch->getSubtitleForSearchResult($result);
                            $place = array(
                                'title' => $title,
                                'subtitle' => $subtitle,
                                'url' => $this->detailURLForResult($mapSearch->getURLArgsForSearchResult($result)),
                            );
                            $places[] = $place;
                        }
                    }
        
                    $this->assign('searchTerms', $searchTerms);
                    $this->assign('places',      $places);
                  
                } else {
                  $this->redirectTo('index');
                }
                break;
            
            case 'category':
                if (isset($this->args['category'])) {
                    if (!$this->feeds)
                      $this->feeds = $this->loadFeedData();
        
                    // populate drop-down list at the bottom
                    $categories = array();
                    foreach ($this->feeds as $id => $feed) {
                        $categories[] = array(
                            'id' => $id,
                            'title' => $feed['TITLE'],
                            );
                    }
                    $this->assign('categories', $categories);
        
                    // build the drill-down list
                    $category = $this->args['category'];
                    $dataController = $this->getDataController($category);
        
                    if (isset($this->args['subcategory'])) {
                        $subCategory = $this->args['subcategory'];
                    } else {
                        $subCategory = null;
                    }
        
                    $listItems = $dataController->getListItems($subCategory);
        
                    $places = array();
                    foreach ($listItems as $listItem) {
                        if ($listItem instanceof MapFeature) {
                            $url = $this->detailURL($listItem->getIndex(), $category, $subCategory);
                        } else {
                            // for folder objects, getIndex returns the subcategory ID
                            $url = $this->categoryURL($category, $listItem->getIndex(), false); // don't add breadcrumb
                        }
                        $places[] = array(
                            'title'    => $listItem->getTitle(),
                            'subtitle' => $listItem->getSubtitle(),
                            'url'      => $url,
                            );
                    }
                    $this->assign('title',  $dataController->getTitle());
                    $this->assign('places', $places);          
                  
                } else {
                      $this->redirectTo('index');
                }
                break;
          
            case 'detail':
                $detailConfig = $this->loadWebAppConfigFile('map-detail', 'detailConfig');        
                $tabKeys = array();
                $tabJavascripts = array();
                
                if (!$this->feeds)
                    $this->feeds = $this->loadFeedData();
                
                if (isset($this->args['featureindex'])) { // this is a regular place
                    $index = $this->args['featureindex'];
                    $dataController = $this->getDataController($this->args['category']);
                    $subCategory = isset($this->args['subcategory']) ? $this->args['subcategory'] : null;
                    $feature = $dataController->getFeature($index, $subCategory);
                    
                    $cookieParams = array(
                        'category' => $this->args['category'],
                        'subcategory' => $subCategory,
                        'featureindex' => $index,
                        );
                    $cookieID = http_build_query($cookieParams);
                    $this->generateBookmarkOptions($cookieID);
                    
                } elseif (isset($this->args['campus'])) { // this is a campus
                    $index = $this->args['campus'];
                    $campus = $GLOBALS['siteConfig']->getSection('campus-'.$index);
                    $coordParts = explode(',', $campus['center']);
                    $center = array('lat' => $coordParts[0], 'lon' => $coordParts[1]);

                    $dataController = $this->getDataController(NULL);
                    
                    $feature = new EmptyMapFeature($center);
                    $feature->setTitle($campus['title']);
                    $feature->setAddress($campus['address']);
                    $feature->setDescription($campus['description']);
                    $feature->setIndex($index);
                } else {
                    $center = array('lat' => 0, 'lon' => 0);
                    $feature = new EmptyMapFeature($center);
                    $dataController = $this->getDataController(NULL);
                    $cookieID = http_build_query($this->args);
                    $this->generateBookmarkOptions($cookieID);
                }
                
                $this->assign('name', $this->getArg('title', $feature->getTitle()));
                // prevent infinite loop in smarty_modifier_replace
                // TODO figure out why smarty gets in an infinite loop
                $address = str_replace("\n", " ", $feature->getSubtitle());
                $this->assign('address', $this->getArg('address', $address));

                $possibleTabs = $detailConfig['tabs']['tabkeys'];
                foreach ($possibleTabs as $tabKey) {
                    if ($this->generateTabForKey($tabKey, $feature, $dataController, $tabJavascripts)) {
                        $tabKeys[] = $tabKey;
                    }
                }
        
                $this->assign('tabKeys', $tabKeys);
                $this->enableTabs($tabKeys, null, $tabJavascripts);
                break;
                
            case 'fullscreen':
                if (!$this->feeds)
                    $this->feeds = $this->loadFeedData();
                
                $index = $this->args['featureindex'];
                $dataController = $this->getDataController($this->args['category']);
                $subCategory = isset($this->args['subcategory']) ? $this->args['subcategory'] : null;
                $feature = $dataController->getFeature($index, $subCategory);

                $this->initializeMap($dataController, $feature, true);
                break;
        }
    }