pages/search/SearchHandler.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 // $Id$
00017 
00018 import('search.PaperSearch');
00019 import('handler.Handler');
00020 
00021 class SearchHandler extends Handler {
00025    function SearchHandler() {
00026       parent::Handler();
00027    }
00028 
00032    function index() {
00033       parent::validate();
00034       SearchHandler::advanced();
00035    }
00036 
00040    function search() {
00041       parent::validate();
00042       SearchHandler::advanced();
00043    }
00044 
00048    function advanced() {
00049       parent::validate();
00050       SearchHandler::setupTemplate(false);
00051       $templateMgr =& TemplateManager::getManager();
00052       $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
00053 
00054       if (Request::getConference() == null) {
00055          $conferenceDao =& DAORegistry::getDAO('ConferenceDAO');
00056          $conferences =& $conferenceDao->getEnabledConferenceTitles();  //Enabled added
00057          $templateMgr->assign('siteSearch', true);
00058          $templateMgr->assign('conferenceOptions', array('' => AppLocale::Translate('search.allConferences')) + $conferences);
00059          $yearRange = $publishedPaperDao->getPaperYearRange(null);
00060       } else {
00061          $conference =& Request::getConference();
00062          $yearRange = $publishedPaperDao->getPaperYearRange($conference->getId());
00063       }  
00064 
00065       SearchHandler::assignAdvancedSearchParameters($templateMgr, $yearRange);
00066 
00067       $templateMgr->display('search/advancedSearch.tpl');
00068    }
00069 
00073    function authors($args) {
00074       parent::validate();
00075       SearchHandler::setupTemplate(true);
00076 
00077       $authorDao =& DAORegistry::getDAO('AuthorDAO');
00078 
00079       if (isset($args[0]) && $args[0] == 'view') {
00080          // View a specific author
00081          $firstName = Request::getUserVar('firstName');
00082          $middleName = Request::getUserVar('middleName');
00083          $lastName = Request::getUserVar('lastName');
00084          $affiliation = Request::getUserVar('affiliation');
00085          $country = Request::getUserVar('country');
00086 
00087          $schedConf =& Request::getSchedConf();
00088          $publishedPapers = $authorDao->getPublishedPapersForAuthor(
00089             $schedConf?$schedConf->getId():null,
00090             $firstName,
00091             $middleName,
00092             $lastName,
00093             $affiliation,
00094             $country
00095          );
00096          unset($schedConf);
00097 
00098          // Load information associated with each paper.
00099          $conferences = array();
00100          $schedConfs = array();
00101          $tracks = array();
00102          $schedConfsUnavailable = array();
00103 
00104          $trackDao =& DAORegistry::getDAO('TrackDAO');
00105          $schedConfDao =& DAORegistry::getDAO('SchedConfDAO');
00106          $conferenceDao =& DAORegistry::getDAO('ConferenceDAO');
00107 
00108          foreach ($publishedPapers as $paper) {
00109             $trackId = $paper->getTrackId();
00110             $schedConfId = $paper->getSchedConfId();
00111 
00112             if (!isset($schedConfs[$schedConfId])) {
00113                import('schedConf.SchedConfAction');
00114                $schedConf =& $schedConfDao->getSchedConf($schedConfId);
00115                $schedConfs[$schedConfId] =& $schedConf;
00116                $schedConfsUnavailable[$schedConfId] = !SchedConfAction::mayViewProceedings($schedConf);
00117                unset($schedConf);
00118             }
00119             if (!isset($tracks[$trackId])) {
00120                $tracks[$trackId] =& $trackDao->getTrack($trackId);
00121             }
00122 
00123             $conferenceId = $schedConfs[$schedConfId]->getConferenceId();
00124             if (!isset($conferences[$conferenceId])) {
00125                $conferences[$conferenceId] =& $conferenceDao->getConference($conferenceId);
00126             }
00127          }
00128 
00129          if (empty($publishedPapers)) {
00130             Request::redirect(null, null, Request::getRequestedPage());
00131          }
00132 
00133          $templateMgr =& TemplateManager::getManager();
00134          $templateMgr->assign_by_ref('publishedPapers', $publishedPapers);
00135          $templateMgr->assign_by_ref('conferences', $conferences);
00136          $templateMgr->assign_by_ref('schedConfs', $schedConfs);
00137          $templateMgr->assign('schedConfsUnavailable', $schedConfsUnavailable);
00138          $templateMgr->assign_by_ref('tracks', $tracks);
00139          $templateMgr->assign('firstName', $firstName);
00140          $templateMgr->assign('middleName', $middleName);
00141          $templateMgr->assign('lastName', $lastName);
00142          $templateMgr->assign('affiliation', $affiliation);
00143 
00144          $countryDao =& DAORegistry::getDAO('CountryDAO');
00145          $country = $countryDao->getCountry($country);
00146          $templateMgr->assign('country', $country);
00147 
00148          $templateMgr->display('search/authorDetails.tpl');
00149       } else {
00150          // Show the author index
00151          $searchInitial = Request::getUserVar('searchInitial');
00152          $rangeInfo = Handler::getRangeInfo('authors');
00153 
00154          $schedConf =& Request::getSchedConf();
00155 
00156          $authors =& $authorDao->getAuthorsAlphabetizedBySchedConf(
00157             isset($schedConf)?$schedConf->getId():null,
00158             $searchInitial,
00159             $rangeInfo
00160          );
00161 
00162          $templateMgr =& TemplateManager::getManager();
00163          $templateMgr->assign('searchInitial', Request::getUserVar('searchInitial'));
00164          $templateMgr->assign('alphaList', explode(' ', __('common.alphaList')));
00165          $templateMgr->assign_by_ref('authors', $authors);
00166          $templateMgr->display('search/authorIndex.tpl');
00167       }
00168    }
00169 
00173    function titles($args) {
00174       parent::validate();
00175       SearchHandler::setupTemplate(true);
00176 
00177       $conference =& Request::getConference();
00178       $schedConf =& Request::getSchedConf();
00179       import('schedConf.SchedConfAction');
00180 
00181       $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
00182       $schedConfDao =& DAORegistry::getDAO('SchedConfDAO');
00183 
00184       $rangeInfo = Handler::getRangeInfo('search');
00185 
00186       $allPaperIds =& $publishedPaperDao->getPublishedPaperIdsAlphabetizedByTitle(
00187          $conference? $conference->getId():null,
00188          $schedConf?$schedConf->getId():null,
00189          $rangeInfo);
00190 
00191       // FIXME: this is horribly inefficient.
00192       $paperIds = array();
00193       $schedConfAbstractPermissions = array();
00194       $schedConfPaperPermissions = array();
00195       foreach($allPaperIds as $paperId) {
00196          $publishedPaper =& $publishedPaperDao->getPublishedPaperByPaperId($paperId);
00197          if (!$publishedPaper) continue; // Bonehead check (e.g. cached IDs)
00198          $schedConfId = $publishedPaper->getSchedConfId();
00199 
00200          if(!isset($schedConfAbstractPermissions[$schedConfId])) {
00201             unset($schedConf);
00202             $schedConf =& $schedConfDao->getSchedConf($schedConfId);
00203             $schedConfAbstractPermissions[$schedConfId] = SchedConfAction::mayViewProceedings($schedConf);
00204             $schedConfPaperPermissions[$schedConfId] = SchedConfAction::mayViewPapers($schedConf, $conference);
00205          }
00206 
00207          if($schedConfAbstractPermissions[$schedConfId]) {
00208             $paperIds[] = $paperId;
00209          }
00210       }
00211 
00212       $totalResults = count($paperIds);
00213       $paperIds = array_slice($paperIds, $rangeInfo->getCount() * ($rangeInfo->getPage()-1), $rangeInfo->getCount());
00214       import('core.VirtualArrayIterator');
00215       $results = new VirtualArrayIterator(PaperSearch::formatResults($paperIds), $totalResults, $rangeInfo->getPage(), $rangeInfo->getCount());
00216 
00217       $templateMgr =& TemplateManager::getManager();
00218       $templateMgr->assign_by_ref('results', $results);
00219       $templateMgr->display('search/titleIndex.tpl');
00220    }
00221 
00225    function schedConfs($args) {
00226       parent::validate();
00227       SearchHandler::setupTemplate(true);
00228 
00229       $conferenceDao =& DAORegistry::getDAO('ConferenceDAO');
00230       $schedConfDao =& DAORegistry::getDAO('SchedConfDAO');
00231 
00232       $conferences =& $conferenceDao->getEnabledConferences();
00233       $conferenceIndex = array();
00234       $schedConfIndex = array();
00235       while ($conference =& $conferences->next()) {
00236          $conferenceId = $conference->getId();
00237          $conferenceIndex[$conferenceId] =& $conference;
00238          $schedConfsIterator =& $schedConfDao->getSchedConfsByConferenceId($conferenceId);
00239          $schedConfIndex[$conferenceId] =& $schedConfsIterator->toArray();
00240          unset($schedConfsIterator);
00241          unset($conference);
00242       }
00243 
00244       $templateMgr =& TemplateManager::getManager();
00245       $templateMgr->assign_by_ref('conferenceIndex', $conferenceIndex);
00246       $templateMgr->assign_by_ref('schedConfIndex', $schedConfIndex);
00247       $templateMgr->display('search/schedConfIndex.tpl');
00248    }
00249 
00253    function results() {
00254       parent::validate();
00255       SearchHandler::setupTemplate(true);
00256 
00257       $rangeInfo = Handler::getRangeInfo('search');
00258 
00259       $searchConferenceId = Request::getUserVar('searchConference');
00260       if (!empty($searchConferenceId)) {
00261          $conferenceDao =& DAORegistry::getDAO('ConferenceDAO');
00262          $conference =& $conferenceDao->getConference($searchConferenceId);
00263       } else {
00264          $conference =& Request::getConference();
00265       }
00266 
00267       $searchType = Request::getUserVar('searchField');
00268       if (!is_numeric($searchType)) $searchType = null;
00269 
00270       // Load the keywords array with submitted values
00271       $keywords = array($searchType => PaperSearch::parseQuery(Request::getUserVar('query')));
00272 
00273       $results =& PaperSearch::retrieveResults($conference, $keywords, null, null, $rangeInfo);
00274 
00275       $templateMgr =& TemplateManager::getManager();
00276       $templateMgr->assign_by_ref('results', $results);
00277       $templateMgr->assign('basicQuery', Request::getUserVar('query'));
00278       $templateMgr->assign('searchField', Request::getUserVar('searchField'));
00279       $templateMgr->display('search/searchResults.tpl');
00280    }
00281 
00285    function advancedResults() {
00286       parent::validate();
00287       SearchHandler::setupTemplate(true);
00288 
00289       $rangeInfo = Handler::getRangeInfo('search');
00290 
00291       $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
00292       $searchConferenceId = Request::getUserVar('searchConference');
00293       if (!empty($searchConferenceId)) {
00294          $conferenceDao =& DAORegistry::getDAO('ConferenceDAO');
00295          $conference =& $conferenceDao->getConference($searchConferenceId);
00296          $yearRange = $publishedPaperDao->getPaperYearRange($conference->getId());
00297       } else {
00298          $conference =& Request::getConference();
00299          $yearRange = $publishedPaperDao->getPaperYearRange(null);
00300       }
00301 
00302       // Load the keywords array with submitted values
00303       $keywords = array(null => PaperSearch::parseQuery(Request::getUserVar('query')));
00304       $keywords[PAPER_SEARCH_AUTHOR] = PaperSearch::parseQuery(Request::getUserVar('author'));
00305       $keywords[PAPER_SEARCH_TITLE] = PaperSearch::parseQuery(Request::getUserVar('title'));
00306       $keywords[PAPER_SEARCH_DISCIPLINE] = PaperSearch::parseQuery(Request::getUserVar('discipline'));
00307       $keywords[PAPER_SEARCH_SUBJECT] = PaperSearch::parseQuery(Request::getUserVar('subject'));
00308       $keywords[PAPER_SEARCH_TYPE] = PaperSearch::parseQuery(Request::getUserVar('type'));
00309       $keywords[PAPER_SEARCH_COVERAGE] = PaperSearch::parseQuery(Request::getUserVar('coverage'));
00310       $keywords[PAPER_SEARCH_GALLEY_FILE] = PaperSearch::parseQuery(Request::getUserVar('fullText'));
00311       $keywords[PAPER_SEARCH_SUPPLEMENTARY_FILE] = PaperSearch::parseQuery(Request::getUserVar('supplementaryFiles'));
00312 
00313       $fromDate = Request::getUserDateVar('dateFrom', 1, 1);
00314       if ($fromDate !== null) $fromDate = date('Y-m-d H:i:s', $fromDate);
00315       $toDate = Request::getUserDateVar('dateTo', 32, 12, null, 23, 59, 59);
00316       if ($toDate !== null) $toDate = date('Y-m-d H:i:s', $toDate);
00317 
00318       $results =& PaperSearch::retrieveResults($conference, $keywords, $fromDate, $toDate, $rangeInfo);
00319 
00320       $templateMgr =& TemplateManager::getManager();
00321       $templateMgr->setCacheability(CACHEABILITY_NO_STORE);
00322       $templateMgr->assign_by_ref('results', $results);
00323       SearchHandler::assignAdvancedSearchParameters($templateMgr, $yearRange);
00324 
00325       $templateMgr->display('search/searchResults.tpl');
00326    }
00327 
00332    function setupTemplate($subclass = false) {
00333       parent::setupTemplate();
00334       $templateMgr =& TemplateManager::getManager();
00335       $templateMgr->assign('helpTopicId', 'user.searchBrowse');
00336       $templateMgr->assign('pageHierarchy',
00337          $subclass ? array(array(Request::url(null, null, 'search'), 'navigation.search'))
00338             : array()
00339       );
00340 
00341       $templateMgr->setCacheability(CACHEABILITY_PUBLIC);
00342    }
00343 
00344    function assignAdvancedSearchParameters(&$templateMgr, $yearRange) {
00345       $templateMgr->assign('query', Request::getUserVar('query'));
00346       $templateMgr->assign('searchConference', Request::getUserVar('searchConference'));
00347       $templateMgr->assign('author', Request::getUserVar('author'));
00348       $templateMgr->assign('title', Request::getUserVar('title'));
00349       $templateMgr->assign('fullText', Request::getUserVar('fullText'));
00350       $templateMgr->assign('supplementaryFiles', Request::getUserVar('supplementaryFiles'));
00351       $templateMgr->assign('discipline', Request::getUserVar('discipline'));
00352       $templateMgr->assign('subject', Request::getUserVar('subject'));
00353       $templateMgr->assign('type', Request::getUserVar('type'));
00354       $templateMgr->assign('coverage', Request::getUserVar('coverage'));
00355       $fromMonth = Request::getUserVar('dateFromMonth');
00356       $fromDay = Request::getUserVar('dateFromDay');
00357       $fromYear = Request::getUserVar('dateFromYear');
00358       $templateMgr->assign('dateFromMonth', $fromMonth);
00359       $templateMgr->assign('dateFromDay', $fromDay);
00360       $templateMgr->assign('dateFromYear', $fromYear);
00361       if (!empty($fromYear)) $templateMgr->assign('dateFrom', date('Y-m-d H:i:s',mktime(0,0,0,$fromMonth==null?12:$fromMonth,$fromDay==null?31:$fromDay,$fromYear)));
00362 
00363       $toMonth = Request::getUserVar('dateToMonth');
00364       $toDay = Request::getUserVar('dateToDay');
00365       $toYear = Request::getUserVar('dateToYear');
00366       $templateMgr->assign('dateToMonth', $toMonth);
00367       $templateMgr->assign('dateToDay', $toDay);
00368       $templateMgr->assign('dateToYear', $toYear);
00369       if (!empty($toYear)) $templateMgr->assign('dateTo', date('Y-m-d H:i:s',mktime(0,0,0,$toMonth==null?12:$toMonth,$toDay==null?31:$toDay,$toYear)));
00370    
00371       $startYear = substr($yearRange[1], 0, 4);
00372       $endYear = substr($yearRange[0], 0, 4);
00373       $templateMgr->assign('endYear', $endYear);
00374       $templateMgr->assign('startYear', $startYear);
00375    }
00376 }
00377 
00378 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7