*/ WBClass::load('WBPAT_Forms_Rule'); /** * patForms Rule VFSIsDir * * Check whether value is a proper VFS folder * * @version 0.2.0 * @package Wombat * @subpackage patForms */ class patForms_Rule_VFSIsDir 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', 'This is not a folder'), ); return true; } /** * find user * * Try to find user by nickname or email address * * @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); } // load explorer $params = array( 'user' => $this->config['user'] ); $expl = WBClass::create('WBVFS_Explorer', $params); /** @var $expl WBVFS_Explorer */ foreach ($value as $v) { // pseudo id for root folder if ($v == 'NULL') { continue; } try { $node = $expl->getDir($v); } catch (WBException_Datasource $e) { if ($e->getCode() != 'WBDatasource_Tree.1') { throw $e; } $node = null; } if (!is_array($node)) { $this->addValidationError(1); return false; } } return true; } } ?>