idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
11,200 | private function buildAudienceTargeting ( $ targetGroupId , $ locale ) { if ( ! $ targetGroupId ) { return ; } $ structure = $ this -> structureManager -> getStructure ( 'excerpt' ) ; $ property = new TranslatedProperty ( $ structure -> getProperty ( 'audience_targeting_groups' ) , $ locale , $ this -> languageNamespace , 'excerpt' ) ; return 'page.[' . $ property -> getName ( ) . '] = ' . $ targetGroupId ; } | Returns the where part for the audience targeting . |
11,201 | private function buildTagsWhere ( $ tags , $ operator , $ languageCode ) { $ structure = $ this -> structureManager -> getStructure ( 'excerpt' ) ; $ sql2Where = [ ] ; if ( $ structure -> hasProperty ( 'tags' ) ) { $ property = new TranslatedProperty ( $ structure -> getProperty ( 'tags' ) , $ languageCode , $ this -> languageNamespace , 'excerpt' ) ; foreach ( $ tags as $ tag ) { $ sql2Where [ ] = 'page.[' . $ property -> getName ( ) . '] = ' . $ tag ; } if ( count ( $ sql2Where ) > 0 ) { return '(' . implode ( ' ' . strtoupper ( $ operator ) . ' ' , $ sql2Where ) . ')' ; } } return '' ; } | build tags where clauses . |
11,202 | private function buildCategoriesWhere ( $ categories , $ operator , $ languageCode ) { $ structure = $ this -> structureManager -> getStructure ( 'excerpt' ) ; $ sql2Where = [ ] ; if ( $ structure -> hasProperty ( 'categories' ) ) { $ property = new TranslatedProperty ( $ structure -> getProperty ( 'categories' ) , $ languageCode , $ this -> languageNamespace , 'excerpt' ) ; foreach ( $ categories as $ category ) { $ sql2Where [ ] = 'page.[' . $ property -> getName ( ) . '] = ' . $ category ; } if ( count ( $ sql2Where ) > 0 ) { return '(' . implode ( ' ' . strtoupper ( $ operator ) . ' ' , $ sql2Where ) . ')' ; } } return '' ; } | build categories where clauses . |
11,203 | protected function buildPageSelector ( ) { $ idsWhere = [ ] ; foreach ( $ this -> ids as $ id ) { $ idsWhere [ ] = sprintf ( "page.[jcr:uuid] = '%s'" , $ id ) ; } return '(' . implode ( ' OR ' , $ idsWhere ) . ')' ; } | build select for uuids . |
11,204 | private function buildPageExclude ( ) { $ idsWhere = [ ] ; foreach ( $ this -> excluded as $ id ) { $ idsWhere [ ] = sprintf ( "(NOT page.[jcr:uuid] = '%s')" , $ id ) ; } return $ idsWhere ; } | build sql for exluded Pages . |
11,205 | public function onPostDeserialize ( ObjectEvent $ event ) { $ targetGroup = $ event -> getObject ( ) ; if ( ! $ targetGroup instanceof TargetGroupInterface ) { return ; } if ( $ targetGroup -> getWebspaces ( ) ) { foreach ( $ targetGroup -> getWebspaces ( ) as $ webspace ) { $ webspace -> setTargetGroup ( $ targetGroup ) ; } } if ( $ targetGroup -> getRules ( ) ) { foreach ( $ targetGroup -> getRules ( ) as $ rule ) { $ rule -> setTargetGroup ( $ targetGroup ) ; } } } | Called after a target group was deserialized . |
11,206 | protected function handleCreatedExpressions ( array $ expressions , $ conjunction ) { $ expressionCounter = count ( $ expressions ) ; switch ( $ expressionCounter ) { case 0 : break ; case 1 : $ this -> listBuilder -> addExpression ( $ expressions [ 0 ] ) ; break ; default : $ conjunctionExpression = $ this -> createConjunctionExpression ( $ expressions , $ conjunction ) ; $ this -> listBuilder -> addExpression ( $ conjunctionExpression ) ; break ; } } | Handles the previouse created expressions and passes the over to the listbuilder . |
11,207 | protected function createConjunctionExpression ( array $ expressions , $ conjunction ) { if ( ListBuilderInterface :: CONJUNCTION_AND === strtoupper ( $ conjunction ) ) { return $ this -> listBuilder -> createAndExpression ( $ expressions ) ; } return $ this -> listBuilder -> createOrExpression ( $ expressions ) ; } | Creates a conjunction expression based on the given expressions and conjunction . |
11,208 | protected function createExpression ( Condition $ condition , $ fieldDescriptor ) { $ value = $ this -> getValue ( $ condition ) ; if ( 'between' === $ condition -> getOperator ( ) && DataTypes :: DATETIME_TYPE === $ condition -> getType ( ) ) { $ this -> expressions [ ] = $ this -> listBuilder -> createBetweenExpression ( $ fieldDescriptor , [ $ value , new \ DateTime ( ) ] ) ; } else { $ this -> expressions [ ] = $ this -> listBuilder -> createWhereExpression ( $ fieldDescriptor , $ value , $ condition -> getOperator ( ) ) ; } } | Creates expressions from conditions and add them to the expressions array . |
11,209 | protected function getValue ( Condition $ condition ) { $ value = $ condition -> getValue ( ) ; $ type = $ condition -> getType ( ) ; switch ( $ type ) { case DataTypes :: UNDEFINED_TYPE : case DataTypes :: STRING_TYPE : case DataTypes :: TAGS_TYPE : case DataTypes :: AUTO_COMPLETE_TYPE : return $ value ; case DataTypes :: NUMBER_TYPE : if ( is_numeric ( $ value ) ) { return floatval ( $ value ) ; } throw new ConditionTypeMismatchException ( $ condition -> getId ( ) , $ value , $ type ) ; case DataTypes :: BOOLEAN_TYPE : return $ this -> getBoolean ( $ value ) ; case DataTypes :: DATETIME_TYPE : try { return new \ DateTime ( $ value ) ; } catch ( \ Exception $ ex ) { throw new ConditionTypeMismatchException ( $ condition -> getId ( ) , $ value , $ type ) ; } default : throw new ConditionTypeMismatchException ( $ condition -> getId ( ) , $ value , $ type ) ; } } | Parses and returns the value of a condition . |
11,210 | public function findSettingValue ( $ roleId , $ key ) { $ queryBuilder = $ this -> createQueryBuilder ( 's' ) -> select ( 's.value' ) -> join ( 's.role' , 'r' ) -> where ( 'r.id = :roleId' ) -> andWhere ( 's.key = :key' ) -> setParameters ( [ 'roleId' => $ roleId , 'key' => $ key ] ) ; try { return json_decode ( $ queryBuilder -> getQuery ( ) -> getSingleScalarResult ( ) , true ) ; } catch ( NoResultException $ e ) { return ; } } | Returns value of given role - setting . |
11,211 | public function findSetting ( $ roleId , $ key ) { $ queryBuilder = $ this -> createQueryBuilder ( 's' ) -> join ( 's.role' , 'r' ) -> where ( 'r.id = :roleId' ) -> andWhere ( 's.key = :key' ) -> setParameters ( [ 'roleId' => $ roleId , 'key' => $ key ] ) ; try { return $ queryBuilder -> getQuery ( ) -> getSingleResult ( ) ; } catch ( NoResultException $ e ) { return ; } } | Returns role - setting object . |
11,212 | public function get ( $ name ) { if ( ! isset ( $ this -> geolocators [ $ name ] ) ) { throw new GeolocatorNotFoundException ( sprintf ( 'Attempt to retrieve unknown geolocator "%s"' , $ name ) ) ; } return $ this -> container -> get ( $ this -> geolocators [ $ name ] ) ; } | Retrieve the named name . |
11,213 | public function cgetAction ( Request $ request ) { $ serializationGroups = [ ] ; $ locale = $ this -> getLocale ( $ request ) ; if ( 'true' == $ request -> get ( 'flat' ) ) { $ list = $ this -> getList ( $ request , $ locale ) ; } else { if ( true == $ request -> get ( 'bySystem' ) ) { $ contacts = $ this -> getContactsByUserSystem ( ) ; $ serializationGroups [ ] = 'select' ; } else { $ contacts = $ this -> getDoctrine ( ) -> getRepository ( $ this -> container -> getParameter ( 'sulu.model.contact.class' ) ) -> findAll ( ) ; $ serializationGroups = array_merge ( $ serializationGroups , static :: $ contactSerializationGroups ) ; } $ apiContacts = [ ] ; foreach ( $ contacts as $ contact ) { $ apiContacts [ ] = $ this -> getContactManager ( ) -> getContact ( $ contact , $ locale ) ; } $ exclusion = null ; if ( count ( $ serializationGroups ) > 0 ) { $ exclusion = new Exclusion ( $ serializationGroups ) ; } $ list = new CollectionRepresentation ( $ apiContacts , self :: $ entityKey , null , $ exclusion , $ exclusion ) ; } $ view = $ this -> view ( $ list , 200 ) ; if ( count ( $ serializationGroups ) > 0 ) { $ context = new Context ( ) ; $ context -> setGroups ( $ serializationGroups ) ; $ view -> setContext ( $ context ) ; } return $ this -> handleView ( $ view ) ; } | lists all contacts optional parameter flat calls listAction . |
11,214 | private function getList ( Request $ request , $ locale ) { $ restHelper = $ this -> getRestHelper ( ) ; $ factory = $ this -> get ( 'sulu_core.doctrine_list_builder_factory' ) ; $ listBuilder = $ factory -> create ( $ this -> container -> getParameter ( 'sulu.model.contact.class' ) ) ; $ restHelper -> initializeListBuilder ( $ listBuilder , $ this -> getFieldDescriptors ( ) ) ; $ listResponse = $ this -> prepareListResponse ( $ listBuilder , $ locale ) ; return new ListRepresentation ( $ listResponse , self :: $ entityKey , 'get_contacts' , $ request -> query -> all ( ) , $ listBuilder -> getCurrentPage ( ) , $ listBuilder -> getLimit ( ) , $ listBuilder -> count ( ) ) ; } | Returns list for cget . |
11,215 | private function prepareListResponse ( DoctrineListBuilder $ listBuilder , $ locale ) { $ listResponse = $ listBuilder -> execute ( ) ; $ listResponse = $ this -> addAvatars ( $ listResponse , $ locale ) ; $ ids = $ listBuilder -> getIds ( ) ; if ( null !== $ ids ) { $ comparator = $ this -> getComparator ( ) ; @ usort ( $ listResponse , function ( $ a , $ b ) use ( $ comparator , $ ids ) { return $ comparator -> compare ( $ a [ 'id' ] , $ b [ 'id' ] , $ ids ) ; } ) ; } return $ listResponse ; } | Prepare list response . |
11,216 | public function deleteAction ( $ id ) { try { $ deleteCallback = $ this -> getContactManager ( ) -> delete ( ) ; $ view = $ this -> responseDelete ( $ id , $ deleteCallback ) ; } catch ( EntityNotFoundException $ e ) { $ view = $ this -> view ( $ e -> toArray ( ) , 404 ) ; } return $ this -> handleView ( $ view ) ; } | Deletes a Contact with the given ID from database . |
11,217 | public function getAction ( $ id ) { $ contactManager = $ this -> getContactManager ( ) ; $ locale = $ this -> getUser ( ) -> getLocale ( ) ; try { $ view = $ this -> responseGetById ( $ id , function ( $ id ) use ( $ contactManager , $ locale ) { return $ contactManager -> getById ( $ id , $ locale ) ; } ) ; $ context = new Context ( ) ; $ context -> setGroups ( static :: $ contactSerializationGroups ) ; $ view -> setContext ( $ context ) ; } catch ( EntityNotFoundException $ e ) { $ view = $ this -> view ( $ e -> toArray ( ) , 404 ) ; } return $ this -> handleView ( $ view ) ; } | Shows the contact with the given Id . |
11,218 | public function postAction ( Request $ request ) { try { $ this -> checkArguments ( $ request ) ; $ contact = $ this -> getContactManager ( ) -> save ( $ request -> request -> all ( ) ) ; $ apiContact = $ this -> getContactManager ( ) -> getContact ( $ contact , $ this -> getLocale ( $ request ) ) ; $ view = $ this -> view ( $ apiContact , 200 ) ; $ context = new Context ( ) ; $ context -> setGroups ( static :: $ contactSerializationGroups ) ; $ view -> setContext ( $ context ) ; } catch ( EntityNotFoundException $ enfe ) { $ view = $ this -> view ( $ enfe -> toArray ( ) , 404 ) ; } catch ( MissingArgumentException $ maex ) { $ view = $ this -> view ( $ maex -> toArray ( ) , 400 ) ; } catch ( RestException $ re ) { $ view = $ this -> view ( $ re -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; } | Creates a new contact . |
11,219 | protected function getContactsByUserSystem ( ) { $ repo = $ this -> get ( 'sulu_security.user_repository' ) ; $ users = $ repo -> findUserBySystem ( $ this -> getParameter ( 'sulu_security.system' ) ) ; $ contacts = [ ] ; foreach ( $ users as $ user ) { $ contacts [ ] = $ user -> getContact ( ) ; } return $ contacts ; } | Returns a list of contacts which have a user in the sulu system . |
11,220 | private function addAvatars ( $ contacts , $ locale ) { $ ids = array_filter ( array_column ( $ contacts , 'avatar' ) ) ; $ avatars = $ this -> get ( 'sulu_media.media_manager' ) -> getFormatUrls ( $ ids , $ locale ) ; foreach ( $ contacts as $ key => $ contact ) { if ( array_key_exists ( 'avatar' , $ contact ) && $ contact [ 'avatar' ] && array_key_exists ( $ contact [ 'avatar' ] , $ avatars ) ) { $ contacts [ $ key ] [ 'avatar' ] = $ avatars [ $ contact [ 'avatar' ] ] ; } } return $ contacts ; } | Takes an array of contacts and resets the avatar containing the media id with the actual urls to the avatars thumbnail . |
11,221 | protected function filterNullValues ( array $ values ) { $ result = array_filter ( $ values , function ( $ val ) { return $ val || 0 === $ val || false === $ val ; } ) ; return $ result ; } | Returns a new array without null values . |
11,222 | private function setTargetGroupHeader ( Request $ request , CacheInvalidation $ kernel ) { $ hadValidTargetGroup = true ; $ visitorTargetGroup = $ request -> cookies -> get ( static :: TARGET_GROUP_COOKIE ) ; $ visitorSession = $ request -> cookies -> get ( static :: VISITOR_SESSION_COOKIE ) ; if ( null === $ visitorTargetGroup || null === $ visitorSession ) { $ hadValidTargetGroup = false ; $ visitorTargetGroup = $ this -> requestTargetGroup ( $ request , $ kernel , $ visitorTargetGroup ) ; } if ( $ request -> isMethodCacheable ( ) ) { $ request -> headers -> set ( static :: TARGET_GROUP_HEADER , ( string ) $ visitorTargetGroup ) ; } return $ hadValidTargetGroup ; } | Sets the target group header based on an existing cookie so that the application can adapt the content according to it . If the cookie didn t exist yet another request is fired in order to set the value for the cookie . |
11,223 | private function requestTargetGroup ( Request $ request , CacheInvalidation $ kernel , int $ currentTargetGroup = null ) { $ targetGroupRequest = Request :: create ( static :: TARGET_GROUP_URL , Request :: METHOD_GET , [ ] , [ ] , [ ] , $ request -> server -> all ( ) ) ; if ( $ currentTargetGroup ) { $ targetGroupRequest -> headers -> set ( static :: TARGET_GROUP_HEADER , $ currentTargetGroup ) ; } $ targetGroupRequest -> headers -> set ( static :: USER_CONTEXT_URL_HEADER , $ request -> getUri ( ) ) ; $ targetGroupResponse = $ kernel -> handle ( $ targetGroupRequest ) ; return $ targetGroupResponse -> headers -> get ( static :: TARGET_GROUP_HEADER ) ; } | Sends a request to the application to determine the target group of the current visitor . |
11,224 | private function setTargetGroupCookie ( Response $ response , Request $ request ) { $ response -> headers -> setCookie ( new Cookie ( static :: TARGET_GROUP_COOKIE , $ request -> headers -> get ( static :: TARGET_GROUP_HEADER ) , static :: TARGET_GROUP_COOKIE_LIFETIME ) ) ; $ response -> headers -> setCookie ( new Cookie ( static :: VISITOR_SESSION_COOKIE , time ( ) ) ) ; } | Set the cookie for the target group from the request . Should only be set in case the cookie was not set before . |
11,225 | public function getAvailableLocalization ( StructureBehavior $ document , $ locale ) { $ availableLocales = $ this -> inspector -> getLocales ( $ document ) ; if ( in_array ( $ locale , $ availableLocales ) ) { return $ locale ; } $ fallbackLocale = null ; if ( $ document instanceof WebspaceBehavior ) { $ fallbackLocale = $ this -> localizationFinder -> findAvailableLocale ( $ this -> inspector -> getWebspace ( $ document ) , $ availableLocales , $ locale ) ; } if ( ! $ fallbackLocale ) { $ fallbackLocale = reset ( $ availableLocales ) ; } if ( ! $ fallbackLocale ) { $ fallbackLocale = $ this -> documentRegistry -> getDefaultLocale ( ) ; } return $ fallbackLocale ; } | Return available localizations . |
11,226 | public function loadClassMetadata ( LoadClassMetadataEventArgs $ event ) { $ metadata = $ event -> getClassMetadata ( ) ; $ reflection = $ metadata -> getReflectionClass ( ) ; if ( null !== $ reflection && $ reflection -> implementsInterface ( 'Sulu\Component\Persistence\Model\UserBlameInterface' ) ) { if ( ! $ metadata -> hasAssociation ( self :: CREATOR_FIELD ) ) { $ metadata -> mapManyToOne ( [ 'fieldName' => self :: CREATOR_FIELD , 'targetEntity' => $ this -> userClass , 'joinColumns' => [ [ 'name' => 'idUsersCreator' , 'onDelete' => 'SET NULL' , 'referencedColumnName' => 'id' , 'nullable' => true , ] , ] , ] ) ; } if ( ! $ metadata -> hasAssociation ( self :: CHANGER_FIELD ) ) { $ metadata -> mapManyToOne ( [ 'fieldName' => self :: CHANGER_FIELD , 'targetEntity' => $ this -> userClass , 'joinColumns' => [ [ 'name' => 'idUsersChanger' , 'onDelete' => 'SET NULL' , 'referencedColumnName' => 'id' , 'nullable' => true , ] , ] , ] ) ; } } } | Map creator and changer fields to User objects . |
11,227 | private function sortTeasers ( array $ teasers , array $ result , array $ positions , array $ items ) { foreach ( $ teasers as $ teaser ) { $ index = $ positions [ sprintf ( '%s;%s' , $ teaser -> getType ( ) , $ teaser -> getId ( ) ) ] ; $ result [ $ index ] = $ teaser ; $ item = $ items [ $ index ] ; if ( [ 'type' , 'id' ] !== array_keys ( $ item ) ) { $ result [ $ index ] = $ result [ $ index ] -> merge ( $ item ) ; } } return $ result ; } | Returns sorted teaser by given position array . |
11,228 | private function sortItems ( $ items ) { $ ids = [ ] ; $ positions = [ ] ; $ index = 0 ; foreach ( $ items as $ item ) { if ( ! array_key_exists ( $ item [ 'type' ] , $ ids ) ) { $ ids [ $ item [ 'type' ] ] = [ ] ; } $ ids [ $ item [ 'type' ] ] [ ] = $ item [ 'id' ] ; $ positions [ sprintf ( '%s;%s' , $ item [ 'type' ] , $ item [ 'id' ] ) ] = $ index ++ ; } return [ $ ids , $ positions ] ; } | Returns items sorted by type . |
11,229 | public function getChild ( $ name ) { if ( ! isset ( $ this -> children [ $ name ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Unknown child "%s" in structure "%s" loaded from: "%s". Children: "%s"' , $ name , $ this -> name , $ this -> resource , implode ( '", "' , array_keys ( $ this -> children ) ) ) ) ; } return $ this -> children [ $ name ] ; } | Return the named property . |
11,230 | public function addChild ( self $ child ) { if ( isset ( $ this -> children [ $ child -> name ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Child with key "%s" already exists' , $ child -> name ) ) ; } $ this -> children [ $ child -> name ] = $ child ; } | Adds a child item . |
11,231 | public function getParameter ( $ name ) { if ( ! isset ( $ this -> parameters [ $ name ] ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Unknown parameter "%s", known parameters: "%s"' , $ name , implode ( '", "' , array_keys ( $ this -> parameters ) ) ) ) ; } return $ this -> parameters [ $ name ] ; } | Return the paramter with the given name . |
11,232 | public function getTag ( $ tagName ) { foreach ( $ this -> tags as $ tag ) { if ( $ tag [ 'name' ] === $ tagName ) { return $ tag ; } } throw new \ InvalidArgumentException ( sprintf ( 'Unknown tag "%s"' , $ tagName ) ) ; } | Return the named tag . |
11,233 | public function handlePersist ( PersistEvent $ event ) { $ document = $ event -> getDocument ( ) ; if ( ! $ this -> supports ( $ document ) || ! $ document -> getPermissions ( ) ) { return ; } $ node = $ event -> getNode ( ) ; foreach ( $ document -> getPermissions ( ) as $ roleId => $ permission ) { $ node -> setProperty ( 'sec:role-' . $ roleId , $ this -> getAllowedPermissions ( $ permission ) ) ; } } | Adds the security information to the node . |
11,234 | public function handleHydrate ( HydrateEvent $ event ) { $ document = $ event -> getDocument ( ) ; $ node = $ event -> getNode ( ) ; if ( ! $ this -> supports ( $ document ) ) { return ; } $ permissions = [ ] ; foreach ( $ node -> getProperties ( 'sec:*' ) as $ property ) { $ roleId = substr ( $ property -> getName ( ) , 9 ) ; $ allowedPermissions = $ property -> getValue ( ) ; foreach ( $ this -> permissions as $ permission => $ value ) { $ permissions [ $ roleId ] [ $ permission ] = in_array ( $ permission , $ allowedPermissions ) ; } } $ document -> setPermissions ( $ permissions ) ; } | Adds the security information to the hydrated object . |
11,235 | private function getAllowedPermissions ( $ permissions ) { $ allowedPermissions = [ ] ; foreach ( $ permissions as $ permission => $ allowed ) { if ( $ allowed ) { $ allowedPermissions [ ] = $ permission ; } } return $ allowedPermissions ; } | Extracts the keys of the allowed permissions into an own array . |
11,236 | private function createNode ( NodeInterface $ node , $ pathSegment , $ uuid ) { if ( $ node -> hasNode ( $ pathSegment ) ) { return $ node -> getNode ( $ pathSegment ) ; } $ node = $ node -> addNode ( $ pathSegment ) ; $ node -> addMixin ( 'mix:referenceable' ) ; $ node -> setProperty ( 'jcr:uuid' , $ uuid ) ; return $ node ; } | Adds a node with the given path segment as a node name to the given node . |
11,237 | public function cgetAction ( Request $ request , $ webspace ) { $ entities = $ this -> get ( 'sulu_website.analytics.manager' ) -> findAll ( $ webspace ) ; $ list = new RouteAwareRepresentation ( new CollectionRepresentation ( $ entities , self :: RESULT_KEY ) , 'cget_webspace_analytics' , array_merge ( $ request -> request -> all ( ) , [ 'webspace' => $ webspace ] ) ) ; return $ this -> handleView ( $ this -> view ( $ list , 200 ) ) ; } | Returns webspace analytics by webspace key . |
11,238 | public function getAction ( $ webspace , $ id ) { $ entity = $ this -> get ( 'sulu_website.analytics.manager' ) -> find ( $ id ) ; return $ this -> handleView ( $ this -> view ( $ entity , 200 ) ) ; } | Returns a single analytics by id . |
11,239 | public function postAction ( Request $ request , $ webspace ) { $ data = $ request -> request -> all ( ) ; $ data [ 'content' ] = $ this -> buildContent ( $ data ) ; $ entity = $ this -> get ( 'sulu_website.analytics.manager' ) -> create ( $ webspace , $ data ) ; $ this -> get ( 'doctrine.orm.entity_manager' ) -> flush ( ) ; $ this -> get ( 'sulu_website.http_cache.clearer' ) -> clear ( ) ; return $ this -> handleView ( $ this -> view ( $ entity , 200 ) ) ; } | Creates a analytics for given webspace . |
11,240 | public function putAction ( Request $ request , $ webspace , $ id ) { $ data = $ request -> request -> all ( ) ; $ data [ 'content' ] = $ this -> buildContent ( $ data ) ; $ entity = $ this -> get ( 'sulu_website.analytics.manager' ) -> update ( $ id , $ data ) ; $ this -> get ( 'doctrine.orm.entity_manager' ) -> flush ( ) ; $ this -> get ( 'sulu_website.http_cache.clearer' ) -> clear ( ) ; return $ this -> handleView ( $ this -> view ( $ entity , 200 ) ) ; } | Updates analytics with given id . |
11,241 | public function deleteAction ( $ webspace , $ id ) { $ this -> get ( 'sulu_website.analytics.manager' ) -> remove ( $ id ) ; $ this -> get ( 'doctrine.orm.entity_manager' ) -> flush ( ) ; $ this -> get ( 'sulu_website.http_cache.clearer' ) -> clear ( ) ; return $ this -> handleView ( $ this -> view ( null , 204 ) ) ; } | Removes given analytics . |
11,242 | public function cdeleteAction ( Request $ request , $ webspace ) { $ ids = array_filter ( explode ( ',' , $ request -> get ( 'ids' , '' ) ) ) ; $ this -> get ( 'sulu_website.analytics.manager' ) -> removeMultiple ( $ ids ) ; $ this -> get ( 'doctrine.orm.entity_manager' ) -> flush ( ) ; $ this -> get ( 'sulu_website.http_cache.clearer' ) -> clear ( ) ; return $ this -> handleView ( $ this -> view ( null , 204 ) ) ; } | Removes a list of analytics . |
11,243 | protected function getTypeForString ( $ type ) { switch ( $ type ) { case 'string' : return DataTypes :: STRING_TYPE ; case 'number' : return DataTypes :: NUMBER_TYPE ; case 'date' : case 'datetime' : return DataTypes :: DATETIME_TYPE ; case 'boolean' : return DataTypes :: BOOLEAN_TYPE ; case 'tags' : return DataTypes :: TAGS_TYPE ; case 'auto-complete' : return DataTypes :: AUTO_COMPLETE_TYPE ; default : return DataTypes :: UNDEFINED_TYPE ; } } | Returns integer for string type . |
11,244 | public function slugify ( $ text ) { $ text = $ this -> slugifier -> slugify ( $ text ) ; $ text = preg_replace ( '((\d+)([eE]))' , '$1-$2' , $ text ) ; return $ text ; } | Slugifies given string to a valid node - name . |
11,245 | public function getAction ( $ id ) { $ view = $ this -> responseGetById ( $ id , function ( $ id ) { return $ this -> getManager ( ) -> findById ( $ id ) ; } ) ; $ context = new Context ( ) ; $ context -> setGroups ( [ 'partialTag' ] ) ; $ view -> setContext ( $ context ) ; return $ this -> handleView ( $ view ) ; } | Returns a single tag with the given id . |
11,246 | public function cgetAction ( Request $ request ) { if ( 'true' == $ request -> get ( 'flat' ) ) { $ restHelper = $ this -> get ( 'sulu_core.doctrine_rest_helper' ) ; $ factory = $ this -> get ( 'sulu_core.doctrine_list_builder_factory' ) ; $ tagEntityName = $ this -> getParameter ( 'sulu.model.tag.class' ) ; $ fieldDescriptors = $ this -> get ( 'sulu_core.list_builder.field_descriptor_factory' ) -> getFieldDescriptors ( 'tags' ) ; $ listBuilder = $ factory -> create ( $ tagEntityName ) ; $ names = array_filter ( explode ( ',' , $ request -> get ( 'names' , '' ) ) ) ; if ( count ( $ names ) > 0 ) { $ listBuilder -> in ( $ fieldDescriptors [ 'name' ] , $ names ) ; } $ restHelper -> initializeListBuilder ( $ listBuilder , $ fieldDescriptors ) ; $ list = new ListRepresentation ( $ listBuilder -> execute ( ) , self :: $ entityKey , 'get_tags' , $ request -> query -> all ( ) , $ listBuilder -> getCurrentPage ( ) , $ listBuilder -> getLimit ( ) , $ listBuilder -> count ( ) ) ; $ view = $ this -> view ( $ list , 200 ) ; } else { $ list = new CollectionRepresentation ( $ this -> getManager ( ) -> findAll ( ) , self :: $ entityKey ) ; $ context = new Context ( ) ; $ context -> setGroups ( [ 'partialTag' ] ) ; $ view = $ this -> view ( $ list , 200 ) -> setContext ( $ context ) ; } return $ this -> handleView ( $ view ) ; } | returns all tags . |
11,247 | public function postAction ( Request $ request ) { $ name = $ request -> get ( 'name' ) ; try { if ( null == $ name ) { throw new MissingArgumentException ( self :: $ entityName , 'name' ) ; } $ tag = $ this -> getManager ( ) -> save ( $ this -> getData ( $ request ) ) ; $ context = new Context ( ) ; $ context -> setGroups ( [ 'partialTag' ] ) ; $ view = $ this -> view ( $ tag ) -> setContext ( $ context ) ; } catch ( TagAlreadyExistsException $ exc ) { $ cvExistsException = new ConstraintViolationException ( 'A tag with the name "' . $ exc -> getName ( ) . '"already exists!' , 'name' , ConstraintViolationException :: EXCEPTION_CODE_NON_UNIQUE_NAME ) ; $ view = $ this -> view ( $ cvExistsException -> toArray ( ) , 400 ) ; } catch ( RestException $ exc ) { $ view = $ this -> view ( $ exc -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; } | Inserts a new tag . |
11,248 | public function deleteAction ( $ id ) { $ delete = function ( $ id ) { try { $ this -> getManager ( ) -> delete ( $ id ) ; } catch ( TagNotFoundException $ tnfe ) { throw new EntityNotFoundException ( self :: $ entityName , $ id ) ; } } ; $ view = $ this -> responseDelete ( $ id , $ delete ) ; return $ this -> handleView ( $ view ) ; } | Deletes the tag with the given ID . |
11,249 | public function postMergeAction ( Request $ request ) { try { $ srcTagIds = explode ( ',' , $ request -> get ( 'src' ) ) ; $ destTagId = $ request -> get ( 'dest' ) ; $ destTag = $ this -> getManager ( ) -> merge ( $ srcTagIds , $ destTagId ) ; $ view = $ this -> view ( null , 303 , [ 'location' => $ this -> get ( 'router' ) -> generate ( 'get_tag' , [ 'id' => $ destTag -> getId ( ) ] ) , ] ) ; } catch ( TagNotFoundException $ exc ) { $ entityNotFoundException = new EntityNotFoundException ( self :: $ entityName , $ exc -> getId ( ) ) ; $ view = $ this -> view ( $ entityNotFoundException -> toArray ( ) , 404 ) ; } return $ this -> handleView ( $ view ) ; } | POST Route annotation . |
11,250 | private function addStructureProperties ( StructureMetadata $ structureMetadata , StructureBehavior $ document , VisitorInterface $ visitor ) { $ structure = $ document -> getStructure ( ) ; $ data = $ structure -> toArray ( ) ; foreach ( $ structureMetadata -> getProperties ( ) as $ name => $ property ) { if ( 'title' === $ name || ! array_key_exists ( $ name , $ data ) || $ property -> hasTag ( 'sulu.rlp' ) ) { continue ; } $ visitor -> addData ( $ name , $ data [ $ name ] ) ; } } | Adds the properties of the structure to the serialization . |
11,251 | private function addBreadcrumb ( StructureBehavior $ document , VisitorInterface $ visitor ) { $ items = [ ] ; $ parentDocument = $ this -> inspector -> getParent ( $ document ) ; while ( $ parentDocument instanceof StructureBehavior ) { $ item = [ ] ; if ( $ parentDocument instanceof UuidBehavior ) { $ item [ 'uuid' ] = $ parentDocument -> getUuid ( ) ; } $ item [ 'title' ] = $ parentDocument -> getStructure ( ) -> getProperty ( 'title' ) -> getValue ( ) ; $ items [ ] = $ item ; $ parentDocument = $ this -> inspector -> getParent ( $ parentDocument ) ; } $ items = array_reverse ( $ items ) ; array_walk ( $ items , function ( & $ item , $ index ) { $ item [ 'depth' ] = $ index ; } ) ; $ visitor -> addData ( 'breadcrumb' , $ items ) ; } | Adds the breadcrumb to the serialization . |
11,252 | private function upgradeNode ( NodeInterface $ node ) { foreach ( $ node -> getProperties ( 'i18n:-*' ) as $ property ) { $ property -> remove ( ) ; } foreach ( $ node -> getNodes ( ) as $ childNode ) { $ this -> upgradeNode ( $ childNode ) ; } } | Removes non translated properties . |
11,253 | public function getMetadataForObject ( $ object ) { if ( ! $ object instanceof StructureBehavior ) { return ; } $ documentMetadata = $ this -> metadataFactory -> getMetadataForClass ( get_class ( $ object ) ) ; $ structure = $ this -> structureFactory -> getStructureMetadata ( $ documentMetadata -> getAlias ( ) , $ object -> getStructureType ( ) ) ; return $ this -> getMetadata ( $ documentMetadata , $ structure ) ; } | loads metadata for a given class if its derived from StructureInterface . |
11,254 | private function findRouteByPath ( $ path , $ locale ) { $ path = '/' . ltrim ( $ path , '/' ) ; if ( ! array_key_exists ( $ path , $ this -> routeCache ) ) { $ this -> routeCache [ $ path ] = $ this -> routeRepository -> findByPath ( $ path , $ locale ) ; } return $ this -> routeCache [ $ path ] ; } | Find route and cache it . |
11,255 | protected function createRoute ( RouteInterface $ route , Request $ request ) { $ routePath = $ this -> decodePathInfo ( $ request -> getPathInfo ( ) ) ; if ( $ route -> isHistory ( ) ) { return new Route ( $ routePath , [ '_controller' => 'SuluWebsiteBundle:Redirect:redirect' , 'url' => $ request -> getSchemeAndHttpHost ( ) . $ this -> requestAnalyzer -> getResourceLocatorPrefix ( ) . $ route -> getTarget ( ) -> getPath ( ) . ( $ request -> getQueryString ( ) ? ( '?' . $ request -> getQueryString ( ) ) : '' ) , ] ) ; } $ symfonyRoute = $ this -> proxyFactory -> createProxy ( Route :: class , function ( & $ wrappedObject , LazyLoadingInterface $ proxy , $ method , array $ parameters , & $ initializer ) use ( $ routePath , $ route , $ request ) { $ initializer = null ; $ wrappedObject = new Route ( $ routePath , $ this -> routeDefaultsProvider -> getByEntity ( $ route -> getEntityClass ( ) , $ route -> getEntityId ( ) , $ request -> getLocale ( ) ) ) ; return true ; } ) ; return $ this -> symfonyRouteCache [ $ route -> getId ( ) ] = $ symfonyRoute ; } | Will create a symfony route . |
11,256 | private function stripFormatExtension ( $ path , $ format ) { $ extension = '.' . $ format ; if ( substr ( $ path , - strlen ( $ extension ) ) === $ extension ) { $ path = substr ( $ path , 0 , strlen ( $ path ) - strlen ( $ extension ) ) ; } return $ path ; } | Return the given path without the format extension . |
11,257 | public function getCategoriesFunction ( $ locale , $ parentKey = null ) { return $ this -> memoizeCache -> memoizeById ( 'sulu_categories' , func_get_args ( ) , function ( $ locale , $ parentKey = null ) { $ entities = $ this -> categoryManager -> findChildrenByParentKey ( $ parentKey ) ; $ categories = $ this -> categoryManager -> getApiObjects ( $ entities , $ locale ) ; $ context = SerializationContext :: create ( ) ; $ context -> setSerializeNull ( true ) ; return $ this -> serializer -> serialize ( $ categories , 'array' , $ context ) ; } ) ; } | Returns an array of serialized categories . If parentKey is set only the children of the category which is assigned to the given key are returned . |
11,258 | private function findDateProperties ( StructureMetadata $ structureMetadata , array & $ properties ) { $ structureName = $ structureMetadata -> getName ( ) ; foreach ( $ structureMetadata -> getProperties ( ) as $ property ) { if ( 'date' === $ property -> getType ( ) ) { $ properties [ $ structureName ] [ ] = [ 'property' => $ property ] ; } elseif ( $ property instanceof BlockMetadata ) { $ this -> findDateBlockProperties ( $ property , $ structureName , $ properties ) ; } } } | Returns all properties which are a date field . |
11,259 | private function findDateBlockProperties ( BlockMetadata $ property , $ structureName , array & $ properties ) { $ result = [ 'property' => $ property , 'components' => [ ] ] ; foreach ( $ property -> getComponents ( ) as $ component ) { $ componentResult = [ 'component' => $ component , 'children' => [ ] ] ; foreach ( $ component -> getChildren ( ) as $ childProperty ) { if ( 'date' === $ childProperty -> getType ( ) ) { $ componentResult [ 'children' ] [ $ childProperty -> getName ( ) ] = $ childProperty ; } } if ( count ( $ componentResult [ 'children' ] ) > 0 ) { $ result [ 'components' ] [ $ component -> getName ( ) ] = $ componentResult ; } } if ( count ( $ result [ 'components' ] ) > 0 ) { $ properties [ $ structureName ] [ ] = $ result ; } } | Adds the block property to the list if it contains a date field . |
11,260 | private function iterateStructureNodes ( StructureMetadata $ structureMetadata , array $ properties , $ up ) { foreach ( $ this -> localizationManager -> getLocalizations ( ) as $ localization ) { $ rows = $ this -> session -> getWorkspace ( ) -> getQueryManager ( ) -> createQuery ( sprintf ( 'SELECT * FROM [nt:unstructured] WHERE [%s] = "%s" OR [%s] = "%s"' , $ this -> propertyEncoder -> localizedSystemName ( 'template' , $ localization -> getLocale ( ) ) , $ structureMetadata -> getName ( ) , 'template' , $ structureMetadata -> getName ( ) ) , 'JCR-SQL2' ) -> execute ( ) ; foreach ( $ rows -> getNodes ( ) as $ node ) { $ this -> upgradeNode ( $ node , $ localization -> getLocale ( ) , $ properties , $ up ) ; } } } | Iterates over all nodes of the given type and upgrades them . |
11,261 | private function upgradeBlockProperty ( BlockMetadata $ blockProperty , array $ components , NodeInterface $ node , $ locale , $ up ) { $ componentNames = array_map ( function ( $ item ) { return $ item [ 'component' ] -> getName ( ) ; } , $ components ) ; $ lengthName = sprintf ( 'i18n:%s-%s-length' , $ locale , $ blockProperty -> getName ( ) ) ; $ length = $ node -> getPropertyValue ( $ lengthName ) ; for ( $ i = 0 ; $ i < $ length ; ++ $ i ) { $ type = $ node -> getPropertyValue ( sprintf ( 'i18n:%s-%s-type#%s' , $ locale , $ blockProperty -> getName ( ) , $ i ) ) ; if ( ! in_array ( $ type , $ componentNames ) ) { continue ; } foreach ( $ components [ $ type ] [ 'children' ] as $ child ) { $ name = sprintf ( 'i18n:%s-%s-%s#%s' , $ locale , $ blockProperty -> getName ( ) , $ child -> getName ( ) , $ i ) ; if ( ! $ node -> hasProperty ( $ name ) ) { continue ; } $ value = $ node -> getPropertyValue ( $ name ) ; if ( $ up ) { $ value = $ this -> upgradeDate ( $ value ) ; } else { $ value = $ this -> downgradeDate ( $ value ) ; } $ node -> setProperty ( $ name , $ value ) ; } } } | Upgrades the given block property to the new date representation . |
11,262 | private function upgradeProperty ( PropertyMetadata $ property , NodeInterface $ node , $ locale , $ up ) { $ name = sprintf ( 'i18n:%s-%s' , $ locale , $ property -> getName ( ) ) ; if ( ! $ node -> hasProperty ( $ name ) ) { return ; } $ value = $ node -> getPropertyValue ( $ name ) ; if ( $ up ) { $ value = $ this -> upgradeDate ( $ value ) ; } else { $ value = $ this -> downgradeDate ( $ value ) ; } $ node -> setProperty ( $ name , $ value ) ; } | Upgrades the given property to the new date representation . |
11,263 | private function upgradeDate ( & $ value ) { if ( $ value instanceof \ DateTime ) { return $ value ; } $ value = \ DateTime :: createFromFormat ( 'Y-m-d' , $ value ) ; return $ value ; } | Upgrades the given date to the new representation . |
11,264 | public function setOperatorValue ( \ Sulu \ Bundle \ ResourceBundle \ Entity \ OperatorValue $ operatorValue ) { $ this -> operatorValue = $ operatorValue ; return $ this ; } | Set operatorValue . |
11,265 | private function applyTransformations ( ImageInterface $ image , $ tansformations ) { foreach ( $ tansformations as $ transformation ) { if ( ! isset ( $ transformation [ 'effect' ] ) ) { throw new ImageProxyInvalidFormatOptionsException ( 'Effect not found' ) ; } $ image = $ this -> modifyAllLayers ( $ image , function ( ImageInterface $ layer ) use ( $ transformation ) { return $ this -> transformationPool -> get ( $ transformation [ 'effect' ] ) -> execute ( $ layer , $ transformation [ 'parameters' ] ) ; } ) ; } return $ image ; } | Applies an array of transformations on a passed image . |
11,266 | private function applyFormatCrop ( ImageInterface $ image , array $ cropParameters ) { return $ this -> modifyAllLayers ( $ image , function ( ImageInterface $ layer ) use ( $ cropParameters ) { return $ this -> cropper -> crop ( $ layer , $ cropParameters [ 'x' ] , $ cropParameters [ 'y' ] , $ cropParameters [ 'width' ] , $ cropParameters [ 'height' ] ) ; } ) ; } | Crops a given image according to given parameters . |
11,267 | private function applyFocus ( ImageInterface $ image , FileVersion $ fileVersion , array $ scale ) { return $ this -> modifyAllLayers ( $ image , function ( ImageInterface $ layer ) use ( $ fileVersion , $ scale ) { return $ this -> focus -> focus ( $ layer , $ fileVersion -> getFocusPointX ( ) , $ fileVersion -> getFocusPointY ( ) , $ scale [ 'x' ] , $ scale [ 'y' ] ) ; } ) ; } | Crops the given image according to the focus point defined in the file version . |
11,268 | private function applyScale ( ImageInterface $ image , $ scale ) { return $ this -> modifyAllLayers ( $ image , function ( ImageInterface $ layer ) use ( $ scale ) { return $ this -> scaler -> scale ( $ layer , $ scale [ 'x' ] , $ scale [ 'y' ] , $ scale [ 'mode' ] , $ scale [ 'forceRatio' ] , $ scale [ 'retina' ] ) ; } ) ; } | Scales a given image according to the information passed as the second argument . |
11,269 | private function toRGB ( ImageInterface $ image ) { if ( 'cmyk' == $ image -> palette ( ) -> name ( ) ) { $ image -> usePalette ( new RGB ( ) ) ; } return $ image ; } | Ensures that the color mode of the passed image is RGB . |
11,270 | private function getCropParameters ( ImageInterface $ image , $ formatOptions , array $ format ) { if ( isset ( $ formatOptions ) ) { $ parameters = [ 'x' => $ formatOptions -> getCropX ( ) , 'y' => $ formatOptions -> getCropY ( ) , 'width' => $ formatOptions -> getCropWidth ( ) , 'height' => $ formatOptions -> getCropHeight ( ) , ] ; if ( $ this -> cropper -> isValid ( $ image , $ parameters [ 'x' ] , $ parameters [ 'y' ] , $ parameters [ 'width' ] , $ parameters [ 'height' ] , $ format ) ) { return $ parameters ; } } return ; } | Constructs the parameters for the cropper . Returns null when the image should not be cropped . |
11,271 | private function modifyAllLayers ( ImageInterface $ image , callable $ modifier ) { if ( count ( $ image -> layers ( ) ) ) { $ countLayer = 0 ; $ image -> layers ( ) -> coalesce ( ) ; $ temporaryImage = null ; foreach ( $ image -> layers ( ) as $ layer ) { ++ $ countLayer ; $ layer = call_user_func ( $ modifier , $ layer ) ; if ( 1 === $ countLayer ) { $ temporaryImage = $ layer ; } else { $ temporaryImage -> layers ( ) -> add ( $ layer ) ; } } $ image = $ temporaryImage ; } else { $ image = call_user_func ( $ modifier , $ image ) ; } return $ image ; } | Applies a callback to every layer of an image and returns the resulting image . |
11,272 | private function getFormat ( $ formatKey ) { if ( ! isset ( $ this -> formats [ $ formatKey ] ) ) { throw new ImageProxyInvalidImageFormat ( 'Format was not found' ) ; } return $ this -> formats [ $ formatKey ] ; } | Return the options for the given format . |
11,273 | public function findByWebspaceKey ( $ webspaceKey ) { $ queryBuilder = $ this -> createQueryBuilder ( 'a' ) -> addSelect ( 'domains' ) -> leftJoin ( 'a.domains' , 'domains' ) -> where ( 'a.webspaceKey = :webspaceKey' ) -> andWhere ( 'a.allDomains = TRUE OR domains.environment = :environment' ) -> orderBy ( 'a.id' , 'ASC' ) ; $ query = $ queryBuilder -> getQuery ( ) ; $ query -> setParameter ( 'webspaceKey' , $ webspaceKey ) ; $ query -> setParameter ( 'environment' , $ this -> environment ) ; return $ query -> getResult ( ) ; } | Returns list of analytics filterd by webspace key and environment . |
11,274 | public function findById ( $ id ) { $ queryBuilder = $ this -> createQueryBuilder ( 'a' ) -> addSelect ( 'domains' ) -> leftJoin ( 'a.domains' , 'domains' ) -> where ( 'a.id = :id' ) ; $ query = $ queryBuilder -> getQuery ( ) ; $ query -> setParameter ( 'id' , $ id ) ; return $ query -> getSingleResult ( ) ; } | Returns analytics by id . |
11,275 | public function onPostSerialize ( ObjectEvent $ event ) { $ document = $ event -> getObject ( ) ; if ( ! $ document instanceof WorkflowStageBehavior ) { return ; } $ visitor = $ event -> getVisitor ( ) ; $ visitor -> addData ( 'publishedState' , WorkflowStage :: PUBLISHED === $ document -> getWorkflowStage ( ) ) ; } | Adds the published state to the serialization . |
11,276 | public function merge ( array $ item ) { $ this -> title = $ this -> getValue ( 'title' , $ item , $ this -> getTitle ( ) ) ; $ this -> description = $ this -> getValue ( 'description' , $ item , $ this -> getDescription ( ) ) ; $ this -> moreText = $ this -> getValue ( 'moreText' , $ item , $ this -> getMoreText ( ) ) ; $ this -> url = $ this -> getValue ( 'url' , $ item , $ this -> getUrl ( ) ) ; $ this -> mediaId = $ this -> getValue ( 'mediaId' , $ item , $ this -> getMediaId ( ) ) ; return $ this ; } | Merges given data with this teaser . |
11,277 | public function onPostSerialize ( ObjectEvent $ event ) { $ content = $ event -> getObject ( ) ; $ visitor = $ event -> getVisitor ( ) ; if ( ! ( $ content instanceof Content ) ) { return ; } foreach ( $ content -> getData ( ) as $ key => $ value ) { $ visitor -> setData ( $ key , $ value ) ; } $ visitor -> setData ( 'publishedState' , ( WorkflowStage :: PUBLISHED === $ content -> getWorkflowStage ( ) ) ) ; if ( RedirectType :: EXTERNAL === $ content -> getNodeType ( ) ) { $ visitor -> setData ( 'linked' , 'external' ) ; } elseif ( RedirectType :: INTERNAL === $ content -> getNodeType ( ) ) { $ visitor -> setData ( 'linked' , 'internal' ) ; } if ( null !== $ content -> getLocalizationType ( ) ) { $ visitor -> setData ( 'type' , $ content -> getLocalizationType ( ) -> toArray ( ) ) ; } $ visitor -> setData ( '_permissions' , $ this -> accessControlManager -> getUserPermissionByArray ( $ content -> getLocale ( ) , PageAdmin :: SECURITY_CONTEXT_PREFIX . $ content -> getWebspaceKey ( ) , $ content -> getPermissions ( ) , $ this -> tokenStorage -> getToken ( ) -> getUser ( ) ) ) ; } | Add data for serialization of content objects . |
11,278 | private function parse ( $ locale ) { $ parts = explode ( '_' , $ locale ) ; $ localization = new Localization ( ) ; $ localization -> setLanguage ( $ parts [ 0 ] ) ; if ( count ( $ parts ) > 1 ) { $ localization -> setCountry ( $ parts [ 1 ] ) ; } return $ localization ; } | Converts locale string to localization object . |
11,279 | private function generateTreeByPath ( array $ contents , $ uuid ) { $ childrenByPath = [ ] ; foreach ( $ contents as $ content ) { $ path = PathHelper :: getParentPath ( $ content -> getPath ( ) ) ; if ( ! isset ( $ childrenByPath [ $ path ] ) ) { $ childrenByPath [ $ path ] = [ ] ; } $ order = $ content [ 'order' ] ; while ( isset ( $ childrenByPath [ $ path ] [ $ order ] ) ) { ++ $ order ; } $ childrenByPath [ $ path ] [ $ order ] = $ content ; } foreach ( $ contents as $ content ) { if ( ! isset ( $ childrenByPath [ $ content -> getPath ( ) ] ) ) { if ( $ content -> getId ( ) === $ uuid ) { $ content -> setChildren ( [ ] ) ; } continue ; } ksort ( $ childrenByPath [ $ content -> getPath ( ) ] ) ; $ content -> setChildren ( array_values ( $ childrenByPath [ $ content -> getPath ( ) ] ) ) ; } if ( ! array_key_exists ( '/' , $ childrenByPath ) || ! is_array ( $ childrenByPath [ '/' ] ) ) { return [ ] ; } ksort ( $ childrenByPath [ '/' ] ) ; return array_values ( $ childrenByPath [ '/' ] ) ; } | Generates a content - tree with paths of given content array . |
11,280 | private function resolvePathByUuid ( $ uuid ) { $ queryBuilder = new QueryBuilder ( $ this -> qomFactory ) ; $ queryBuilder -> select ( 'node' , 'jcr:uuid' , 'uuid' ) -> from ( $ this -> qomFactory -> selector ( 'node' , 'nt:unstructured' ) ) -> where ( $ this -> qomFactory -> comparison ( $ this -> qomFactory -> propertyValue ( 'node' , 'jcr:uuid' ) , '=' , $ this -> qomFactory -> literal ( $ uuid ) ) ) ; $ rows = $ queryBuilder -> execute ( ) ; if ( 1 !== count ( iterator_to_array ( $ rows -> getRows ( ) ) ) ) { throw new ItemNotFoundException ( ) ; } return $ rows -> getRows ( ) -> current ( ) -> getPath ( ) ; } | Resolve path for node with given uuid . |
11,281 | private function resolveQueryBuilder ( QueryBuilder $ queryBuilder , $ locale , $ locales , MappingInterface $ mapping , UserInterface $ user = null ) { return array_values ( array_filter ( array_map ( function ( Row $ row ) use ( $ mapping , $ locale , $ locales , $ user ) { return $ this -> resolveContent ( $ row , $ locale , $ locales , $ mapping , $ user ) ; } , iterator_to_array ( $ queryBuilder -> execute ( ) ) ) ) ) ; } | Resolves query results to content . |
11,282 | private function getQueryBuilder ( $ locale , $ locales , UserInterface $ user = null ) { $ queryBuilder = new QueryBuilder ( $ this -> qomFactory ) ; $ queryBuilder -> select ( 'node' , 'jcr:uuid' , 'uuid' ) -> addSelect ( 'node' , $ this -> getPropertyName ( 'nodeType' , $ locale ) , 'nodeType' ) -> addSelect ( 'node' , $ this -> getPropertyName ( 'internal_link' , $ locale ) , 'internalLink' ) -> addSelect ( 'node' , $ this -> getPropertyName ( 'state' , $ locale ) , 'state' ) -> addSelect ( 'node' , $ this -> getPropertyName ( 'shadow-on' , $ locale ) , 'shadowOn' ) -> addSelect ( 'node' , $ this -> getPropertyName ( 'shadow-base' , $ locale ) , 'shadowBase' ) -> addSelect ( 'node' , $ this -> propertyEncoder -> systemName ( 'order' ) , 'order' ) -> from ( $ this -> qomFactory -> selector ( 'node' , 'nt:unstructured' ) ) -> orderBy ( $ this -> qomFactory -> propertyValue ( 'node' , 'sulu:order' ) ) ; $ this -> appendSingleMapping ( $ queryBuilder , 'template' , $ locales ) ; $ this -> appendSingleMapping ( $ queryBuilder , 'shadow-on' , $ locales ) ; $ this -> appendSingleMapping ( $ queryBuilder , 'state' , $ locales ) ; if ( null !== $ user ) { foreach ( $ user -> getRoleObjects ( ) as $ role ) { $ queryBuilder -> addSelect ( 'node' , sprintf ( 'sec:%s' , 'role-' . $ role -> getId ( ) ) , sprintf ( 'role%s' , $ role -> getId ( ) ) ) ; } } return $ queryBuilder ; } | Returns QueryBuilder with basic select and where statements . |
11,283 | private function getLocalesByWebspaceKey ( $ webspaceKey ) { $ webspace = $ this -> webspaceManager -> findWebspaceByKey ( $ webspaceKey ) ; return array_map ( function ( Localization $ localization ) { return $ localization -> getLocale ( ) ; } , $ webspace -> getAllLocalizations ( ) ) ; } | Returns array of locales for given webspace key . |
11,284 | private function getLocalesByPortalKey ( $ portalKey ) { $ portal = $ this -> webspaceManager -> findPortalByKey ( $ portalKey ) ; return array_map ( function ( Localization $ localization ) { return $ localization -> getLocale ( ) ; } , $ portal -> getLocalizations ( ) ) ; } | Returns array of locales for given portal key . |
11,285 | private function appendMapping ( QueryBuilder $ queryBuilder , MappingInterface $ mapping , $ locale , $ locales ) { if ( $ mapping -> onlyPublished ( ) ) { $ queryBuilder -> andWhere ( $ this -> qomFactory -> comparison ( $ this -> qomFactory -> propertyValue ( 'node' , $ this -> propertyEncoder -> localizedSystemName ( 'state' , $ locale ) ) , '=' , $ this -> qomFactory -> literal ( WorkflowStage :: PUBLISHED ) ) ) ; } $ properties = $ mapping -> getProperties ( ) ; foreach ( $ properties as $ propertyName ) { $ this -> appendSingleMapping ( $ queryBuilder , $ propertyName , $ locales ) ; } if ( $ mapping -> resolveUrl ( ) ) { $ this -> appendUrlMapping ( $ queryBuilder , $ locales ) ; } } | Append mapping selects to given query - builder . |
11,286 | private function appendSingleMapping ( QueryBuilder $ queryBuilder , $ propertyName , $ locales ) { foreach ( $ locales as $ locale ) { $ alias = sprintf ( '%s%s' , $ locale , str_replace ( '-' , '_' , ucfirst ( $ propertyName ) ) ) ; $ queryBuilder -> addSelect ( 'node' , $ this -> propertyEncoder -> localizedContentName ( $ propertyName , $ locale ) , $ alias ) ; } } | Append mapping selects for a single property to given query - builder . |
11,287 | private function appendUrlMapping ( QueryBuilder $ queryBuilder , $ locales ) { $ structures = $ this -> structureManager -> getStructures ( Structure :: TYPE_PAGE ) ; $ urlNames = [ ] ; foreach ( $ structures as $ structure ) { if ( ! $ structure -> hasTag ( 'sulu.rlp' ) ) { continue ; } $ propertyName = $ structure -> getPropertyByTagName ( 'sulu.rlp' ) -> getName ( ) ; if ( ! in_array ( $ propertyName , $ urlNames ) ) { $ this -> appendSingleMapping ( $ queryBuilder , $ propertyName , $ locales ) ; $ urlNames [ ] = $ propertyName ; } } } | Append mapping for url to given query - builder . |
11,288 | private function resolveAvailableLocales ( Row $ row ) { $ locales = [ ] ; foreach ( $ row -> getValues ( ) as $ key => $ value ) { if ( preg_match ( '/^node.([a-zA-Z_]*?)Template/' , $ key , $ matches ) && '' !== $ value && ! $ row -> getValue ( sprintf ( 'node.%sShadow_on' , $ matches [ 1 ] ) ) ) { $ locales [ ] = $ matches [ 1 ] ; } } return $ locales ; } | Resolves all available localizations for given row . |
11,289 | public function resolveInternalLinkContent ( Row $ row , $ locale , $ webspaceKey , MappingInterface $ mapping , StructureType $ type = null , UserInterface $ user = null ) { $ linkedContent = $ this -> find ( $ row -> getValue ( 'internalLink' ) , $ locale , $ webspaceKey , $ mapping ) ; $ data = $ linkedContent -> getData ( ) ; $ properties = array_intersect ( self :: $ nonFallbackProperties , array_keys ( $ data ) ) ; foreach ( $ properties as $ property ) { $ data [ $ property ] = $ this -> resolveProperty ( $ row , $ property , $ locale ) ; } $ content = new Content ( $ locale , $ webspaceKey , $ row -> getValue ( 'uuid' ) , $ this -> resolvePath ( $ row , $ webspaceKey ) , $ row -> getValue ( 'state' ) , $ row -> getValue ( 'nodeType' ) , $ this -> resolveHasChildren ( $ row ) , $ this -> resolveProperty ( $ row , 'template' , $ locale ) , $ data , $ this -> resolvePermissions ( $ row , $ user ) , $ type ) ; if ( ! $ content -> getTemplate ( ) || ! $ this -> structureManager -> getStructure ( $ content -> getTemplate ( ) ) ) { $ content -> setBrokenTemplate ( ) ; } return $ content ; } | Resolve a single result row which is an internal link to a content object . |
11,290 | private function resolveProperty ( Row $ row , $ name , $ locale , $ shadowLocale = null ) { if ( array_key_exists ( sprintf ( 'node.%s' , $ name ) , $ row -> getValues ( ) ) ) { return $ row -> getValue ( $ name ) ; } if ( null !== $ shadowLocale && ! in_array ( $ name , self :: $ nonFallbackProperties ) ) { $ locale = $ shadowLocale ; } $ name = sprintf ( '%s%s' , $ locale , str_replace ( '-' , '_' , ucfirst ( $ name ) ) ) ; try { return $ row -> getValue ( $ name ) ; } catch ( ItemNotFoundException $ e ) { return '' ; } } | Resolve a property and follow shadow locale if it has one . |
11,291 | private function resolveUrl ( Row $ row , $ locale ) { if ( WorkflowStage :: PUBLISHED !== $ this -> resolveProperty ( $ row , $ locale . 'State' , $ locale ) ) { return ; } $ template = $ this -> resolveProperty ( $ row , 'template' , $ locale ) ; if ( empty ( $ template ) ) { return ; } $ structure = $ this -> structureManager -> getStructure ( $ template ) ; if ( ! $ structure || ! $ structure -> hasTag ( 'sulu.rlp' ) ) { return ; } $ propertyName = $ structure -> getPropertyByTagName ( 'sulu.rlp' ) -> getName ( ) ; return $ this -> resolveProperty ( $ row , $ propertyName , $ locale ) ; } | Resolve url property . |
11,292 | private function resolvePath ( Row $ row , $ webspaceKey ) { return '/' . ltrim ( str_replace ( $ this -> sessionManager -> getContentPath ( $ webspaceKey ) , '' , $ row -> getPath ( ) ) , '/' ) ; } | Resolves path for given row . |
11,293 | private function resolvePermissions ( Row $ row , UserInterface $ user = null ) { $ permissions = [ ] ; if ( null !== $ user ) { foreach ( $ user -> getRoleObjects ( ) as $ role ) { foreach ( array_filter ( explode ( ' ' , $ row -> getValue ( sprintf ( 'role%s' , $ role -> getId ( ) ) ) ) ) as $ permission ) { $ permissions [ $ role -> getId ( ) ] [ $ permission ] = true ; } } } return $ permissions ; } | Resolves permissions for given user . |
11,294 | private function resolveHasChildren ( Row $ row ) { $ queryBuilder = new QueryBuilder ( $ this -> qomFactory ) ; $ queryBuilder -> select ( 'node' , 'jcr:uuid' , 'uuid' ) -> from ( $ this -> qomFactory -> selector ( 'node' , 'nt:unstructured' ) ) -> where ( $ this -> qomFactory -> childNode ( 'node' , $ row -> getPath ( ) ) ) -> setMaxResults ( 1 ) ; $ result = $ queryBuilder -> execute ( ) ; return count ( iterator_to_array ( $ result -> getRows ( ) ) ) > 0 ; } | Resolve property has - children with given node . |
11,295 | public function onPostSerialize ( ObjectEvent $ event ) { $ document = $ event -> getObject ( ) ; if ( ! $ document instanceof ShadowLocaleBehavior || ! $ this -> documentRegistry -> hasDocument ( $ document ) ) { return ; } $ visitor = $ event -> getVisitor ( ) ; $ visitor -> addData ( 'shadowLocales' , $ this -> documentInspector -> getShadowLocales ( $ document ) ) ; } | Adds the enabled shadow languages to the serialization . |
11,296 | protected function loadStructures ( $ webspaceKey ) { $ structures = [ ] ; $ keys = [ ] ; foreach ( $ this -> structureManager -> getStructures ( ) as $ page ) { $ template = sprintf ( '%s.html.twig' , $ page -> getView ( ) ) ; if ( $ this -> templateExists ( $ template ) ) { $ keys [ ] = $ page -> getKey ( ) ; $ structures [ ] = $ page ; } } $ this -> cache -> save ( $ webspaceKey , $ keys ) ; return $ structures ; } | Returns and caches structures for given webspace . |
11,297 | protected function templateExists ( $ template ) { $ loader = $ this -> twig -> getLoader ( ) ; if ( method_exists ( $ loader , 'exists' ) ) { return $ loader -> exists ( $ template ) ; } try { $ loader -> getSource ( $ template ) -> getCode ( ) ; } catch ( \ Twig_Error_Loader $ e ) { return false ; } return true ; } | checks if a template with given name exists . |
11,298 | public static function truncate ( $ text , $ length , $ suffix = '...' ) { $ strlen = mb_strlen ( $ text , 'UTF-8' ) ; if ( $ strlen > $ length ) { $ truncatedLength = $ length - strlen ( $ suffix ) ; $ text = mb_substr ( $ text , 0 , $ truncatedLength , 'UTF-8' ) . $ suffix ; } return $ text ; } | UTF - 8 safe text truncation . |
11,299 | protected function findIdsByGivenCriteria ( ) { $ select = $ this -> getSelectAs ( $ this -> idField ) ; $ subQueryBuilder = $ this -> createSubQueryBuilder ( $ select ) ; if ( null != $ this -> limit ) { $ subQueryBuilder -> setMaxResults ( $ this -> limit ) -> setFirstResult ( $ this -> limit * ( $ this -> page - 1 ) ) ; } foreach ( $ this -> sortFields as $ index => $ sortField ) { if ( $ sortField -> getName ( ) !== $ this -> idField -> getName ( ) ) { $ subQueryBuilder -> addSelect ( $ this -> getSelectAs ( $ sortField ) ) ; } } $ this -> assignSortFields ( $ subQueryBuilder ) ; $ this -> assignParameters ( $ this -> queryBuilder ) ; $ ids = $ subQueryBuilder -> getQuery ( ) -> getArrayResult ( ) ; if ( count ( $ ids ) < 1 ) { return [ ] ; } $ ids = array_map ( function ( $ array ) { return $ array [ $ this -> idField -> getName ( ) ] ; } , $ ids ) ; return $ ids ; } | Function that finds all IDs of entities that match the search criteria . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.