Ejemplo n.º 1
0
 public function search()
 {
     // Pick up parameters
     $params = $_POST;
     $keyword = $params['keyword'];
     $city = $params['city'];
     $institutions = $params['institutions'];
     $accepted_max = $params['accepted_max'];
     $accepted_min = $params['accepted_min'];
     $extent_max = $params['extent_max'];
     $extent_min = $params['extent_min'];
     //check number values are valid
     if (!is_numeric($accepted_max) || !is_numeric($accepted_min) || !is_numeric($extent_min) || !is_numeric($extent_max)) {
         View::make('search.html', array('error' => 'Some search parameters were weird, try again!'));
     }
     //Convert percentages to decimal
     $accepted_max = $accepted_max / 100;
     $accepted_min = $accepted_min / 100;
     //Find degrees that match the city and numeric parameters
     $degrees = Degree::search($city, $accepted_max, $accepted_min, $extent_max, $extent_min);
     $institutionCorrectDegrees = array();
     //filter the results that contain correct institution
     foreach ($degrees as $degree) {
         foreach ($degree->institutions as $degreeInstitution) {
             if (in_array($degreeInstitution->id, $institutions)) {
                 $institutionCorrectDegrees[] = $degree;
                 break;
             }
         }
     }
     //filter the results that match the keyword
     $keywordMatchingDegrees = array();
     if (strlen($keyword) > 0) {
         $keywordMatchingDegrees = $this->filterByKeyword($institutionCorrectDegrees, $keyword);
     } else {
         $keywordMatchingDegrees = $institutionCorrectDegrees;
     }
     self::makeInstitutionsStrings($keywordMatchingDegrees);
     $allInstitutions = Institution::all();
     //add favorites
     $favorites = FavoriteController::getUserFavorites();
     //return view
     if (empty($keywordMatchingDegrees)) {
         $error = 'No results were found, sorry!';
         View::make('search.html', array('institutions' => $allInstitutions, 'error' => $error, 'degrees' => $keywordMatchingDegrees));
     }
     View::make('search.html', array('institutions' => $allInstitutions, 'degrees' => $keywordMatchingDegrees, 'favorites' => $favorites));
 }
Ejemplo n.º 2
0
    DegreeController::edit($id);
});
$routes->post('/degree/:id/update', function ($id) {
    DegreeController::update($id);
});
$routes->post('/degree/:id/delete', function ($id) {
    DegreeController::delete($id);
});
$routes->post('/favorite/:id/new', function ($id) {
    FavoriteController::store($id);
});
$routes->post('/favorite/:id/delete', function ($id) {
    FavoriteController::delete($id);
});
$routes->post('/favorite/:id/remove', function ($id) {
    FavoriteController::remove($id);
});
$routes->get('/institutions', function () {
    InstitutionController::index();
});
$routes->get('/institutions/new', function () {
    InstitutionController::create();
});
$routes->post('/institutions/new', function () {
    InstitutionController::store();
});
$routes->get('/institution/:id/update', function ($id) {
    InstitutionController::edit($id);
});
$routes->post('/institution/:id/update', function ($id) {
    InstitutionController::update($id);