public function executeSearch(sfWebRequest $request) { $form = $request->getPostParameters(); $this->searchForm = new GcrSearchEschoolForm(); $this->eschoolList = ''; if ($request->isMethod(sfRequest::POST)) { $form['eschoolPattern'] = stripslashes(trim($form['eschoolPattern'])); $this->searchForm->bind($form); if ($this->searchForm->isValid()) { $exact_matches_start_of_first_word = array(); $exact_matches_start_of_word = array(); $exact_matches_middle_of_word = array(); $inexact_matches = array(); $pattern = strtolower($form['eschoolPattern']); $search = new Approximate_Search($pattern, 1); $institutions = Doctrine::getTable('GcrInstitution')->findAll(); foreach ($institutions as $institution) { if (!$institution->is_internal) { $full_name = strtolower($institution->getFullName()); $matches = $search->search($full_name); if (count($matches) > 0) { $index = strpos($full_name, $pattern); if ($index || $index === 0) { if ($index == 0) { $exact_matches_start_of_first_word[$institution->getShortName()] = $institution; } else { if ($full_name[$index - 1] == ' ') { $exact_matches_start_of_word[$institution->getShortName()] = $institution; } else { $exact_matches_middle_of_word[$institution->getShortName()] = $institution; } } } else { $inexact_matches[$institution->getShortName()] = $institution; } } } } $this->eschoolList = array($exact_matches_start_of_first_word, $exact_matches_start_of_word, $exact_matches_middle_of_word, $inexact_matches); } } $this->getResponse()->setTitle('Global Classroom - Search for a Community'); $this->getResponse()->addMeta('description', 'Search for a Community on the Global Classroom platform'); }
public function executeSearch(sfWebRequest $request) { $form = $request->getPostParameters(); $this->searchForm = new GcrSearchEschoolForm(); if ($request->isMethod(sfRequest::POST)) { $form['eschoolPattern'] = stripslashes(trim($form['eschoolPattern'])); $this->searchForm->bind($form); if ($this->searchForm->isValid()) { $exact_matches_start_of_first_word = array(); $exact_matches_start_of_word = array(); $exact_matches_middle_of_word = array(); $inexact_matches = array(); $pattern = strtolower($form['eschoolPattern']); $search = new Approximate_Search($pattern, 1); $eschools = Doctrine::getTable('GcrEschool')->findAll(); $institutions = Doctrine::getTable('GcrInstitution')->findAll(); $appList = array(); foreach ($eschools as $eschool) { $appList[$eschool->getShortName] = strtolower($eschool->getFullName()); } foreach ($institutions as $institution) { $appList[$institution->getShortName] = strtolower($institution->getFullName()); } foreach ($appList as $short_name => $full_name) { $matches = $search->search($full_name); if (count($matches) > 0) { $index = strpos($full_name, $pattern); if ($index || $index === 0) { if ($index == 0) { $exact_matches_start_of_first_word[$short_name] = $eschool; } else { if ($full_name[$index - 1] == ' ') { $exact_matches_start_of_word[$short_name] = $eschool; } else { $exact_matches_middle_of_word[$short_name] = $eschool; } } } else { $inexact_matches[$short_name] = $eschool; } } } } $this->eschoolList = array($exact_matches_start_of_first_word, $exact_matches_start_of_word, $exact_matches_middle_of_word, $inexact_matches); } $this->getResponse()->setTitle('Search for an eSchool'); }