public function execute($request) { parent::execute($request); $this->dc = new sfDcPlugin($this->resource); if (1 > strlen($title = $this->resource)) { $title = $this->context->i18n->__('Untitled'); } $this->response->setTitle("{$title} - {$this->response->getTitle()}"); if (QubitAcl::check($this->resource, 'update')) { $validatorSchema = new sfValidatorSchema(); $values = array(); $validatorSchema->identifier = new sfValidatorString(array('required' => true), array('required' => $this->context->i18n->__('%1%Identifier%2% - This is a mandatory element.', array('%1%' => '<a href="http://dublincore.org/documents/dcmi-terms/#elements-identifier">', '%2%' => '</a>')))); $values['identifier'] = $this->resource->identifier; $validatorSchema->title = new sfValidatorString(array('required' => true), array('required' => $this->context->i18n->__('%1%Title%2% - This is a mandatory element.', array('%1%' => '<a href="http://dublincore.org/documents/dcmi-terms/#elements-title">', '%2%' => '</a>')))); $values['title'] = $this->resource->getTitle(array('cultureFallback' => true)); $validatorSchema->repository = new sfValidatorString(array('required' => true), array('required' => $this->context->i18n->__('%1%Relation%2% (%3%isLocatedAt%4%) - This is a mandatory element for this resource or one its higher descriptive levels (if part of a collection hierarchy).', array('%1%' => '<a href="http://dublincore.org/documents/dcmi-terms/#elements-relation">', '%2%' => '</a>', '%3%' => '<a href="http://dublincore.org/groups/collections/collection-application-profile/#colcldisLocatedAt">', '%4%' => '</a>')))); foreach ($this->resource->ancestors->andSelf() as $item) { $values['repository'] = $item->repository; if (isset($values['repository'])) { break; } } try { $validatorSchema->clean($values); } catch (sfValidatorErrorSchema $e) { $this->errorSchema = $e; } } }
public function execute($request) { parent::execute($request); $this->isdiah = new sfEhriIsdiahPlugin($this->resource); if (1 > strlen($title = $this->resource)) { $title = $this->context->i18n->__('Untitled'); } $this->response->setTitle("{$title} - {$this->response->getTitle()}"); if (QubitAcl::check($this->resource, 'update')) { $validatorSchema = new sfValidatorSchema(); $valuess = array(); $validatorSchema->authorizedFormOfName = new sfValidatorString(array('required' => true), array('required' => $this->context->i18n->__('%1%Authorized form of name%2% - This is a %3%mandatory%4% element.', array('%1%' => '<a href="http://ica-atom.org/doc/RS-3#5.1.2">', '%2%' => '</a>', '%3%' => '<a href="http://ica-atom.org/doc/RS-3#4.7">', '%4%' => '</a>')))); $values['authorizedFormOfName'] = $this->resource->getAuthorizedFormOfName(array('culltureFallback' => true)); $validatorSchema->identifier = new sfValidatorString(array('required' => true), array('required' => $this->context->i18n->__('%1%Identifier%2% - This is a %3%mandatory%4% element.', array('%1%' => '<a href="http://ica-atom.org/doc/RS-3#5.1.1">', '%2%' => '</a>', '%3%' => '<a href="http://ica-atom.org/doc/RS-3#4.7">', '%4%' => '</a>')))); $values['identifier'] = $this->resource->identifier; $validatorSchema->primaryContact = new sfValidatorAnd(array(new QubitValidatorCountable(), new sfValidatorOr(array(new sfValidatorSchema(array('city' => new sfValidatorString(array('required' => true))), array('allow_extra_fields' => true)), new sfValidatorSchema(array('countryCode' => new sfValidatorString(array('required' => true))), array('allow_extra_fields' => true)), new sfValidatorSchema(array('postalCode' => new sfValidatorString(array('required' => true))), array('allow_extra_fields' => true)), new sfValidatorSchema(array('region' => new sfValidatorString(array('required' => true))), array('allow_extra_fields' => true)), new sfValidatorSchema(array('streetAddress' => new sfValidatorString(array('required' => true))), array('allow_extra_fields' => true))), array('required' => true), array('invalid' => $this->context->i18n->__('%1%Contact information%2% - You %3%must%4% at least include one of the following location or address fields: city, country, postal code, region or street address.', array('%1%' => '<a href="http://ica-atom.org/doc/RS-3#5.2.1">', '%2%' => '</a>', '%3%' => '<a href="<a href="http://ica-atom.org/doc/RS-3#4.7">', '%4%' => '</a>'))))), array('required' => true), array('required' => $this->context->i18n->__('%1%Contact information%2% - This is a %3%mandatory%4% element.', array('%1%' => '<a href="http://ica-atom.org/doc/RS-3#5.2.1">', '%2%' => '</a>', '%3%' => '<a href="http://ica-atom.org/doc/RS-3#4.7">', '%4%' => '</a>')))); if (null !== $this->resource->getPrimaryContact()) { $values['primaryContact']['city'] = $this->resource->getPrimaryContact()->getCity(array('culltureFallback' => true)); $values['primaryContact']['countryCode'] = $this->resource->getPrimaryContact()->countryCode; $values['primaryContact']['postalCode'] = $this->resource->getPrimaryContact()->postalCode; $values['primaryContact']['region'] = $this->resource->getPrimaryContact()->getRegion(array('culltureFallback' => true)); $values['primaryContact']['streetAddress'] = $this->resource->getPrimaryContact()->streetAddress; } try { $validatorSchema->clean($values); } catch (sfValidatorErrorSchema $e) { $this->errorSchema = $e; } } }
public function execute($request) { parent::execute($request); $this->isaar = new sfIsaarPlugin($this->resource); if (1 > strlen($title = $this->resource->__toString())) { $title = $this->context->i18n->__('Untitled'); } $this->response->setTitle("{$title} - {$this->response->getTitle()}"); if (QubitAcl::check($this->resource, 'update')) { $validatorSchema = new sfValidatorSchema(); $values = array(); $validatorSchema->authorizedFormOfName = new sfValidatorString(array('required' => true), array('required' => $this->context->i18n->__('%1%Authorized form of name%2% - This is a %3%mandatory%4% element.', array('%1%' => '<a href="http://ica-atom.org/doc/RS-2#5.1.2">', '%2%' => '</a>', '%3%' => '<a href="http://ica-atom.org/doc/RS-2#4.7">', '%4%' => '</a>')))); $values['authorizedFormOfName'] = $this->resource->getAuthorizedFormOfName(array('cultureFallback' => true)); $validatorSchema->datesOfExistence = new sfValidatorString(array('required' => true), array('required' => $this->context->i18n->__('%1%Dates of existence%2% - This is a %3%mandatory%4% element.', array('%1%' => '<a href="http://ica-atom.org/doc/RS-2#5.2.1">', '%2%' => '</a>', '%3%' => '<a href="http://ica-atom.org/doc/RS-2#4.7">', '%4%' => '</a>')))); $values['datesOfExistence'] = $this->resource->getDatesOfExistence(array('cultureFallback' => true)); $validatorSchema->descriptionIdentifier = new sfValidatorString(array('required' => true), array('required' => $this->context->i18n->__('%1%Description identifier%2% - This is a %3%mandatory%4% element.', array('%1%' => '<a href="http://ica-atom.org/doc/RS-2#5.4.1">', '%2%' => '</a>', '%3%' => '<a href="http://ica-atom.org/doc/RS-2#4.7">', '%4%' => '</a>')))); $values['descriptionIdentifier'] = $this->resource->descriptionIdentifier; $validatorSchema->entityType = new sfValidatorString(array('required' => true), array('required' => $this->context->i18n->__('%1%Type of entity%2% - This is a %3%mandatory%4% element.', array('%1%' => '<a href="http://ica-atom.org/doc/RS-2#5.1.1">', '%2%' => '</a>', '%3%' => '<a href="http://ica-atom.org/doc/RS-2#4.7">', '%4%' => '</a>')))); $values['entityType'] = $this->resource->entityType; try { $validatorSchema->clean($values); } catch (sfValidatorErrorSchema $e) { $this->errorSchema = $e; } } }
public function execute($request) { $this->resource = $this->getRoute()->resource; // Check user authorization if (!QubitAcl::check($this->resource, 'read')) { QubitAcl::forwardToSecureAction(); } if (1 > strlen($title = $this->resource->__toString())) { $title = $this->context->i18n->__('Untitled'); } $this->response->setTitle("{$title} - {$this->response->getTitle()}"); if (QubitAcl::check($this->resource, 'update')) { $validatorSchema = new sfValidatorSchema(); $values = array(); $validatorSchema->date = new sfValidatorString(array('required' => true), array('required' => $this->context->i18n->__('Acquisition date - This is a mandatory element.'))); $values['date'] = $this->resource->date; $validatorSchema->sourceOfAcquisition = new sfValidatorString(array('required' => true), array('required' => $this->context->i18n->__('Source of acquisition - This is a mandatory element.'))); $values['sourceOfAcquisition'] = $this->resource->getSourceOfAcquisition(array('culltureFallback' => true)); $validatorSchema->locationInformation = new sfValidatorString(array('required' => true), array('required' => $this->context->i18n->__('Location information - This is a mandatory element.'))); $values['locationInformation'] = $this->resource->getLocationInformation(array('culltureFallback' => true)); try { $validatorSchema->clean($values); } catch (sfValidatorErrorSchema $e) { $this->errorSchema = $e; } } }
public function execute($request) { $this->resource = $this->getRoute()->resource; if (!$this->resource instanceof QubitTerm) { $this->forward404(); } // Check that this isn't the root if (!isset($this->resource->parent)) { $this->forward404(); } if (1 > strlen($title = $this->resource->__toString())) { $title = $this->context->i18n->__('Untitled'); } $this->response->setTitle("{$title} - {$this->response->getTitle()}"); if (QubitAcl::check($this->resource, 'update')) { $validatorSchema = new sfValidatorSchema(); $values = array(); $validatorSchema->name = new sfValidatorCallback(array('callback' => array($this, 'checkForRepeatedNames'))); $values['name'] = $this->resource->getName(array('cultureFallback' => true)); try { $validatorSchema->clean($values); } catch (sfValidatorErrorSchema $e) { $this->errorSchema = $e; } } QubitTreeView::addAssets($this->response); }
protected function doClean($values) { if (!call_user_func($this->getOption('callable'), $values[$this->getOption('conditional_field')])) { return $values; } // get the validators and turn them into an sfValidatorSchema for easy processing $validators = $this->getOption('conditional_validators'); if (is_array($validators)) { $validators = new sfValidatorSchema($validators); } elseif (!$validators instanceof sfValidatorSchema) { throw new sfException('Options conditional_validators must be an array or an instance of sfValidatorSchema.'); } // have the validator schema simply ignore the extra fields $validators->setOption('allow_extra_fields', true); $validators->setOption('filter_extra_fields', false); return $validators->clean($values); }
public function execute($request) { $this->resource = $this->getRoute()->resource; // Check user authorization if (!QubitAcl::check($this->resource, 'read')) { QubitAcl::forwardUnauthorized(); } if (1 > strlen($title = $this->resource->__toString())) { $title = $this->context->i18n->__('Untitled'); } $this->response->setTitle("{$title} - {$this->response->getTitle()}"); if (QubitAcl::check($this->resource, 'update')) { $validatorSchema = new sfValidatorSchema(); $values = array(); $validatorSchema->authorizedFormOfName = new sfValidatorString(array('required' => true), array('required' => $this->context->i18n->__('Authorized form of name - This is a mandatory element.'))); $values['authorizedFormOfName'] = $this->resource->getAuthorizedFormOfName(array('cultureFallback' => true)); try { $validatorSchema->clean($values); } catch (sfValidatorErrorSchema $e) { $this->errorSchema = $e; } } }
public function execute($request) { parent::execute($request); $this->isdf = new sfIsdfPlugin($this->resource); if (1 > strlen($title = $this->resource)) { $title = $this->context->i18n->__('Untitled'); } $this->response->setTitle("{$title} - {$this->response->getTitle()}"); if (QubitAcl::check($this->resource, 'update')) { $validatorSchema = new sfValidatorSchema(); $values = array(); $validatorSchema->type = new sfValidatorString(array('required' => true), array('required' => $this->context->i18n->__('%1%Type%2% - This is a %3%mandatory%4% element.', array('%1%' => '<a href="http://ica-atom.org/doc/RS-4#Type_of_description">', '%2%' => '</a>', '%3%' => '<a href="http://ica-atom.org/doc/RS-4#Structure_and_use_4.7">', '%4%' => '</a>')))); $values['type'] = $this->resource->type; $validatorSchema->authorizedFormOfName = new sfValidatorString(array('required' => true), array('required' => $this->context->i18n->__('%1%Authorized form of name%2% - This is a %3%mandatory%4% element.', array('%1%' => '<a href="http://ica-atom.org/doc/RS-4#Authorised_name">', '%2%' => '</a>', '%3%' => '<a href="http://ica-atom.org/doc/RS-4#Structure_and_use_4.7">', '%4%' => '</a>')))); $values['authorizedFormOfName'] = $this->resource->getAuthorizedFormOfName(array('cultureFallback' => true)); $validatorSchema->descriptionIdentifier = new sfValidatorString(array('required' => true), array('required' => $this->context->i18n->__('%1%Description identifier%2% - This is a %3%mandatory%4% element.', array('%1%' => '<a href="http://ica-atom.org/doc/RS-4#Function.2Factivity_description_identifier">', '%2%' => '</a>', '%3%' => '<a href="http://ica-atom.org/doc/RS-4#Structure_and_use_4.7">', '%4%' => '</a>')))); $values['descriptionIdentifier'] = $this->resource->descriptionIdentifier; try { $validatorSchema->clean($values); } catch (sfValidatorErrorSchema $e) { $this->errorSchema = $e; } } }
} $comparator->setOption('throw_global_error', true); try { $v->clean(array('left' => 'foo', 'right' => 'bar', 'password' => 'oof', 'password_bis' => 'rab')); $t->skip('', 3); } catch (sfValidatorErrorSchema $e) { $t->is(count($e->getNamedErrors()), 1, '->clean() throws an exception with all error messages'); $t->is(count($e->getGlobalErrors()), 1, '->clean() throws an exception with all error messages'); $t->is($e->getCode(), 'invalid password [invalid]', '->clean() throws an exception with all error messages'); } $userValidator = new sfValidatorSchema(array('left' => new sfValidatorString(array('min_length' => 2)), 'right' => new sfValidatorString(array('min_length' => 2)), 'password' => new sfValidatorString(array('min_length' => 2)), 'password_bis' => new sfValidatorString(array('min_length' => 2)))); $userValidator->setPostValidator(new sfValidatorAnd(array($comparator, $comparator1))); $v = new sfValidatorSchema(array('left' => new sfValidatorString(array('min_length' => 2)), 'right' => new sfValidatorString(array('min_length' => 2)), 'password' => new sfValidatorString(array('min_length' => 2)), 'password_bis' => new sfValidatorString(array('min_length' => 2)), 'user' => $userValidator)); $v->setPostValidator(new sfValidatorAnd(array($comparator, $comparator1))); try { $v->clean(array('left' => 'foo', 'right' => 'bar', 'password' => 'oof', 'password_bis' => 'rab', 'user' => array('left' => 'foo', 'right' => 'bar', 'password' => 'oof', 'password_bis' => 'rab'))); $t->skip('', 7); } catch (sfValidatorErrorSchema $e) { $t->is(count($e->getNamedErrors()), 2, '->clean() throws an exception with all error messages'); $t->is(count($e->getGlobalErrors()), 1, '->clean() throws an exception with all error messages'); $t->is(count($e['user']->getNamedErrors()), 1, '->clean() throws an exception with all error messages'); $t->is(count($e['user']->getGlobalErrors()), 1, '->clean() throws an exception with all error messages'); $t->is(isset($e['user']) ? $e['user']->getCode() : '', 'invalid password [invalid]', '->clean() throws an exception with all error messages'); $t->is(isset($e['user']['password']) ? $e['user']['password']->getCode() : '', 'invalid', '->clean() throws an exception with all error messages'); $t->is($e->getCode(), 'invalid user [invalid password [invalid]] password [invalid]', '->clean() throws an exception with all error messages'); } // __clone() $t->diag('__clone()'); $v = new sfValidatorSchema(array('v1' => $v1, 'v2' => $v2)); $v1 = clone $v; $f1 = $v1->getFields();