idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
11,100 | public function delete ( $ id ) { $ tag = $ this -> tagRepository -> findTagById ( $ id ) ; if ( ! $ tag ) { throw new TagNotFoundException ( $ id ) ; } $ this -> em -> remove ( $ tag ) ; $ this -> em -> flush ( ) ; $ event = new TagDeleteEvent ( $ tag ) ; $ this -> eventDispatcher -> dispatch ( TagEvents :: TAG_DELETE , $ event ) ; } | Deletes the given Tag . |
11,101 | public function merge ( $ srcTagIds , $ destTagId ) { $ srcTags = [ ] ; $ destTag = $ this -> tagRepository -> findTagById ( $ destTagId ) ; if ( ! $ destTag ) { throw new TagNotFoundException ( $ destTagId ) ; } foreach ( $ srcTagIds as $ srcTagId ) { $ srcTag = $ this -> tagRepository -> findTagById ( $ srcTagId ) ; if ( ! $ srcTag ) { throw new TagNotFoundException ( $ srcTagId ) ; } $ this -> em -> remove ( $ srcTag ) ; $ srcTags [ ] = $ srcTag ; } $ this -> em -> flush ( ) ; $ event = new TagMergeEvent ( $ srcTags , $ destTag ) ; $ this -> eventDispatcher -> dispatch ( TagEvents :: TAG_MERGE , $ event ) ; return $ destTag ; } | Merges the source tag into the destination tag . The source tag will be deleted . |
11,102 | public function resolveTagIds ( $ tagIds ) { $ resolvedTags = [ ] ; foreach ( $ tagIds as $ tagId ) { $ tag = $ this -> findById ( $ tagId ) ; if ( null !== $ tag ) { $ resolvedTags [ ] = $ tag -> getName ( ) ; } } return $ resolvedTags ; } | Resolves tag ids to names . |
11,103 | public function resolveTagNames ( $ tagNames ) { $ resolvedTags = [ ] ; foreach ( $ tagNames as $ tagName ) { $ tag = $ this -> findByName ( $ tagName ) ; if ( null !== $ tag ) { $ resolvedTags [ ] = $ tag -> getId ( ) ; } } return $ resolvedTags ; } | Resolves tag names to ids . |
11,104 | public function createSelfLink ( ) { if ( is_null ( $ this -> getApiPath ( ) ) ) { $ class = explode ( '\\' , get_class ( $ this ) ) ; $ plural = Inflector :: pluralize ( strtolower ( end ( $ class ) ) ) ; $ this -> apiPath = $ this -> apiBasePath . '/' . $ plural ; } $ idPath = '' ; if ( $ this -> getId ( ) ) { $ idPath = '/' . $ this -> getId ( ) ; } $ this -> _links = [ 'self' => $ this -> getApiPath ( ) . $ idPath , ] ; } | creates the _links array including the self path . |
11,105 | public function getProperty ( $ name ) { foreach ( $ this -> getChildProperties ( ) as $ property ) { if ( $ property -> getName ( ) === $ name ) { return $ property ; } } return ; } | returns child property with given name . |
11,106 | public function getChild ( $ name ) { foreach ( $ this -> childProperties as $ child ) { if ( $ child -> getName ( ) === $ name ) { return $ child ; } } throw new NoSuchPropertyException ( ) ; } | returns property with given name . |
11,107 | public function evaluate ( array $ options ) { $ request = $ this -> requestStack -> getCurrentRequest ( ) ; $ referrer = $ request -> headers -> get ( 'referer' ) ; if ( $ this -> referrerHeader && $ request -> headers -> has ( $ this -> referrerHeader ) ) { $ referrer = $ request -> headers -> get ( $ this -> referrerHeader ) ; } return ( bool ) preg_match ( '/^' . str_replace ( [ '*' , '/' ] , [ '(.*)' , '\/' ] , $ options [ static :: REFERRER ] ) . '$/' , $ referrer ) ; } | Returns a string representation of the evaluation of the rule for the current context . |
11,108 | private function loadFormatsFromFile ( $ path , array & $ formats ) { $ folder = dirname ( $ path ) ; $ file = basename ( $ path ) ; $ locator = new FileLocator ( $ folder ) ; $ xmlLoader10 = new XmlFormatLoader10 ( $ locator ) ; $ xmlLoader11 = new XmlFormatLoader11 ( $ locator ) ; $ xmlLoader10 -> setGlobalOptions ( $ this -> globalOptions ) ; $ xmlLoader11 -> setGlobalOptions ( $ this -> globalOptions ) ; $ resolver = new LoaderResolver ( [ $ xmlLoader10 , $ xmlLoader11 ] ) ; $ loader = new DelegatingLoader ( $ resolver ) ; $ fileFormats = $ loader -> load ( $ file ) ; foreach ( $ fileFormats as $ format ) { if ( array_key_exists ( $ format [ 'key' ] , $ formats ) && $ formats [ $ format [ 'key' ] ] !== $ format ) { throw new InvalidArgumentException ( sprintf ( 'Media format with key "%s" already exists!' , $ format [ 'key' ] ) ) ; } $ formats [ $ format [ 'key' ] ] = $ format ; } } | Adds the image formats from the file at the given path to the given array . |
11,109 | public function cgetAction ( $ webspace , Request $ request ) { $ result = $ this -> get ( 'sulu_custom_urls.manager' ) -> findList ( $ webspace ) ; $ list = new RouteAwareRepresentation ( new CollectionRepresentation ( $ result , self :: $ relationName ) , 'cget_webspace_custom-urls' , array_merge ( $ request -> request -> all ( ) , [ 'webspace' => $ webspace ] ) ) ; return $ this -> handleView ( $ this -> view ( $ list ) ) ; } | Returns a list of custom - urls . |
11,110 | public function getAction ( $ webspace , $ id , Request $ request ) { $ document = $ this -> get ( 'sulu_custom_urls.manager' ) -> find ( $ id ) ; if ( null !== $ document -> getTargetDocument ( ) ) { $ document -> getTargetDocument ( ) -> getTitle ( ) ; } $ view = $ this -> view ( $ document ) ; $ context = new Context ( ) ; $ context -> setGroups ( [ 'defaultCustomUrl' , 'fullRoute' ] ) ; $ view -> setContext ( $ context ) ; return $ this -> handleView ( $ view ) ; } | Returns a single custom - url identified by uuid . |
11,111 | public function postAction ( $ webspace , Request $ request ) { $ document = $ this -> get ( 'sulu_custom_urls.manager' ) -> create ( $ webspace , $ request -> request -> all ( ) , $ this -> getRequestParameter ( $ request , 'targetLocale' , true ) ) ; $ this -> get ( 'sulu_document_manager.document_manager' ) -> flush ( ) ; $ context = new Context ( ) ; $ context -> setGroups ( [ 'defaultCustomUrl' , 'fullRoute' ] ) ; return $ this -> handleView ( $ this -> view ( $ document ) -> setContext ( $ context ) ) ; } | Create a new custom - url object . |
11,112 | public function putAction ( $ webspace , $ id , Request $ request ) { $ manager = $ this -> get ( 'sulu_custom_urls.manager' ) ; $ document = $ manager -> save ( $ id , $ request -> request -> all ( ) ) ; $ this -> get ( 'sulu_document_manager.document_manager' ) -> flush ( ) ; $ context = new Context ( ) ; $ context -> setGroups ( [ 'defaultCustomUrl' , 'fullRoute' ] ) ; return $ this -> handleView ( $ this -> view ( $ document ) -> setContext ( $ context ) ) ; } | Update an existing custom - url object identified by uuid . |
11,113 | public function deleteAction ( $ webspace , $ id ) { $ manager = $ this -> get ( 'sulu_custom_urls.manager' ) ; $ manager -> delete ( $ id ) ; $ this -> get ( 'sulu_document_manager.document_manager' ) -> flush ( ) ; return $ this -> handleView ( $ this -> view ( ) ) ; } | Delete a single custom - url identified by uuid . |
11,114 | public function cdeleteAction ( $ webspace , Request $ request ) { $ ids = array_filter ( explode ( ',' , $ request -> get ( 'ids' , '' ) ) ) ; $ manager = $ this -> get ( 'sulu_custom_urls.manager' ) ; foreach ( $ ids as $ ids ) { $ manager -> delete ( $ ids ) ; } $ this -> get ( 'sulu_document_manager.document_manager' ) -> flush ( ) ; return $ this -> handleView ( $ this -> view ( ) ) ; } | Deletes a list of custom - urls identified by a list of uuids . |
11,115 | public function getParent ( $ document ) { $ parentNode = $ this -> getNode ( $ document ) -> getParent ( ) ; if ( ! $ parentNode ) { return ; } return $ this -> proxyFactory -> createProxyForNode ( $ document , $ parentNode ) ; } | Return the parent document for the given document . |
11,116 | private function getLocalizedMeta ( ) { if ( $ this -> localizedMeta ) { return $ this -> localizedMeta ; } $ metas = $ this -> getFileVersion ( ) -> getMeta ( ) ; $ this -> localizedMeta = $ metas [ 0 ] ; foreach ( $ metas as $ key => $ meta ) { if ( $ meta -> getLocale ( ) == $ this -> locale ) { $ this -> localizedMeta = $ meta ; break ; } } return $ this -> localizedMeta ; } | Searches the meta for the file version in the media locale . Might also return a fallback . |
11,117 | public function addCategory ( CategoryEntity $ category ) { $ fileVersion = $ this -> getFileVersion ( ) ; $ fileVersion -> addCategory ( $ category ) ; return $ this ; } | Adds a category to the entity . |
11,118 | public function getCategories ( ) { $ apiCategories = [ ] ; $ fileVersion = $ this -> getFileVersion ( ) ; $ categories = $ fileVersion -> getCategories ( ) ; return array_map ( function ( CategoryEntity $ category ) { return $ category -> getId ( ) ; } , $ categories -> toArray ( ) ) ; } | Returns the categories of the media . |
11,119 | public function addTargetGroup ( TargetGroupInterface $ targetGroup ) { $ fileVersion = $ this -> getFileVersion ( ) ; $ fileVersion -> addTargetGroup ( $ targetGroup ) ; return $ this ; } | Adds a target group to the entity . |
11,120 | private function dumpWebspace ( Webspace $ webspace ) { foreach ( $ webspace -> getAllLocalizations ( ) as $ localization ) { $ this -> output -> writeln ( sprintf ( ' - %s (%s)' , $ webspace -> getKey ( ) , $ localization -> getLocale ( ) ) ) ; $ this -> dumpPortalInformations ( $ this -> webspaceManager -> findPortalInformationsByWebspaceKeyAndLocale ( $ webspace -> getKey ( ) , $ localization -> getLocale ( ) , $ this -> environment ) ) ; } } | Dump given webspace . |
11,121 | private function dumpPortalInformations ( array $ portalInformations ) { try { foreach ( $ portalInformations as $ portalInformation ) { $ this -> sitemapDumper -> dumpPortalInformation ( $ portalInformation , $ this -> scheme ) ; } } catch ( \ InvalidArgumentException $ exception ) { $ this -> clear ( ) ; throw $ exception ; } } | Dump given portal - informations . |
11,122 | public function addAddress ( $ account , AddressEntity $ address , $ isMain = false ) { if ( ! $ account || ! $ address ) { throw new \ Exception ( 'Account and Address cannot be null' ) ; } $ accountAddress = new AccountAddressEntity ( ) ; $ accountAddress -> setAccount ( $ account ) ; $ accountAddress -> setAddress ( $ address ) ; if ( $ isMain ) { $ this -> unsetMain ( $ account -> getAccountAddresses ( ) ) ; } $ accountAddress -> setMain ( $ isMain ) ; $ account -> addAccountAddress ( $ accountAddress ) ; $ address -> addAccountAddress ( $ accountAddress ) ; $ this -> em -> persist ( $ accountAddress ) ; return $ accountAddress ; } | Adds an address to the entity . |
11,123 | public function removeAddressRelation ( $ account , $ accountAddress ) { if ( ! $ account || ! $ accountAddress ) { throw new \ Exception ( 'Account and AccountAddress cannot be null' ) ; } $ address = $ accountAddress -> getAddress ( ) ; $ address = $ this -> em -> getRepository ( 'SuluContactBundle:Address' ) -> findById ( $ address -> getId ( ) ) ; $ isMain = $ accountAddress -> getMain ( ) ; $ address -> removeAccountAddress ( $ accountAddress ) ; $ account -> removeAccountAddress ( $ accountAddress ) ; if ( $ isMain ) { $ this -> setMainForCollection ( $ account -> getAccountContacts ( ) ) ; } if ( ! $ address -> hasRelations ( ) ) { $ this -> em -> remove ( $ address ) ; } $ this -> em -> remove ( $ accountAddress ) ; } | Removes the address relation from a contact and also deletes the address if it has no more relations . |
11,124 | public function getById ( $ id , $ locale ) { $ account = $ this -> accountRepository -> findAccountById ( $ id ) ; if ( ! $ account ) { throw new EntityNotFoundException ( $ this -> accountRepository -> getClassName ( ) , $ id ) ; } return $ this -> getApiObject ( $ account , $ locale ) ; } | Gets account by id . |
11,125 | public function getByIds ( $ ids , $ locale ) { if ( ! is_array ( $ ids ) || 0 === count ( $ ids ) ) { return [ ] ; } $ accounts = $ this -> accountRepository -> findByIds ( $ ids ) ; return array_map ( function ( $ account ) use ( $ locale ) { return $ this -> getApiObject ( $ account , $ locale ) ; } , $ accounts ) ; } | Returns account entities by ids . |
11,126 | public function getByIdAndInclude ( $ id , $ locale , $ includes ) { $ account = $ this -> accountRepository -> findAccountById ( $ id , in_array ( 'contacts' , $ includes ) ) ; if ( ! $ account ) { throw new EntityNotFoundException ( $ this -> accountRepository -> getClassName ( ) , $ id ) ; } return $ this -> getApiObject ( $ account , $ locale ) ; } | Gets account by id - can include relations . |
11,127 | public function findContactsByAccountId ( $ id , $ locale , $ onlyFetchMainAccounts = false ) { $ contactsEntities = $ this -> contactRepository -> findByAccountId ( $ id , null , false , $ onlyFetchMainAccounts ) ; if ( ! empty ( $ contactsEntities ) ) { $ contacts = [ ] ; foreach ( $ contactsEntities as $ contact ) { $ contacts [ ] = new Contact ( $ contact , $ locale ) ; } return $ contacts ; } return ; } | Returns contacts by account id . |
11,128 | public function setMedias ( Account $ account , $ medias ) { $ mediaIds = array_map ( function ( $ media ) { return $ media [ 'id' ] ; } , $ medias ) ; $ foundMedias = $ this -> mediaRepository -> findById ( $ mediaIds ) ; $ foundMediaIds = array_map ( function ( $ mediaEntity ) { return $ mediaEntity -> getId ( ) ; } , $ foundMedias ) ; if ( $ missingMediaIds = array_diff ( $ mediaIds , $ foundMediaIds ) ) { throw new EntityNotFoundException ( $ this -> mediaRepository -> getClassName ( ) , reset ( $ missingMediaIds ) ) ; } $ account -> getMedias ( ) -> clear ( ) ; foreach ( $ foundMedias as $ media ) { $ account -> addMedia ( $ media ) ; } } | Sets the medias of the given account to the given medias . Currently associated medias are replaced . |
11,129 | public function findAll ( $ locale , $ filter = null ) { if ( $ filter ) { $ accountEntities = $ this -> accountRepository -> findByFilter ( $ filter ) ; } else { $ accountEntities = $ this -> accountRepository -> findAll ( ) ; } if ( ! empty ( $ accountEntities ) ) { $ accounts = [ ] ; foreach ( $ accountEntities as $ account ) { $ accounts [ ] = $ this -> getApiObject ( $ account , $ locale ) ; } return $ accounts ; } return ; } | Returns all accounts . |
11,130 | protected function getApiObject ( $ account , $ locale ) { $ apiObject = $ this -> accountFactory -> createApiEntity ( $ account , $ locale ) ; if ( $ account -> getLogo ( ) ) { $ apiLogo = $ this -> mediaManager -> getById ( $ account -> getLogo ( ) -> getId ( ) , $ locale ) ; $ apiObject -> setLogo ( $ apiLogo ) ; } return $ apiObject ; } | Takes a account entity and a locale and returns the api object . |
11,131 | public function create ( $ entityName ) { return new DoctrineListBuilder ( $ this -> em , $ entityName , $ this -> eventDispatcher , $ this -> permissions ) ; } | Creates a new DoctrineListBuilder for the given entity name and returns it . |
11,132 | public function redirectTrailingSlashOrHtml ( GetResponseForExceptionEvent $ event ) { if ( ! $ event -> getException ( ) instanceof NotFoundHttpException ) { return ; } $ request = $ event -> getRequest ( ) ; $ attributes = $ request -> attributes -> get ( '_sulu' ) ; if ( ! $ attributes ) { return ; } $ prefix = $ attributes -> getAttribute ( 'resourceLocatorPrefix' ) ; $ resourceLocator = $ attributes -> getAttribute ( 'resourceLocator' ) ; $ route = '/' . trim ( $ prefix . $ resourceLocator , '/' ) ; if ( ! in_array ( $ request -> getRequestFormat ( ) , [ 'htm' , 'html' ] ) || $ route === $ request -> getPathInfo ( ) || ! $ this -> matchRoute ( $ request -> getSchemeAndHttpHost ( ) . $ route ) ) { return ; } $ event -> setResponse ( new RedirectResponse ( $ route , 301 ) ) ; } | Redirect trailing slashes or . html . |
11,133 | public function redirectPartialMatch ( GetResponseForExceptionEvent $ event ) { if ( ! $ event -> getException ( ) instanceof NotFoundHttpException ) { return ; } $ request = $ event -> getRequest ( ) ; $ attributes = $ event -> getRequest ( ) -> attributes -> get ( '_sulu' ) ; if ( ! $ attributes ) { return ; } $ types = [ RequestAnalyzerInterface :: MATCH_TYPE_REDIRECT , RequestAnalyzerInterface :: MATCH_TYPE_PARTIAL ] ; $ matchType = $ attributes -> getAttribute ( 'matchType' ) ; if ( ! in_array ( $ matchType , $ types ) ) { return ; } $ localization = $ this -> defaultLocaleProvider -> getDefaultLocale ( ) ; $ redirect = $ attributes -> getAttribute ( 'redirect' ) ; $ redirect = $ this -> urlReplacer -> replaceCountry ( $ redirect , $ localization -> getCountry ( ) ) ; $ redirect = $ this -> urlReplacer -> replaceLanguage ( $ redirect , $ localization -> getLanguage ( ) ) ; $ redirect = $ this -> urlReplacer -> replaceLocalization ( $ redirect , $ localization -> getLocale ( Localization :: DASH ) ) ; $ route = $ this -> resolveRedirectUrl ( $ redirect , $ request -> getUri ( ) , $ attributes -> getAttribute ( 'resourceLocatorPrefix' ) ) ; if ( ! $ this -> matchRoute ( $ route ) ) { return ; } $ event -> setResponse ( new RedirectResponse ( $ route , 301 ) ) ; } | Redirect partial and redirect matches . |
11,134 | private function matchUrl ( $ url ) { $ request = Request :: create ( $ url ) ; $ this -> requestAnalyzer -> analyze ( $ request ) ; try { return null !== $ this -> router -> matchRequest ( $ request ) ; } catch ( ResourceNotFoundException $ exception ) { return false ; } } | Returns true if given url exists . |
11,135 | private function resolveRedirectUrl ( $ redirectUrl , $ requestUri , $ resourceLocatorPrefix ) { $ redirectInfo = $ this -> parseUrl ( $ redirectUrl ) ; $ requestInfo = $ this -> parseUrl ( $ requestUri ) ; $ url = sprintf ( '%s://%s' , $ requestInfo [ 'scheme' ] , $ requestInfo [ 'host' ] ) ; if ( isset ( $ redirectInfo [ 'host' ] ) ) { $ url = sprintf ( '%s://%s' , $ requestInfo [ 'scheme' ] , $ redirectInfo [ 'host' ] ) ; } if ( isset ( $ requestInfo [ 'port' ] ) ) { $ url .= ':' . $ requestInfo [ 'port' ] ; } if ( isset ( $ redirectInfo [ 'path' ] ) && ( ! isset ( $ requestInfo [ 'path' ] ) || 0 !== strpos ( $ requestInfo [ 'path' ] , $ redirectInfo [ 'path' ] . '/' ) ) ) { $ url .= $ redirectInfo [ 'path' ] ; } if ( isset ( $ requestInfo [ 'path' ] ) && $ resourceLocatorPrefix !== $ requestInfo [ 'path' ] ) { $ path = $ requestInfo [ 'path' ] ; if ( $ resourceLocatorPrefix && 0 === strpos ( $ path , $ resourceLocatorPrefix ) ) { $ path = substr ( $ path , strlen ( $ resourceLocatorPrefix ) ) ; } $ url .= $ path ; $ url = rtrim ( $ url , '/' ) ; } if ( isset ( $ requestInfo [ 'query' ] ) ) { $ url .= '?' . $ requestInfo [ 'query' ] ; } if ( isset ( $ requestInfo [ 'fragment' ] ) ) { $ url .= '#' . $ requestInfo [ 'fragment' ] ; } return $ url ; } | Resolve the redirect URL appending any additional path data . |
11,136 | public function postSubmitDocumentParent ( FormEvent $ event ) { $ document = $ event -> getData ( ) ; if ( $ document -> getParent ( ) ) { return ; } $ form = $ event -> getForm ( ) ; $ webspaceKey = $ form -> getConfig ( ) -> getAttribute ( 'webspace_key' ) ; $ parent = $ this -> documentManager -> find ( $ this -> sessionManager -> getContentPath ( $ webspaceKey ) ) ; if ( null === $ parent ) { throw new \ InvalidArgumentException ( sprintf ( 'Could not determine parent for document with title "%s" in webspace "%s"' , $ document -> getTitle ( ) , $ webspaceKey ) ) ; } $ document -> setParent ( $ parent ) ; } | Set the document parent to be the webspace content path when the document has no parent . |
11,137 | private static function getRegularExpression ( $ portalUrl ) { $ patternUrl = rtrim ( $ portalUrl , '/' ) ; $ patternUrl = preg_quote ( $ patternUrl ) ; $ patternUrl = str_replace ( [ '/' , '\*' ] , [ '\/' , '([^\/.]+)' ] , $ patternUrl ) ; return sprintf ( '/^%s($|([\/].*)|([.].*))$/' , $ patternUrl ) ; } | Returns regular expression to match given portal - url . |
11,138 | public static function resolve ( $ url , $ portalUrl ) { $ regexp = self :: getRegularExpression ( $ portalUrl ) ; if ( preg_match ( $ regexp , $ url , $ matches ) ) { for ( $ i = 0 , $ countStar = substr_count ( $ portalUrl , '*' ) ; $ i < $ countStar ; ++ $ i ) { $ pos = strpos ( $ portalUrl , '*' ) ; if ( false !== $ pos ) { $ portalUrl = substr_replace ( $ portalUrl , $ matches [ $ i + 1 ] , $ pos , 1 ) ; } } return $ portalUrl ; } return ; } | Replaces wildcards with occurrences in the given url . |
11,139 | public function getConditionGroups ( ) { $ groups = $ this -> entity -> getConditionGroups ( ) ; if ( $ groups ) { $ result = [ ] ; foreach ( $ groups as $ group ) { $ result [ ] = new ConditionGroup ( $ group , $ this -> locale ) ; } return $ result ; } return ; } | Get conditionGroups . |
11,140 | public function onPostSerialize ( ObjectEvent $ event ) { $ customUrl = $ event -> getObject ( ) ; $ visitor = $ event -> getVisitor ( ) ; if ( ! $ customUrl instanceof CustomUrlDocument ) { return ; } if ( null !== $ customUrl -> getTargetDocument ( ) ) { $ visitor -> addData ( 'targetTitle' , $ customUrl -> getTargetDocument ( ) -> getTitle ( ) ) ; $ visitor -> addData ( 'targetDocument' , $ customUrl -> getTargetDocument ( ) -> getUuid ( ) ) ; } $ visitor -> addData ( 'customUrl' , $ this -> generator -> generate ( $ customUrl -> getBaseDomain ( ) , $ customUrl -> getDomainParts ( ) ) ) ; $ visitor -> addData ( 'creatorFullName' , $ this -> userManager -> getFullNameByUserId ( $ customUrl -> getCreator ( ) ) ) ; $ visitor -> addData ( 'changerFullName' , $ this -> userManager -> getFullNameByUserId ( $ customUrl -> getChanger ( ) ) ) ; } | Add information to serialized custom - url document . |
11,141 | private function setData ( Analytics $ analytics , $ webspaceKey , $ data ) { $ analytics -> setTitle ( $ this -> getValue ( $ data , 'title' ) ) ; $ analytics -> setType ( $ this -> getValue ( $ data , 'type' ) ) ; $ analytics -> setContent ( $ this -> getValue ( $ data , 'content' , '' ) ) ; $ analytics -> setAllDomains ( $ this -> getValue ( $ data , 'allDomains' , false ) ) ; $ analytics -> setWebspaceKey ( $ webspaceKey ) ; $ analytics -> clearDomains ( ) ; if ( ! $ analytics -> isAllDomains ( ) ) { foreach ( $ this -> getValue ( $ data , 'domains' , [ ] ) as $ domain ) { $ domainEntity = $ this -> findOrCreateNewDomain ( $ domain ) ; $ analytics -> addDomain ( $ domainEntity ) ; } } } | Set data to given key . |
11,142 | public function setUrlType ( \ Sulu \ Bundle \ ContactBundle \ Entity \ UrlType $ urlType ) { $ this -> urlType = $ urlType ; return $ this ; } | Set urlType . |
11,143 | protected function getIdFromUrl ( $ url ) { $ fileName = basename ( $ url ) ; $ idParts = explode ( '-' , $ fileName ) ; if ( count ( $ idParts ) < 2 ) { throw new ImageProxyInvalidUrl ( 'No `id` was found in the url' ) ; } $ id = $ idParts [ 0 ] ; if ( preg_match ( '/[^0-9]/' , $ id ) ) { throw new ImageProxyInvalidUrl ( 'The founded `id` was not a valid integer' ) ; } return $ id ; } | return the id of by a given url . |
11,144 | protected function getFormatFromUrl ( $ url ) { $ path = dirname ( $ url ) ; $ formatParts = array_reverse ( explode ( '/' , $ path ) ) ; if ( count ( $ formatParts ) < 2 ) { throw new ImageProxyInvalidUrl ( 'No `format` was found in the url' ) ; } $ format = $ formatParts [ 1 ] ; return $ format ; } | return the format by a given url . |
11,145 | private function appendRelation ( QueryBuilder $ queryBuilder , $ relation , $ values , $ operator , $ alias ) { switch ( $ operator ) { case 'or' : return $ this -> appendRelationOr ( $ queryBuilder , $ relation , $ values , $ alias ) ; case 'and' : return $ this -> appendRelationAnd ( $ queryBuilder , $ relation , $ values , $ alias ) ; } return [ ] ; } | Append tags to query builder with given operator . |
11,146 | private function appendRelationOr ( QueryBuilder $ queryBuilder , $ relation , $ values , $ alias ) { $ queryBuilder -> leftJoin ( $ relation , $ alias ) -> andWhere ( $ alias . '.id IN (:' . $ alias . ')' ) ; return [ $ alias => $ values ] ; } | Append tags to query builder with or operator . |
11,147 | private function appendRelationAnd ( QueryBuilder $ queryBuilder , $ relation , $ values , $ alias ) { $ parameter = [ ] ; $ expr = $ queryBuilder -> expr ( ) -> andX ( ) ; $ length = count ( $ values ) ; for ( $ i = 0 ; $ i < $ length ; ++ $ i ) { $ queryBuilder -> leftJoin ( $ relation , $ alias . $ i ) ; $ expr -> add ( $ queryBuilder -> expr ( ) -> eq ( $ alias . $ i . '.id' , ':' . $ alias . $ i ) ) ; $ parameter [ $ alias . $ i ] = $ values [ $ i ] ; } $ queryBuilder -> andWhere ( $ expr ) ; return $ parameter ; } | Append tags to query builder with and operator . |
11,148 | public function getStructure ( $ locale ) { return $ this -> contentMapper -> loadShallowStructureByNode ( $ this -> node , $ locale , $ this -> webspace ) ; } | Return the structure which was deleted . |
11,149 | private function getResourceLocatorFromRequest ( PortalInformation $ portalInformation , Request $ request , $ path ) { $ pathParts = explode ( '/' , $ path ) ; $ fileInfo = explode ( '.' , array_pop ( $ pathParts ) ) ; $ path = rtrim ( implode ( '/' , $ pathParts ) , '/' ) . '/' . $ fileInfo [ 0 ] ; $ formatResult = null ; if ( count ( $ fileInfo ) > 1 ) { $ formatResult = end ( $ fileInfo ) ; } $ resourceLocator = substr ( $ request -> getHost ( ) . $ path , strlen ( $ portalInformation -> getUrl ( ) ) ) ; return [ $ resourceLocator , $ formatResult ] ; } | Returns resource locator and format of current request . |
11,150 | private function getProvider ( PropertyInterface $ property ) { $ params = $ property -> getParams ( ) ; $ providerAlias = 'pages' ; if ( array_key_exists ( 'provider' , $ params ) ) { $ providerAlias = $ params [ 'provider' ] -> getValue ( ) ; } return $ this -> dataProviderPool -> get ( $ providerAlias ) ; } | Returns provider for given property . |
11,151 | private function getCurrentPage ( $ pageParameter ) { if ( null === $ this -> requestStack -> getCurrentRequest ( ) ) { return 1 ; } $ page = $ this -> requestStack -> getCurrentRequest ( ) -> get ( $ pageParameter , 1 ) ; if ( $ page < 1 || $ page > PHP_INT_MAX ) { throw new PageOutOfBoundsException ( $ page ) ; } return $ page ; } | Determine current page from current request . |
11,152 | public function createResponse ( ViewHandler $ handler , View $ view , Request $ request , $ format ) { if ( ! $ view -> getData ( ) instanceof ListRepresentation ) { throw new ObjectNotSupportedException ( $ view ) ; } $ viewData = $ view -> getData ( ) ; $ data = new CallbackCollection ( $ viewData -> getData ( ) , [ $ this , 'prepareData' ] ) ; $ fileName = sprintf ( '%s.csv' , $ viewData -> getRel ( ) ) ; $ config = new ExporterConfig ( ) ; $ exporter = new Exporter ( $ config ) ; $ data -> rewind ( ) ; if ( $ row = $ data -> current ( ) ) { $ config -> setColumnHeaders ( array_keys ( $ row ) ) ; } $ config -> setDelimiter ( $ this -> convertValue ( $ request -> get ( 'delimiter' , ';' ) , self :: $ delimiterMap ) ) ; $ config -> setNewline ( $ this -> convertValue ( $ request -> get ( 'newLine' , '\\n' ) , self :: $ newLineMap ) ) ; $ config -> setEnclosure ( $ request -> get ( 'enclosure' , '"' ) ) ; $ config -> setEscape ( $ request -> get ( 'escape' , '\\' ) ) ; $ response = new StreamedResponse ( ) ; $ disposition = $ response -> headers -> makeDisposition ( ResponseHeaderBag :: DISPOSITION_ATTACHMENT , $ fileName , $ fileName ) ; $ response -> headers -> set ( 'Content-Type' , 'text/csv' ) ; $ response -> headers -> set ( 'Content-Disposition' , $ disposition ) ; $ response -> setCallback ( function ( ) use ( $ data , $ exporter ) { $ exporter -> export ( 'php://output' , $ data ) ; } ) ; $ response -> send ( ) ; return $ response ; } | Handles response for csv - request . |
11,153 | public function prepareData ( $ row ) { if ( ! $ row ) { return $ row ; } if ( ! is_array ( $ row ) ) { $ row = $ this -> serializer -> serialize ( $ row , 'array' , SerializationContext :: create ( ) -> setSerializeNull ( true ) ) ; } foreach ( $ row as $ key => $ value ) { if ( $ value instanceof \ DateTime ) { $ row [ $ key ] = $ value -> format ( \ DateTime :: RFC3339 ) ; } elseif ( is_bool ( $ value ) ) { $ row [ $ key ] = true === $ value ? 1 : 0 ; } elseif ( is_array ( $ value ) || is_object ( $ value ) ) { $ row [ $ key ] = json_encode ( $ value ) ; } } return $ row ; } | The exporter is not able to write DateTime objects into csv . This method converts them to string . |
11,154 | public function buildPersistence ( array $ interfaces , ContainerBuilder $ container ) { if ( ! empty ( $ interfaces ) ) { $ container -> addCompilerPass ( new ResolveTargetEntitiesPass ( $ interfaces ) ) ; } } | Build persistence adds a ResolveTargetEntitiesPass for the given interfaces . |
11,155 | public function up ( SessionInterface $ session ) { $ this -> session = $ session ; $ this -> iterateStructures ( true ) ; $ this -> upgradeExternalLinks ( true ) ; } | Migrate the repository up . |
11,156 | public function down ( SessionInterface $ session ) { $ this -> session = $ session ; $ this -> iterateStructures ( false ) ; $ this -> upgradeExternalLinks ( false ) ; } | Migrate the system down . |
11,157 | private function upgradeExternalLinks ( $ addScheme ) { foreach ( $ this -> localizationManager -> getLocalizations ( ) as $ localization ) { $ rows = $ this -> session -> getWorkspace ( ) -> getQueryManager ( ) -> createQuery ( sprintf ( 'SELECT * FROM [nt:unstructured] WHERE [%s] = "%s"' , $ this -> propertyEncoder -> localizedSystemName ( 'nodeType' , $ localization -> getLocale ( ) ) , RedirectType :: EXTERNAL ) , 'JCR-SQL2' ) -> execute ( ) ; $ name = $ this -> propertyEncoder -> localizedSystemName ( 'external' , $ localization -> getLocale ( ) ) ; foreach ( $ rows -> getNodes ( ) as $ node ) { $ value = $ node -> getPropertyValue ( $ name ) ; if ( $ addScheme ) { $ this -> upgradeUrl ( $ value ) ; } else { $ this -> downgradeUrl ( $ value ) ; } $ node -> setProperty ( $ name , $ value ) ; } } } | External links are easily updated by fetching all nodes with the external redirect type and add or remove the scheme to the external property . |
11,158 | private function iterateStructures ( $ addScheme ) { $ properties = [ ] ; $ structureMetadatas = array_merge ( $ this -> structureMetadataFactory -> getStructures ( 'page' ) , $ this -> structureMetadataFactory -> getStructures ( 'snippet' ) ) ; $ structureMetadatas = array_filter ( $ structureMetadatas , function ( StructureMetadata $ structureMetadata ) use ( & $ properties ) { $ structureName = $ structureMetadata -> getName ( ) ; $ this -> findUrlProperties ( $ structureMetadata , $ properties ) ; return ! empty ( $ properties [ $ structureName ] ) || ! empty ( $ blockProperties [ $ structureName ] ) ; } ) ; foreach ( $ structureMetadatas as $ structureMetadata ) { $ this -> iterateStructureNodes ( $ structureMetadata , $ properties [ $ structureMetadata -> getName ( ) ] , $ addScheme ) ; } $ this -> documentManager -> flush ( ) ; } | Structures are updated according to their xml definition . |
11,159 | private function findUrlProperties ( StructureMetadata $ structureMetadata , array & $ properties ) { $ structureName = $ structureMetadata -> getName ( ) ; foreach ( $ structureMetadata -> getProperties ( ) as $ property ) { if ( 'url' === $ property -> getType ( ) ) { $ properties [ $ structureName ] [ ] = [ 'property' => $ property ] ; } elseif ( $ property instanceof BlockMetadata ) { $ this -> findUrlBlockProperties ( $ property , $ structureName , $ properties ) ; } } } | Returns all properties which are a URL field . |
11,160 | private function upgradeNode ( NodeInterface $ node , $ locale , array $ properties , $ addScheme ) { $ document = $ this -> documentManager -> find ( $ node -> getIdentifier ( ) , $ locale ) ; $ documentLocales = $ this -> documentInspector -> getLocales ( $ document ) ; if ( ! in_array ( $ locale , $ documentLocales ) ) { return ; } foreach ( $ properties as $ property ) { $ propertyValue = $ document -> getStructure ( ) -> getProperty ( $ property [ 'property' ] -> getName ( ) ) ; if ( $ property [ 'property' ] instanceof BlockMetadata ) { $ this -> upgradeBlockProperty ( $ property [ 'property' ] , $ property [ 'components' ] , $ propertyValue , $ addScheme ) ; } else { $ this -> upgradeProperty ( $ propertyValue , $ addScheme ) ; } } $ this -> documentManager -> persist ( $ document , $ locale , [ 'auto_name' => false ] ) ; } | Upgrades the node to new URL representation . |
11,161 | private function upgradeBlockProperty ( BlockMetadata $ blockProperty , array $ components , PropertyValue $ propertyValue , $ addScheme ) { $ componentNames = array_map ( function ( $ item ) { return $ item [ 'component' ] -> getName ( ) ; } , $ components ) ; $ value = $ propertyValue -> getValue ( ) ; foreach ( $ value as & $ item ) { if ( ! in_array ( $ item [ 'type' ] , $ componentNames ) ) { continue ; } foreach ( $ components [ $ item [ 'type' ] ] [ 'children' ] as $ child ) { if ( ! isset ( $ item [ $ child -> getName ( ) ] ) ) { continue ; } if ( $ addScheme ) { $ item [ $ child -> getName ( ) ] = $ this -> upgradeUrl ( $ item [ $ child -> getName ( ) ] ) ; } else { $ item [ $ child -> getName ( ) ] = $ this -> downgradeUrl ( $ item [ $ child -> getName ( ) ] ) ; } } } $ propertyValue -> setValue ( $ value ) ; } | Upgrades the given block property to the new URL representation . |
11,162 | private function upgradeUrl ( & $ value ) { if ( ! empty ( $ value ) && false === strpos ( $ value , 'http://' ) && false === strpos ( $ value , 'https://' ) && false === strpos ( $ value , 'ftp://' ) && false === strpos ( $ value , 'ftps://' ) && false === strpos ( $ value , 'mailto:' ) && false === strpos ( $ value , '//' ) ) { $ value = 'http://' . $ value ; } return $ value ; } | Upgrades the given URL to the new representation . |
11,163 | public function handleScheduleRename ( PersistEvent $ event ) { $ document = $ event -> getDocument ( ) ; if ( ! $ event -> getOption ( 'auto_name' ) || ! $ document instanceof AutoNameBehavior || $ event -> getOption ( 'auto_name_locale' ) !== $ event -> getLocale ( ) || ! $ event -> hasNode ( ) || $ event -> getNode ( ) -> isNew ( ) ) { return ; } $ node = $ event -> getNode ( ) ; $ name = $ this -> getName ( $ document , $ event -> getParentNode ( ) , $ event -> getOption ( 'auto_rename' ) , $ node ) ; if ( $ name === $ node -> getName ( ) ) { return ; } $ uuid = $ event -> getNode ( ) -> getIdentifier ( ) ; $ this -> scheduledRename [ ] = [ 'uuid' => $ uuid , 'name' => $ name , 'locale' => $ event -> getLocale ( ) ] ; } | Renames node if necessary . |
11,164 | private function getName ( AutoNameBehavior $ document , NodeInterface $ parentNode , $ autoRename = true , NodeInterface $ node = null ) { $ title = $ document -> getTitle ( ) ; if ( ! $ title ) { throw new DocumentManagerException ( sprintf ( 'Document has no title (title is required for auto name behavior): %s)' , DocumentHelper :: getDebugTitle ( $ document ) ) ) ; } $ name = $ this -> slugifier -> slugify ( $ title ) ; return $ this -> resolver -> resolveName ( $ parentNode , $ name , $ node , $ autoRename ) ; } | Returns unique name for given document and nodes . |
11,165 | private function handleMoveCopy ( MoveEvent $ event ) { $ document = $ event -> getDocument ( ) ; if ( ! $ document instanceof AutoNameBehavior ) { return ; } $ destId = $ event -> getDestId ( ) ; $ node = $ this -> registry -> getNodeForDocument ( $ document ) ; $ destNode = $ this -> nodeManager -> find ( $ destId ) ; $ nodeName = $ this -> resolver -> resolveName ( $ destNode , $ node -> getName ( ) ) ; $ event -> setDestName ( $ nodeName ) ; } | Resolve the destination name on move and copy events . |
11,166 | public function onPostSerialize ( ObjectEvent $ event ) { $ object = $ event -> getObject ( ) ; if ( $ object instanceof ApiWrapper ) { $ object = $ object -> getEntity ( ) ; } if ( ! $ object instanceof AuditableInterface && ! $ object instanceof LocalizedAuditableBehavior ) { return ; } $ visitor = $ event -> getVisitor ( ) ; if ( ! $ visitor instanceof GenericSerializationVisitor ) { return ; } $ visitor -> setData ( '_hash' , $ this -> hasher -> hash ( $ object ) ) ; } | Adds the hash of the given object to its serialization . |
11,167 | private function getSystemCollections ( ) { if ( ! $ this -> systemCollections ) { if ( ! $ this -> cache -> isFresh ( ) ) { $ systemCollections = $ this -> buildSystemCollections ( $ this -> locale , $ this -> getUserId ( ) ) ; $ this -> cache -> write ( $ systemCollections ) ; } $ this -> systemCollections = $ this -> cache -> read ( ) ; } return $ this -> systemCollections ; } | Returns system collections . |
11,168 | private function getUserId ( ) { if ( ! $ this -> tokenProvider || null === ( $ token = $ this -> tokenProvider -> getToken ( ) ) ) { return ; } if ( ! $ token -> getUser ( ) instanceof UserInterface ) { return ; } return $ token -> getUser ( ) -> getId ( ) ; } | Returns current user . |
11,169 | private function buildSystemCollections ( $ locale , $ userId ) { $ root = $ this -> getOrCreateRoot ( SystemCollectionManagerInterface :: COLLECTION_KEY , 'System' , $ locale , $ userId ) ; $ collections = [ 'root' => $ root -> getId ( ) ] ; $ collections = array_merge ( $ collections , $ this -> iterateOverCollections ( $ this -> config , $ userId , $ root -> getId ( ) ) ) ; $ this -> entityManager -> flush ( ) ; return $ collections ; } | Go thru configuration and build all system collections . |
11,170 | private function iterateOverCollections ( $ children , $ userId , $ parent = null , $ namespace = '' ) { $ format = ( '' !== $ namespace ? '%s.%s' : '%s%s' ) ; $ collections = [ ] ; foreach ( $ children as $ collectionKey => $ collectionItem ) { $ key = sprintf ( $ format , $ namespace , $ collectionKey ) ; $ collections [ $ key ] = $ this -> getOrCreateCollection ( $ key , $ collectionItem [ 'meta_title' ] , $ userId , $ parent ) -> getId ( ) ; if ( array_key_exists ( 'collections' , $ collectionItem ) ) { $ childCollections = $ this -> iterateOverCollections ( $ collectionItem [ 'collections' ] , $ userId , $ collections [ $ key ] , $ key ) ; $ collections = array_merge ( $ collections , $ childCollections ) ; } } return $ collections ; } | Iterates over an array of children collections creates them . This function is recursive! |
11,171 | private function getOrCreateRoot ( $ namespace , $ title , $ locale , $ userId , $ parent = null ) { if ( null !== ( $ collection = $ this -> collectionManager -> getByKey ( $ namespace , $ locale ) ) ) { $ collection -> setTitle ( $ title ) ; return $ collection ; } return $ this -> createCollection ( $ title , $ namespace , $ locale , $ userId , $ parent ) ; } | Finds or create a new system - collection namespace . |
11,172 | private function getOrCreateCollection ( $ key , $ localizedTitles , $ userId , $ parent ) { $ locales = array_keys ( $ localizedTitles ) ; $ firstLocale = array_shift ( $ locales ) ; $ collection = $ this -> collectionManager -> getByKey ( $ key , $ firstLocale ) ; if ( null === $ collection ) { $ collection = $ this -> createCollection ( $ localizedTitles [ $ firstLocale ] , $ key , $ firstLocale , $ userId , $ parent ) ; } else { $ collection -> setTitle ( $ localizedTitles [ $ firstLocale ] ) ; } foreach ( $ locales as $ locale ) { $ this -> createCollection ( $ localizedTitles [ $ locale ] , $ key , $ locale , $ userId , $ parent , $ collection -> getId ( ) ) ; } return $ collection ; } | Finds or create a new system - collection . |
11,173 | public function getExportData ( ) { $ snippets = $ this -> getSnippets ( ) ; $ snippetsData = [ ] ; $ progress = new ProgressBar ( $ this -> output , count ( $ snippets ) ) ; $ progress -> start ( ) ; foreach ( $ snippets as $ snippet ) { $ contentData = $ this -> getContentData ( $ snippet , $ this -> exportLocale ) ; $ snippetsData [ ] = [ 'uuid' => $ snippet -> getUuid ( ) , 'locale' => $ snippet -> getLocale ( ) , 'content' => $ contentData , ] ; $ progress -> advance ( ) ; } $ progress -> finish ( ) ; return [ 'locale' => $ this -> exportLocale , 'format' => $ this -> format , 'snippetData' => $ snippetsData , ] ; } | Returns all data that we need to create a xliff - File . |
11,174 | public function registerDocument ( $ document , NodeInterface $ node , $ locale ) { $ oid = $ this -> getObjectIdentifier ( $ document ) ; $ uuid = $ node -> getIdentifier ( ) ; $ this -> validateDocumentRegistration ( $ document , $ locale , $ node , $ oid , $ uuid ) ; $ this -> documentMap [ $ oid ] = $ document ; $ this -> documentNodeMap [ $ oid ] = $ uuid ; $ this -> nodeMap [ $ node -> getIdentifier ( ) ] = $ node ; $ this -> nodeDocumentMap [ $ this -> getNodeLocaleKey ( $ node -> getIdentifier ( ) , $ locale ) ] = $ document ; $ this -> documentLocaleMap [ $ oid ] = $ locale ; } | Register a document . |
11,175 | public function hasDocument ( $ document ) { $ oid = $ this -> getObjectIdentifier ( $ document ) ; return isset ( $ this -> documentMap [ $ oid ] ) ; } | Return true if the document is managed . |
11,176 | public function hasNode ( NodeInterface $ node , $ locale ) { return array_key_exists ( $ this -> getNodeLocaleKey ( $ node -> getIdentifier ( ) , $ locale ) , $ this -> nodeDocumentMap ) ; } | Return true if the node is managed . |
11,177 | public function deregisterDocument ( $ document ) { $ oid = $ this -> getObjectIdentifier ( $ document ) ; $ this -> assertDocumentExists ( $ document ) ; $ nodeIdentifier = $ this -> documentNodeMap [ $ oid ] ; $ locale = $ this -> documentLocaleMap [ $ oid ] ; unset ( $ this -> nodeMap [ $ nodeIdentifier ] ) ; unset ( $ this -> nodeDocumentMap [ $ this -> getNodeLocaleKey ( $ nodeIdentifier , $ locale ) ] ) ; unset ( $ this -> documentMap [ $ oid ] ) ; unset ( $ this -> documentNodeMap [ $ oid ] ) ; unset ( $ this -> documentLocaleMap [ $ oid ] ) ; unset ( $ this -> hydrationState [ $ oid ] ) ; } | Remove all references to the given document and its associated node . |
11,178 | public function getNodeForDocument ( $ document ) { $ oid = $ this -> getObjectIdentifier ( $ document ) ; $ this -> assertDocumentExists ( $ document ) ; return $ this -> nodeMap [ $ this -> documentNodeMap [ $ oid ] ] ; } | Return the node for the given managed document . |
11,179 | public function getLocaleForDocument ( $ document ) { $ oid = $ this -> getObjectIdentifier ( $ document ) ; $ this -> assertDocumentExists ( $ document ) ; return $ this -> documentLocaleMap [ $ oid ] ; } | Return the current locale for the given document . |
11,180 | public function getOriginalLocaleForDocument ( $ document ) { $ this -> assertDocumentExists ( $ document ) ; if ( $ document instanceof LocaleBehavior ) { return $ document -> getOriginalLocale ( ) ? : $ document -> getLocale ( ) ; } return $ this -> getLocaleForDocument ( $ document ) ; } | Return the original locale for the document . |
11,181 | public function getDocumentForNode ( NodeInterface $ node , $ locale ) { $ identifier = $ node -> getIdentifier ( ) ; $ this -> assertNodeExists ( $ identifier ) ; return $ this -> nodeDocumentMap [ $ this -> getNodeLocaleKey ( $ node -> getIdentifier ( ) , $ locale ) ] ; } | Return the document for the given managed node . |
11,182 | private function validateDocumentRegistration ( $ document , $ locale , NodeInterface $ node , $ oid , $ uuid ) { if ( null === $ uuid ) { throw new DocumentManagerException ( sprintf ( 'Node "%s" of type "%s" has no UUID. Only referencable nodes can be registered by the document manager' , $ node -> getPath ( ) , $ node -> getPrimaryNodeType ( ) -> getName ( ) ) ) ; } $ documentNodeKey = $ this -> getNodeLocaleKey ( $ node -> getIdentifier ( ) , $ locale ) ; if ( array_key_exists ( $ uuid , $ this -> nodeMap ) && array_key_exists ( $ documentNodeKey , $ this -> nodeDocumentMap ) ) { $ registeredDocument = $ this -> nodeDocumentMap [ $ documentNodeKey ] ; throw new \ RuntimeException ( sprintf ( 'Document "%s" (%s) is already registered for node "%s" (%s) when trying to register document "%s" (%s)' , spl_object_hash ( $ registeredDocument ) , get_class ( $ registeredDocument ) , $ uuid , $ node -> getPath ( ) , $ oid , get_class ( $ document ) ) ) ; } } | Ensure that the document is not already registered and that the node has a UUID . |
11,183 | protected function getFilterQuery ( $ locale ) { $ qb = $ this -> createQueryBuilder ( 'filter' ) -> addSelect ( 'conditionGroups' ) -> addSelect ( 'translations' ) -> addSelect ( 'conditions' ) -> leftJoin ( 'filter.translations' , 'translations' , 'WITH' , 'translations.locale = :locale' ) -> leftJoin ( 'filter.conditionGroups' , 'conditionGroups' ) -> leftJoin ( 'conditionGroups.conditions' , 'conditions' ) -> setParameter ( 'locale' , $ locale ) ; return $ qb ; } | Returns the query for filters . |
11,184 | public function deleteByIds ( $ ids ) { $ qb = $ this -> createQueryBuilder ( 'filter' ) -> delete ( ) -> where ( 'filter.id IN (:ids)' ) -> setParameter ( 'ids' , $ ids ) ; $ qb -> getQuery ( ) -> execute ( ) ; } | Deletes multiple filters . |
11,185 | public function getReferences ( $ uuid ) { $ session = $ this -> sessionManager -> getSession ( ) ; $ node = $ session -> getNodeByIdentifier ( $ uuid ) ; return iterator_to_array ( $ node -> getReferences ( ) ) ; } | Return the nodes which refer to the structure with the given UUID . |
11,186 | public function getSnippetsByUuids ( array $ uuids , $ locale , $ loadGhostContent = false ) { $ snippets = [ ] ; foreach ( $ uuids as $ uuid ) { try { $ snippet = $ this -> documentManager -> find ( $ uuid , $ locale , [ 'load_ghost_content' => $ loadGhostContent , ] ) ; $ snippets [ ] = $ snippet ; } catch ( DocumentNotFoundException $ e ) { } } return $ snippets ; } | Return snippets identified by the given UUIDs . |
11,187 | public function getSnippets ( $ locale , $ type = null , $ offset = null , $ max = null , $ search = null , $ sortBy = null , $ sortOrder = null ) { $ query = $ this -> getSnippetsQuery ( $ locale , $ type , $ offset , $ max , $ search , $ sortBy , $ sortOrder ) ; $ documents = $ this -> documentManager -> createQuery ( $ query , $ locale , [ 'load_ghost_content' => true , ] ) -> execute ( ) ; return $ documents ; } | Return snippets . |
11,188 | public function getSnippetsAmount ( $ locale , $ type = null , $ search = null , $ sortBy = null , $ sortOrder = null ) { $ query = $ this -> getSnippetsQuery ( $ locale , $ type , null , null , $ search , $ sortBy , $ sortOrder ) ; $ result = $ query -> execute ( ) ; return count ( iterator_to_array ( $ result -> getRows ( ) ) ) ; } | Return snippets amount . |
11,189 | public function copyLocale ( $ uuid , $ userId , $ srcLocale , $ destLocales ) { return $ this -> contentMapper -> copyLanguage ( $ uuid , $ userId , null , $ srcLocale , $ destLocales , Structure :: TYPE_SNIPPET ) ; } | Copy snippet from src - locale to dest - locale . |
11,190 | private function getSnippetsQuery ( $ locale , $ type = null , $ offset = null , $ max = null , $ search = null , $ sortBy = null , $ sortOrder = null ) { $ snippetNode = $ this -> sessionManager -> getSnippetNode ( $ type ) ; $ workspace = $ this -> sessionManager -> getSession ( ) -> getWorkspace ( ) ; $ queryManager = $ workspace -> getQueryManager ( ) ; $ qf = $ queryManager -> getQOMFactory ( ) ; $ qb = new QueryBuilder ( $ qf ) ; $ qb -> from ( $ qb -> qomf ( ) -> selector ( 'a' , 'nt:unstructured' ) ) ; if ( null === $ type ) { $ qb -> where ( $ qb -> qomf ( ) -> descendantNode ( 'a' , $ snippetNode -> getPath ( ) ) ) ; } else { $ qb -> where ( $ qb -> qomf ( ) -> childNode ( 'a' , $ snippetNode -> getPath ( ) ) ) ; } $ qb -> andWhere ( $ qb -> qomf ( ) -> comparison ( $ qb -> qomf ( ) -> propertyValue ( 'a' , 'jcr:mixinTypes' ) , QueryObjectModelConstantsInterface :: JCR_OPERATOR_EQUAL_TO , $ qb -> qomf ( ) -> literal ( 'sulu:snippet' ) ) ) ; if ( null !== $ offset ) { $ qb -> setFirstResult ( $ offset ) ; if ( null === $ max ) { throw new \ InvalidArgumentException ( 'If you specify an offset then you must also specify $max' ) ; } $ qb -> setMaxResults ( $ max ) ; } if ( null !== $ search ) { $ search = str_replace ( '*' , '%' , $ search ) ; $ searchConstraint = $ qf -> orConstraint ( $ qf -> comparison ( $ qf -> propertyValue ( 'a' , 'i18n:' . $ locale . '-title' ) , QueryObjectModelConstantsInterface :: JCR_OPERATOR_LIKE , $ qf -> literal ( '%' . $ search . '%' ) ) , $ qf -> comparison ( $ qf -> propertyValue ( 'a' , 'template' ) , QueryObjectModelConstantsInterface :: JCR_OPERATOR_LIKE , $ qf -> literal ( '%' . $ search . '%' ) ) ) ; $ qb -> andWhere ( $ searchConstraint ) ; } $ sortOrder = ( null !== $ sortOrder ? strtoupper ( $ sortOrder ) : 'ASC' ) ; $ sortBy = ( null !== $ sortBy ? $ sortBy : 'title' ) ; $ qb -> orderBy ( $ qb -> qomf ( ) -> propertyValue ( 'a' , 'i18n:' . $ locale . '-' . $ sortBy ) , null !== $ sortOrder ? strtoupper ( $ sortOrder ) : 'ASC' ) ; return $ qb -> getQuery ( ) ; } | Return snippets load query . |
11,191 | public function cgetAction ( Request $ request , $ uuid ) { $ locale = $ this -> getRequestParameter ( $ request , 'language' , true ) ; $ document = $ this -> get ( 'sulu_document_manager.document_manager' ) -> find ( $ uuid , $ request -> query -> get ( 'language' ) ) ; $ versions = array_reverse ( array_filter ( $ document -> getVersions ( ) , function ( $ version ) use ( $ locale ) { return $ version -> getLocale ( ) === $ locale ; } ) ) ; $ total = count ( $ versions ) ; $ listRestHelper = $ this -> get ( 'sulu_core.list_rest_helper' ) ; $ limit = $ listRestHelper -> getLimit ( ) ; $ versions = array_slice ( $ versions , $ listRestHelper -> getOffset ( ) , $ limit ) ; $ userIds = array_unique ( array_map ( function ( $ version ) { return $ version -> getAuthor ( ) ; } , $ versions ) ) ; $ users = $ this -> get ( 'sulu_security.user_repository' ) -> findUsersById ( $ userIds ) ; $ fullNamesByIds = [ ] ; foreach ( $ users as $ user ) { $ fullNamesByIds [ $ user -> getId ( ) ] = $ user -> getContact ( ) -> getFullName ( ) ; } $ versionData = [ ] ; foreach ( $ versions as $ version ) { $ versionData [ ] = [ 'id' => str_replace ( '.' , '_' , $ version -> getId ( ) ) , 'locale' => $ version -> getLocale ( ) , 'author' => array_key_exists ( $ version -> getAuthor ( ) , $ fullNamesByIds ) ? $ fullNamesByIds [ $ version -> getAuthor ( ) ] : '' , 'authored' => $ version -> getAuthored ( ) , ] ; } $ versionCollection = new ListRepresentation ( $ versionData , 'versions' , 'get_node_versions' , [ 'uuid' => $ uuid , 'language' => $ locale , 'webspace' => $ request -> get ( 'webspace' ) , ] , $ listRestHelper -> getPage ( ) , $ limit , $ total ) ; return $ this -> handleView ( $ this -> view ( $ versionCollection ) ) ; } | Returns the versions for the node with the given UUID . |
11,192 | private function findOrCreateCategoryTranslation ( CategoryInterface $ category , CategoryWrapper $ categoryWrapper , $ locale ) { $ translationEntity = $ category -> findTranslationByLocale ( $ locale ) ; if ( ! $ translationEntity ) { $ translationEntity = $ this -> categoryTranslationRepository -> createNew ( ) ; $ translationEntity -> setLocale ( $ locale ) ; $ categoryWrapper -> setTranslation ( $ translationEntity ) ; } return $ translationEntity ; } | Returns category - translation or create a new one . |
11,193 | public function getApiObject ( $ category , $ locale ) { if ( $ category instanceof CategoryWrapper ) { $ category = $ category -> getEntity ( ) ; } if ( ! $ category instanceof CategoryInterface ) { return ; } return new CategoryWrapper ( $ category , $ locale ) ; } | Returns an API - Object for a given category - entity . The API - Object wraps the entity and provides neat getters and setters . If the given object is already an API - object the associated entity is used for wrapping . |
11,194 | public function getApiObjects ( $ entities , $ locale ) { return array_map ( function ( $ entity ) use ( $ locale ) { return $ this -> getApiObject ( $ entity , $ locale ) ; } , $ entities ) ; } | Returns an array of API - Objects for a given array of category - entities . The returned array can contain null - values if the given entities are not valid . |
11,195 | public function getQueryBuilderWithoutSecurity ( QueryBuilder $ queryBuilder ) { $ queryBuilder -> addSelect ( 'fileVersion' ) -> addSelect ( 'file' ) -> addSelect ( 'media' ) -> addSelect ( 'collection' ) -> leftJoin ( 'd.fileVersion' , 'fileVersion' ) -> leftJoin ( 'fileVersion.file' , 'file' ) -> leftJoin ( 'file.media' , 'media' ) -> leftJoin ( 'media.collection' , 'collection' ) -> leftJoin ( AccessControl :: class , 'accessControl' , 'WITH' , 'accessControl.entityClass = :entityClass AND accessControl.entityId = collection.id' ) -> where ( 'file.version = fileVersion.version' ) -> andWhere ( 'accessControl.id is null' ) -> setParameter ( 'entityClass' , Collection :: class ) ; return $ queryBuilder ; } | Returns query - builder to find file - version - meta without permissions . |
11,196 | private function buildPropertiesSelect ( $ locale , & $ additionalFields ) { foreach ( $ this -> propertiesConfig as $ parameter ) { $ alias = $ parameter -> getName ( ) ; $ propertyName = $ parameter -> getValue ( ) ; if ( false !== strpos ( $ propertyName , '.' ) ) { $ parts = explode ( '.' , $ propertyName ) ; $ this -> buildExtensionSelect ( $ alias , $ parts [ 0 ] , $ parts [ 1 ] , $ locale , $ additionalFields ) ; } else { $ this -> buildPropertySelect ( $ alias , $ propertyName , $ locale , $ additionalFields ) ; } } } | build select for properties . |
11,197 | private function buildPropertySelect ( $ alias , $ propertyName , $ locale , & $ additionalFields ) { foreach ( $ this -> structureManager -> getStructures ( static :: $ structureType ) as $ structure ) { if ( $ structure -> hasProperty ( $ propertyName ) ) { $ property = $ structure -> getProperty ( $ propertyName ) ; $ additionalFields [ $ locale ] [ ] = [ 'name' => $ alias , 'property' => $ property , 'templateKey' => $ structure -> getKey ( ) , ] ; } } } | build select for single property . |
11,198 | private function buildExtensionSelect ( $ alias , $ extension , $ propertyName , $ locale , & $ additionalFields ) { $ extension = $ this -> extensionManager -> getExtension ( 'all' , $ extension ) ; $ additionalFields [ $ locale ] [ ] = [ 'name' => $ alias , 'extension' => $ extension , 'property' => $ propertyName , ] ; } | build select for extension property . |
11,199 | private function buildDatasourceWhere ( ) { $ dataSource = $ this -> getConfig ( 'dataSource' ) ; $ includeSubFolders = $ this -> getConfig ( 'includeSubFolders' , false ) ; $ sqlFunction = false !== $ includeSubFolders && 'false' !== $ includeSubFolders ? 'ISDESCENDANTNODE' : 'ISCHILDNODE' ; $ node = $ this -> sessionManager -> getSession ( ) -> getNodeByIdentifier ( $ dataSource ) ; return $ sqlFunction . '(page, \'' . $ node -> getPath ( ) . '\')' ; } | build datasource where clause . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.