*/ WBClass::load('WBPAT_Forms_Rule'); /** * patForms Rule VFSIsDir * * Check whether value is a proper VFS file * * @version 0.2.0 * @package wombat * @subpackage patForms */ class patForms_Rule_VFSIsFile extends WBPAT_Forms_Rule { /** * config values * - user * * @todo implement "paren" and "descendent" * @var array */ protected $config = array( 'user' => null, ); /** * Initialize validation codes using gettext * * @access protected * @return bool $success Always returns true. * @see $attributeDefaults */ function loadValidatiorErrorCodes() { $this->validatorErrorCodes = array( 1 => patI18n::dgettext('wombat', 'Given value is not a valid file'), ); return true; } /** * check file obscure id * * Try to load file by obscure id * * @param patForms|patForms_Element form element object * @param string $type validateion type */ public function applyRule(&$element, $type = PATFORMS_RULE_AFTER_VALIDATION) { if (empty($this->config['user'])) { WBClass::load('WBException_Config'); throw new WBException_Config('Config value "user" must be a valid user id', 1, __CLASS__); } $value = $element->getValue(); if (empty($value)) { return true; } if (!is_array($value)) { $value = array($value); } $params = array( 'user' => $this->config['user'] ); $file = WBClass::create('WBVFS_File', $params); // check all files foreach ($value as $v) { $file = $file->loadByObscureId($v); if (!$file->isOK()) { $this->addValidationError(1); return false; } } return true; } } ?>