예제 #1
0
 /**
  * {@inheritDoc}
  */
 public function validateEntity(EntityInterface $entity, ErrorStore $errorStore)
 {
     $label = $entity->getLabel();
     if (false == trim($label)) {
         $errorStore->addError('o:label', 'The label cannot be empty.');
     }
     if (!$this->isUnique($entity, ['label' => $label])) {
         $errorStore->addError('o:label', 'The label is already taken.');
     }
 }
 /**
  * {@inheritDoc}
  */
 public function hydrate(Request $request, EntityInterface $entity, ErrorStore $errorStore)
 {
     $data = $request->getContent();
     if ($this->shouldHydrate($request, 'o:is_public')) {
         $entity->setIsPublic($request->getValue('o:is_public', true));
     }
     // Hydrate this resource's values.
     $append = $request->getOperation() === Request::UPDATE && $request->isPartial();
     $valueHydrator = new ValueHydrator($this);
     $valueHydrator->hydrate($data, $entity, $append);
     // o:owner
     $this->hydrateOwner($request, $entity);
     // o:resource_class
     $this->hydrateResourceClass($request, $entity);
     // o:resource_template
     $this->hydrateResourceTemplate($request, $entity);
 }
예제 #3
0
 /**
  * {@inheritDoc}
  */
 public function validateEntity(EntityInterface $entity, ErrorStore $errorStore)
 {
     if (false == $entity->getName()) {
         $errorStore->addError('o:name', 'The name cannot be empty.');
     }
     $email = $entity->getEmail();
     $validator = new EmailAddress();
     if (!$validator->isValid($email)) {
         $errorStore->addValidatorMessages('o:email', $validator->getMessages());
     }
     if (!$this->isUnique($entity, ['email' => $email])) {
         $errorStore->addError('o:email', sprintf('The email "%s" is already taken.', $email));
     }
     if (false == $entity->getRole()) {
         $errorStore->addError('o:role', 'Users must have a role.');
     }
 }
예제 #4
0
 /**
  * {@inheritDoc}
  */
 public function validateEntity(EntityInterface $entity, ErrorStore $errorStore)
 {
     if (!$entity->getSite()) {
         $errorStore->addError('o:site', 'A page must belong to a site.');
     }
     $slug = $entity->getSlug();
     if (!is_string($slug) || $slug === '') {
         $errorStore->addError('o:slug', 'The slug cannot be empty.');
     }
     if (preg_match('/[^a-zA-Z0-9-]/u', $slug)) {
         $errorStore->addError('o:slug', 'A slug can only contain letters, numbers, and hyphens.');
     }
     if ($entity->getSite() && !$this->isUnique($entity, ['slug' => $slug, 'site' => $entity->getSite()])) {
         $errorStore->addError('o:slug', sprintf('The slug "%s" is already taken.', $slug));
     }
     if (!$entity->getTitle()) {
         $errorStore->addError('o:title', 'A page must have a title.');
     }
 }
예제 #5
0
 /**
  * Validate navigation.
  *
  * Prevent corrupt navigation data by validating prior to saving.
  *
  * @param EntityInterface $entity
  * @param ErrorStore $errorStore
  */
 protected function validateNavigation(EntityInterface $entity, ErrorStore $errorStore)
 {
     $navigation = $entity->getNavigation();
     if (!is_array($navigation)) {
         $errorStore->addError('o:navigation', 'Invalid navigation: navigation must be an array');
         return;
     }
     $pagesInNavigation = [];
     $manager = $this->getServiceLocator()->get('Omeka\\Site\\NavigationLinkManager');
     $validateLinks = function ($linksIn) use(&$validateLinks, $manager, $errorStore, $pagesInNavigation) {
         foreach ($linksIn as $key => $data) {
             if (!isset($data['type'])) {
                 $errorStore->addError('o:navigation', 'Invalid navigation: link missing type');
                 return;
             }
             if (!isset($data['data'])) {
                 $errorStore->addError('o:navigation', 'Invalid navigation: link missing data');
                 return;
             }
             if (!$manager->get($data['type'])->isValid($data['data'], $errorStore)) {
                 $errorStore->addError('o:navigation', 'Invalid navigation: invalid link data');
                 return;
             }
             if ('page' === $data['type']) {
                 if (in_array($data['data']['id'], $pagesInNavigation)) {
                     $errorStore->addError('o:navigation', 'Invalid navigation: page links must be unique');
                     return;
                 }
                 $pagesInNavigation[] = $data['data']['id'];
             }
             if (isset($data['links'])) {
                 if (!is_array($data['links'])) {
                     $errorStore->addError('o:navigation', 'Invalid navigation: links must be an array');
                     return;
                 }
                 $validateLinks($data['links']);
             }
         }
     };
     $validateLinks($navigation);
 }
예제 #6
0
 /**
  * Hydrate the entity's resource template.
  *
  * Assumes the resource template can be set to NULL.
  *
  * @param Request $request
  * @param EntityInterface $entity
  */
 public function hydrateResourceTemplate(Request $request, EntityInterface $entity)
 {
     $data = $request->getContent();
     $resourceTemplate = $entity->getResourceTemplate();
     if ($this->shouldHydrate($request, 'o:resource_template')) {
         if (isset($data['o:resource_template']['o:id']) && is_numeric($data['o:resource_template']['o:id'])) {
             $resourceTemplate = $this->getAdapter('resource_templates')->findEntity($data['o:resource_template']['o:id']);
         } else {
             $resourceTemplate = null;
         }
     }
     $entity->setResourceTemplate($resourceTemplate);
 }
예제 #7
0
 /**
  * {@inheritDoc}
  */
 public function validateEntity(EntityInterface $entity, ErrorStore $errorStore)
 {
     // Validate local name
     if (false == $entity->getLocalName()) {
         $errorStore->addError('o:local_name', 'The local name cannot be empty.');
     }
     // Validate label
     if (false == $entity->getLabel()) {
         $errorStore->addError('o:label', 'The label cannot be empty.');
     }
     // Validate vocabulary
     if ($entity->getVocabulary() instanceof Vocabulary) {
         if ($entity->getVocabulary()->getId()) {
             // Vocabulary is persistent. Check for unique local name.
             $criteria = ['vocabulary' => $entity->getVocabulary(), 'localName' => $entity->getLocalName()];
             if (!$this->isUnique($entity, $criteria)) {
                 $errorStore->addError('o:local_name', sprintf('The local name "%s" is already taken.', $entity->getLocalName()));
             }
         }
     } else {
         $errorStore->addError('o:vocabulary', 'A vocabulary must be set.');
     }
 }
예제 #8
0
 /**
  * {@inheritDoc}
  */
 public function hydrateOwner(Request $request, EntityInterface $entity)
 {
     if ($entity->getItem() instanceof Item) {
         $entity->setOwner($entity->getItem()->getOwner());
     }
 }
예제 #9
0
 /**
  * {@inheritDoc}
  */
 public function validateEntity(EntityInterface $entity, ErrorStore $errorStore)
 {
     // Validate namespace URI
     $namespaceUri = $entity->getNamespaceUri();
     if (false == $entity->getNamespaceUri()) {
         $errorStore->addError('o:namespace_uri', 'The namespace URI cannot be empty.');
     }
     if (!$this->isUnique($entity, ['namespaceUri' => $namespaceUri])) {
         $errorStore->addError('o:namespace_uri', sprintf('The namespace URI "%s" is already taken.', $namespaceUri));
     }
     // Validate prefix
     $prefix = $entity->getPrefix();
     if (false == $entity->getPrefix()) {
         $errorStore->addError('o:prefix', 'The prefix cannot be empty.');
     }
     if (!$this->isUnique($entity, ['prefix' => $prefix])) {
         $errorStore->addError('o:prefix', sprintf('The prefix "%s" is already taken.', $prefix));
     }
     // Validate label
     if (false == $entity->getLabel()) {
         $errorStore->addError('o:label', 'The label cannot be empty.');
     }
     // Check for uniqueness of resource class local names.
     $uniqueLocalNames = [];
     foreach ($entity->getResourceClasses() as $resourceClass) {
         if (in_array($resourceClass->getLocalName(), $uniqueLocalNames)) {
             $errorStore->addError('o:resource_class', sprintf('The local name "%s" is already taken.', $resourceClass->getLocalName()));
         } else {
             $uniqueLocalNames[] = $resourceClass->getLocalName();
         }
     }
     // Check for uniqueness of property local names.
     $uniqueLocalNames = [];
     foreach ($entity->getProperties() as $property) {
         if (in_array($property->getLocalName(), $uniqueLocalNames)) {
             $errorStore->addError('o:resource_class', sprintf('The local name "%s" is already taken.', $property->getLocalName()));
         } else {
             $uniqueLocalNames[] = $property->getLocalName();
         }
     }
 }