*/ WBClass::load('WBPAT_Forms_Rule'); /** * patForms Rule UserFind * * Try to find user by email or nichname * * @version 0.1.0 * @package Wombat * @subpackage patForms */ class patForms_Rule_UserFind extends WBPAT_Forms_Rule { /** * Initialize validation codes using gettext * * @access protected * @return bool $success Always returns true. * @see $attributeDefaults */ function loadValidatiorErrorCodes() { $this->validatorErrorCodes = array( 1 => patI18n::dgettext('wombat', 'Value must not be empty'), 2 => patI18n::dgettext('wombat', 'No matching user found.') ); return true; } /** * find user * * Try to find user by nickname or email address * * @param patForms|patForms_Element form object */ public function applyRule(&$form, $type = PATFORMS_RULE_AFTER_VALIDATION) { if (!($form instanceof patForms_Element)) { $element = $form->getElementByName('nicknameoremail'); } $value = $element->getValue(); if (empty($value)) { $this->addValidationError(1); return false; } $data = array(); if (strstr($value, '@')) { $data['email'] = $value; } else { $data['nickname'] = $value; } $storage = WBClass::create( 'WBUser_Storage_Table' ); /** @var $storage WBUser_Storage */ $id = $storage->find($data); if (empty($id)) { $this->addValidationError(2); return false; } return true; } } ?>