Skip to content

Instantly share code, notes, and snippets.

@zeelot
Forked from kiall/bla.php
Created August 21, 2011 18:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeelot/1160928 to your computer and use it in GitHub Desktop.
Save zeelot/1160928 to your computer and use it in GitHub Desktop.
Valid::at_least()
<?php defined('SYSPATH') or die('No direct script access.');
class Model_Bla extends ORM {
public function rules()
{
return array(
'phone_one' => array(
array('at_least', array(':validation', 1, array('phone_one', 'phone_two', 'phone_three'))),
),
);
}
}
<?php defined('SYSPATH') or die('No direct script access.');
class Valid exetends Kohana_Valid {
/**
* Checks that at least $needed of $fields are not_empty
*
* @param array array of values
* @param integer Number of fields required
* @param array Field names to check.
* @return boolean
*/
public static function at_least($validation, $needed = 1, $fields)
{
$found = 0;
foreach ($fields as $field)
{
if (isset($validation[$field]) AND Valid::not_empty($validation[$field]))
{
$found++;
}
}
if ($found >= $needed)
return TRUE;
$validation->error($fields[0], 'at_least', array($needed, $fields));
}
} // End Valid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment