Created
August 20, 2011 16:02
-
-
Save kiall/1159271 to your computer and use it in GitHub Desktop.
Valid::at_least()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'))), | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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