idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
11,700
public function getSorting ( ) { $ sortOrder = $ this -> getRequest ( ) -> get ( 'sortOrder' , 'asc' ) ; $ sortBy = $ this -> getRequest ( ) -> get ( 'sortBy' , 'id' ) ; return [ $ sortBy => $ sortOrder ] ; }
Returns an array containing the desired sorting .
11,701
public function getOffset ( ) { $ page = $ this -> getRequest ( ) -> get ( 'page' , 1 ) ; $ limit = $ this -> getRequest ( ) -> get ( 'limit' ) ; return ( null != $ limit ) ? $ limit * ( $ page - 1 ) : null ; }
Returns the calculated value for the starting position based on the page and limit values .
11,702
public function getTotalPages ( $ totalNumber = null ) { if ( is_null ( $ totalNumber ) ) { $ totalNumber = $ this -> totalNumberOfElements ; } return $ this -> getLimit ( ) ? ( ceil ( $ totalNumber / $ this -> getLimit ( ) ) ) : 1 ; }
returns total amount of pages .
11,703
public function onKernelController ( FilterControllerEvent $ event ) { $ controllerDefinition = $ event -> getController ( ) ; $ controller = $ controllerDefinition [ 0 ] ; if ( ! $ controller instanceof SecuredControllerInterface && ! $ controller instanceof SecuredObjectControllerInterface ) { return ; } $ request = $ event -> getRequest ( ) ; $ permission = '' ; switch ( $ request -> getMethod ( ) ) { case 'GET' : $ permission = PermissionTypes :: VIEW ; break ; case 'POST' : if ( 'postAction' == $ controllerDefinition [ 1 ] ) { $ permission = PermissionTypes :: ADD ; } else { $ permission = PermissionTypes :: EDIT ; } break ; case 'PUT' : case 'PATCH' : $ permission = PermissionTypes :: EDIT ; break ; case 'DELETE' : $ permission = PermissionTypes :: DELETE ; break ; } $ securityContext = null ; $ locale = $ controller -> getLocale ( $ request ) ; $ objectType = null ; $ objectId = null ; if ( $ controller instanceof SecuredObjectControllerInterface ) { $ objectType = $ controller -> getSecuredClass ( ) ; $ objectId = $ controller -> getSecuredObjectId ( $ request ) ; } if ( $ controller instanceof SecuredControllerInterface ) { $ securityContext = $ controller -> getSecurityContext ( ) ; } if ( null !== $ securityContext ) { $ this -> securityChecker -> checkPermission ( new SecurityCondition ( $ securityContext , $ locale , $ objectType , $ objectId ) , $ permission ) ; } }
Checks if the action is allowed for the current user and throws an Exception otherwise .
11,704
protected function localizeDomain ( $ domain , Localization $ locale ) { if ( ! $ this -> urlReplacer -> hasLocalizationReplacer ( $ domain ) && ! $ this -> urlReplacer -> hasLanguageReplacer ( $ domain ) ) { $ domain = $ this -> urlReplacer -> appendLocalizationReplacer ( $ domain ) ; } $ domain = $ this -> urlReplacer -> replaceLanguage ( $ domain , $ locale -> getLanguage ( ) ) ; $ domain = $ this -> urlReplacer -> replaceCountry ( $ domain , $ locale -> getCountry ( ) ) ; $ domain = $ this -> urlReplacer -> replaceLocalization ( $ domain , $ locale -> getLocale ( ) ) ; return $ this -> urlReplacer -> cleanup ( $ domain ) ; }
Localize given domain .
11,705
public function build ( array $ segments ) { $ results = [ ] ; foreach ( $ segments as $ segment ) { $ result = $ this -> buildSegment ( $ segment ) ; if ( null === $ result ) { continue ; } $ results [ ] = $ result ; } return '/' . implode ( '/' , $ results ) ; }
Build a path from an array of path segments .
11,706
private function createOrGetFolder ( $ directory , ContainerBuilder $ container ) { $ filesystem = new Filesystem ( ) ; $ directory = $ container -> getParameterBag ( ) -> resolveValue ( $ directory ) ; if ( ! file_exists ( $ directory ) ) { $ filesystem -> mkdir ( $ directory ) ; } return $ directory ; }
Create and return directory .
11,707
private function setDefaultForFilterConditionsConjunction ( & $ config ) { if ( ! array_key_exists ( 'filters' , $ config ) || ! array_key_exists ( 'conjunctions' , $ config [ 'filters' ] ) || 0 === count ( $ config [ 'filters' ] [ 'conjunctions' ] ) ) { $ config [ 'filters' ] = [ ] ; $ config [ 'filters' ] [ 'conjunctions' ] = [ [ 'id' => 'and' , 'translation' => 'resource.filter.conjunction.and' , ] , [ 'id' => 'or' , 'translation' => 'resource.filter.conjunction.or' , ] , ] ; } }
Sets default values for filter condition conjunction .
11,708
public function offsetGet ( $ extensionName ) { if ( isset ( $ this -> data [ $ extensionName ] ) ) { return $ this -> data [ $ extensionName ] ; } $ extension = $ this -> extensionManager -> getExtension ( $ this -> structureType , $ extensionName ) ; $ extension -> setLanguageCode ( $ this -> locale , $ this -> prefix , $ this -> internalPrefix ) ; $ data = $ extension -> load ( $ this -> node , $ this -> webspaceName , $ this -> locale ) ; $ this -> data [ $ extensionName ] = $ data ; return $ data ; }
Lazily evaluate the value for the given extension .
11,709
public function queryAction ( Request $ request ) { $ query = $ this -> getRequestParameter ( $ request , 'q' , true ) ; $ locale = $ this -> requestAnalyzer -> getCurrentLocalization ( ) -> getLocale ( ) ; $ webspace = $ this -> requestAnalyzer -> getWebspace ( ) ; $ queryString = '' ; if ( strlen ( $ query ) < 3 ) { $ queryString .= '+("' . self :: escapeDoubleQuotes ( $ query ) . '") ' ; } else { $ queryValues = explode ( ' ' , $ query ) ; foreach ( $ queryValues as $ queryValue ) { if ( strlen ( $ queryValue ) > 2 ) { $ queryString .= '+("' . self :: escapeDoubleQuotes ( $ queryValue ) . '" OR ' . '"' . preg_replace ( '/([^\pL\s\d])/u' , '?' , $ queryValue ) . '*" OR ' . '"' . preg_replace ( '/([^\pL\s\d])/u' , '' , $ queryValue ) . '~") ' ; } else { $ queryString .= '+("' . self :: escapeDoubleQuotes ( $ queryValue ) . '") ' ; } } } $ hits = $ this -> searchManager -> createSearch ( $ queryString ) -> locale ( $ locale ) -> index ( 'page_' . $ webspace -> getKey ( ) . '_published' ) -> execute ( ) ; $ template = $ webspace -> getTemplate ( 'search' , $ request -> getRequestFormat ( ) ) ; if ( ! $ this -> twig -> getLoader ( ) -> exists ( $ template ) ) { throw new NotFoundHttpException ( ) ; } return new Response ( $ this -> twig -> render ( $ template , $ this -> parameterResolver -> resolve ( [ 'query' => $ query , 'hits' => $ hits ] , $ this -> requestAnalyzer ) ) ) ; }
Returns the search results for the given query .
11,710
public function copyChildless ( ) { $ new = $ this -> copyWithName ( ) ; $ new -> setAction ( $ this -> getAction ( ) ) ; $ new -> setMainRoute ( $ this -> getMainRoute ( ) ) ; $ new -> setChildRoutes ( $ this -> getChildRoutes ( ) ) ; $ new -> setEvent ( $ this -> getEvent ( ) ) ; $ new -> setEventArguments ( $ this -> getEventArguments ( ) ) ; $ new -> setIcon ( $ this -> getIcon ( ) ) ; $ new -> setHeaderIcon ( $ this -> getHeaderIcon ( ) ) ; $ new -> setHeaderTitle ( $ this -> getHeaderTitle ( ) ) ; $ new -> setId ( $ this -> getId ( ) ) ; $ new -> setHasSettings ( $ this -> getHasSettings ( ) ) ; $ new -> setPosition ( $ this -> getPosition ( ) ) ; $ new -> setLabel ( $ this -> getLabel ( ) ) ; return $ new ; }
Returns a copy of this navigation item without its children .
11,711
public function find ( $ navigationItem ) { $ stack = [ $ this ] ; while ( ! empty ( $ stack ) ) { $ item = array_pop ( $ stack ) ; if ( $ item -> equalsChildless ( $ navigationItem ) ) { return $ item ; } foreach ( $ item -> getChildren ( ) as $ child ) { $ stack [ ] = $ child ; } } return ; }
Searches for the equivalent of a specific NavigationItem .
11,712
public function findChildren ( self $ navigationItem ) { foreach ( $ this -> getChildren ( ) as $ child ) { if ( $ child -> equalsChildless ( $ navigationItem ) ) { return $ child ; } } return ; }
Searches for a specific NavigationItem in the children of this NavigationItem .
11,713
public function merge ( self $ other = null ) { $ new = $ this -> copyChildless ( ) ; foreach ( $ this -> getChildren ( ) as $ child ) { $ new -> addChild ( $ child -> merge ( ( null != $ other ) ? $ other -> findChildren ( $ child ) : null ) ) ; } if ( null != $ other ) { foreach ( $ other -> getChildren ( ) as $ child ) { if ( ! $ new -> find ( $ child ) ) { $ new -> addChild ( $ child -> merge ( $ this -> copyChildless ( ) ) ) ; } } } return $ new ; }
Merges this navigation item with the other parameter and returns a new NavigationItem . Works only if there are no duplicate values on one level .
11,714
public function toArray ( ) { $ array = [ 'title' => $ this -> getName ( ) , 'label' => $ this -> getLabel ( ) , 'icon' => $ this -> getIcon ( ) , 'action' => $ this -> getAction ( ) , 'mainRoute' => $ this -> getMainRoute ( ) , 'event' => $ this -> getEvent ( ) , 'eventArguments' => $ this -> getEventArguments ( ) , 'hasSettings' => $ this -> getHasSettings ( ) , 'disabled' => $ this -> getDisabled ( ) , 'id' => ( null != $ this -> getId ( ) ) ? $ this -> getId ( ) : str_replace ( '.' , '' , uniqid ( '' , true ) ) , ] ; if ( count ( $ this -> getChildRoutes ( ) ) > 0 ) { $ array [ 'childRoutes' ] = $ this -> getChildRoutes ( ) ; } if ( null != $ this -> getHeaderIcon ( ) || null != $ this -> getHeaderTitle ( ) ) { $ array [ 'header' ] = [ 'title' => $ this -> getHeaderTitle ( ) , 'logo' => $ this -> getHeaderIcon ( ) , ] ; } $ children = $ this -> getChildren ( ) ; usort ( $ children , function ( NavigationItem $ a , NavigationItem $ b ) { $ aPosition = $ a -> getPosition ( ) ? : PHP_INT_MAX ; $ bPosition = $ b -> getPosition ( ) ? : PHP_INT_MAX ; return $ aPosition - $ bPosition ; } ) ; foreach ( $ children as $ key => $ child ) { $ array [ 'items' ] [ $ key ] = $ child -> toArray ( ) ; } return $ array ; }
Returns the content of the NavigationItem as array .
11,715
public function setLanguage ( $ languageKey ) { $ this -> translatedProperties = [ ] ; foreach ( $ this -> properties as $ key => $ property ) { $ this -> translatedProperties [ $ key ] = new TranslatedProperty ( $ property , $ languageKey , $ this -> languageNamespace ) ; } }
set language of translated property names .
11,716
public function getName ( $ key ) { if ( Structure :: TYPE_SNIPPET === $ this -> structureType ) { if ( 'template' === $ key ) { return $ key ; } } if ( isset ( $ this -> translatedProperties [ $ key ] ) ) { return $ this -> translatedProperties [ $ key ] -> getName ( ) ; } else { throw new NoSuchPropertyException ( $ key ) ; } }
returns translated property name .
11,717
public function putLanguageAction ( Request $ request ) { $ user = $ this -> tokenStorage -> getToken ( ) -> getUser ( ) ; $ user -> setLocale ( $ request -> get ( 'locale' ) ) ; $ this -> objectManager -> flush ( ) ; return $ this -> viewHandler -> handle ( View :: create ( [ 'locale' => $ user -> getLocale ( ) ] ) ) ; }
Sets the given language on the current user .
11,718
public function patchSettingsAction ( Request $ request ) { $ settings = $ request -> request -> all ( ) ; try { $ user = $ this -> tokenStorage -> getToken ( ) -> getUser ( ) ; foreach ( $ settings as $ settingKey => $ settingValue ) { $ setting = $ this -> userSettingRepository -> findOneBy ( [ 'user' => $ user , 'key' => $ settingKey ] ) ; if ( ! $ setting ) { $ setting = new UserSetting ( ) ; $ setting -> setKey ( $ settingKey ) ; $ setting -> setUser ( $ user ) ; $ this -> objectManager -> persist ( $ setting ) ; } $ setting -> setValue ( json_encode ( $ settingValue ) ) ; } $ this -> objectManager -> flush ( ) ; $ view = View :: create ( $ settings , 200 ) ; } catch ( RestException $ exc ) { $ view = View :: create ( $ exc -> toArray ( ) , 400 ) ; } return $ this -> viewHandler -> handle ( $ view ) ; }
Takes a key value pair and stores it as settings for the user .
11,719
public function deleteSettingsAction ( Request $ request ) { $ key = $ request -> get ( 'key' ) ; try { if ( ! $ key ) { throw new MissingArgumentException ( static :: $ entityNameUserSetting , 'key' ) ; } $ user = $ this -> tokenStorage -> getToken ( ) -> getUser ( ) ; $ setting = $ this -> userSettingRepository -> findOneBy ( [ 'user' => $ user , 'key' => $ key ] ) ; if ( $ setting ) { $ this -> objectManager -> remove ( $ setting ) ; $ this -> objectManager -> flush ( ) ; $ view = View :: create ( null , 204 ) ; } else { $ view = View :: create ( null , 400 ) ; } } catch ( RestException $ exc ) { $ view = View :: create ( $ exc -> toArray ( ) , 400 ) ; } return $ this -> viewHandler -> handle ( $ view ) ; }
Deletes a user setting by a given key .
11,720
public function setTargetGroup ( GetResponseEvent $ event ) { $ request = $ event -> getRequest ( ) ; if ( $ targetGroupId = $ request -> headers -> get ( $ this -> targetGroupHeader ) ) { $ this -> targetGroupStore -> setTargetGroupId ( $ targetGroupId ) ; } elseif ( $ targetGroupId = $ request -> cookies -> get ( $ this -> targetGroupCookie ) ) { $ visitorSession = $ request -> cookies -> get ( $ this -> visitorSessionCookie ) ; if ( $ visitorSession ) { $ this -> targetGroupStore -> setTargetGroupId ( $ targetGroupId ) ; return ; } $ targetGroup = $ this -> targetGroupEvaluator -> evaluate ( TargetGroupRuleInterface :: FREQUENCY_SESSION , $ this -> targetGroupRepository -> find ( $ targetGroupId ) ) ; if ( $ targetGroup ) { $ this -> targetGroupStore -> updateTargetGroupId ( $ targetGroup -> getId ( ) ) ; } } elseif ( $ request -> getPathInfo ( ) !== $ this -> targetGroupUrl ) { $ targetGroup = $ this -> targetGroupEvaluator -> evaluate ( ) ; $ targetGroupId = 0 ; if ( $ targetGroup ) { $ targetGroupId = $ targetGroup -> getId ( ) ; } $ this -> targetGroupStore -> updateTargetGroupId ( $ targetGroupId ) ; } }
Evaluates the cookie holding the target group information . This has only an effect if there is no cache used since in that case the cache already did it .
11,721
public function addVaryHeader ( FilterResponseEvent $ event ) { $ request = $ event -> getRequest ( ) ; $ response = $ event -> getResponse ( ) ; if ( $ this -> targetGroupStore -> hasInfluencedContent ( ) && $ request -> getRequestUri ( ) !== $ this -> targetGroupUrl ) { $ response -> setVary ( $ this -> targetGroupHeader , false ) ; } }
Adds the vary header on the response so that the cache takes the target group into account .
11,722
public function addSetCookieHeader ( FilterResponseEvent $ event ) { if ( ! $ this -> targetGroupStore -> hasChangedTargetGroup ( ) || $ event -> getRequest ( ) -> getPathInfo ( ) === $ this -> targetGroupUrl ) { return ; } $ response = $ event -> getResponse ( ) ; $ response -> headers -> setCookie ( new Cookie ( $ this -> targetGroupCookie , $ this -> targetGroupStore -> getTargetGroupId ( true ) , AudienceTargetingCacheListener :: TARGET_GROUP_COOKIE_LIFETIME ) ) ; $ response -> headers -> setCookie ( new Cookie ( $ this -> visitorSessionCookie , time ( ) ) ) ; }
Adds the SetCookie header for the target group if the user context has changed . In addition to that a second cookie without a lifetime is set whose expiration marks a new session .
11,723
public function addTargetGroupHitScript ( FilterResponseEvent $ event ) { $ request = $ event -> getRequest ( ) ; $ response = $ event -> getResponse ( ) ; if ( $ this -> preview || 0 !== strpos ( $ response -> headers -> get ( 'Content-Type' ) , 'text/html' ) || Request :: METHOD_GET !== $ request -> getMethod ( ) ) { return ; } $ script = $ this -> twig -> render ( 'SuluAudienceTargetingBundle:Template:hit-script.html.twig' , [ 'url' => $ this -> targetGroupHitUrl , 'urlHeader' => $ this -> urlHeader , 'refererHeader' => $ this -> referrerHeader , 'uuidHeader' => $ this -> uuidHeader , 'uuid' => $ request -> attributes -> has ( 'structure' ) ? $ request -> attributes -> get ( 'structure' ) -> getUuid ( ) : null , ] ) ; $ response -> setContent ( str_replace ( '</body>' , $ script . '</body>' , $ response -> getContent ( ) ) ) ; }
Adds a script for triggering an ajax request which updates the target group on every hit .
11,724
public function getNavigation ( ) { $ navigation = null ; $ this -> iterateAdmins ( function ( Admin $ admin ) use ( & $ navigation ) { if ( null === $ navigation ) { $ navigation = $ admin -> getNavigation ( ) ; return ; } $ navigation = $ navigation -> merge ( $ admin -> getNavigation ( ) ) ; } ) ; return $ navigation ; }
Returns the navigation combined from all Admin objects .
11,725
public function getSecurityContexts ( ) { $ contexts = [ ] ; $ this -> iterateAdmins ( function ( Admin $ admin ) use ( & $ contexts ) { $ contexts = array_merge_recursive ( $ contexts , $ admin -> getSecurityContexts ( ) ) ; } ) ; return $ contexts ; }
Returns the combined security contexts from all Admin objects .
11,726
public static function filter ( array $ collection , $ expression , array $ context = [ ] ) { $ language = new ExpressionLanguage ( ) ; $ result = [ ] ; foreach ( $ collection as $ key => $ item ) { if ( $ language -> evaluate ( $ expression , array_merge ( $ context , [ 'item' => $ item , 'key' => $ key ] ) ) ) { $ result [ $ key ] = $ item ; } } return $ result ; }
Filter array with given symfony - expression .
11,727
protected function renderStructure ( StructureInterface $ structure , $ attributes = [ ] , $ preview = false , $ partial = false ) { if ( ! $ preview ) { $ request = $ this -> getRequest ( ) ; $ requestFormat = $ request -> getRequestFormat ( ) ; } else { $ requestFormat = 'html' ; } $ viewTemplate = $ structure -> getView ( ) . '.' . $ requestFormat . '.twig' ; try { $ data = $ this -> getAttributes ( $ attributes , $ structure , $ preview ) ; if ( $ partial ) { $ content = $ this -> renderBlock ( $ viewTemplate , 'content' , $ data ) ; } elseif ( $ preview ) { $ content = $ this -> renderPreview ( $ viewTemplate , $ data ) ; } else { $ content = $ this -> renderView ( $ viewTemplate , $ data ) ; } $ response = new Response ( $ content ) ; if ( ! $ preview && $ this -> getCacheTimeLifeEnhancer ( ) ) { $ this -> getCacheTimeLifeEnhancer ( ) -> enhance ( $ response , $ structure ) ; } return $ response ; } catch ( InvalidArgumentException $ e ) { throw new HttpException ( 406 , 'Error encountered when rendering content' , $ e ) ; } }
Returns a rendered structure .
11,728
protected function getAttributes ( $ attributes , StructureInterface $ structure = null , $ preview = false ) { return $ this -> get ( 'sulu_website.resolver.parameter' ) -> resolve ( $ attributes , $ this -> get ( 'sulu_core.webspace.request_analyzer' ) , $ structure , $ preview ) ; }
Generates attributes .
11,729
protected function renderBlock ( $ template , $ block , $ attributes = [ ] ) { $ twig = $ this -> get ( 'twig' ) ; $ attributes = $ twig -> mergeGlobals ( $ attributes ) ; $ template = $ twig -> loadTemplate ( $ template ) ; $ level = ob_get_level ( ) ; ob_start ( ) ; try { $ rendered = $ template -> renderBlock ( $ block , $ attributes ) ; ob_end_clean ( ) ; return $ rendered ; } catch ( \ Exception $ e ) { while ( ob_get_level ( ) > $ level ) { ob_end_clean ( ) ; } throw $ e ; } }
Returns rendered part of template specified by block .
11,730
public function addChild ( self $ child ) { if ( ! is_array ( $ this -> children ) ) { $ this -> children = [ ] ; } $ this -> children [ ] = $ child ; }
Add child to resource .
11,731
private function adaptResourceLocators ( ResourceSegmentBehavior $ document , $ userId ) { if ( ! $ document instanceof ChildrenBehavior ) { return ; } $ webspaceKey = $ this -> documentInspector -> getWebspace ( $ document ) ; $ languageCode = $ this -> documentInspector -> getOriginalLocale ( $ document ) ; $ node = $ this -> documentInspector -> getNode ( $ document ) ; $ node -> getSession ( ) -> save ( ) ; foreach ( $ document -> getChildren ( ) as $ childDocument ) { if ( ! $ childDocument instanceof ResourceSegmentBehavior || ! ( $ currentResourceLocator = $ childDocument -> getResourceSegment ( ) ) ) { $ this -> adaptResourceLocators ( $ childDocument , $ userId ) ; continue ; } $ parentUuid = $ this -> documentInspector -> getUuid ( $ document ) ; $ childPart = $ this -> getChildPart ( $ currentResourceLocator ) ; $ newResourceLocator = $ this -> generate ( $ childPart , $ parentUuid , $ webspaceKey , $ languageCode ) ; $ childNode = $ this -> documentInspector -> getNode ( $ childDocument ) ; $ templatePropertyName = $ this -> nodeHelper -> getTranslatedPropertyName ( 'template' , $ languageCode ) ; $ template = $ childNode -> getPropertyValue ( $ templatePropertyName ) ; $ structure = $ this -> structureManager -> getStructure ( $ template ) ; $ property = $ structure -> getPropertyByTagName ( 'sulu.rlp' ) ; $ property -> setValue ( $ newResourceLocator ) ; $ contentType = $ this -> contentTypeManager -> get ( $ property -> getContentTypeName ( ) ) ; $ translatedProperty = $ this -> nodeHelper -> getTranslatedProperty ( $ property , $ languageCode ) ; $ contentType -> write ( $ childNode , $ translatedProperty , $ userId , $ webspaceKey , $ languageCode , null ) ; $ childDocument -> setResourceSegment ( $ newResourceLocator ) ; if ( ! $ childDocument -> getPublished ( ) ) { $ this -> adaptResourceLocators ( $ childDocument , $ userId ) ; } else { $ this -> save ( $ childDocument , $ userId ) ; } } }
adopts resource locator of children by iteration .
11,732
public function replaceOrAddUrlString ( $ url , $ key , $ value , $ add = true ) { if ( $ value ) { if ( $ pos = strpos ( $ url , $ key ) ) { return preg_replace ( '/(.*' . $ key . ')([\,|\w]*)(\&*.*)/' , '${1}' . $ value . '${3}' , $ url ) ; } else { if ( $ add ) { $ and = ( false === strpos ( $ url , '?' ) ) ? '?' : '&' ; return $ url . $ and . $ key . $ value ; } } } else { if ( $ pos = strpos ( $ url , $ key ) ) { $ result = preg_replace ( '/(.*)([\\?|\&]{1}' . $ key . ')([\,|\w]*)(\&*.*)/' , '${1}${4}' , $ url ) ; if ( strpos ( $ url , '?' . $ key ) ) { $ result = preg_replace ( '/&/' , '?' , $ result , 1 ) ; } return $ result ; } } return $ url ; }
function replaces a url parameter .
11,733
protected function responseGetById ( $ id , $ findCallback ) { $ entity = $ findCallback ( $ id ) ; if ( ! $ entity ) { $ exception = new EntityNotFoundException ( self :: $ entityName , $ id ) ; $ view = $ this -> view ( $ exception -> toArray ( ) , 404 ) ; } else { $ view = $ this -> view ( $ entity , 200 ) ; } return $ view ; }
Returns the response with the entity with the given id or a response with a status of 404 in case the entity is not found . The find method is injected by a callback .
11,734
public function responseDelete ( $ id , $ deleteCallback ) { try { $ deleteCallback ( $ id ) ; $ view = $ this -> view ( null , 204 ) ; } catch ( EntityNotFoundException $ enfe ) { $ view = $ this -> view ( $ enfe -> toArray ( ) , 404 ) ; } catch ( RestException $ re ) { $ view = $ this -> view ( $ re -> toArray ( ) , 400 ) ; } return $ view ; }
Deletes the entity with the given id using the deleteCallback and return a successful response or an error message with a 4xx status code .
11,735
public function replaceMarkup ( FilterResponseEvent $ event ) { $ request = $ event -> getRequest ( ) ; $ response = $ event -> getResponse ( ) ; $ format = $ request -> getRequestFormat ( ) ; $ content = $ response -> getContent ( ) ; if ( ! $ content || ! array_key_exists ( $ format , $ this -> markupParser ) ) { return ; } $ response -> setContent ( $ this -> markupParser [ $ format ] -> parse ( $ content , $ request -> getLocale ( ) ) ) ; }
Parses content of response and set the replaced html as new content .
11,736
public function getLocales ( ) { $ entities = [ ] ; if ( $ this -> entity -> getLocales ( ) ) { foreach ( $ this -> entity -> getLocales ( ) as $ locale ) { $ entities [ ] = new ContactLocale ( $ locale ) ; } } return $ entities ; }
Get locales .
11,737
public function getAvatar ( ) { if ( $ this -> avatar ) { return [ 'id' => $ this -> avatar -> getId ( ) , 'url' => $ this -> avatar -> getUrl ( ) , 'thumbnails' => $ this -> avatar -> getFormats ( ) , ] ; } return ; }
Get the contacts avatar and return the array of different formats .
11,738
public function getAccount ( ) { $ mainAccount = $ this -> entity -> getMainAccount ( ) ; if ( ! is_null ( $ mainAccount ) ) { return new Account ( $ mainAccount , $ this -> locale ) ; } return ; }
Returns main account .
11,739
public function getAddresses ( ) { $ contactAddresses = $ this -> entity -> getContactAddresses ( ) ; $ addresses = [ ] ; if ( ! is_null ( $ contactAddresses ) ) { foreach ( $ contactAddresses as $ contactAddress ) { $ address = $ contactAddress -> getAddress ( ) ; $ address -> setPrimaryAddress ( $ contactAddress -> getMain ( ) ) ; $ addresses [ ] = new Address ( $ address , $ this -> locale ) ; } } return $ addresses ; }
Returns main addresses .
11,740
public function getMedias ( ) { $ entities = [ ] ; if ( $ this -> entity -> getMedias ( ) ) { foreach ( $ this -> entity -> getMedias ( ) as $ media ) { $ entities [ ] = new Media ( $ media , $ this -> locale , null ) ; } } return $ entities ; }
Get medias .
11,741
private function extractFilterVars ( array $ filter ) { $ collection = array_key_exists ( 'collection' , $ filter ) ? $ filter [ 'collection' ] : null ; $ systemCollections = array_key_exists ( 'systemCollections' , $ filter ) ? $ filter [ 'systemCollections' ] : true ; $ types = array_key_exists ( 'types' , $ filter ) ? $ filter [ 'types' ] : null ; $ search = array_key_exists ( 'search' , $ filter ) ? $ filter [ 'search' ] : null ; $ orderBy = array_key_exists ( 'orderBy' , $ filter ) ? $ filter [ 'orderBy' ] : null ; $ orderSort = array_key_exists ( 'orderSort' , $ filter ) ? $ filter [ 'orderSort' ] : null ; $ ids = array_key_exists ( 'ids' , $ filter ) ? $ filter [ 'ids' ] : null ; return [ $ collection , $ systemCollections , $ types , $ search , $ orderBy , $ orderSort , $ ids ] ; }
Extracts filter vars .
11,742
public function findMediaWithFilenameInCollectionWithId ( $ filename , $ collectionId ) { $ queryBuilder = $ this -> createQueryBuilder ( 'media' ) -> innerJoin ( 'media.files' , 'files' ) -> innerJoin ( 'files.fileVersions' , 'versions' , 'WITH' , 'versions.version = files.version' ) -> join ( 'media.collection' , 'collection' ) -> where ( 'collection.id = :collectionId' ) -> andWhere ( 'versions.name = :filename' ) -> orderBy ( 'versions.created' ) -> setMaxResults ( 1 ) -> setParameter ( 'filename' , $ filename ) -> setParameter ( 'collectionId' , $ collectionId ) ; $ result = $ queryBuilder -> getQuery ( ) -> getResult ( ) ; if ( count ( $ result ) > 0 ) { return $ result [ 0 ] ; } return ; }
Returns the most recent version of a media for the specified filename within a collection .
11,743
private function getIdsQuery ( $ collection = null , $ systemCollections = true , $ types = null , $ search = null , $ orderBy = null , $ orderSort = null , $ limit = null , $ offset = null , $ select = 'media.id' ) { $ queryBuilder = $ this -> createQueryBuilder ( 'media' ) -> select ( $ select ) ; $ queryBuilder -> innerJoin ( 'media.collection' , 'collection' ) ; if ( ! empty ( $ collection ) ) { $ queryBuilder -> andWhere ( 'collection.id = :collection' ) ; $ queryBuilder -> setParameter ( 'collection' , $ collection ) ; } if ( ! $ systemCollections ) { $ queryBuilder -> leftJoin ( 'collection.type' , 'collectionType' ) ; $ queryBuilder -> andWhere ( sprintf ( 'collectionType.key != \'%s\'' , SystemCollectionManagerInterface :: COLLECTION_TYPE ) ) ; } if ( ! empty ( $ types ) ) { $ queryBuilder -> innerJoin ( 'media.type' , 'type' ) ; $ queryBuilder -> andWhere ( 'type.name IN (:types)' ) ; $ queryBuilder -> setParameter ( 'types' , $ types ) ; } if ( ! empty ( $ search ) ) { $ queryBuilder -> innerJoin ( 'media.files' , 'file' ) -> innerJoin ( 'file.fileVersions' , 'fileVersion' , 'WITH' , 'fileVersion.version = file.version' ) -> leftJoin ( 'fileVersion.meta' , 'fileVersionMeta' ) ; $ queryBuilder -> andWhere ( 'fileVersionMeta.title LIKE :search' ) ; $ queryBuilder -> setParameter ( 'search' , '%' . $ search . '%' ) ; } if ( $ offset ) { $ queryBuilder -> setFirstResult ( $ offset ) ; } if ( $ limit ) { $ queryBuilder -> setMaxResults ( $ limit ) ; } if ( ! empty ( $ orderBy ) ) { $ queryBuilder -> addOrderBy ( $ orderBy , $ orderSort ) ; } return $ queryBuilder -> getQuery ( ) ; }
create a query for ids with given filter .
11,744
private function getIds ( $ collection = null , $ systemCollections = true , $ types = null , $ search = null , $ orderBy = null , $ orderSort = null , $ limit = null , $ offset = null ) { $ subQuery = $ this -> getIdsQuery ( $ collection , $ systemCollections , $ types , $ search , $ orderBy , $ orderSort , $ limit , $ offset ) ; return $ subQuery -> getScalarResult ( ) ; }
returns ids with given filters .
11,745
private function outputWebspace ( Webspace $ webspace ) { $ this -> output -> writeln ( sprintf ( '<info>%s</info> - <info>%s</info>' , $ webspace -> getKey ( ) , $ webspace -> getName ( ) ) ) ; $ this -> outputWebspaceDefaultTemplates ( $ webspace ) ; $ this -> outputWebspacePageTemplates ( $ webspace ) ; $ this -> outputWebspaceTemplates ( $ webspace ) ; $ this -> outputWebspaceLocalizations ( $ webspace ) ; }
Output webspace .
11,746
private function outputWebspacePageTemplates ( Webspace $ webspace ) { $ this -> output -> writeln ( 'Page Templates:' ) ; $ structures = $ this -> structureManager -> getStructures ( ) ; $ checkedTemplates = [ ] ; foreach ( $ webspace -> getDefaultTemplates ( ) as $ template ) { $ checkedTemplates [ ] = $ template ; } foreach ( $ structures as $ structure ) { $ template = $ structure -> getKey ( ) ; if ( ! $ structure -> getInternal ( ) && ! in_array ( $ template , $ checkedTemplates ) ) { $ this -> validatePageTemplate ( 'page' , $ structure -> getKey ( ) ) ; } } }
Output webspace page templates .
11,747
private function outputWebspaceLocalizations ( Webspace $ webspace ) { $ this -> output -> writeln ( 'Localizations:' ) ; foreach ( $ webspace -> getAllLocalizations ( ) as $ localization ) { $ this -> output -> writeln ( sprintf ( ' %s' , $ localization -> getLocale ( ) ) ) ; } }
Output webspace localizations .
11,748
private function validatePageTemplate ( $ type , $ template ) { $ status = '<info>ok</info>' ; try { $ this -> validateStructure ( $ type , $ template ) ; } catch ( \ Exception $ e ) { $ status = sprintf ( '<error>failed: %s</error>' , $ e -> getMessage ( ) ) ; $ this -> errors [ ] = $ e -> getMessage ( ) ; } $ this -> output -> writeln ( sprintf ( ' %s: %s -> %s' , $ type , $ template , $ status ) ) ; }
Validate page templates .
11,749
private function validateStructure ( $ type , $ template ) { $ valid = true ; $ metadata = $ this -> structureMetadataFactory -> getStructureMetadata ( $ type , $ template ) ; if ( ! $ metadata ) { throw new \ RuntimeException ( sprintf ( 'Structure meta data not found for type "%s" and template "%s".' , $ type , $ template ) ) ; } foreach ( [ 'title' , 'url' ] as $ property ) { if ( ! $ metadata -> hasProperty ( $ property ) ) { throw new \ RuntimeException ( sprintf ( 'No property "%s" found in "%s" template.' , $ property , $ metadata -> getName ( ) ) ) ; } } $ this -> validateTwigTemplate ( $ metadata -> getView ( ) . '.html.twig' ) ; $ this -> validateControllerAction ( $ metadata -> getController ( ) ) ; return $ valid ; }
Is template valid .
11,750
private function validateTemplate ( $ type , $ template ) { $ status = '<info>ok</info>' ; try { $ this -> validateTwigTemplate ( $ template ) ; } catch ( \ Exception $ e ) { $ status = sprintf ( '<error>failed: %s</error>' , $ e -> getMessage ( ) ) ; $ this -> errors [ ] = $ e -> getMessage ( ) ; } $ this -> output -> writeln ( sprintf ( ' %s: %s -> %s' , $ type , $ template , $ status ) ) ; }
Validate template .
11,751
private function validateTwigTemplate ( $ template ) { $ loader = $ this -> twig -> getLoader ( ) ; if ( ! $ loader -> exists ( $ template ) ) { throw new \ Exception ( sprintf ( 'Unable to find template "%s".' , $ template ) ) ; } }
Validate twig template .
11,752
private function validateControllerAction ( $ controllerAction ) { $ result = $ this -> controllerNameConverter -> parse ( $ controllerAction ) ; list ( $ class , $ method ) = explode ( '::' , $ result ) ; if ( ! method_exists ( $ class , $ method ) ) { $ reflector = new \ ReflectionClass ( $ class ) ; throw new \ Exception ( sprintf ( 'Controller Action "%s" not exist in "%s" (looked into: %s).' , $ method , $ class , $ reflector -> getFileName ( ) ) ) ; } }
Validate controller action .
11,753
public function cgetAction ( $ categoryId , Request $ request ) { $ restHelper = $ this -> get ( 'sulu_core.doctrine_rest_helper' ) ; $ factory = $ this -> get ( 'sulu_core.doctrine_list_builder_factory' ) ; $ category = $ this -> getCategoryRepository ( ) -> find ( $ categoryId ) ; $ fieldDescriptor = $ this -> getFieldDescriptors ( ) ; $ listBuilder = $ factory -> create ( $ this -> getParameter ( 'sulu.model.keyword.class' ) ) ; $ restHelper -> initializeListBuilder ( $ listBuilder , $ fieldDescriptor ) ; $ listBuilder -> where ( $ fieldDescriptor [ 'locale' ] , $ request -> get ( 'locale' ) ) ; $ listBuilder -> where ( $ fieldDescriptor [ 'categoryTranslationIds' ] , $ category -> findTranslationByLocale ( $ request -> get ( 'locale' ) ) ) ; $ listBuilder -> distinct ( true ) ; $ listBuilder -> addGroupBy ( $ fieldDescriptor [ 'id' ] ) ; $ listResponse = $ listBuilder -> execute ( ) ; $ list = new ListRepresentation ( $ listResponse , self :: $ entityKey , 'get_category_keywords' , array_merge ( [ 'categoryId' => $ categoryId ] , $ request -> query -> all ( ) ) , $ listBuilder -> getCurrentPage ( ) , $ listBuilder -> getLimit ( ) , $ listBuilder -> count ( ) ) ; return $ this -> handleView ( $ this -> view ( $ list , 200 ) ) ; }
Returns list of keywords filtered by the category .
11,754
public function postAction ( $ categoryId , Request $ request ) { $ keyword = $ this -> getKeywordRepository ( ) -> createNew ( ) ; $ category = $ this -> getCategoryRepository ( ) -> findCategoryById ( $ categoryId ) ; $ keyword -> setKeyword ( $ request -> get ( 'keyword' ) ) ; $ keyword -> setLocale ( $ request -> get ( 'locale' ) ) ; $ keyword = $ this -> getKeywordManager ( ) -> save ( $ keyword , $ category ) ; $ this -> getEntityManager ( ) -> persist ( $ keyword ) ; $ this -> getEntityManager ( ) -> flush ( ) ; return $ this -> handleView ( $ this -> view ( $ keyword ) ) ; }
Creates new keyword for given category .
11,755
public function putAction ( $ categoryId , $ keywordId , Request $ request ) { $ keyword = $ this -> getKeywordRepository ( ) -> findById ( $ keywordId ) ; if ( ! $ keyword ) { return $ this -> handleView ( $ this -> view ( null , 404 ) ) ; } $ force = $ request -> get ( 'force' ) ; $ category = $ this -> getCategoryRepository ( ) -> findCategoryById ( $ categoryId ) ; $ keyword -> setKeyword ( $ request -> get ( 'keyword' ) ) ; $ keyword = $ this -> getKeywordManager ( ) -> save ( $ keyword , $ category , $ force ) ; $ this -> getEntityManager ( ) -> persist ( $ keyword ) ; $ this -> getEntityManager ( ) -> flush ( ) ; return $ this -> handleView ( $ this -> view ( $ keyword ) ) ; }
Updates given keyword for given category .
11,756
public function postAction ( Request $ request ) { $ name = $ request -> get ( 'title' ) ; try { if ( null == $ name ) { throw new RestException ( 'There is no title-name for the given title' ) ; } $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ title = new ContactTitle ( ) ; $ title -> setTitle ( $ name ) ; $ em -> persist ( $ title ) ; $ em -> flush ( ) ; $ view = $ this -> view ( $ title , 200 ) ; } catch ( EntityNotFoundException $ enfe ) { $ view = $ this -> view ( $ enfe -> toArray ( ) , 404 ) ; } catch ( RestException $ re ) { $ view = $ this -> view ( $ re -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; }
Creates a new contact title .
11,757
public function putAction ( Request $ request , $ id ) { try { $ title = $ this -> getDoctrine ( ) -> getRepository ( self :: $ entityName ) -> find ( $ id ) ; if ( ! $ title ) { throw new EntityNotFoundException ( self :: $ entityName , $ id ) ; } else { $ name = $ request -> get ( 'title' ) ; if ( empty ( $ name ) ) { throw new RestException ( 'There is no title-name for the given title' ) ; } else { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ title -> setTitle ( $ name ) ; $ em -> flush ( ) ; $ view = $ this -> view ( $ title , 200 ) ; } } } catch ( EntityNotFoundException $ enfe ) { $ view = $ this -> view ( $ enfe -> toArray ( ) , 404 ) ; } catch ( RestException $ exc ) { $ view = $ this -> view ( $ exc -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; }
Edits the existing contact title for the given id .
11,758
public function deleteAction ( $ id ) { try { $ delete = function ( $ id ) { $ title = $ this -> getDoctrine ( ) -> getRepository ( self :: $ entityName ) -> find ( $ id ) ; if ( ! $ title ) { throw new EntityNotFoundException ( self :: $ entityName , $ id ) ; } $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> remove ( $ title ) ; $ em -> flush ( ) ; } ; $ view = $ this -> responseDelete ( $ id , $ delete ) ; } catch ( EntityNotFoundException $ enfe ) { $ view = $ this -> view ( $ enfe -> toArray ( ) , 404 ) ; } return $ this -> handleView ( $ view ) ; }
Delete a contact title for the given id .
11,759
public function cpatchAction ( Request $ request ) { try { $ data = [ ] ; $ i = 0 ; while ( $ item = $ request -> get ( $ i ) ) { if ( ! isset ( $ item [ 'title' ] ) ) { throw new RestException ( 'There is no title-name for the given title' ) ; } $ data [ ] = $ this -> addAndUpdateTitles ( $ item ) ; ++ $ i ; } $ this -> getDoctrine ( ) -> getManager ( ) -> flush ( ) ; $ view = $ this -> view ( $ data , 200 ) ; } catch ( EntityNotFoundException $ enfe ) { $ view = $ this -> view ( $ enfe -> toArray ( ) , 404 ) ; } catch ( RestException $ exc ) { $ view = $ this -> view ( $ exc -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; }
Add or update a bunch of contact titles .
11,760
protected function getRootRouteNode ( $ webspaceKey , $ locale , $ segment ) { return $ this -> documentManager -> find ( $ this -> sessionManager -> getRoutePath ( $ webspaceKey , $ locale , $ segment ) ) ; }
Return the node in the content repository which contains all of the routes .
11,761
private function getFieldData ( $ field , Row $ row , NodeInterface $ node , $ document , $ templateKey , $ webspaceKey , $ locale ) { if ( isset ( $ field [ 'column' ] ) ) { return $ row -> getValue ( $ field [ 'column' ] ) ; } elseif ( isset ( $ field [ 'extension' ] ) ) { return $ this -> getExtensionData ( $ node , $ field [ 'extension' ] , $ field [ 'property' ] , $ webspaceKey , $ locale ) ; } elseif ( isset ( $ field [ 'property' ] ) && ( ! isset ( $ field [ 'templateKey' ] ) || $ field [ 'templateKey' ] === $ templateKey ) ) { return $ this -> getPropertyData ( $ document , $ field [ 'property' ] ) ; } return ; }
Return data for one field .
11,762
private function getPropertyData ( $ document , LegacyProperty $ property ) { return $ document -> getStructure ( ) -> getContentViewProperty ( $ property -> getName ( ) ) -> getValue ( ) ; }
Returns data for property .
11,763
private function getExtensionData ( NodeInterface $ node , ExtensionInterface $ extension , $ propertyName , $ webspaceKey , $ locale ) { if ( ! $ this -> extensionDataCache -> contains ( $ extension -> getName ( ) ) ) { $ this -> extensionDataCache -> save ( $ extension -> getName ( ) , $ this -> loadExtensionData ( $ node , $ extension , $ webspaceKey , $ locale ) ) ; } $ data = $ this -> extensionDataCache -> fetch ( $ extension -> getName ( ) ) ; return isset ( $ data [ $ propertyName ] ) ? $ data [ $ propertyName ] : null ; }
Returns data for extension and property name .
11,764
private function loadExtensionData ( NodeInterface $ node , ExtensionInterface $ extension , $ webspaceKey , $ locale ) { $ extension -> setLanguageCode ( $ locale , $ this -> namespaceRegistry -> getPrefix ( 'extension_localized' ) , '' ) ; $ data = $ extension -> load ( $ node , $ webspaceKey , $ locale ) ; return $ extension -> getContentData ( $ data ) ; }
load data from extension .
11,765
public function onPostSerialize ( ObjectEvent $ event ) { $ document = $ event -> getObject ( ) ; if ( ! ( $ document instanceof SecurityBehavior && $ document instanceof LocaleBehavior && $ document instanceof WebspaceBehavior && null !== $ this -> tokenStorage && null !== $ this -> tokenStorage -> getToken ( ) && $ this -> tokenStorage -> getToken ( ) -> getUser ( ) instanceof UserInterface ) ) { return ; } $ visitor = $ event -> getVisitor ( ) ; $ visitor -> addData ( '_permissions' , $ this -> accessControlManager -> getUserPermissionByArray ( $ document -> getLocale ( ) , PageAdmin :: SECURITY_CONTEXT_PREFIX . $ document -> getWebspaceName ( ) , $ document -> getPermissions ( ) , $ this -> tokenStorage -> getToken ( ) -> getUser ( ) ) ) ; }
Adds the permissions for the current user to the serialization .
11,766
public function setFileVersion ( \ Sulu \ Bundle \ MediaBundle \ Entity \ FileVersion $ fileVersion = null ) { $ this -> fileVersion = $ fileVersion ; return $ this ; }
Set fileVersion .
11,767
private function findInitialWrongDepthGap ( ) { $ qb = $ this -> accountRepository -> createQueryBuilder ( 'c2' ) -> select ( 'count(c2.id) as results' ) -> join ( 'c2.parent' , 'c1' ) -> where ( '(c2.depth - 1) <> c1.depth' ) ; $ depthGapResult = $ qb -> getQuery ( ) -> getSingleScalarResult ( ) ; return $ depthGapResult ; }
Find number of nodes where difference to parents depth > 1 .
11,768
private function findNodesWithoutParents ( ) { $ qb = $ this -> accountRepository -> createQueryBuilder ( 'c2' ) -> select ( 'count(c2.id)' ) -> leftJoin ( 'c2.parent' , 'c1' ) -> where ( 'c2.depth <> 0 AND c2.parent IS NULL' ) ; return $ qb -> getQuery ( ) -> getSingleScalarResult ( ) ; }
Find number of nodes that have no parent but depth > 0 .
11,769
private function fixNodesWithoutParents ( ) { $ qb = $ this -> accountRepository -> createQueryBuilder ( 'c2' ) -> update ( ) -> set ( 'c2.depth' , 0 ) -> where ( 'c2.parent IS NULL AND depth != 0' ) ; $ qb -> getQuery ( ) -> execute ( ) ; }
Set every node where depth > 0 and has no parents to depth 0 .
11,770
public function onPostSerialize ( ObjectEvent $ event ) { $ visitor = $ event -> getVisitor ( ) ; $ document = $ event -> getObject ( ) ; if ( ! $ document instanceof ParentBehavior || ! $ document -> getParent ( ) instanceof UuidBehavior ) { return ; } $ visitor -> addData ( 'parentUuid' , $ document -> getParent ( ) -> getUuid ( ) ) ; }
Adds the identifier of the parent document to the serialization .
11,771
private function setNodePropertyForSession ( SessionInterface $ session , $ nodePath , $ propertyName , $ value ) { $ session -> getNode ( $ nodePath ) -> setProperty ( $ propertyName , $ value ) ; }
Sets the property of the node at the given path to the given value . The change is only applied to the given session .
11,772
private function getFileVersionForMedia ( MediaInterface $ media ) { $ file = $ media -> getFiles ( ) -> get ( 0 ) ; if ( ! isset ( $ file ) ) { throw new FileVersionNotFoundException ( $ media -> getId ( ) , 'latest' ) ; } $ fileVersion = $ file -> getLatestFileVersion ( ) ; if ( ! isset ( $ fileVersion ) ) { throw new FileVersionNotFoundException ( $ media -> getId ( ) , 'latest' ) ; } return $ fileVersion ; }
Gets the latest file - version of a given media .
11,773
private function setDataOnEntity ( FormatOptions $ formatOptions , array $ data ) { if ( ! isset ( $ data [ 'cropX' ] ) || ! isset ( $ data [ 'cropY' ] ) || ! isset ( $ data [ 'cropWidth' ] ) || ! isset ( $ data [ 'cropHeight' ] ) ) { throw new FormatOptionsMissingParameterException ( ) ; } $ formatOptions -> setCropX ( $ data [ 'cropX' ] ) ; $ formatOptions -> setCropY ( $ data [ 'cropY' ] ) ; $ formatOptions -> setCropWidth ( $ data [ 'cropWidth' ] ) ; $ formatOptions -> setCropHeight ( $ data [ 'cropHeight' ] ) ; return $ formatOptions ; }
Sets a given array of data onto a given format - options entity .
11,774
private function entityToArray ( FormatOptions $ formatOptions ) { return [ 'cropX' => $ formatOptions -> getCropX ( ) , 'cropY' => $ formatOptions -> getCropY ( ) , 'cropWidth' => $ formatOptions -> getCropWidth ( ) , 'cropHeight' => $ formatOptions -> getCropHeight ( ) , ] ; }
Converts a given entity to its array representation .
11,775
private function purgeMedia ( $ mediaId , FileVersion $ fileVersion ) { $ this -> formatManager -> purge ( $ mediaId , $ fileVersion -> getName ( ) , $ fileVersion -> getMimeType ( ) , $ fileVersion -> getStorageOptions ( ) ) ; }
Purges a file - version of a media with a given id .
11,776
private function findUrlBlockProperties ( BlockMetadata $ property , $ structureName , array & $ properties ) { foreach ( $ property -> getComponents ( ) as $ component ) { foreach ( $ component -> getChildren ( ) as $ childProperty ) { if ( 'url' === $ childProperty -> getType ( ) ) { $ properties [ $ structureName ] [ ] = $ property -> getName ( ) ; } } } }
Adds the block property to the list if it contains a URL field .
11,777
public function getAction ( Request $ request , $ id ) { $ locale = $ this -> getRequestParameter ( $ request , 'locale' , true ) ; $ view = $ this -> responseGetById ( $ id , function ( $ id ) use ( $ locale ) { return $ this -> getManager ( ) -> findByIdAndLocale ( $ id , $ locale ) ; } ) ; return $ this -> handleView ( $ view ) ; }
Retrieves a filter by id .
11,778
public function cgetAction ( Request $ request ) { try { $ context = $ request -> get ( 'context' ) ; if ( ! $ this -> getManager ( ) -> hasContext ( $ context ) ) { throw new UnknownContextException ( $ context ) ; } if ( ! $ this -> getManager ( ) -> isFeatureEnabled ( $ context , 'filters' ) ) { throw new MissingFeatureException ( $ context , 'filters' ) ; } if ( 'true' == $ request -> get ( 'flat' ) ) { $ list = $ this -> getListRepresentation ( $ request ) ; } else { $ list = new CollectionRepresentation ( $ this -> getManager ( ) -> findFiltersForUserAndContext ( $ context , $ this -> getUser ( ) -> getId ( ) , $ this -> getRequestParameter ( $ request , 'locale' , true ) ) , self :: $ entityKey ) ; } $ view = $ this -> view ( $ list , 200 ) ; } catch ( UnknownContextException $ exc ) { $ exception = new RestException ( $ exc -> getMessage ( ) ) ; $ view = $ this -> view ( $ exception -> toArray ( ) , 400 ) ; } catch ( MissingFeatureException $ exc ) { $ exception = new RestException ( $ exc -> getMessage ( ) ) ; $ view = $ this -> view ( $ exception -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; }
Returns a list of filters .
11,779
public function postAction ( Request $ request ) { try { $ filter = $ this -> getManager ( ) -> save ( $ request -> request -> all ( ) , $ this -> getRequestParameter ( $ request , 'locale' , true ) , $ this -> getUser ( ) -> getId ( ) ) ; $ view = $ this -> view ( $ filter , 200 ) ; } catch ( FilterDependencyNotFoundException $ e ) { $ exception = new EntityNotFoundException ( $ e -> getEntityName ( ) , $ e -> getId ( ) ) ; $ view = $ this -> view ( $ exception -> toArray ( ) , 400 ) ; } catch ( MissingFilterException $ e ) { $ exception = new MissingArgumentException ( self :: $ entityName , $ e -> getFilter ( ) ) ; $ view = $ this -> view ( $ exception -> toArray ( ) , 400 ) ; } catch ( MissingFilterAttributeException $ e ) { $ exception = new MissingArgumentException ( self :: $ entityName , $ e -> getAttribute ( ) ) ; $ view = $ this -> view ( $ exception -> toArray ( ) , 400 ) ; } catch ( ConditionGroupMismatchException $ e ) { $ exception = new InvalidArgumentException ( self :: $ groupConditionEntityName , $ e -> getId ( ) ) ; $ view = $ this -> view ( $ exception -> toArray ( ) , 400 ) ; } catch ( UnknownContextException $ e ) { $ exception = new RestException ( $ e -> getMessage ( ) ) ; $ view = $ this -> view ( $ exception -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; }
Creates and stores a new filter .
11,780
public function fieldsAction ( Request $ request ) { $ locale = $ this -> getRequestParameter ( $ request , 'locale' , true ) ; return $ this -> handleView ( $ this -> view ( array_values ( $ this -> getManager ( ) -> getFieldDescriptors ( $ locale ) ) , 200 ) ) ; }
returns all fields that can be used by list .
11,781
public function getAction ( $ id ) { return $ this -> handleView ( $ this -> view ( $ this -> get ( 'sulu_contact.country_repository' ) -> find ( $ id ) ) ) ; }
Returns country identified by code .
11,782
public function invalidateDocumentBeforeUnpublishing ( UnpublishEvent $ event ) { $ document = $ event -> getDocument ( ) ; if ( $ document instanceof StructureBehavior ) { $ this -> invalidateDocumentStructure ( $ document ) ; } if ( $ document instanceof ResourceSegmentBehavior && $ document instanceof WorkflowStageBehavior && $ document -> getPublished ( ) ) { $ this -> invalidateDocumentUrls ( $ document , $ this -> documentInspector -> getLocale ( $ document ) ) ; } }
Invalidates the assigned structure and all urls in the locale of the document when a document gets unpublished . This method is executed before the actual unpublishing of the document because the document must still be published to gather the urls of the document .
11,783
public function invalidateDocumentBeforeRemoving ( RemoveEvent $ event ) { $ document = $ event -> getDocument ( ) ; if ( $ document instanceof StructureBehavior ) { $ this -> invalidateDocumentStructure ( $ document ) ; } if ( $ document instanceof ResourceSegmentBehavior ) { foreach ( $ this -> documentInspector -> getPublishedLocales ( $ document ) as $ locale ) { $ this -> invalidateDocumentUrls ( $ document , $ locale ) ; } } }
Invalidates the assigned structure and all urls in all locales of the document when a document gets removed . This method is executed before the actual removing of the document because the document must still exist to gather the urls of the document .
11,784
private function invalidateDocumentStructure ( $ document ) { if ( ! $ this -> cacheManager ) { return ; } $ structureBridge = $ this -> structureManager -> wrapStructure ( $ this -> documentInspector -> getMetadata ( $ document ) -> getAlias ( ) , $ this -> documentInspector -> getStructureMetadata ( $ document ) ) ; $ structureBridge -> setDocument ( $ document ) ; $ this -> cacheManager -> invalidateTag ( $ document -> getUuid ( ) ) ; }
Invalidates the structure of the given document .
11,785
private function invalidateDocumentUrls ( $ document , $ locale ) { if ( ! $ this -> cacheManager ) { return ; } foreach ( $ this -> getLocaleUrls ( $ document , $ locale ) as $ url ) { $ this -> cacheManager -> invalidatePath ( $ url ) ; } }
Invalidates all urls which are assigned to the given document in the given locale .
11,786
private function invalidateDocumentExcerpt ( ExtensionBehavior $ document ) { if ( ! $ this -> cacheManager ) { return ; } $ extensionData = $ document -> getExtensionsData ( ) ; if ( ! isset ( $ extensionData [ 'excerpt' ] ) ) { return ; } $ excerpt = $ extensionData [ 'excerpt' ] ; if ( isset ( $ excerpt [ 'tags' ] ) ) { foreach ( $ this -> tagManager -> resolveTagNames ( $ excerpt [ 'tags' ] ) as $ tag ) { $ this -> cacheManager -> invalidateReference ( 'tag' , $ tag ) ; } } if ( isset ( $ excerpt [ 'categories' ] ) ) { foreach ( $ excerpt [ 'categories' ] as $ category ) { $ this -> cacheManager -> invalidateReference ( 'category' , $ category ) ; } } }
Invalidates all tags and categories from excerpt extension .
11,787
private function findUrlsByResourceLocator ( $ resourceLocator , $ locale , $ webspace ) { $ scheme = 'http' ; if ( $ request = $ this -> requestStack -> getCurrentRequest ( ) ) { $ scheme = $ request -> getScheme ( ) ; } return $ this -> webspaceManager -> findUrlsByResourceLocator ( $ resourceLocator , $ this -> environment , $ locale , $ webspace , null , $ scheme ) ; }
Returns array of resource - locators with http and https .
11,788
public function getByIds ( $ ids , $ locale ) { if ( ! is_array ( $ ids ) || 0 === count ( $ ids ) ) { return [ ] ; } $ contacts = $ this -> contactRepository -> findByIds ( $ ids ) ; return array_map ( function ( $ contact ) use ( $ locale ) { return $ this -> getApiObject ( $ contact , $ locale ) ; } , $ contacts ) ; }
Returns contact entities by ids .
11,789
public function addAddress ( $ contact , Address $ address , $ isMain ) { if ( ! $ contact || ! $ address ) { throw new \ Exception ( 'Contact and Address cannot be null' ) ; } $ contactAddress = new ContactAddress ( ) ; $ contactAddress -> setContact ( $ contact ) ; $ contactAddress -> setAddress ( $ address ) ; if ( $ isMain ) { $ this -> unsetMain ( $ contact -> getContactAddresses ( ) ) ; } $ contactAddress -> setMain ( $ isMain ) ; $ this -> em -> persist ( $ contactAddress ) ; $ contact -> addContactAddress ( $ contactAddress ) ; return $ contactAddress ; }
adds an address to the entity .
11,790
public function removeAddressRelation ( $ contact , $ contactAddress ) { if ( ! $ contact || ! $ contactAddress ) { throw new \ Exception ( 'Contact and ContactAddress cannot be null' ) ; } $ address = $ contactAddress -> getAddress ( ) ; $ address = $ this -> em -> getRepository ( 'SuluContactBundle:Address' ) -> findById ( $ address -> getId ( ) ) ; $ isMain = $ contactAddress -> getMain ( ) ; $ contact -> removeContactAddress ( $ contactAddress ) ; $ address -> removeContactAddress ( $ contactAddress ) ; if ( $ isMain ) { $ this -> setMainForCollection ( $ contact -> getContactAddresses ( ) ) ; } if ( ! $ address -> hasRelations ( ) ) { $ this -> em -> remove ( $ address ) ; } $ this -> em -> remove ( $ contactAddress ) ; }
removes the address relation from a contact and also deletes the address if it has no more relations .
11,791
private function setAvatar ( Contact $ contact , $ avatar ) { $ mediaEntity = null ; if ( is_array ( $ avatar ) && $ this -> getProperty ( $ avatar , 'id' ) ) { $ mediaId = $ this -> getProperty ( $ avatar , 'id' ) ; $ mediaEntity = $ this -> mediaRepository -> findMediaById ( $ mediaId ) ; if ( ! $ mediaEntity ) { throw new EntityNotFoundException ( $ this -> mediaRepository -> getClassName ( ) , $ mediaId ) ; } } $ contact -> setAvatar ( $ mediaEntity ) ; }
Sets a media with a given id as the avatar of a given contact .
11,792
protected function getApiObject ( $ contact , $ locale ) { $ apiObject = new ContactApi ( $ contact , $ locale ) ; if ( $ contact -> getAvatar ( ) ) { $ apiAvatar = $ this -> mediaManager -> getById ( $ contact -> getAvatar ( ) -> getId ( ) , $ locale ) ; $ apiObject -> setAvatar ( $ apiAvatar ) ; } return $ apiObject ; }
Takes a contact entity and a locale and returns the api object .
11,793
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' ) ; $ listBuilder = $ factory -> create ( static :: $ entityName ) ; $ restHelper -> initializeListBuilder ( $ listBuilder , $ this -> fieldDescriptors ) ; $ list = new ListRepresentation ( $ listBuilder -> execute ( ) , static :: $ entityKey , 'get_groups' , $ request -> query -> all ( ) , $ listBuilder -> getCurrentPage ( ) , $ listBuilder -> getLimit ( ) , $ listBuilder -> count ( ) ) ; } else { $ list = new CollectionRepresentation ( $ this -> getDoctrine ( ) -> getRepository ( static :: $ entityName ) -> findAllGroups ( ) , static :: $ entityKey ) ; } $ view = $ this -> view ( $ list , 200 ) ; return $ this -> handleView ( $ view ) ; }
returns all groups .
11,794
public function getAction ( $ id ) { $ find = function ( $ id ) { $ group = $ this -> getDoctrine ( ) -> getRepository ( static :: $ entityName ) -> findGroupById ( $ id ) ; return $ group ; } ; $ view = $ this -> responseGetById ( $ id , $ find ) ; return $ this -> handleView ( $ view ) ; }
Returns the group with the given id .
11,795
public function postAction ( Request $ request ) { $ name = $ request -> get ( 'name' ) ; if ( null != $ name ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ group = new Group ( ) ; $ group -> setName ( $ name ) ; $ this -> setParent ( $ group , $ request ) ; $ roles = $ request -> get ( 'roles' ) ; if ( ! empty ( $ roles ) ) { foreach ( $ roles as $ roleData ) { $ this -> addRole ( $ group , $ roleData ) ; } } $ em -> persist ( $ group ) ; $ em -> flush ( ) ; $ view = $ this -> view ( $ group , 200 ) ; } else { $ view = $ this -> view ( null , 400 ) ; } return $ this -> handleView ( $ view ) ; }
Creates a new group with the given data .
11,796
public function putAction ( Request $ request , $ id ) { $ group = $ this -> getDoctrine ( ) -> getRepository ( static :: $ entityName ) -> findGroupById ( $ id ) ; try { if ( ! $ group ) { throw new EntityNotFoundException ( static :: $ entityName , $ id ) ; } else { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ name = $ request -> get ( 'name' ) ; $ group -> setName ( $ name ) ; $ this -> setParent ( $ group , $ request ) ; if ( ! $ this -> processRoles ( $ group , $ request -> get ( 'roles' , [ ] ) ) ) { throw new RestException ( 'Could not update dependencies!' ) ; } $ em -> flush ( ) ; $ view = $ this -> view ( $ group , 200 ) ; } } catch ( EntityNotFoundException $ enfe ) { $ view = $ this -> view ( $ enfe -> toArray ( ) , 404 ) ; } catch ( RestException $ re ) { $ view = $ this -> view ( $ re -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; }
Updates the group with the given id and the data given by the request .
11,797
protected function processRoles ( Group $ group , $ roles ) { $ restHelper = $ this -> get ( 'sulu_core.doctrine_rest_helper' ) ; $ get = function ( $ entity ) { return $ entity -> getId ( ) ; } ; $ delete = function ( $ role ) { $ this -> getDoctrine ( ) -> getManager ( ) -> remove ( $ role ) ; } ; $ update = function ( $ role , $ roleData ) { return $ this -> updateRole ( $ role , $ roleData ) ; } ; $ add = function ( $ role ) use ( $ group ) { return $ this -> addRole ( $ group , $ role ) ; } ; return $ restHelper -> processSubEntities ( $ group -> getRoles ( ) , $ roles , $ get , $ add , $ update , $ delete ) ; }
Process all roles from request .
11,798
public function deleteAction ( $ id ) { $ delete = function ( $ id ) { $ group = $ this -> getDoctrine ( ) -> getRepository ( static :: $ entityName ) -> findGroupById ( $ id ) ; if ( ! $ group ) { throw new EntityNotFoundException ( static :: $ entityName , $ id ) ; } $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> remove ( $ group ) ; $ em -> flush ( ) ; } ; $ view = $ this -> responseDelete ( $ id , $ delete ) ; return $ this -> handleView ( $ view ) ; }
Deletes the group with the given id .
11,799
private function addRole ( Group $ group , $ roleData ) { if ( isset ( $ roleData [ 'id' ] ) ) { $ role = $ this -> get ( 'sulu.repository.role' ) -> findRoleById ( $ roleData [ 'id' ] ) ; if ( ! $ role ) { throw new EntityNotFoundException ( $ this -> get ( 'sulu.repository.role' ) -> getClassName ( ) , $ roleData [ 'id' ] ) ; } if ( ! $ group -> getRoles ( ) -> contains ( $ role ) ) { $ group -> addRole ( $ role ) ; } } return true ; }
Adds the given role to the group .