Exemple #1
0
 /**
  * Form input validation.
  * @param  array $input
  * @return array
  */
 public function validateInput($input)
 {
     // Initialize SumaGump class
     $validator = new SumaGump();
     // Sanitize input
     $input = $validator->sanitize($input);
     // Define filters
     $filters = array('id' => 'trim', 'sdate' => 'trim|sanitize_numbers|rmhyphen', 'edate' => 'trim|sanitize_numbers|rmhyphen', 'stime' => 'trim|sanitize_numbers', 'etime' => 'trim|sanitize_numbers');
     // Define validation rules
     $rules = array('id' => 'required|numeric', 'sdate' => 'numeric|multi_exact_len, 0 8', 'edate' => 'numeric|multi_exact_len, 0 8', 'stime' => 'numeric|multi_exact_len, 0 4', 'etime' => 'numeric|multi_exact_len, 0 4');
     // Filter input
     $input = $validator->filter($input, $filters);
     // Validate input
     $validated = $validator->validate($input, $rules);
     // If input validates, return params array
     if ($validated === TRUE) {
         $params = array('id' => $input['id'], 'sdate' => $input['sdate'], 'edate' => $input['edate'], 'stime' => $input['stime'], 'etime' => $input['etime']);
         // If end date parameter is greater than or equal
         // to today, set end date to yesterday
         $today = date('Ymd');
         if ($params['edate'] > $today) {
             $params['edate'] = $today;
         }
         return $params;
     } else {
         $message = 'Query Parameter Input Error.';
         foreach ($validator->get_readable_errors() as $error) {
             $message = $message . " " . strip_tags($error);
         }
         throw new Exception($message, 500);
     }
 }
Exemple #2
0
 public function testFilterPadTimeNotEqualsThree()
 {
     $original = array('id' => '0300');
     $expected = array('id' => '0300');
     $filters = array('id' => 'pad_time');
     $gump = new SumaGump();
     $filtered = $gump->filter($original, $filters);
     $this->assertEquals($expected, $filtered);
 }
Exemple #3
0
 /**
  * Validates form input from client
  *
  * @access  private
  * @param  array $input Form input from client
  * @return array
  */
 private function populateParams($input)
 {
     // Initialize SumaGump class
     $validator = new SumaGump();
     // Sanitize input
     $input = $validator->sanitize($input);
     // Define filters
     $filters = array('id' => 'trim', 'sdate' => 'trim|rmpunctuation|rmhyphen', 'edate' => 'trim|rmpunctuation|rmhyphen', 'stime' => 'trim|rmpunctuation|pad_time', 'etime' => 'trim|rmpunctuation|pad_time', 'startHour' => 'trim|rmpunctuation|pad_time', 'classifyCounts' => 'trim', 'wholeSession' => 'trim', 'days' => 'trim', 'excludeLocs' => 'trim', 'requireActs' => 'trim', 'excludeActs' => 'trim', 'requireActGrps' => 'trim', 'excludeActGrps' => 'trim');
     // Define validation rules
     $rules = array('id' => 'required|numeric', 'sdate' => 'numeric|multi_exact_len, 0 8', 'edate' => 'numeric|multi_exact_len, 0 8', 'stime' => 'numeric|multi_exact_len, 0 4', 'etime' => 'numeric|multi_exact_len, 0 4', 'startHour' => 'numeric|multi_exact_len, 0 4', 'classifyCounts' => 'alpha|contains, count start end', 'wholeSession' => 'alpha|contains, yes no', 'days' => 'day_of_week', 'excludeLocs' => 'activities', 'requireActs' => 'activities', 'excludeActs' => 'activities', 'requireActGrps' => 'activities', 'excludeActGrps' => 'activities');
     // Filter input
     $input = $validator->filter($input, $filters);
     // Validate input
     $validated = $validator->validate($input, $rules);
     // If input validates, return params array
     if ($validated === TRUE) {
         $params = array('id' => $input['id'], 'sdate' => $input['sdate'], 'edate' => $input['edate'], 'stime' => $input['stime'], 'etime' => $input['etime'], 'startHour' => $input['startHour'], 'classifyCounts' => $input['classifyCounts'], 'wholeSession' => $input['wholeSession'], 'days' => $input['days'], 'excludeLocs' => $input['excludeLocs'], 'excludeActs' => $input['excludeActs'], 'requireActs' => $input['requireActs'], 'excludeActGrps' => $input['excludeActGrps'], 'requireActGrps' => $input['requireActGrps']);
         // Set query type and format
         $params['format'] = 'lca';
         // Set days of the week
         $days = explode(",", $input['days']);
         $params['days'] = array();
         foreach ($days as $day) {
             if (array_key_exists($day, $this->daysDict)) {
                 array_push($params['days'], $this->daysDict[$day]);
             }
         }
         return $params;
     } else {
         $message = 'Query parameter input error.';
         foreach ($validator->get_readable_errors() as $error) {
             $message = $message . " " . strip_tags($error);
         }
         throw new Exception($message, 500);
     }
 }