/** * Constructor. */ function MetadataForm($paper) { $roleDao =& DAORegistry::getDAO('RoleDAO'); $schedConf =& Request::getSchedConf(); $user =& Request::getUser(); $roleId = $roleDao->getRoleIdFromPath(Request::getRequestedPage()); // If the user is a director of this paper, make the form editable. $this->canEdit = false; if ($roleId != null && ($roleId == ROLE_ID_DIRECTOR || $roleId == ROLE_ID_TRACK_DIRECTOR)) { $this->canEdit = true; } // Check if the author can modify metadata. if ($roleId == ROLE_ID_AUTHOR) { if (AuthorAction::mayEditPaper($paper)) { $this->canEdit = true; } } if ($this->canEdit) { parent::Form('submission/metadata/metadataEdit.tpl'); $this->addCheck(new FormValidatorLocale($this, 'title', 'required', 'author.submit.form.titleRequired')); $this->addCheck(new FormValidatorArray($this, 'authors', 'required', 'author.submit.form.authorRequiredFields', array('firstName', 'lastName'))); $this->addCheck(new FormValidatorArrayCustom($this, 'authors', 'required', 'author.submit.form.authorRequiredFields', create_function('$email, $regExp', 'return String::regexp_match($regExp, $email);'), array(FormValidatorEmail::getRegexp()), false, array('email'))); $this->addCheck(new FormValidatorArrayCustom($this, 'authors', 'required', 'user.profile.form.urlInvalid', create_function('$url, $regExp', 'return empty($url) ? true : String::regexp_match($regExp, $url);'), array(FormValidatorUrl::getRegexp()), false, array('url'))); } else { parent::Form('submission/metadata/metadataView.tpl'); } // If the user is a reviewer of this paper, do not show authors. $this->canViewAuthors = true; if ($roleId != null && $roleId == ROLE_ID_REVIEWER) { $this->canViewAuthors = false; } $this->paper = $paper; $this->addCheck(new FormValidatorPost($this)); }
/** * @covers FormValidatorUrl * @covers FormValidator */ public function testIsValid() { $form = new Form('some template'); // test valid urls $form->setData('testUrl', 'http://some.domain.org/some/path?some=query#fragment'); $validator = new FormValidatorUrl($form, 'testUrl', FORM_VALIDATOR_REQUIRED_VALUE, 'some.message.key'); self::assertTrue($validator->isValid()); self::assertEquals(array('testUrl' => array('required', 'url')), $form->cssValidation); $form->setData('testUrl', 'http://192.168.0.1/'); $validator = new FormValidatorUrl($form, 'testUrl', FORM_VALIDATOR_REQUIRED_VALUE, 'some.message.key'); self::assertTrue($validator->isValid()); // test invalid urls $form->setData('testUrl', 'gopher://some.domain.org/'); $validator = new FormValidatorUrl($form, 'testUrl', FORM_VALIDATOR_REQUIRED_VALUE, 'some.message.key'); self::assertFalse($validator->isValid()); $form->setData('testUrl', 'http://some.domain.org/#frag1#frag2'); $validator = new FormValidatorUrl($form, 'testUrl', FORM_VALIDATOR_REQUIRED_VALUE, 'some.message.key'); self::assertFalse($validator->isValid()); $form->setData('testUrl', 'http://256.168.0.1/'); $validator = new FormValidatorUrl($form, 'testUrl', FORM_VALIDATOR_REQUIRED_VALUE, 'some.message.key'); self::assertFalse($validator->isValid()); }
/** * Constructor. */ function AuthorSubmitStep3Form($paper) { parent::AuthorSubmitForm($paper, 3); // Validation checks for this form $this->addCheck(new FormValidatorCustom($this, 'authors', 'required', 'author.submit.form.authorRequired', create_function('$authors', 'return count($authors) > 0;'))); $this->addCheck(new FormValidatorArray($this, 'authors', 'required', 'author.submit.form.authorRequiredFields', array('firstName', 'lastName'))); $this->addCheck(new FormValidatorArrayCustom($this, 'authors', 'required', 'author.submit.form.authorRequiredFields', create_function('$email, $regExp', 'return String::regexp_match($regExp, $email);'), array(FormValidatorEmail::getRegexp()), false, array('email'))); $this->addCheck(new FormValidatorArrayCustom($this, 'authors', 'required', 'user.profile.form.urlInvalid', create_function('$url, $regExp', 'return empty($url) ? true : String::regexp_match($regExp, $url);'), array(FormValidatorUrl::getRegexp()), false, array('url'))); $this->addCheck(new FormValidatorLocale($this, 'title', 'required', 'author.submit.form.titleRequired')); $schedConf =& Request::getSchedConf(); $reviewMode = $paper->getReviewMode(); if ($reviewMode != REVIEW_MODE_PRESENTATIONS_ALONE) { $this->addCheck(new FormValidatorLocale($this, 'abstract', 'required', 'author.submit.form.abstractRequired')); $trackDao =& DAORegistry::getDAO('TrackDAO'); $track = $trackDao->getTrack($paper->getTrackId()); $abstractWordCount = $track->getAbstractWordCount(); if (isset($abstractWordCount) && $abstractWordCount > 0) { $this->addCheck(new FormValidatorCustom($this, 'abstract', 'required', 'author.submit.form.wordCountAlert', create_function('$abstract, $wordCount', 'foreach ($abstract as $localizedAbstract) {return count(explode(" ",$localizedAbstract)) < $wordCount; }'), array($abstractWordCount))); } } }
/** * Constructor. * @see FormValidatorRegExp::FormValidatorRegExp() */ function FormValidatorUrl(&$form, $field, $type, $message) { parent::FormValidatorRegExp($form, $field, $type, $message, FormValidatorUrl::getRegexp()); }