phplibrary/src/Validator/Rule/Code.php
2018-04-13 17:59:57 +03:00

62 lines
1.8 KiB
PHP

<?php
/**
* Проверка формата электронной почты
*/
namespace ctiso\Validator\Rule;
use ctiso\Validator\Rule\AbstractRule,
ctiso\Collection;
class Code extends AbstractRule
{
public function getErrorMsg()
{
return "Неправильно указан персональный код";
}
function checkCode($code) {
foreach($code as $c) {
if (empty($c)) {
return false;
}
}
return true;
}
public function isValid(Collection $container, $status = null)
{
if ($status == 'update') return true;
$name = $this->field;
if (is_array($_POST[$name . '_code_genre'])) {
$count = count($_POST[$name . '_code_genre']);
for($n = 0; $n < $count; $n++) {
$code = array(
$_POST[$name . '_code_genre'][$n],
$_POST[$name . '_code_f'][$n],
$_POST[$name . '_code_i'][$n],
$_POST[$name . '_code_o'][$n],
$_POST[$name . '_code_year'][$n],
$_POST[$name . '_code_month'][$n],
$_POST[$name . '_code_day'][$n]
);
if (!$this->checkCode($code)) {
return false;
}
}
return true;
} else {
$code = array(
$_POST[$name . '_code_genre'],
$_POST[$name . '_code_f'],
$_POST[$name . '_code_i'],
$_POST[$name . '_code_o'],
$_POST[$name . '_code_year'],
$_POST[$name . '_code_month'],
$_POST[$name . '_code_day']
);
return $this->checkCode($code);
}
}
}