Exemplo n.º 1
0
 /**
  * Validate Local Search Options
  *
  * @param array $options
  */
 protected function _validateLocalSearch($options)
 {
     $valid_options = array('appid', 'query', 'results', 'start', 'sort', 'radius', 'street', 'city', 'state', 'zip', 'location', 'latitude', 'longitude');
     if (!is_array($options)) {
         return;
     }
     $this->_compareOptions($options, $valid_options);
     $filter = new Zend_InputFilter($options, false);
     if (isset($options['results'])) {
         if (!$filter->isBetween('results', 1, 20, true)) {
             throw new Zend_Service_Exception($options['results'] . ' is not valid for the "results" option.');
         }
     }
     if (isset($options['start'])) {
         if (!$filter->isBetween('start', 1, 1000, true)) {
             throw new Zend_Service_Exception($options['start'] . ' is not valid for the "start" option.');
         }
     }
     if (isset($options['longitude'])) {
         if (!$filter->isBetween('longitude', -90, 90, true)) {
             throw new Zend_Service_Exception($options['longitude'] . ' is not valid for the "longitude" option.');
         }
     }
     if (isset($options['latitude'])) {
         if (!$filter->isBetween('latitude', -180, 180, true)) {
             throw new Zend_Service_Exception($options['latitude'] . ' is not valid for the "latitude" option.');
         }
     }
     if (isset($options['zip'])) {
         if (!$filter->isZip('zip')) {
             throw new Zend_Service_Exception($options['zip'] . ' is not a valid for the "zip" option.');
         }
     }
     $locationFields = array('street', 'city', 'state', 'zip', 'location', 'lon');
     foreach ($locationFields as $field) {
         if (isset($options[$field]) && $options[$field] != '') {
             $locations[] = 1;
         }
     }
     if (!is_array($locations) && $options['latitude'] == '' && $options['longitude'] == '') {
         throw new Zend_Service_Exception('You must enter a locale to search near.');
     }
     if (!in_array($options['sort'], array('relevance', 'title', 'distance', 'rating'))) {
         throw new Zend_Service_Exception('You have entered an invalid sort property.');
     }
 }