Skip to content

Instantly share code, notes, and snippets.

@kiall

kiall/bla.php

Created Aug 20, 2011
Embed
What would you like to do?
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($this, 1, array('phone_one', 'phone_two', 'phone_three'))),
),
'phone_two' => array(
array('at_least', array($this, 1, array('phone_one', 'phone_two', 'phone_three'))),
),
'phone_three' => array(
array('at_least', array($this, 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($array, $needed = 1, $fields)
{
$found = 0;
foreach ($fields as $field)
{
if (isset($array[$field]) AND Valid::not_empty($array[$field]))
{
$found++;
}
}
return ($found >= $needed);
}
} // End Valid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment