idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
11,800 | protected function addAccessControl ( QueryBuilder $ queryBuilder , UserInterface $ user , $ permission , $ entityClass , $ entityAlias ) { $ queryBuilder -> leftJoin ( AccessControl :: class , 'accessControl' , 'WITH' , 'accessControl.entityClass = :entityClass AND accessControl.entityId = ' . $ entityAlias . '.id' ) ; $ queryBuilder -> leftJoin ( 'accessControl.role' , 'role' ) ; $ queryBuilder -> andWhere ( 'BIT_AND(accessControl.permissions, :permission) = :permission OR accessControl.permissions IS NULL' ) ; $ roleIds = [ ] ; foreach ( $ user -> getRoleObjects ( ) as $ role ) { $ roleIds [ ] = $ role -> getId ( ) ; } $ queryBuilder -> andWhere ( 'role.id IN(:roleIds) OR role.id IS NULL' ) ; $ queryBuilder -> setParameter ( 'roleIds' , $ roleIds ) ; $ queryBuilder -> setParameter ( 'entityClass' , $ entityClass ) ; $ queryBuilder -> setParameter ( 'permission' , $ permission ) ; } | Adds joins and conditions to the QueryBuilder in order to only return entities the given user is allowed to see . |
11,801 | private function initListBuilder ( ContainerBuilder $ container , Loader \ XmlFileLoader $ loader ) { if ( SuluKernel :: CONTEXT_ADMIN === $ container -> getParameter ( 'sulu.context' ) ) { $ loader -> load ( 'list_builder.xml' ) ; } } | Initializes list builder . |
11,802 | protected function getExtensionData ( BasePageDocument $ document ) { $ extensionData = [ ] ; foreach ( $ document -> getExtensionsData ( ) -> toArray ( ) as $ extensionName => $ extensionProperties ) { $ extension = $ this -> extensionManager -> getExtension ( $ document -> getStructureType ( ) , $ extensionName ) ; if ( $ extension instanceof ExportExtensionInterface ) { $ extensionData [ $ extensionName ] = $ extension -> export ( $ extensionProperties , $ this -> format ) ; } } return $ extensionData ; } | Returns a flat array with the extensions of the given document . |
11,803 | protected function getSettingData ( BasePageDocument $ document ) { if ( $ created = $ document -> getCreated ( ) ) { $ created = $ created -> format ( 'c' ) ; } if ( $ changed = $ document -> getChanged ( ) ) { $ changed = $ changed -> format ( 'c' ) ; } if ( $ published = $ document -> getPublished ( ) ) { $ published = $ published -> format ( 'c' ) ; } $ settingOptions = [ ] ; if ( '1.2.xliff' === $ this -> format ) { $ settingOptions = [ 'translate' => false ] ; } return [ 'structureType' => $ this -> createProperty ( 'structureType' , $ document -> getStructureType ( ) , $ settingOptions ) , 'published' => $ this -> createProperty ( 'published' , $ published , $ settingOptions ) , 'created' => $ this -> createProperty ( 'created' , $ created , $ settingOptions ) , 'changed' => $ this -> createProperty ( 'changed' , $ changed , $ settingOptions ) , 'creator' => $ this -> createProperty ( 'creator' , $ document -> getCreator ( ) , $ settingOptions ) , 'changer' => $ this -> createProperty ( 'changer' , $ document -> getChanger ( ) , $ settingOptions ) , 'locale' => $ this -> createProperty ( 'locale' , $ document -> getLocale ( ) , $ settingOptions ) , 'navigationContexts' => $ this -> createProperty ( 'navigationContexts' , json_encode ( $ document -> getNavigationContexts ( ) ) , $ settingOptions ) , 'permissions' => $ this -> createProperty ( 'permissions' , json_encode ( $ document -> getPermissions ( ) ) , $ settingOptions ) , 'shadowLocale' => $ this -> createProperty ( 'shadowLocale' , $ document -> getShadowLocale ( ) , $ settingOptions ) , 'originalLocale' => $ this -> createProperty ( 'originalLocale' , $ document -> getOriginalLocale ( ) , $ settingOptions ) , 'resourceSegment' => $ this -> createProperty ( 'resourceSegment' , $ document -> getResourceSegment ( ) , $ settingOptions ) , 'webspaceName' => $ this -> createProperty ( 'webspaceName' , $ document -> getWebspaceName ( ) , $ settingOptions ) , 'redirectExternal' => $ this -> createProperty ( 'redirectExternal' , $ document -> getRedirectExternal ( ) , $ settingOptions ) , 'redirectType' => $ this -> createProperty ( 'redirectType' , $ document -> getRedirectType ( ) , $ settingOptions ) , 'redirectTarget' => $ this -> createProperty ( 'redirectTarget' , $ document -> getRedirectTarget ( ) , $ settingOptions ) , 'workflowStage' => $ this -> createProperty ( 'workflowStage' , $ document -> getWorkflowStage ( ) , $ settingOptions ) , 'path' => $ this -> createProperty ( 'path' , $ document -> getPath ( ) , $ settingOptions ) , ] ; } | Returns a flat array with the settings of the given document . |
11,804 | protected function getDocuments ( $ webspaceKey , $ uuid = null , $ nodes = null , $ ignoredNodes = null ) { $ queryString = $ this -> getDocumentsQueryString ( $ webspaceKey , $ uuid , $ nodes , $ ignoredNodes ) ; $ query = $ this -> documentManager -> createQuery ( $ queryString , $ this -> exportLocale ) ; return $ query -> execute ( ) ; } | Returns all Documents from given webspace . |
11,805 | protected function getDocumentsQueryString ( $ webspaceKey , $ uuid = null , $ nodes = null , $ ignoredNodes = null ) { $ where = [ ] ; $ where [ ] = '([jcr:mixinTypes] = "sulu:page" OR [jcr:mixinTypes] = "sulu:home")' ; $ where [ ] = sprintf ( '(ISDESCENDANTNODE("/cmf/%s/contents") OR ISSAMENODE("/cmf/%s/contents"))' , $ webspaceKey , $ webspaceKey ) ; $ where [ ] = sprintf ( '[i18n:%s-template] IS NOT NULL' , $ this -> exportLocale ) ; if ( $ uuid ) { $ where [ ] = sprintf ( '[jcr:uuid] = "%s"' , $ uuid ) ; } $ nodeWhere = $ this -> buildNodeUuidToPathWhere ( $ nodes , false ) ; if ( $ nodeWhere ) { $ where [ ] = $ nodeWhere ; } $ ignoreWhere = $ this -> buildNodeUuidToPathWhere ( $ ignoredNodes , true ) ; if ( $ ignoreWhere ) { $ where [ ] = $ ignoreWhere ; } $ queryString = 'SELECT * FROM [nt:unstructured] AS a WHERE ' . implode ( ' AND ' , $ where ) ; return $ queryString ; } | Create the query to get all documents from given webspace and language . |
11,806 | protected function buildNodeUuidToPathWhere ( $ nodes , $ not = false ) { if ( $ nodes ) { $ paths = $ this -> getPathsByUuids ( $ nodes ) ; $ wheres = [ ] ; foreach ( $ nodes as $ key => $ uuid ) { if ( isset ( $ paths [ $ uuid ] ) ) { $ wheres [ ] = sprintf ( 'ISDESCENDANTNODE("%s")' , $ paths [ $ uuid ] ) ; } } if ( ! empty ( $ wheres ) ) { return ( $ not ? 'NOT ' : '' ) . '(' . implode ( ' OR ' , $ wheres ) . ')' ; } } } | Build query to return only specific nodes . |
11,807 | protected function getPathsByUuids ( $ uuids ) { $ paths = [ ] ; $ where = [ ] ; foreach ( $ uuids as $ uuid ) { $ where [ ] = sprintf ( '[jcr:uuid] = "%s"' , $ uuid ) ; } $ queryString = 'SELECT * FROM [nt:unstructured] AS a WHERE ' . implode ( ' OR ' , $ where ) ; $ query = $ this -> documentManager -> createQuery ( $ queryString ) ; $ result = $ query -> execute ( ) ; foreach ( $ result as $ page ) { $ paths [ $ page -> getUuid ( ) ] = $ page -> getPath ( ) ; } return $ paths ; } | Returns node path from given uuid . |
11,808 | public function onPostSerialize ( ObjectEvent $ event ) { $ teaser = $ event -> getObject ( ) ; $ visitor = $ event -> getVisitor ( ) ; $ context = $ event -> getContext ( ) ; if ( ! ( $ teaser instanceof Teaser ) ) { return ; } $ visitor -> addData ( 'teaserId' , $ context -> accept ( sprintf ( '%s;%s' , $ teaser -> getType ( ) , $ teaser -> getId ( ) ) ) ) ; } | Add uniqueid and media - data to serialized data . |
11,809 | private function setNodeName ( AbstractMappingEvent $ event ) { $ document = $ event -> getDocument ( ) ; if ( ! $ document instanceof NodeNameBehavior ) { return ; } $ node = $ event -> getNode ( ) ; $ accessor = $ event -> getAccessor ( ) ; $ accessor -> set ( 'nodeName' , $ node -> getName ( ) ) ; } | Sets the node name . |
11,810 | private function getChildPropertyDatas ( $ child ) { $ childProperties = [ ] ; foreach ( array_keys ( $ child ) as $ childKey ) { $ childProperties [ $ childKey ] = $ this -> getPropertyData ( $ childKey , $ child , $ contentTypeName = null , $ extension = null ) ; } return $ childProperties ; } | Prepare data for structure . |
11,811 | private function utf8ToCharset ( $ content , $ encoding = null ) { if ( 'UTF-8' !== $ encoding && ! empty ( $ encoding ) ) { if ( function_exists ( 'mb_convert_encoding' ) ) { return mb_convert_encoding ( $ content , $ encoding , 'UTF-8' ) ; } if ( function_exists ( 'iconv' ) ) { return iconv ( 'UTF-8' , $ encoding , $ content ) ; } throw new \ RuntimeException ( 'No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).' ) ; } return $ content ; } | Part of Symfony XliffFileLoader . |
11,812 | private function getArea ( $ template , $ area , $ locales , $ templateTitles ) { $ key = $ area [ 'key' ] ; $ titles = [ ] ; foreach ( $ locales as $ locale ) { $ title = $ templateTitles [ $ locale ] . ' ' . ucfirst ( $ key ) ; if ( isset ( $ area [ 'title' ] [ $ locale ] ) ) { $ title = $ area [ 'title' ] [ $ locale ] ; } $ titles [ $ locale ] = $ title ; } return [ 'key' => $ key , 'template' => $ template , 'title' => $ titles , ] ; } | Get area . |
11,813 | public function setConditionGroup ( \ Sulu \ Bundle \ ResourceBundle \ Entity \ ConditionGroup $ conditionGroup ) { $ this -> conditionGroup = $ conditionGroup ; return $ this ; } | Set conditionGroup . |
11,814 | public function onPostDeserialize ( ObjectEvent $ event ) { $ targetGroupRule = $ event -> getObject ( ) ; if ( ! $ targetGroupRule instanceof TargetGroupRuleInterface ) { return ; } if ( $ targetGroupRule -> getConditions ( ) ) { foreach ( $ targetGroupRule -> getConditions ( ) as $ condition ) { $ condition -> setRule ( $ targetGroupRule ) ; } } } | Called after a target group rule was deserialized . |
11,815 | protected function buildWhere ( $ webspaceKey , $ locale ) { $ where = [ ] ; if ( null !== $ this -> context ) { $ where [ ] = sprintf ( "page.[i18n:%s-navContexts] = '%s'" , $ locale , $ this -> context ) ; } if ( null !== $ this -> parent ) { $ where [ ] = sprintf ( "ISDESCENDANTNODE(page, '%s')" , $ this -> parent ) ; } else { $ where [ ] = sprintf ( "ISDESCENDANTNODE(page, '%s')" , '/cmf/' . $ webspaceKey . '/contents' ) ; } return implode ( ' AND ' , $ where ) ; } | Returns custom select statement . |
11,816 | public function getAction ( $ id , Request $ request ) { try { $ locale = $ this -> getRequestParameter ( $ request , 'locale' , true ) ; $ mediaManager = $ this -> getMediaManager ( ) ; $ view = $ this -> responseGetById ( $ id , function ( $ id ) use ( $ locale , $ mediaManager ) { $ media = $ mediaManager -> getById ( $ id , $ locale ) ; $ collection = $ media -> getEntity ( ) -> getCollection ( ) ; if ( SystemCollectionManagerInterface :: COLLECTION_TYPE === $ collection -> getType ( ) -> getKey ( ) ) { $ this -> getSecurityChecker ( ) -> checkPermission ( 'sulu.media.system_collections' , PermissionTypes :: VIEW ) ; } $ this -> getSecurityChecker ( ) -> checkPermission ( new SecurityCondition ( $ this -> getSecurityContext ( ) , $ locale , $ this -> getSecuredClass ( ) , $ collection -> getId ( ) ) , PermissionTypes :: VIEW ) ; return $ media ; } ) ; } catch ( MediaNotFoundException $ e ) { $ view = $ this -> view ( $ e -> toArray ( ) , 404 ) ; } catch ( MediaException $ e ) { $ view = $ this -> view ( $ e -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; } | Shows a single media with the given id . |
11,817 | public function cgetAction ( Request $ request ) { $ locale = $ this -> getRequestParameter ( $ request , 'locale' , true ) ; $ fieldDescriptors = $ this -> getFieldDescriptors ( $ locale , false ) ; $ types = array_filter ( explode ( ',' , $ request -> get ( 'types' ) ) ) ; $ listBuilder = $ this -> getListBuilder ( $ request , $ fieldDescriptors , $ types ) ; $ listBuilder -> setParameter ( 'locale' , $ locale ) ; $ listResponse = $ listBuilder -> execute ( ) ; $ count = $ listBuilder -> count ( ) ; for ( $ i = 0 , $ length = count ( $ listResponse ) ; $ i < $ length ; ++ $ i ) { $ format = $ this -> getFormatManager ( ) -> getFormats ( $ listResponse [ $ i ] [ 'id' ] , $ listResponse [ $ i ] [ 'name' ] , $ listResponse [ $ i ] [ 'storageOptions' ] , $ listResponse [ $ i ] [ 'version' ] , $ listResponse [ $ i ] [ 'subVersion' ] , $ listResponse [ $ i ] [ 'mimeType' ] ) ; if ( 0 < count ( $ format ) ) { $ listResponse [ $ i ] [ 'thumbnails' ] = $ format ; } $ listResponse [ $ i ] [ 'url' ] = $ this -> getMediaManager ( ) -> getUrl ( $ listResponse [ $ i ] [ 'id' ] , $ listResponse [ $ i ] [ 'name' ] , $ listResponse [ $ i ] [ 'version' ] ) ; } $ ids = $ listBuilder -> getIds ( ) ; if ( null != $ ids ) { $ result = [ ] ; foreach ( $ listResponse as $ item ) { $ result [ array_search ( $ item [ 'id' ] , $ ids ) ] = $ item ; } ksort ( $ result ) ; $ listResponse = array_values ( $ result ) ; } $ list = new ListRepresentation ( $ listResponse , self :: $ entityKey , 'cget_media' , $ request -> query -> all ( ) , $ listBuilder -> getCurrentPage ( ) , $ listBuilder -> getLimit ( ) , $ count ) ; $ view = $ this -> view ( $ list , 200 ) ; return $ this -> handleView ( $ view ) ; } | Lists all media . |
11,818 | private function getListBuilder ( Request $ request , array $ fieldDescriptors , $ types ) { $ restHelper = $ this -> get ( 'sulu_core.doctrine_rest_helper' ) ; $ factory = $ this -> get ( 'sulu_core.doctrine_list_builder_factory' ) ; $ listBuilder = $ factory -> create ( $ this -> getParameter ( 'sulu.model.media.class' ) ) ; $ restHelper -> initializeListBuilder ( $ listBuilder , $ fieldDescriptors ) ; if ( ! $ request -> get ( 'sortBy' ) ) { $ listBuilder -> sort ( $ fieldDescriptors [ 'created' ] , 'desc' ) ; } $ collectionId = $ request -> get ( 'collection' ) ; if ( $ collectionId ) { $ collectionType = $ this -> getCollectionRepository ( ) -> findCollectionTypeById ( $ collectionId ) ; if ( SystemCollectionManagerInterface :: COLLECTION_TYPE === $ collectionType ) { $ this -> getSecurityChecker ( ) -> checkPermission ( 'sulu.media.system_collections' , PermissionTypes :: VIEW ) ; } $ listBuilder -> addSelectField ( $ fieldDescriptors [ 'collection' ] ) ; $ listBuilder -> where ( $ fieldDescriptors [ 'collection' ] , $ collectionId ) ; } else { $ listBuilder -> addPermissionCheckField ( $ fieldDescriptors [ 'collection' ] ) ; $ listBuilder -> setPermissionCheck ( $ this -> getUser ( ) , PermissionTypes :: VIEW , $ this -> getParameter ( 'sulu.model.collection.class' ) ) ; } if ( count ( $ types ) ) { $ listBuilder -> in ( $ fieldDescriptors [ 'type' ] , $ types ) ; } if ( ! $ this -> getSecurityChecker ( ) -> hasPermission ( 'sulu.media.system_collections' , PermissionTypes :: VIEW ) ) { $ systemCollection = $ this -> getCollectionRepository ( ) -> findCollectionByKey ( SystemCollectionManagerInterface :: COLLECTION_KEY ) ; $ lftExpression = $ listBuilder -> createWhereExpression ( $ fieldDescriptors [ 'lft' ] , $ systemCollection -> getLft ( ) , ListBuilderInterface :: WHERE_COMPARATOR_LESS ) ; $ rgtExpression = $ listBuilder -> createWhereExpression ( $ fieldDescriptors [ 'rgt' ] , $ systemCollection -> getRgt ( ) , ListBuilderInterface :: WHERE_COMPARATOR_GREATER ) ; $ listBuilder -> addExpression ( $ listBuilder -> createOrExpression ( [ $ lftExpression , $ rgtExpression , ] ) ) ; } $ listBuilder -> addSelectField ( $ fieldDescriptors [ 'version' ] ) ; $ listBuilder -> addSelectField ( $ fieldDescriptors [ 'subVersion' ] ) ; $ listBuilder -> addSelectField ( $ fieldDescriptors [ 'name' ] ) ; $ listBuilder -> addSelectField ( $ fieldDescriptors [ 'locale' ] ) ; $ listBuilder -> addSelectField ( $ fieldDescriptors [ 'mimeType' ] ) ; $ listBuilder -> addSelectField ( $ fieldDescriptors [ 'storageOptions' ] ) ; $ listBuilder -> addSelectField ( $ fieldDescriptors [ 'id' ] ) ; $ listBuilder -> addSelectField ( $ fieldDescriptors [ 'collection' ] ) ; return $ listBuilder ; } | Returns a list - builder for media list . |
11,819 | public function deleteAction ( $ id ) { $ delete = function ( $ id ) { try { $ this -> getMediaManager ( ) -> delete ( $ id , true ) ; } catch ( MediaNotFoundException $ e ) { $ entityName = $ this -> getParameter ( 'sulu.model.media.class' ) ; throw new EntityNotFoundException ( $ entityName , $ id ) ; } catch ( MediaException $ e ) { throw new RestException ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } } ; $ view = $ this -> responseDelete ( $ id , $ delete ) ; return $ this -> handleView ( $ view ) ; } | Delete a media with the given id . |
11,820 | protected function moveEntity ( $ id , Request $ request ) { try { $ locale = $ this -> getRequestParameter ( $ request , 'locale' , true ) ; $ destination = $ this -> getRequestParameter ( $ request , 'destination' , true ) ; $ mediaManager = $ this -> getMediaManager ( ) ; $ media = $ mediaManager -> move ( $ id , $ locale , $ destination ) ; $ view = $ this -> view ( $ media , 200 ) ; } catch ( MediaNotFoundException $ e ) { $ view = $ this -> view ( $ e -> toArray ( ) , 404 ) ; } catch ( MediaException $ e ) { $ view = $ this -> view ( $ e -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; } | Move an entity to another collection . |
11,821 | public function getContactsAction ( $ id , Request $ request ) { if ( 'true' == $ request -> get ( 'flat' ) ) { $ account = $ this -> getRepository ( ) -> findById ( $ id ) ; $ restHelper = $ this -> getRestHelper ( ) ; $ factory = $ this -> get ( 'sulu_core.doctrine_list_builder_factory' ) ; $ listBuilder = $ factory -> create ( self :: $ accountContactEntityName ) ; $ fieldDescriptors = $ this -> getAccountContactFieldDescriptors ( ) ; $ restHelper -> initializeListBuilder ( $ listBuilder , $ fieldDescriptors ) ; $ listBuilder -> addSelectField ( $ fieldDescriptors [ 'contactId' ] ) ; $ listBuilder -> setIdField ( $ fieldDescriptors [ 'id' ] ) ; $ listBuilder -> where ( $ fieldDescriptors [ 'account' ] , $ id ) ; $ listBuilder -> sort ( $ fieldDescriptors [ 'lastName' ] , $ listBuilder :: SORTORDER_ASC ) ; $ values = $ listBuilder -> execute ( ) ; foreach ( $ values as & $ value ) { $ value [ 'id' ] = $ value [ 'contactId' ] ; unset ( $ value [ 'contactId' ] ) ; if ( null != $ account -> getMainContact ( ) && $ value [ 'id' ] === $ account -> getMainContact ( ) -> getId ( ) ) { $ value [ 'isMainContact' ] = true ; } else { $ value [ 'isMainContact' ] = false ; } } $ list = new ListRepresentation ( $ values , 'contacts' , 'get_account_contacts' , array_merge ( [ 'id' => $ id ] , $ request -> query -> all ( ) ) , $ listBuilder -> getCurrentPage ( ) , $ listBuilder -> getLimit ( ) , $ listBuilder -> count ( ) ) ; } else { $ contactManager = $ this -> getAccountManager ( ) ; $ locale = $ this -> getUser ( ) -> getLocale ( ) ; $ contacts = $ contactManager -> findContactsByAccountId ( $ id , $ locale , false ) ; $ list = new CollectionRepresentation ( $ contacts , self :: $ contactEntityKey ) ; } $ view = $ this -> view ( $ list , 200 ) ; return $ this -> handleView ( $ view ) ; } | Lists all contacts of an account . optional parameter flat calls listAction . |
11,822 | public function getAddressesAction ( $ id , Request $ request ) { if ( 'true' == $ request -> get ( 'flat' ) ) { $ restHelper = $ this -> getRestHelper ( ) ; $ factory = $ this -> get ( 'sulu_core.doctrine_list_builder_factory' ) ; $ listBuilder = $ factory -> create ( $ this -> getAccountEntityName ( ) ) ; $ restHelper -> initializeListBuilder ( $ listBuilder , $ this -> getAccountAddressesFieldDescriptors ( ) ) ; $ listBuilder -> where ( $ this -> getFieldDescriptors ( ) [ 'id' ] , $ id ) ; $ values = $ listBuilder -> execute ( ) ; $ list = new ListRepresentation ( $ values , 'addresses' , 'get_account_addresses' , array_merge ( [ 'id' => $ id ] , $ request -> query -> all ( ) ) , $ listBuilder -> getCurrentPage ( ) , $ listBuilder -> getLimit ( ) , $ listBuilder -> count ( ) ) ; } else { $ addresses = $ this -> getDoctrine ( ) -> getRepository ( self :: $ addressEntityName ) -> findByAccountId ( $ id ) ; $ list = new CollectionRepresentation ( $ addresses , 'addresses' ) ; } $ view = $ this -> view ( $ list , 200 ) ; return $ this -> handleView ( $ view ) ; } | Lists all addresses of an account optional parameter flat calls listAction . |
11,823 | public function deleteContactsAction ( $ accountId , $ contactId ) { try { $ accountContact = $ this -> getDoctrine ( ) -> getRepository ( self :: $ accountContactEntityName ) -> findByForeignIds ( $ accountId , $ contactId ) ; if ( ! $ accountContact ) { throw new EntityNotFoundException ( 'AccountContact' , $ accountId . $ contactId ) ; } $ id = $ accountContact -> getId ( ) ; $ account = $ accountContact -> getAccount ( ) ; if ( $ account -> getMainContact ( ) && strval ( $ account -> getMainContact ( ) -> getId ( ) ) === $ contactId ) { $ account -> setMainContact ( null ) ; } $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> remove ( $ accountContact ) ; $ em -> flush ( ) ; $ view = $ this -> view ( $ id , 200 ) ; } catch ( EntityNotFoundException $ enfe ) { $ view = $ this -> view ( $ enfe -> toArray ( ) , 404 ) ; } return $ this -> handleView ( $ view ) ; } | Deleted account contact . |
11,824 | public function cgetAction ( Request $ request ) { $ locale = $ this -> getUser ( ) -> getLocale ( ) ; if ( 'true' == $ request -> get ( 'flat' ) ) { $ restHelper = $ this -> get ( 'sulu_core.doctrine_rest_helper' ) ; $ fieldDescriptors = $ this -> getFieldDescriptors ( ) ; $ listBuilder = $ this -> generateFlatListBuilder ( ) ; $ restHelper -> initializeListBuilder ( $ listBuilder , $ fieldDescriptors ) ; $ this -> applyRequestParameters ( $ request , $ listBuilder ) ; $ listResponse = $ listBuilder -> execute ( ) ; $ listResponse = $ this -> addLogos ( $ listResponse , $ locale ) ; $ list = new ListRepresentation ( $ listResponse , self :: $ entityKey , 'get_accounts' , $ request -> query -> all ( ) , $ listBuilder -> getCurrentPage ( ) , $ listBuilder -> getLimit ( ) , $ listBuilder -> count ( ) ) ; $ view = $ this -> view ( $ list , 200 ) ; } else { $ filter = $ this -> retrieveFilter ( $ request ) ; $ accountManager = $ this -> getAccountManager ( ) ; $ accounts = $ accountManager -> findAll ( $ locale , $ filter ) ; $ list = new CollectionRepresentation ( $ accounts , self :: $ entityKey ) ; $ view = $ this -> view ( $ list , 200 ) ; } $ context = new Context ( ) ; $ context -> setGroups ( [ 'fullAccount' , 'partialContact' , 'Default' ] ) ; $ view -> setContext ( $ context ) ; return $ this -> handleView ( $ view ) ; } | Lists all accounts . Optional parameter flat calls listAction . |
11,825 | protected function generateFlatListBuilder ( ) { $ factory = $ this -> get ( 'sulu_core.doctrine_list_builder_factory' ) ; $ listBuilder = $ factory -> create ( $ this -> getAccountEntityName ( ) ) ; return $ listBuilder ; } | Creates a listbuilder instance . |
11,826 | protected function applyRequestParameters ( Request $ request , $ listBuilder ) { if ( json_decode ( $ request -> get ( 'hasNoParent' , null ) ) ) { $ listBuilder -> where ( $ this -> getFieldDescriptorForNoParent ( ) , null ) ; } if ( json_decode ( $ request -> get ( 'hasEmail' , null ) ) ) { $ listBuilder -> whereNot ( $ this -> getFieldDescriptors ( ) [ 'mainEmail' ] , null ) ; } } | Applies the filter parameter and hasNoparent parameter for listbuilder . |
11,827 | public function postAction ( Request $ request ) { $ name = $ request -> get ( 'name' ) ; try { if ( null == $ name ) { throw new RestException ( 'There is no name for the account given' ) ; } $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ account = $ this -> doPost ( $ request ) ; $ em -> persist ( $ account ) ; $ em -> flush ( ) ; $ accountManager = $ this -> getAccountManager ( ) ; $ locale = $ this -> getUser ( ) -> getLocale ( ) ; $ acc = $ accountManager -> getAccount ( $ account , $ locale ) ; $ view = $ this -> view ( $ acc , 200 ) ; $ context = new Context ( ) ; $ context -> setGroups ( self :: $ accountSerializationGroups ) ; $ view -> setContext ( $ context ) ; } 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 account . |
11,828 | protected function doPost ( Request $ request ) { $ accountManager = $ this -> getAccountManager ( ) ; $ account = $ this -> get ( 'sulu_contact.account_factory' ) -> createEntity ( ) ; $ account -> setName ( $ request -> get ( 'name' ) ) ; $ account -> setCorporation ( $ request -> get ( 'corporation' ) ) ; if ( null !== $ request -> get ( 'uid' ) ) { $ account -> setUid ( $ request -> get ( 'uid' ) ) ; } if ( null !== $ request -> get ( 'note' ) ) { $ account -> setNote ( $ request -> get ( 'note' ) ) ; } $ logo = $ request -> get ( 'logo' , [ ] ) ; if ( $ logo && array_key_exists ( 'id' , $ logo ) ) { $ accountManager -> setLogo ( $ account , $ request -> get ( 'logo' ) [ 'id' ] ) ; } $ this -> setParent ( $ request -> get ( 'parent' ) , $ account ) ; $ accountManager -> processCategories ( $ account , $ request -> get ( 'categories' , [ ] ) ) ; $ account -> setCreator ( $ this -> getUser ( ) ) ; $ account -> setChanger ( $ this -> getUser ( ) ) ; $ accountManager -> addNewContactRelations ( $ account , $ request -> request -> all ( ) ) ; return $ account ; } | Maps data from request to a new account . |
11,829 | public function putAction ( $ id , Request $ request ) { try { $ account = $ this -> getRepository ( ) -> findAccountById ( $ id ) ; if ( ! $ account ) { throw new EntityNotFoundException ( $ this -> getAccountEntityName ( ) , $ id ) ; } else { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ this -> doPut ( $ account , $ request ) ; $ em -> flush ( ) ; $ accountManager = $ this -> getAccountManager ( ) ; $ locale = $ this -> getUser ( ) -> getLocale ( ) ; $ acc = $ accountManager -> getAccount ( $ account , $ locale ) ; $ context = new Context ( ) ; $ context -> setGroups ( self :: $ accountSerializationGroups ) ; $ view = $ this -> view ( $ acc , 200 ) ; $ view -> setContext ( $ context ) ; } } 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 with the given id . |
11,830 | protected function doPut ( AccountInterface $ account , Request $ request ) { $ account -> setName ( $ request -> get ( 'name' ) ) ; $ account -> setCorporation ( $ request -> get ( 'corporation' ) ) ; $ accountManager = $ this -> getAccountManager ( ) ; if ( null !== $ request -> get ( 'uid' ) ) { $ account -> setUid ( $ request -> get ( 'uid' ) ) ; } if ( null !== $ request -> get ( 'note' ) ) { $ account -> setNote ( $ request -> get ( 'note' ) ) ; } $ logo = $ request -> get ( 'logo' , [ ] ) ; if ( $ logo && array_key_exists ( 'id' , $ logo ) ) { $ accountManager -> setLogo ( $ account , $ request -> get ( 'logo' ) [ 'id' ] ) ; } $ this -> setParent ( $ request -> get ( 'parent' ) , $ account ) ; $ user = $ this -> getUser ( ) ; $ account -> setChanger ( $ user ) ; if ( ! ( $ accountManager -> processUrls ( $ account , $ request -> get ( 'urls' , [ ] ) ) && $ accountManager -> processEmails ( $ account , $ request -> get ( 'emails' , [ ] ) ) && $ accountManager -> processFaxes ( $ account , $ request -> get ( 'faxes' , [ ] ) ) && $ accountManager -> processSocialMediaProfiles ( $ account , $ request -> get ( 'socialMediaProfiles' , [ ] ) ) && $ accountManager -> processPhones ( $ account , $ request -> get ( 'phones' , [ ] ) ) && $ accountManager -> processAddresses ( $ account , $ request -> get ( 'addresses' , [ ] ) ) && $ accountManager -> processTags ( $ account , $ request -> get ( 'tags' , [ ] ) ) && $ accountManager -> processNotes ( $ account , $ request -> get ( 'notes' , [ ] ) ) && $ accountManager -> processCategories ( $ account , $ request -> get ( 'categories' , [ ] ) ) && $ accountManager -> processBankAccounts ( $ account , $ request -> get ( 'bankAccounts' , [ ] ) ) ) ) { throw new RestException ( 'Updating dependencies is not possible' , 0 ) ; } } | processes given entity for put . |
11,831 | private function setParent ( $ parentData , AccountInterface $ account ) { if ( null != $ parentData && isset ( $ parentData [ 'id' ] ) && 'null' != $ parentData [ 'id' ] && '' != $ parentData [ 'id' ] ) { $ parent = $ this -> getRepository ( ) -> findAccountById ( $ parentData [ 'id' ] ) ; if ( ! $ parent ) { throw new EntityNotFoundException ( $ this -> getAccountEntityName ( ) , $ parentData [ 'id' ] ) ; } $ account -> setParent ( $ parent ) ; } else { $ account -> setParent ( null ) ; } } | Set parent to account . |
11,832 | protected function doPatch ( AccountInterface $ account , Request $ request , ObjectManager $ entityManager ) { $ accountManager = $ this -> getAccountManager ( ) ; if ( null !== $ request -> get ( 'uid' ) ) { $ account -> setUid ( $ request -> get ( 'uid' ) ) ; } if ( null !== $ request -> get ( 'registerNumber' ) ) { $ account -> setRegisterNumber ( $ request -> get ( 'registerNumber' ) ) ; } if ( null !== $ request -> get ( 'number' ) ) { $ account -> setNumber ( $ request -> get ( 'number' ) ) ; } if ( null !== $ request -> get ( 'placeOfJurisdiction' ) ) { $ account -> setPlaceOfJurisdiction ( $ request -> get ( 'placeOfJurisdiction' ) ) ; } if ( array_key_exists ( 'id' , $ request -> get ( 'logo' , [ ] ) ) ) { $ accountManager -> setLogo ( $ account , $ request -> get ( 'logo' ) [ 'id' ] ) ; } if ( null !== $ request -> get ( 'medias' ) ) { $ accountManager -> setMedias ( $ account , $ request -> get ( 'medias' ) ) ; } if ( null !== ( $ mainContactRequest = $ request -> get ( 'mainContact' ) ) ) { $ mainContact = $ entityManager -> getRepository ( $ this -> container -> getParameter ( 'sulu.model.contact.class' ) ) -> find ( $ mainContactRequest [ 'id' ] ) ; if ( $ mainContact ) { $ account -> setMainContact ( $ mainContact ) ; } } if ( null !== $ request -> get ( 'bankAccounts' ) ) { $ accountManager -> processBankAccounts ( $ account , $ request -> get ( 'bankAccounts' , [ ] ) ) ; } } | Process geiven entity for patch . |
11,833 | public function deleteAction ( $ id , Request $ request ) { $ delete = function ( $ id ) use ( $ request ) { $ account = $ this -> getRepository ( ) -> findAccountByIdAndDelete ( $ id ) ; if ( ! $ account ) { throw new EntityNotFoundException ( $ this -> getAccountEntityName ( ) , $ id ) ; } $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ addresses = $ account -> getAddresses ( ) ; foreach ( $ addresses as $ address ) { if ( ! $ address -> hasRelations ( ) ) { $ em -> remove ( $ address ) ; } } if ( null !== $ request -> get ( 'removeContacts' ) && 'true' == $ request -> get ( 'removeContacts' ) ) { foreach ( $ account -> getAccountContacts ( ) as $ accountContact ) { $ em -> remove ( $ accountContact -> getContact ( ) ) ; } } $ em -> remove ( $ account ) ; $ em -> flush ( ) ; } ; $ view = $ this -> responseDelete ( $ id , $ delete ) ; return $ this -> handleView ( $ view ) ; } | Delete an account with the given id . |
11,834 | public function multipledeleteinfoAction ( Request $ request ) { $ ids = $ request -> get ( 'ids' ) ; $ response = [ ] ; $ numContacts = 0 ; $ numChildren = 0 ; foreach ( $ ids as $ id ) { $ account = $ this -> getRepository ( ) -> countDistinctAccountChildrenAndContacts ( $ id ) ; $ numChildren += $ account [ 'numChildren' ] ; $ numContacts += $ account [ 'numContacts' ] ; } $ response [ 'numContacts' ] = $ numContacts ; $ response [ 'numChildren' ] = $ numChildren ; $ view = $ this -> view ( $ response , 200 ) ; return $ this -> handleView ( $ view ) ; } | Returns delete info for multiple ids . |
11,835 | public function getAction ( $ id , Request $ request ) { $ includes = explode ( ',' , $ request -> get ( 'include' ) ) ; $ accountManager = $ this -> getAccountManager ( ) ; $ locale = $ this -> getUser ( ) -> getLocale ( ) ; try { $ view = $ this -> responseGetById ( $ id , function ( $ id ) use ( $ includes , $ accountManager , $ locale ) { return $ accountManager -> getByIdAndInclude ( $ id , $ locale , $ includes ) ; } ) ; $ context = new Context ( ) ; $ context -> setGroups ( self :: $ accountSerializationGroups ) ; $ view -> setContext ( $ context ) ; } catch ( EntityNotFoundException $ enfe ) { $ view = $ this -> view ( $ enfe -> toArray ( ) , 404 ) ; } return $ this -> handleView ( $ view ) ; } | Shows a single account with the given id . |
11,836 | private function addLogos ( $ accounts , $ locale ) { $ ids = array_filter ( array_column ( $ accounts , 'logo' ) ) ; $ logos = $ this -> get ( 'sulu_media.media_manager' ) -> getFormatUrls ( $ ids , $ locale ) ; foreach ( $ accounts as $ key => $ account ) { if ( array_key_exists ( 'logo' , $ account ) && $ account [ 'logo' ] && array_key_exists ( $ account [ 'logo' ] , $ logos ) ) { $ accounts [ $ key ] [ 'logo' ] = $ logos [ $ account [ 'logo' ] ] ; } } return $ accounts ; } | Takes an array of accounts and resets the logo - property containing the media id with the actual urls to the logo thumbnails . |
11,837 | private function retrieveFilter ( Request $ request ) { $ filter = [ ] ; $ ids = $ request -> get ( 'ids' ) ; if ( $ ids ) { if ( is_string ( $ ids ) ) { $ ids = explode ( ',' , $ ids ) ; } $ filter [ 'id' ] = $ ids ; } return $ filter ; } | Retrieves the ids from the request . |
11,838 | public function findSecurityTypeById ( $ id ) { try { $ qb = $ this -> createQueryBuilder ( 'securityType' ) -> where ( 'securityType.id=:securityTypeId' ) ; $ query = $ qb -> getQuery ( ) ; $ query -> setParameter ( 'securityTypeId' , $ id ) ; return $ query -> getSingleResult ( ) ; } catch ( NoResultException $ ex ) { return ; } } | Searches for a role with a specific id . |
11,839 | protected function saveProperty ( NodeInterface $ node , $ data , $ name , $ default = '' ) { $ value = isset ( $ data [ $ name ] ) ? $ data [ $ name ] : $ default ; $ node -> setProperty ( $ this -> getPropertyName ( $ name ) , $ value ) ; } | save a single property value . |
11,840 | protected function getMainAccountContact ( ) { $ accountContacts = $ this -> getAccountContacts ( ) ; if ( ! is_null ( $ accountContacts ) ) { foreach ( $ accountContacts as $ accountContact ) { if ( $ accountContact -> getMain ( ) ) { return $ accountContact ; } } } return ; } | Returns main account contact . |
11,841 | public function createProxyForNode ( $ fromDocument , NodeInterface $ targetNode , $ options = [ ] ) { $ locale = $ this -> registry -> getOriginalLocaleForDocument ( $ fromDocument ) ; if ( $ this -> registry -> hasNode ( $ targetNode , $ locale ) ) { $ document = $ this -> registry -> getDocumentForNode ( $ targetNode , $ locale ) ; if ( $ this -> registry -> getOriginalLocaleForDocument ( $ document ) !== $ locale ) { $ hydrateEvent = new HydrateEvent ( $ targetNode , $ locale ) ; $ hydrateEvent -> setDocument ( $ document ) ; $ this -> dispatcher -> dispatch ( Events :: HYDRATE , $ hydrateEvent ) ; } return $ document ; } $ initializer = function ( LazyLoadingInterface $ document , $ method , array $ parameters , & $ initializer ) use ( $ targetNode , $ options , $ locale ) { $ hydrateEvent = new HydrateEvent ( $ targetNode , $ locale , $ options ) ; $ hydrateEvent -> setDocument ( $ document ) ; $ this -> dispatcher -> dispatch ( Events :: HYDRATE , $ hydrateEvent ) ; $ initializer = null ; } ; $ targetMetadata = $ this -> metadataFactory -> getMetadataForPhpcrNode ( $ targetNode ) ; $ proxy = $ this -> proxyFactory -> createProxy ( $ targetMetadata -> getClass ( ) , $ initializer ) ; $ locale = $ this -> registry -> getOriginalLocaleForDocument ( $ fromDocument ) ; $ this -> registry -> registerDocument ( $ proxy , $ targetNode , $ locale ) ; return $ proxy ; } | Create a new proxy object from the given document for the given target node . |
11,842 | public function createChildrenCollection ( $ document , array $ options = [ ] ) { $ node = $ this -> registry -> getNodeForDocument ( $ document ) ; $ locale = $ this -> registry -> getOriginalLocaleForDocument ( $ document ) ; return new ChildrenCollection ( $ node , $ this -> dispatcher , $ locale , $ options ) ; } | Create a new children collection for the given document . |
11,843 | public function createReferrerCollection ( $ document ) { $ node = $ this -> registry -> getNodeForDocument ( $ document ) ; $ locale = $ this -> registry -> getOriginalLocaleForDocument ( $ document ) ; return new ReferrerCollection ( $ node , $ this -> dispatcher , $ locale ) ; } | Create a new collection of referrers from a list of referencing items . |
11,844 | public function load ( array $ paths ) { $ finder = new Finder ( ) ; $ finder -> in ( $ paths ) ; $ finder -> name ( '*Fixture.php' ) ; foreach ( $ finder as $ file ) { $ declaredClasses = get_declared_classes ( ) ; require_once $ file ; $ declaredClassesDiff = array_diff ( get_declared_classes ( ) , $ declaredClasses ) ; $ fixtureClass = array_pop ( $ declaredClassesDiff ) ; if ( ! $ fixtureClass ) { throw new \ InvalidArgumentException ( sprintf ( 'Could not determine class from included file "%s". Class detection will only work once per request.' , $ file ) ) ; } $ refl = new \ ReflectionClass ( $ fixtureClass ) ; if ( $ refl -> isAbstract ( ) ) { continue ; } if ( false === $ refl -> isSubclassOf ( DocumentFixtureInterface :: class ) ) { continue ; } $ fixture = new $ fixtureClass ( ) ; if ( $ fixture instanceof ContainerAwareInterface ) { $ fixture -> setContainer ( $ this -> container ) ; } $ fixtures [ ] = $ fixture ; } usort ( $ fixtures , function ( DocumentFixtureInterface $ fixture1 , DocumentFixtureInterface $ fixture2 ) { return $ fixture1 -> getOrder ( ) > $ fixture2 -> getOrder ( ) ; } ) ; return $ fixtures ; } | Load instantiate and sort all fixture files found within the given paths . |
11,845 | public function copyShadowProperties ( AbstractMappingEvent $ event ) { $ document = $ event -> getDocument ( ) ; if ( ! $ this -> supports ( $ document ) ) { return ; } if ( ! $ event -> getDocument ( ) -> isShadowLocaleEnabled ( ) ) { $ this -> copyToShadows ( $ event -> getDocument ( ) , $ event -> getNode ( ) ) ; } else { $ this -> copyFromShadow ( $ event -> getDocument ( ) , $ event -> getNode ( ) ) ; } } | Handles persist event of document manager . |
11,846 | public function copyToShadows ( $ document , NodeInterface $ node ) { $ tags = $ this -> getTags ( $ node , $ document -> getLocale ( ) ) ; $ categories = $ this -> getCategories ( $ node , $ document -> getLocale ( ) ) ; $ navigationContext = $ this -> getNavigationContext ( $ node , $ document -> getLocale ( ) ) ; foreach ( $ node -> getProperties ( self :: SHADOW_BASE_PROPERTY ) as $ property ) { if ( $ property -> getValue ( ) === $ document -> getLocale ( ) ) { $ locale = $ this -> getLocale ( $ property -> getName ( ) ) ; $ node -> setProperty ( sprintf ( self :: TAGS_PROPERTY , $ locale ) , $ tags ) ; $ node -> setProperty ( sprintf ( self :: CATEGORIES_PROPERTY , $ locale ) , $ categories ) ; $ node -> setProperty ( sprintf ( self :: NAVIGATION_CONTEXT_PROPERTY , $ locale ) , $ navigationContext ) ; } } } | Copy tags and categories from current locale to all shadowed pages with this locale as base - locale . |
11,847 | public function copyFromShadow ( $ document , NodeInterface $ node ) { $ shadowLocale = $ document -> getShadowLocale ( ) ; $ tags = $ this -> getTags ( $ node , $ shadowLocale ) ; $ categories = $ this -> getCategories ( $ node , $ shadowLocale ) ; $ navigationContext = $ this -> getNavigationContext ( $ node , $ shadowLocale ) ; $ node -> setProperty ( sprintf ( self :: TAGS_PROPERTY , $ document -> getLocale ( ) ) , $ tags ) ; $ node -> setProperty ( sprintf ( self :: CATEGORIES_PROPERTY , $ document -> getLocale ( ) ) , $ categories ) ; $ node -> setProperty ( sprintf ( self :: NAVIGATION_CONTEXT_PROPERTY , $ document -> getLocale ( ) ) , $ navigationContext ) ; } | Copy tags and categories from base - locale to current locale . |
11,848 | protected function addMediaToEntity ( $ entityName , $ id , $ mediaId ) { try { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ entity = $ em -> getRepository ( $ entityName ) -> find ( $ id ) ; $ media = $ this -> container -> get ( 'sulu.repository.media' ) -> find ( $ mediaId ) ; if ( ! $ entity ) { throw new EntityNotFoundException ( $ entityName , $ id ) ; } if ( ! $ media ) { throw new EntityNotFoundException ( $ this -> getParameter ( 'sulu.model.media.class' ) , $ mediaId ) ; } if ( $ entity -> getMedias ( ) -> contains ( $ media ) ) { throw new RestException ( 'Relation already exists' ) ; } $ entity -> addMedia ( $ media ) ; $ em -> flush ( ) ; $ view = $ this -> view ( new Media ( $ media , $ this -> getUser ( ) -> getLocale ( ) , null ) , 200 ) ; } catch ( EntityNotFoundException $ enfe ) { $ view = $ this -> view ( $ enfe -> toArray ( ) , 404 ) ; } catch ( RestException $ exc ) { $ view = $ this -> view ( $ exc -> toArray ( ) , 400 ) ; } catch ( \ Exception $ e ) { $ view = $ this -> view ( $ e -> getMessage ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; } | Adds a relation between a media and the entity . |
11,849 | protected function removeMediaFromEntity ( $ entityName , $ id , $ mediaId ) { try { $ delete = function ( ) use ( $ entityName , $ id , $ mediaId ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ entity = $ em -> getRepository ( $ entityName ) -> find ( $ id ) ; $ media = $ this -> container -> get ( 'sulu.repository.media' ) -> find ( $ mediaId ) ; if ( ! $ entity ) { throw new EntityNotFoundException ( $ entityName , $ id ) ; } $ mediaEntityName = $ this -> getParameter ( 'sulu.model.media.class' ) ; if ( ! $ media ) { throw new EntityNotFoundException ( $ mediaEntityName , $ mediaId ) ; } if ( ! $ entity -> getMedias ( ) -> contains ( $ media ) ) { throw new RestException ( 'Relation between ' . $ entityName . ' and ' . $ mediaEntityName . ' with id ' . $ mediaId . ' does not exists!' ) ; } $ entity -> removeMedia ( $ media ) ; $ em -> flush ( ) ; } ; $ view = $ this -> responseDelete ( $ id , $ delete ) ; } catch ( EntityNotFoundException $ enfe ) { $ view = $ this -> view ( $ enfe -> toArray ( ) , 404 ) ; } catch ( RestException $ exc ) { $ view = $ this -> view ( $ exc -> toArray ( ) , 400 ) ; } catch ( \ Exception $ e ) { $ view = $ this -> view ( $ e -> getMessage ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; } | Removes a media from the relation with an entity . |
11,850 | protected function getMultipleView ( $ entityName , $ routeName , AbstractContactManager $ contactManager , $ id , $ request ) { try { $ locale = $ this -> getUser ( ) -> getLocale ( ) ; 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 ( $ entityName ) ; $ fieldDescriptors = $ this -> getFieldDescriptors ( $ entityName , $ id ) ; $ listBuilder -> setIdField ( $ fieldDescriptors [ 'id' ] ) ; $ restHelper -> initializeListBuilder ( $ listBuilder , $ fieldDescriptors ) ; $ listResponse = $ listBuilder -> execute ( ) ; $ listResponse = $ this -> addThumbnails ( $ listResponse , $ locale ) ; $ listResponse = $ this -> addUrls ( $ listResponse , $ locale ) ; $ list = new ListRepresentation ( $ listResponse , self :: $ mediaEntityKey , $ routeName , array_merge ( [ 'id' => $ id ] , $ request -> query -> all ( ) ) , $ listBuilder -> getCurrentPage ( ) , $ listBuilder -> getLimit ( ) , $ listBuilder -> count ( ) ) ; } else { $ media = $ contactManager -> getById ( $ id , $ locale ) -> getMedias ( ) ; $ list = new CollectionRepresentation ( $ media , self :: $ mediaEntityKey ) ; } $ view = $ this -> view ( $ list , 200 ) ; } catch ( EntityNotFoundException $ e ) { $ view = $ this -> view ( $ e -> toArray ( ) , 404 ) ; } return $ this -> handleView ( $ view ) ; } | Returns a view containing all media of an entity . |
11,851 | protected function getFieldsView ( $ entityName ) { return $ this -> handleView ( $ this -> view ( array_values ( $ this -> getFieldDescriptors ( $ entityName , null ) ) , 200 ) ) ; } | Returns the the media fields for the current entity . |
11,852 | private function getFieldDescriptors ( $ entityName , $ id ) { if ( null === $ this -> fieldDescriptors ) { $ this -> initFieldDescriptors ( $ entityName , $ id ) ; } return $ this -> fieldDescriptors ; } | Returns the field - descriptors . Ensures that the descriptors get only instantiated once . |
11,853 | private function addThumbnails ( $ entities , $ locale ) { $ ids = array_filter ( array_column ( $ entities , 'thumbnails' ) ) ; $ thumbnails = $ this -> getMediaManager ( ) -> getFormatUrls ( $ ids , $ locale ) ; foreach ( $ entities as $ key => $ entity ) { if ( array_key_exists ( 'thumbnails' , $ entity ) && $ entity [ 'thumbnails' ] && array_key_exists ( $ entity [ 'thumbnails' ] , $ thumbnails ) ) { $ entities [ $ key ] [ 'thumbnails' ] = $ thumbnails [ $ entity [ 'thumbnails' ] ] ; } } return $ entities ; } | Takes an array of entities and resets the thumbnails - property containing the media id with the actual urls to the thumbnails . |
11,854 | private function addUrls ( $ entities , $ locale ) { $ ids = array_filter ( array_column ( $ entities , 'id' ) ) ; $ apiEntities = $ this -> getMediaManager ( ) -> getByIds ( $ ids , $ locale ) ; $ i = 0 ; foreach ( $ entities as $ key => $ entity ) { $ entities [ $ key ] [ 'url' ] = $ apiEntities [ $ i ] -> getUrl ( ) ; ++ $ i ; } return $ entities ; } | Takes an array of entities and resets the url - property with the actual urls to the original file . |
11,855 | public function onPermissionUpdate ( PermissionUpdateEvent $ event ) { if ( Collection :: class !== $ event -> getType ( ) ) { return ; } foreach ( $ this -> fileVersionMetaRepository -> findByCollectionId ( $ event -> getIdentifier ( ) ) as $ fileVersionMeta ) { $ this -> searchManager -> deindex ( $ fileVersionMeta ) ; } } | Removes all FileVersionMetas belonging to the collection which just got secured . |
11,856 | private function checkTemplate ( $ document , $ type ) { $ area = $ this -> areas -> get ( $ type ) ; return $ document -> getStructureType ( ) === $ area [ 'template' ] ; } | Check template . |
11,857 | public function handlePersistStructureType ( PersistEvent $ event ) { $ document = $ event -> getDocument ( ) ; if ( ! $ this -> supportsBehavior ( $ document ) ) { return ; } $ structureMetadata = $ this -> inspector -> getStructureMetadata ( $ document ) ; $ structure = $ document -> getStructure ( ) ; if ( $ structure instanceof ManagedStructure ) { $ structure -> setStructureMetadata ( $ structureMetadata ) ; } } | Set the structure type early so that subsequent subscribers operate upon the correct structure type . |
11,858 | public function handlePersistStagedProperties ( PersistEvent $ event ) { $ document = $ event -> getDocument ( ) ; if ( ! $ this -> supportsBehavior ( $ document ) ) { return ; } $ document -> getStructure ( ) -> commitStagedData ( $ event -> getOption ( 'clear_missing_content' ) ) ; } | Commit the properties which are only staged on the structure yet . |
11,859 | private function getDefaultStructureType ( StructureBehavior $ document ) { $ alias = $ this -> inspector -> getMetadata ( $ document ) -> getAlias ( ) ; $ webspace = $ this -> webspaceManager -> findWebspaceByKey ( $ this -> inspector -> getWebspace ( $ document ) ) ; if ( ! $ webspace ) { return $ this -> getDefaultStructureTypeFromConfig ( $ alias ) ; } return $ webspace -> getDefaultTemplate ( $ alias ) ; } | Return the default structure for the given StructureBehavior implementing document . |
11,860 | private function mapContentToNode ( $ document , NodeInterface $ node , $ locale , $ ignoreRequired ) { $ structure = $ document -> getStructure ( ) ; $ webspaceName = $ this -> inspector -> getWebspace ( $ document ) ; $ metadata = $ this -> inspector -> getStructureMetadata ( $ document ) ; if ( ! $ metadata ) { throw new \ RuntimeException ( sprintf ( 'Metadata for Structure Type "%s" was not found, does the file "%s.xml" exists?' , $ document -> getStructureType ( ) , $ document -> getStructureType ( ) ) ) ; } foreach ( $ metadata -> getProperties ( ) as $ propertyName => $ structureProperty ) { if ( TitleSubscriber :: PROPERTY_NAME === $ propertyName ) { continue ; } $ realProperty = $ structure -> getProperty ( $ propertyName ) ; $ value = $ realProperty -> getValue ( ) ; if ( false === $ ignoreRequired && $ structureProperty -> isRequired ( ) && null === $ value ) { throw new MandatoryPropertyException ( sprintf ( 'Property "%s" in structure "%s" is required but no value was given. Loaded from "%s"' , $ propertyName , $ metadata -> getName ( ) , $ metadata -> getResource ( ) ) ) ; } $ contentTypeName = $ structureProperty -> getType ( ) ; $ contentType = $ this -> contentTypeManager -> get ( $ contentTypeName ) ; $ legacyProperty = $ this -> legacyPropertyFactory -> createTranslatedProperty ( $ structureProperty , $ locale ) ; $ legacyProperty -> setValue ( $ value ) ; $ contentType -> write ( new SuluNode ( $ node ) , $ legacyProperty , null , $ webspaceName , $ locale , null ) ; } } | Map to the content properties to the node using the content types . |
11,861 | private function getStructure ( $ document , $ structureType , $ rehydrate ) { if ( $ structureType ) { return $ this -> createStructure ( $ document ) ; } if ( ! $ rehydrate && $ document -> getStructure ( ) ) { return $ document -> getStructure ( ) ; } return new Structure ( ) ; } | Return the a structure for the document . |
11,862 | public function getLocalization ( $ localization ) { $ localizations = $ this -> getLocalizations ( ) ; if ( ! empty ( $ localizations ) ) { foreach ( $ localizations as $ webspaceLocalization ) { $ result = $ webspaceLocalization -> findLocalization ( $ localization ) ; if ( $ result ) { return $ result ; } } } return ; } | Returns the localization object for a given localization string . |
11,863 | public function setDefaultLocalization ( $ defaultLocalization ) { $ this -> defaultLocalization = $ defaultLocalization ; if ( ! $ this -> getXDefaultLocalization ( ) ) { $ this -> xDefaultLocalization = $ defaultLocalization ; } } | Sets the default localization for this webspace . |
11,864 | public function addSegment ( Segment $ segment ) { $ this -> segments [ ] = $ segment ; if ( $ segment -> isDefault ( ) ) { $ this -> setDefaultSegment ( $ segment ) ; } } | Adds a segment to the webspace . |
11,865 | public function hasDomain ( $ domain , $ environment , $ locale = null ) { $ localizationParts = explode ( '_' , $ locale ) ; $ language = $ localizationParts [ 0 ] ; $ country = isset ( $ localizationParts [ 1 ] ) ? $ localizationParts [ 1 ] : '' ; foreach ( $ this -> getPortals ( ) as $ portal ) { foreach ( $ portal -> getEnvironment ( $ environment ) -> getUrls ( ) as $ url ) { $ host = parse_url ( '//' . $ url -> getUrl ( ) ) [ 'host' ] ; if ( ( null === $ locale || $ url -> isValidLocale ( $ language , $ country ) ) && ( $ host === $ domain || '{host}' === $ host ) ) { return true ; } } } return false ; } | Returns false if domain not exists in webspace . |
11,866 | public function getTemplate ( $ type , $ format = 'html' ) { if ( array_key_exists ( $ type , $ this -> templates ) ) { return $ this -> templates [ $ type ] . '.' . $ format . '.twig' ; } return ; } | Returns a template for the given type . |
11,867 | public function getIsMultiple ( ) { $ minOccurs = $ this -> getMinOccurs ( ) ; $ maxOccurs = $ this -> getMaxOccurs ( ) ; if ( is_null ( $ minOccurs ) && is_null ( $ maxOccurs ) ) { return false ; } if ( 0 === $ minOccurs && 1 === $ maxOccurs ) { return true ; } if ( 1 === $ minOccurs && 1 === $ maxOccurs ) { return false ; } return $ minOccurs >= 1 || $ maxOccurs > 1 ; } | returns TRUE if property is multiple . |
11,868 | protected function getRequestParameter ( Request $ request , $ name , $ force = false , $ default = null ) { $ value = $ request -> get ( $ name , $ default ) ; if ( $ force && null === $ value ) { throw new MissingParameterException ( get_class ( $ this ) , $ name ) ; } return $ value ; } | returns request parameter with given name . |
11,869 | protected function getBooleanRequestParameter ( $ request , $ name , $ force = false , $ default = null ) { $ value = $ this -> getRequestParameter ( $ request , $ name , $ force , $ default ) ; if ( 'true' === $ value || true === $ value ) { $ value = true ; } elseif ( 'false' === $ value || false === $ value ) { $ value = false ; } elseif ( $ force && true !== $ value && false !== $ value ) { throw new ParameterDataTypeException ( get_class ( $ this ) , $ name ) ; } else { $ value = $ default ; } return $ value ; } | returns request parameter as boolean true = > true false = > false . |
11,870 | private function normalizePath ( SessionInterface $ session , $ identifier ) { if ( ! UUIDHelper :: isUUID ( $ identifier ) ) { return $ identifier ; } return $ session -> getNodeByIdentifier ( $ identifier ) -> getPath ( ) ; } | Returns the path based on the given UUID . |
11,871 | public function onPostSerialize ( ObjectEvent $ event ) { $ document = $ event -> getObject ( ) ; if ( ! $ document instanceof RedirectTypeBehavior ) { return ; } $ visitor = $ event -> getVisitor ( ) ; $ redirectType = $ document -> getRedirectType ( ) ; if ( RedirectType :: INTERNAL == $ redirectType && null !== $ document -> getRedirectTarget ( ) ) { $ visitor -> addData ( 'linked' , 'internal' ) ; $ visitor -> addData ( 'internal_link' , $ document -> getRedirectTarget ( ) -> getUuid ( ) ) ; } elseif ( RedirectType :: EXTERNAL == $ redirectType ) { $ visitor -> addData ( 'linked' , 'external' ) ; $ visitor -> addData ( 'external' , $ document -> getRedirectExternal ( ) ) ; } else { $ visitor -> addData ( 'linked' , null ) ; } } | Adds the type of redirect and the redirect location to the serialization . |
11,872 | private function getDocumentFromNode ( NodeInterface $ node ) { $ metadata = $ this -> metadataFactory -> getMetadataForPhpcrNode ( $ node ) ; return $ this -> instantiateFromMetadata ( $ metadata ) ; } | Instantiate a new document . The class is determined from the mixins present in the PHPCR node for legacy reasons . |
11,873 | public function cgetAction ( Request $ request ) { $ locale = $ this -> getRequestParameter ( $ request , 'locale' , true ) ; $ entityClass = $ this -> getRequestParameter ( $ request , 'entityClass' , true ) ; $ entityId = $ this -> getRequestParameter ( $ request , 'entityId' , true ) ; $ history = $ this -> getBooleanRequestParameter ( $ request , 'history' , false , false ) ; $ routes = $ this -> findRoutes ( $ history , $ entityClass , $ entityId , $ locale ) ; return $ this -> handleView ( $ this -> view ( new CollectionRepresentation ( $ routes , 'routes' ) ) ) ; } | Returns list of routes for given entity . |
11,874 | private function findRoutes ( $ history , $ entityClass , $ entityId , $ locale ) { $ routeRespository = $ this -> get ( 'sulu.repository.route' ) ; if ( $ history ) { return $ routeRespository -> findHistoryByEntity ( $ entityClass , $ entityId , $ locale ) ; } return [ $ routeRespository -> findByEntity ( $ entityClass , $ entityId , $ locale ) ] ; } | Find routes with given parameters . |
11,875 | public function deleteAction ( $ id ) { $ routeRespository = $ this -> get ( 'sulu.repository.route' ) ; $ route = $ routeRespository -> find ( $ id ) ; if ( ! $ route ) { throw new EntityNotFoundException ( RouteInterface :: class , $ id ) ; } $ entityManager = $ this -> get ( 'doctrine.orm.entity_manager' ) ; $ entityManager -> remove ( $ route ) ; $ entityManager -> flush ( ) ; return $ this -> handleView ( $ this -> view ( ) ) ; } | Delete given history - route . |
11,876 | public function toArray ( ) { $ res = [ ] ; foreach ( [ 'id' , 'displayTitle' , 'street' , 'number' , 'code' , 'town' , 'country' , 'longitude' , 'latitude' , ] as $ propertyName ) { $ res [ $ propertyName ] = $ this -> { 'get' . ucfirst ( $ propertyName ) } ( ) ; } $ res [ 'name' ] = TextUtils :: truncate ( $ this -> getDisplayTitle ( ) , 75 ) ; return $ res ; } | Serialize the location to an array . |
11,877 | private function needsIndex ( ) { return 1 < count ( $ this -> sitemapProviderPool -> getProviders ( ) ) || 1 < array_reduce ( $ this -> sitemapProviderPool -> getIndex ( ) , function ( $ v1 , Sitemap $ v2 ) { return $ v1 + $ v2 -> getMaxPage ( ) ; } ) ; } | Returns true if a index exists . |
11,878 | private function getArrayIndexByKeyValue ( $ array , $ value , $ key = 'id' ) { foreach ( $ array as $ index => $ result ) { if ( $ result [ $ key ] === $ value ) { return $ index ; } } return false ; } | returns array index of by a specified key value . |
11,879 | public function getCount ( $ where = [ ] , $ joinConditions = [ ] , $ prefix = 'u' ) { return $ this -> find ( $ where , $ prefix , true , $ joinConditions ) ; } | returns the amount of data . |
11,880 | public function getFieldsWitTypes ( array $ types , $ intersectArray = null ) { $ result = [ ] ; foreach ( $ this -> getClassMetadata ( ) -> getFieldNames ( ) as $ field ) { $ type = $ this -> getClassMetadata ( ) -> getTypeOfField ( $ field ) ; if ( in_array ( $ type , $ types ) ) { $ result [ ] = $ field ; } } if ( ! is_null ( $ intersectArray ) ) { $ result = array_intersect ( $ result , $ intersectArray ) ; } return $ result ; } | returns all fields with a specified type . |
11,881 | public function getExtension ( ) { $ pathInfo = pathinfo ( $ this -> getName ( ) ) ; $ extension = ExtensionGuesser :: getInstance ( ) -> guess ( $ this -> getMimeType ( ) ) ; if ( $ extension ) { return $ extension ; } elseif ( isset ( $ pathInfo [ 'extension' ] ) ) { return $ pathInfo [ 'extension' ] ; } return null ; } | Get extension . |
11,882 | public function addPublishLanguage ( \ Sulu \ Bundle \ MediaBundle \ Entity \ FileVersionPublishLanguage $ publishLanguages ) { $ this -> publishLanguages [ ] = $ publishLanguages ; return $ this ; } | Add publishLanguages . |
11,883 | public function removePublishLanguage ( \ Sulu \ Bundle \ MediaBundle \ Entity \ FileVersionPublishLanguage $ publishLanguages ) { $ this -> publishLanguages -> removeElement ( $ publishLanguages ) ; } | Remove publishLanguages . |
11,884 | public function addMeta ( \ Sulu \ Bundle \ MediaBundle \ Entity \ FileVersionMeta $ meta ) { $ this -> meta [ ] = $ meta ; return $ this ; } | Add meta . |
11,885 | public function removeMeta ( \ Sulu \ Bundle \ MediaBundle \ Entity \ FileVersionMeta $ meta ) { $ this -> meta -> removeElement ( $ meta ) ; } | Remove meta . |
11,886 | public function setDefaultMeta ( \ Sulu \ Bundle \ MediaBundle \ Entity \ FileVersionMeta $ defaultMeta = null ) { $ this -> defaultMeta = $ defaultMeta ; return $ this ; } | Set defaultMeta . |
11,887 | public function cgetAction ( Request $ request ) { $ webspaceKey = $ request -> get ( 'webspace' ) ; $ webspaceManager = $ this -> get ( 'sulu_core.webspace.webspace_manager' ) ; $ webspace = $ webspaceManager -> findWebspaceByKey ( $ webspaceKey ) ; if ( $ webspace ) { $ localizations = new CollectionRepresentation ( $ webspace -> getAllLocalizations ( ) , 'localizations' ) ; $ view = $ this -> view ( $ localizations , 200 ) ; } else { $ error = new RestException ( sprintf ( 'No webspace found for key \'%s\'' , $ webspaceKey ) ) ; $ view = $ this -> view ( $ error -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; } | Returns the localizations for the given webspace . |
11,888 | public function getMeta ( ) { $ arrReturn = [ ] ; if ( null !== $ this -> entity -> getMeta ( ) ) { foreach ( $ this -> entity -> getMeta ( ) as $ meta ) { if ( ! $ meta -> getLocale ( ) || $ meta -> getLocale ( ) === $ this -> locale ) { array_push ( $ arrReturn , [ 'id' => $ meta -> getId ( ) , 'key' => $ meta -> getKey ( ) , 'value' => $ meta -> getValue ( ) , ] ) ; } } return $ arrReturn ; } return ; } | Returns the name of the Category dependent on the locale . |
11,889 | public function getCreator ( ) { $ strReturn = '' ; $ creator = $ this -> entity -> getCreator ( ) ; if ( $ creator ) { return $ this -> getUserFullName ( $ creator ) ; } return $ strReturn ; } | Returns the creator of the category . |
11,890 | public function getChanger ( ) { $ strReturn = '' ; $ changer = $ this -> entity -> getChanger ( ) ; if ( $ changer ) { return $ this -> getUserFullName ( $ changer ) ; } return $ strReturn ; } | Returns the changer of the category . |
11,891 | public function getChildren ( ) { $ children = [ ] ; if ( $ this -> entity -> getChildren ( ) ) { foreach ( $ this -> entity -> getChildren ( ) as $ child ) { $ children [ ] = new self ( $ child , $ this -> locale ) ; } } return $ children ; } | Returns the children of a category . |
11,892 | public function setTranslation ( CategoryTranslationInterface $ translation ) { $ translationEntity = $ this -> getTranslationByLocale ( $ translation -> getLocale ( ) ) ; if ( ! $ translationEntity ) { $ translationEntity = $ translation ; $ this -> entity -> addTranslation ( $ translationEntity ) ; } $ translationEntity -> setCategory ( $ this -> entity ) ; $ translationEntity -> setTranslation ( $ translation -> getTranslation ( ) ) ; $ translationEntity -> setLocale ( $ translation -> getLocale ( ) ) ; if ( null === $ this -> getId ( ) && null === $ this -> getDefaultLocale ( ) ) { $ this -> entity -> setDefaultLocale ( $ translationEntity -> getLocale ( ) ) ; } } | Sets a translation to the entity . If no other translation was assigned before the translation is added as default . |
11,893 | public function setMeta ( $ metaEntities ) { $ currentMeta = $ this -> entity -> getMeta ( ) ; foreach ( $ metaEntities as $ singleMeta ) { $ metaEntity = $ this -> getSingleMetaById ( $ currentMeta , $ singleMeta -> getId ( ) ) ; if ( ! $ metaEntity ) { $ metaEntity = $ singleMeta ; $ this -> entity -> addMeta ( $ metaEntity ) ; } $ metaEntity -> setCategory ( $ this -> entity ) ; $ metaEntity -> setKey ( $ singleMeta -> getKey ( ) ) ; $ metaEntity -> setValue ( $ singleMeta -> getValue ( ) ) ; $ metaEntity -> setLocale ( $ singleMeta -> getLocale ( ) ) ; } return $ this ; } | Takes meta as array and sets it to the entity . |
11,894 | public function getParent ( ) { $ parent = $ this -> getEntity ( ) -> getParent ( ) ; if ( $ parent ) { return new self ( $ parent , $ this -> locale ) ; } return ; } | Returns a parent category if one exists . |
11,895 | public function getKeywords ( ) { $ keywords = [ ] ; $ translation = $ this -> getTranslation ( true ) ; if ( ! $ translation ) { return $ keywords ; } foreach ( $ translation -> getKeywords ( ) as $ keyword ) { $ keywords [ ] = $ keyword -> getKeyword ( ) ; } return $ keywords ; } | Returns the keywords of the category translations . |
11,896 | private function getUserFullName ( $ user ) { $ strReturn = '' ; if ( $ user && method_exists ( $ user , 'getContact' ) ) { $ strReturn = $ user -> getContact ( ) -> getFirstName ( ) . ' ' . $ user -> getContact ( ) -> getLastName ( ) ; } return $ strReturn ; } | Takes a user entity and returns the fullname . |
11,897 | private function getSingleMetaById ( $ meta , $ id ) { if ( null !== $ id ) { foreach ( $ meta as $ singleMeta ) { if ( $ singleMeta -> getId ( ) === $ id ) { return $ singleMeta ; } } } } | Takes an array of CollectionMeta and returns a single meta for a given id . |
11,898 | public function toArray ( ) { return [ 'id' => $ this -> getId ( ) , 'key' => $ this -> getKey ( ) , 'name' => $ this -> getName ( ) , 'meta' => $ this -> getMeta ( ) , 'keywords' => $ this -> getKeywords ( ) , 'defaultLocale' => $ this -> getDefaultLocale ( ) , 'creator' => $ this -> getCreator ( ) , 'changer' => $ this -> getChanger ( ) , 'created' => $ this -> getCreated ( ) , 'changed' => $ this -> getChanged ( ) , ] ; } | Returns an array representation of the object . |
11,899 | private function getTranslation ( $ withDefault = false ) { $ translation = $ this -> getTranslationByLocale ( $ this -> locale ) ; if ( true === $ withDefault && null === $ translation && null !== $ this -> getDefaultLocale ( ) ) { return $ this -> getTranslationByLocale ( $ this -> getDefaultLocale ( ) ) ; } return $ translation ; } | Returns the translation with the current locale . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.