Esempio n. 1
0
 public static function index()
 {
     if (self::get_user_admin() == null) {
         Redirect::to('/home');
     }
     $institutions = Institution::all();
     View::make('admin/institutions.html', array('institutions' => $institutions));
 }
Esempio n. 2
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));
 }
Esempio n. 3
0
 public static function update($id)
 {
     if (self::get_user_admin() == null) {
         Redirect::to('/home');
     }
     $params = $_POST;
     $degree = self::createDegree($params, $id);
     $errors = $degree->errors();
     if (count($errors) == 0 && isset($params['institutions'])) {
         $degree->update();
         $degree->updateInstitutions($params['institutions']);
         Redirect::to('/degrees', array('message' => 'Changes saved!'));
     } else {
         $allInstitutions = Institution::all();
         if (isset($params['institutions'])) {
             $degree->institutions = $params['institutions'];
         }
         View::make('edit.html', array('errors' => $errors, 'degree' => $degree, 'institutions' => $allInstitutions));
     }
 }