public function isValid($value) { if ($value == '-') { return true; } return parent::isValid($value); }
public function _beforeSave() { $valid = new Zend_Validate_Between(array('min' => 1, 'max' => 100)); if (!$valid->isValid($this->getValue())) { $this->_dataSaveAllowed = false; Mage::throwException(Mage::helper('welance_kraken')->__('Please use a value between 1 and 100')); } return parent::_beforeSave(); }
public function betweenAction() { $v = new Zend_Validate_Between(array('min' => 1, 'max' => 12)); $valor = 15; if ($v->isValid($valor)) { echo "{$valor} eh valido"; } else { echo "{$valor} eh invalido"; $erros = $v->getMessages(); print_r($erros); } exit; }
/** * Ensures that the validator follows expected behavior * * @return void */ public function testBasic() { /** * The elements of each array are, in order: * - minimum * - maximum * - inclusive * - expected validation result * - array of test input values */ $valuesExpected = array(array(1, 100, true, true, array(1, 10, 100)), array(1, 100, true, false, array(0, 0.99, 100.01, 101)), array(1, 100, false, false, array(0, 1, 100, 101)), array('a', 'z', true, true, array('a', 'b', 'y', 'z')), array('a', 'z', false, false, array('!', 'a', 'z'))); foreach ($valuesExpected as $element) { $validator = new Zend_Validate_Between(array('min' => $element[0], 'max' => $element[1], 'inclusive' => $element[2])); foreach ($element[4] as $input) { $this->assertEquals($element[3], $validator->isValid($input), 'Failed values: ' . $input . ":" . implode("\n", $validator->getMessages())); } } }
/** * Ensures that the validator follows expected behavior * * @return void */ public function testBasic() { /** * The elements of each array are, in order: * - minimum * - maximum * - inclusive * - expected validation result * - array of test input values */ $valuesExpected = array(array(1, 100, true, true, array(1, 10, 100)), array(1, 100, false, false, array(0, 1, 100, 101)), array('a', 'z', true, true, array('a', 'b', 'y', 'z')), array('a', 'z', false, false, array('!', 'a', 'z'))); foreach ($valuesExpected as $element) { $validator = new Zend_Validate_Between($element[0], $element[1], $element[2]); foreach ($element[4] as $input) { $this->assertEquals($element[3], $validator->isValid($input)); } } }
public function isValidDocument($file, $max, $allowedTypes) { //check size $validator = new Zend_Validate_Between('1', $max); if ($validator->isValid($file['size'])) { } else { // value failed validation; print reasons foreach ($validator->getMessages() as $message) { return array('Error' => 'Document:' . $message); } } //check the type $this->_fileName = $file['name']; $return = $this->_checkType($allowedTypes); if ($return == false) { return array('Error' => 'Non-allowed type of document.'); } }
/** * Validate Tag Search Options * * @param array $options * @throws Zend_Service_Exception * @return void */ protected function _validateTagSearch(array $options) { $validOptions = array('method', 'api_key', 'user_id', 'tags', 'tag_mode', 'text', 'min_upload_date', 'max_upload_date', 'min_taken_date', 'max_taken_date', 'license', 'sort', 'privacy_filter', 'bbox', 'accuracy', 'machine_tags', 'machine_tag_mode', 'group_id', 'extras', 'per_page', 'page'); $this->_compareOptions($options, $validOptions); /** * @see Zend_Validate_Between */ require_once 'Zend/Validate/Between.php'; $between = new Zend_Validate_Between(1, 500, true); if (!$between->isValid($options['per_page'])) { /** * @see Zend_Service_Exception */ require_once 'Zend/Service/Exception.php'; throw new Zend_Service_Exception($options['per_page'] . ' is not valid for the "per_page" option'); } /** * @see Zend_Validate_Int */ require_once 'Zend/Validate/Int.php'; $int = new Zend_Validate_Int(); if (!$int->isValid($options['page'])) { /** * @see Zend_Service_Exception */ require_once 'Zend/Service/Exception.php'; throw new Zend_Service_Exception($options['page'] . ' is not valid for the "page" option'); } // validate extras, which are delivered in csv format if ($options['extras']) { $extras = explode(',', $options['extras']); $validExtras = array('license', 'date_upload', 'date_taken', 'owner_name', 'icon_server'); foreach ($extras as $extra) { /** * @todo The following does not do anything [yet], so it is commented out. */ //in_array(trim($extra), $validExtras); } } }
/** * Sets img size * * @throws Zend_View_Exception * @param int $imgSize Size of img must be between 1 and 512 * @return Zend_View_Helper_Gravatar */ public function setImgSize($imgSize) { /** * @see Zend_Validate_Between */ require_once 'Zend/Validate/Between.php'; $betweenValidate = new Zend_Validate_Between(1, 512); $result = $betweenValidate->isValid($imgSize); if (!$result) { /** * @see Zend_View_Exception */ require_once 'Zend/View/Exception.php'; throw new Zend_View_Exception(current($betweenValidate->getMessages())); } $this->_options['imgSize'] = $imgSize; return $this; }
public function testSetGetMessageLengthLimitation() { Zend_Validate::setMessageLength(5); $this->assertEquals(5, Zend_Validate::getMessageLength()); $valid = new Zend_Validate_Between(1, 10); $this->assertFalse($valid->isValid(24)); $message = current($valid->getMessages()); $this->assertTrue(strlen($message) <= 5); }
/** * Built-in Zend between check. Returns true if and only if $value is between the minimum and maximum boundary values. * * @param integer $value * @param integer $min * @param mixed $max * @param boolean $inclusive * * @return boolean Valid? */ public function between($value, $min, $max, $inclusive = true) { $this->m_ErrorMessage = null; require_once 'Zend/Validate/Between.php'; $validator = new Zend_Validate_Between($min, $max, $inclusive); $result = $validator->isValid($value); if (!$result) { $this->m_ErrorMessage = BizSystem::getMessage("VALIDATESVC_BETWEEN", array($this->m_FieldNameMask, $min, $max)); } return $result; }
/** * Validate options for an ItemLookup * * @param array $options Options array to be used for the query * @throws Zend_Service_Exception * @return void */ protected function _validateItemLookup($options = array()) { if (!is_array($options)) { throw new Zend_Service_Exception('Options must be specified as an array'); } // Validate keys in the $options array $this->_compareOptions($options, array('ItemId', 'IdType', 'SearchIndex', 'MerchantId', 'Condition', 'DeliveryMethod', 'ISPUPostalCode', 'OfferPage', 'ReviewPage', 'VariationPage', 'ResponseGroup', 'Service', 'SubscriptionId', 'Operation')); // Validate ResponseGroup (required) if (empty($options['ResponseGroup'])) { throw new Zend_Service_Exception('Query requires a ResponseGroup'); } else { $responseGroup = split(',', $options['ResponseGroup']); foreach ($responseGroup as $r) { if (!in_array($r, array('Request', 'Small', 'Medium', 'Large'))) { throw new Zend_Service_Exception('This wrapper only supports Request, Small, Medium and Large ' . 'ResponseGroups'); } } } // Validate Sort (optional) if (isset($options['Sort'])) { $this->_validateInArray('Sort', $options['Sort'], array_values(self::$_searchSort[$options['SearchIndex']])); } // Validate City (optional) if (isset($options['City'])) { $this->_validateInArray('City', $options['City'], array('Boston', 'Chicago', 'New York', 'San Francisco', 'Seattle', 'Washington, D.C.')); } if (isset($options['ItemPage'])) { /** * @see Zend_Validate_Between */ require_once 'Zend/Validate/Between.php'; $between = new Zend_Validate_Between(0, 2500, true); if (!$between->isValid($options['ItemPage'])) { throw new Zend_Service_Exception($options['ItemPage'] . ' is not a valid value for the "ItemPage" option.'); } } }
/** * Prepares the arguments for the "Video" source * * @param array $options * @return array */ protected function _prepareVideoSourceArguments(array $options = array()) { $arguments = array(); if (isset($options['count'])) { $between = new Zend_Validate_Between(1, 50, true); if (!$between->isValid($options['count'])) { throw new Zend_Service_Exception($options['count'] . ' is not valid for the "count" option'); } $arguments['Video.Count'] = (int) $options['count']; } if (isset($options['offset'])) { $between = new Zend_Validate_Between(0, 1000, true); if (!$between->isValid($options['offset'])) { throw new Zend_Service_Exception($options['offset'] . ' is not valid for the "offset" option'); } $arguments['Video.Offset'] = (int) $options['offset']; } if (isset($options['adult'])) { $arguments['Video.Adult'] = $options['adult']; } if (isset($options['filters'])) { if (is_string($options['filters'])) { $options['filters'] = array($options['filters']); } if (!is_array($options['filters'])) { throw new Zend_Service_Exception('The "filters" option must be a string or array of strings'); } $arguments['Video.Filters'] = implode(',', $options['filters']); } if (isset($options['sortby'])) { $arguments['Video.SortBy'] = $options['sortby']; } return $arguments; }
public function between($min, $max, $value) { $validator = new Zend_Validate_Between(array('min' => $min, 'max' => $max)); return $validator->isValid($value); }
/** * Returns TRUE if value is greater than or equal to $min and less * than or equal to $max, FALSE otherwise. If $inc is set to * FALSE, then the value must be strictly greater than $min and * strictly less than $max. * * @deprecated since 0.8.0 * @param mixed $key * @param mixed $min * @param mixed $max * @param boolean $inc * @return boolean */ public static function isBetween($value, $min, $max, $inc = true) { require_once 'Zend/Validate/Between.php'; $validator = new Zend_Validate_Between($min, $max, $inc); return $validator->isValid($value); }
protected function validateAndSave($facilityRow, $checkName = true) { $districtText = $this->tr('Region B (Health District)'); $provinceText = $this->tr('Region A (Province)'); $localRegionText = $this->tr('Region C (Local Region)'); //validate $status = ValidationContainer::instance(); //check for required fields if ($checkName) { $status->checkRequired($this, 'facility_name', 'Facility name'); //check for unique if ($this->_getParam('facility_name') and !Facility::isUnique($this->_getParam('facility_name'), $this->_getParam('id'))) { $status->addError('facility_name', t('That name already exists.')); } } // validate lat & long require_once 'Zend/Validate/Float.php'; require_once 'Zend/Validate/Between.php'; $lat = $this->getSanParam('facility_latitude'); $long = $this->getSanParam('facility_longitude'); $validator = new Zend_Validate_Float(); $validbetween = new Zend_Validate_Between('-180', '180'); if ($lat && (!$validator->isValid($lat) || !$validbetween->isValid($lat))) { $status->addError('facility_latitude', t('That latitude and longitude does not appear to be valid.')); } if ($long && (!$validator->isValid($long) || !$validbetween->isValid($long))) { $status->addError('facility_longitude', t('That latitude and longitude does not appear to be valid.')); } $status->checkRequired($this, 'facility_type_id', t('Facility type')); $status->checkRequired($this, 'facility_province_id', $provinceText); if ($this->setting('display_region_b')) { $status->checkRequired($this, 'facility_district_id', $districtText); } if ($this->setting('display_region_c')) { $status->checkRequired($this, 'facility_region_c_id', $localRegionText); } //$status->checkRequired ( $this, 'facility_city', t ( "City is required." ) ); list($location_params, $facility_location_tier, $facility_location_id) = $this->getLocationCriteriaValues(array(), 'facility'); $city_id = false; if ($this->getSanParam('facility_city') && !$this->getSanParam('is_new_city')) { $city_id = Location::verifyHierarchy($location_params['facility_city'], $location_params['facility_city_parent_id'], $this->setting('num_location_tiers')); if ($city_id === false) { $status->addError('facility_city', t("That city does not appear to be located in the chosen region. If you want to create a new city, check the new city box.")); } } $sponsor_date_array = $this->getSanParam('sponsor_start_date'); // may or may not be array $sponsor_end_date_array = $this->getSanParam('sponsor_end_date'); $sponsor_id = $this->getSanParam('facility_sponsor_id') ? $this->getSanParam('facility_sponsor_id') : null; if (is_array($sponsor_id)) { $sponsor_array = $sponsor_id; $sponsor_id = $sponsor_id[0]; } // todo case where multip array and no_allow_multi if (@$this->setting('require_sponsor_dates')) { $status->checkRequired($this, 'sponsor_option_id', t('Sponsor dates are required.') . "\n"); if ($this->setting('allow_multi_sponsors')) { // and multiple sponsors option if (!is_array($this->getSanParam('sponsor_option_id'))) { $status->addError('sponsor_end_date', t('Sponsor dates are required.') . "\n"); } foreach ($sponsor_array as $i => $val) { if (empty($sponsor_date_array[$i]) || !empty($val)) { $status->addError('sponsor_start_date', t('Sponsor dates are required.') . "\n"); } if (empty($sponsor_end_date_array[$i]) || !empty($val)) { $status->addError('sponsor_end_date', t('Sponsor dates are required.') . "\n"); } } } } // end validation if ($status->hasError()) { $status->setStatusMessage(t('The facility could not be saved.')); } else { $location_id = null; if ($city_id === false && $this->getSanParam('is_new_city')) { $location_id = Location::insertIfNotFound($location_params['facility_city'], $location_params['facility_city_parent_id'], $this->setting('num_location_tiers')); if ($location_id === false) { $status->addError('facility_city', t('Could not save that city.')); } } else { if ($city_id) { $location_id = $city_id; } else { if ($this->setting('display_region_c')) { $location_id = $this->getSanParam('facility_region_c_id'); } else { if ($this->setting('display_region_b')) { $location_id = $this->getSanParam('facility_district_id'); } else { $location_id = $this->getSanParam('facility_province_id'); } } } if (strstr($location_id, '_')) { $parts = explode('_', $location_id); $location_id = $parts[count($parts) - 1]; } } // save row if ($location_id) { //map db field names to FORM field names $facilityRow->facility_name = $this->getSanParam('facility_name'); $facilityRow->location_id = $location_id; $facilityRow->type_option_id = $this->getSanParam('facility_type_id') ? $this->getSanParam('facility_type_id') : null; $facilityRow->facility_comments = $this->_getParam('facility_comments'); $facilityRow->address_1 = $this->getSanParam('facility_address1'); $facilityRow->address_2 = $this->getSanParam('facility_address2'); $facilityRow->lat = $lat; $facilityRow->long = $long; $facilityRow->postal_code = $this->getSanParam('facility_postal_code'); $facilityRow->phone = $this->getSanParam('facility_phone'); $facilityRow->fax = $this->getSanParam('facility_fax'); $facilityRow->sponsor_option_id = $sponsor_id; //dupecheck $dupe = new Facility(); $select = $dupe->select()->where('location_id =' . $facilityRow->location_id . ' and facility_name = "' . $facilityRow->facility_name . '"'); if (!$facilityRow->id && $dupe->fetchRow($select)) { $status->status = ''; $status->setStatusMessage(t('The facility could not be saved. A facility with this name already exists in that location.')); return false; } $obj_id = $facilityRow->save(); $_SESSION['status'] = t('The facility was saved.'); if ($obj_id) { if (!Facility::saveSponsors($obj_id, $sponsor_array, $sponsor_date_array, $sponsor_end_date_array)) { $status->setStatusMessage(t('There was an error saving sponsor data though.')); return false; } $status->setStatusMessage(t('The facility was saved.')); $status->setRedirect('/facility/view/id/' . $obj_id); return $obj_id; } else { unset($_SESSION['status']); $status->setStatusMessage(t('ERROR: The facility could not be saved.')); } } } return false; }
/** * set the max result hits for this search * * @param integer $hits * @return Zend_Service_DeveloperGarden_LocalSearch_SearchParameters */ public function setHits($hits = 10) { require_once 'Zend/Validate/Between.php'; $validator = new Zend_Validate_Between(0, 1000); if (!$validator->isValid($hits)) { $message = $validator->getMessages(); require_once 'Zend/Service/DeveloperGarden/LocalSearch/Exception.php'; throw new Zend_Service_DeveloperGarden_LocalSearch_Exception(current($message)); } $this->_parameters['hits'] = $hits; return $this; }
/** * Validate Group Search Options * * @param array $options * @throws Zend_Service_Exception * @return void */ protected function _validateGroupPoolGetPhotos(array $options) { $validOptions = array('api_key', 'tags', 'method', 'group_id', 'per_page', 'page', 'extras', 'user_id'); $this->_compareOptions($options, $validOptions); /** * @see Zend_Validate_Between */ //$1 'Zend/Validate/Between.php'; $between = new Zend_Validate_Between(1, 500, true); if (!$between->isValid($options['per_page'])) { /** * @see Zend_Service_Exception */ //$1 'Zend/Service/Exception.php'; throw new Zend_Service_Exception($options['per_page'] . ' is not valid for the "per_page" option'); } /** * @see Zend_Validate_Int */ //$1 'Zend/Validate/Int.php'; $int = new Zend_Validate_Int(); if (!$int->isValid($options['page'])) { /** * @see Zend_Service_Exception */ //$1 'Zend/Service/Exception.php'; throw new Zend_Service_Exception($options['page'] . ' is not valid for the "page" option'); } // validate extras, which are delivered in csv format if (isset($options['extras'])) { $extras = explode(',', $options['extras']); $validExtras = array('license', 'date_upload', 'date_taken', 'owner_name', 'icon_server'); foreach ($extras as $extra) { /** * @todo The following does not do anything [yet], so it is commented out. */ //in_array(trim($extra), $validExtras); } } }
/** * Sets img size * * @throws Zend_View_Exception * @param int $imgSize Size of img must be between 1 and 512 * @return Zwe_View_Helper_Gravatar */ public function setImgSize($imgSize) { $betweenValidate = new Zend_Validate_Between(1, 512); $result = $betweenValidate->isValid($imgSize); if (!$result) { throw new Zend_View_Exception(current($betweenValidate->getMessages())); } $this->_options['imgSize'] = $imgSize; return $this; }