Beispiel #1
0
 /**
  * @param string $entityType
  * @param integer $entityId
  * @param callback $serviceCallback
  * @param string $dtoProperty
  * @return string
  */
 public function getSlugStringForEntity($entityType, $entityId, $serviceCallback, $dtoProperty)
 {
     if (!empty($this->slugs['id'][$entityType][$entityId])) {
         return $this->slugs['id'][$entityType][$entityId]->getString();
     }
     $dbSlug = $this->slugDao->findActiveSlugForEntityItem($entityType, $entityId);
     if ($dbSlug !== null) {
         return $dbSlug->getString();
     }
     // processing and generating new slug
     $dto = call_user_func($serviceCallback, $entityId);
     if ($dto !== null) {
         $vars = get_object_vars($dto);
         if (!empty($vars[$dtoProperty]) && is_string($vars[$dtoProperty])) {
             // do not support non latin strings
             //                if ( preg_match('/[^\\p{Common}\\p{Latin}]/u', $vars[$dtoProperty]) )
             //                {
             //                    return null;
             //                }
             $slug = $this->makeSlug($vars[$dtoProperty]);
             $duplicateSlugDto = $this->slugDao->findDuplicateSlug($entityType, $slug);
             if ($duplicateSlugDto !== null) {
                 $slug = $slug . '-' . $entityId;
             }
             if (strlen($slug) > 2) {
                 $slugDto = $this->slugDao->findSlug($entityType, $entityId, $slug);
                 if ($slugDto === null) {
                     $this->slugDao->updateSlugStatus($entityType, $entityId);
                     $slugDto = new OASEO_BOL_Slug();
                     $slugDto->setEntityType($entityType);
                     $slugDto->setEntityId($entityId);
                     $slugDto->setString($slug);
                     $slugDto->setActive(true);
                     $this->slugDao->save($slugDto);
                 }
                 $this->slugs['id'][$entityType][$entityId] = $slugDto;
                 return $slugDto->getString();
             }
         }
     }
 }