Skip to content

Instantly share code, notes, and snippets.

@Zeelot

Zeelot/bla.php

Forked from kiall/bla.php
Created Aug 21, 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(':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