idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
11,000
private function generateChildNavigation ( StructureInterface $ content , $ webspace , $ language , $ flat = false , $ context = null ) { $ children = [ ] ; if ( is_array ( $ content -> getChildren ( ) ) && count ( $ content -> getChildren ( ) ) > 0 ) { $ children = $ this -> generateNavigation ( $ content -> getChildren ( ) , $ webspace , $ language , $ flat , $ context ) ; } return $ children ; }
generate child navigation of given content .
11,001
public function inNavigation ( StructureInterface $ content , $ context = null ) { $ contexts = $ content -> getNavContexts ( ) ; if ( Structure :: STATE_PUBLISHED !== $ content -> getNodeState ( ) ) { return false ; } if ( is_array ( $ contexts ) && ( null === $ context || in_array ( $ context , $ contexts ) ) ) { return true ; } return false ; }
checks if content should be displayed .
11,002
public function getAction ( $ id ) { $ find = function ( $ id ) { return $ this -> getUserManager ( ) -> getUserById ( $ id ) ; } ; $ view = $ this -> responseGetById ( $ id , $ find ) ; $ this -> addSerializationGroups ( $ view ) ; return $ this -> handleView ( $ view ) ; }
Returns the user with the given id .
11,003
public function postAction ( Request $ request ) { try { $ this -> checkArguments ( $ request ) ; $ locale = $ this -> getRequestParameter ( $ request , 'locale' , true ) ; $ data = $ request -> request -> all ( ) ; $ data [ 'contactId' ] = $ request -> query -> get ( 'contactId' ) ; $ user = $ this -> getUserManager ( ) -> save ( $ data , $ locale ) ; $ view = $ this -> view ( $ user , 200 ) ; } catch ( UsernameNotUniqueException $ exc ) { $ view = $ this -> view ( $ exc -> toArray ( ) , 409 ) ; } catch ( MissingPasswordException $ exc ) { $ view = $ this -> view ( $ exc -> toArray ( ) , 400 ) ; } catch ( EmailNotUniqueException $ exc ) { $ view = $ this -> view ( $ exc -> toArray ( ) , 409 ) ; } catch ( RestException $ re ) { $ view = $ this -> view ( $ re -> toArray ( ) , 400 ) ; } $ this -> addSerializationGroups ( $ view ) ; return $ this -> handleView ( $ view ) ; }
Creates a new user in the system .
11,004
public function putAction ( Request $ request , $ id ) { try { $ this -> checkArguments ( $ request ) ; $ locale = $ this -> getRequestParameter ( $ request , 'locale' , true ) ; $ user = $ this -> getUserManager ( ) -> save ( $ request -> request -> all ( ) , $ locale , $ id ) ; $ view = $ this -> view ( $ user , 200 ) ; } catch ( EntityNotFoundException $ exc ) { $ view = $ this -> view ( $ exc -> toArray ( ) , 404 ) ; } catch ( UsernameNotUniqueException $ exc ) { $ view = $ this -> view ( $ exc -> toArray ( ) , 409 ) ; } catch ( EmailNotUniqueException $ exc ) { $ view = $ this -> view ( $ exc -> toArray ( ) , 409 ) ; } catch ( RestException $ exc ) { $ view = $ this -> view ( $ exc -> toArray ( ) , 400 ) ; } $ this -> addSerializationGroups ( $ view ) ; return $ this -> handleView ( $ view ) ; }
Updates the given user with the given data .
11,005
public function deleteAction ( $ id ) { $ delete = $ this -> getUserManager ( ) -> delete ( ) ; $ view = $ this -> responseDelete ( $ id , $ delete ) ; return $ this -> handleView ( $ view ) ; }
Deletes the user with the given id .
11,006
public function cgetAction ( Request $ request ) { $ view = null ; 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 ( $ this -> container -> getParameter ( 'sulu.model.user.class' ) ) ; $ restHelper -> initializeListBuilder ( $ listBuilder , $ this -> getFieldDescriptors ( ) ) ; $ list = new ListRepresentation ( $ listBuilder -> execute ( ) , static :: $ entityKey , 'get_users' , $ request -> query -> all ( ) , $ listBuilder -> getCurrentPage ( ) , $ listBuilder -> getLimit ( ) , $ listBuilder -> count ( ) ) ; } else { $ contactId = $ request -> get ( 'contactId' ) ; if ( null != $ contactId ) { $ user = $ this -> getDoctrine ( ) -> getRepository ( $ this -> container -> getParameter ( 'sulu.model.user.class' ) ) -> findUserByContact ( $ contactId ) ; $ view = $ this -> view ( $ user ?? new \ stdClass ( ) , 200 ) ; } else { $ entities = $ this -> getUserManager ( ) -> findAll ( ) ; $ list = new CollectionRepresentation ( $ entities , static :: $ entityKey ) ; } } if ( ! $ view ) { $ view = $ this -> view ( $ list , 200 ) ; } $ this -> addSerializationGroups ( $ view ) ; return $ this -> handleView ( $ view ) ; }
Returns a user with a specific contact id or all users optional parameter flat calls listAction .
11,007
public function cgetAction ( ) { $ localizationManager = $ this -> get ( 'sulu.core.localization_manager' ) ; $ representation = new CollectionRepresentation ( array_values ( $ localizationManager -> getLocalizations ( ) ) , 'localizations' ) ; return $ this -> handleView ( $ this -> view ( $ representation , 200 ) ) ; }
Returns all the localizations available in this system .
11,008
public function indexAction ( Request $ request ) { if ( null !== ( $ response = $ this -> getDumpedIndexResponse ( $ request ) ) ) { return $ response ; } $ sitemap = $ this -> get ( 'sulu_website.sitemap.xml_renderer' ) -> renderIndex ( ) ; if ( ! $ sitemap ) { $ aliases = array_keys ( $ this -> get ( 'sulu_website.sitemap.pool' ) -> getProviders ( ) ) ; return $ this -> sitemapPaginatedAction ( $ request , reset ( $ aliases ) , 1 ) ; } return $ this -> setCacheLifetime ( new Response ( $ sitemap ) ) ; }
Render sitemap - index of all available sitemap . xml files . If only one provider exists this provider will be rendered directly .
11,009
public function sitemapAction ( $ alias ) { if ( ! $ this -> get ( 'sulu_website.sitemap.pool' ) -> hasProvider ( $ alias ) ) { return new Response ( null , 404 ) ; } return $ this -> redirectToRoute ( 'sulu_website.paginated_sitemap' , [ 'alias' => $ alias , 'page' => 1 ] , 301 ) ; }
Redirect to the first page of a single sitemap provider .
11,010
public function sitemapPaginatedAction ( Request $ request , $ alias , $ page ) { if ( null !== ( $ response = $ this -> getDumpedSitemapResponse ( $ request , $ alias , $ page ) ) ) { return $ response ; } $ portal = $ request -> get ( '_sulu' ) -> getAttribute ( 'portal' ) ; $ localization = $ request -> get ( '_sulu' ) -> getAttribute ( 'localization' ) ; if ( ! $ localization ) { $ localization = $ portal -> getXDefaultLocalization ( ) ; } $ sitemap = $ this -> get ( 'sulu_website.sitemap.xml_renderer' ) -> renderSitemap ( $ alias , $ page , $ localization -> getLocale ( ) , $ portal , $ request -> getHttpHost ( ) , $ request -> getScheme ( ) ) ; if ( ! $ sitemap ) { return new Response ( null , 404 ) ; } return $ this -> setCacheLifetime ( new Response ( $ sitemap ) ) ; }
Render a single page for a single sitemap . xml provider .
11,011
private function setCacheLifetime ( Response $ response ) { $ response -> headers -> set ( SuluHttpCache :: HEADER_REVERSE_PROXY_TTL , $ response -> getAge ( ) + $ this -> container -> getParameter ( 'sulu_website.sitemap.cache.lifetime' ) ) ; return $ response -> setMaxAge ( 240 ) -> setSharedMaxAge ( 960 ) ; }
Set cache headers .
11,012
private function createBinaryFileResponse ( $ file ) { $ response = new BinaryFileResponse ( $ file ) ; $ response -> headers -> addCacheControlDirective ( 'no-store' , true ) ; return $ response ; }
Create a binary file response .
11,013
public function setPermissions ( $ type , $ identifier , $ permissions ) { foreach ( $ permissions as $ roleId => $ rolePermissions ) { $ accessControl = $ this -> accessControlRepository -> findByTypeAndIdAndRole ( $ type , $ identifier , $ roleId ) ; if ( $ accessControl ) { $ accessControl -> setPermissions ( $ this -> maskConverter -> convertPermissionsToNumber ( $ rolePermissions ) ) ; } else { $ role = $ this -> roleRepository -> findRoleById ( $ roleId ) ; $ accessControl = new AccessControl ( ) ; $ accessControl -> setPermissions ( $ this -> maskConverter -> convertPermissionsToNumber ( $ rolePermissions ) ) ; $ accessControl -> setRole ( $ role ) ; $ accessControl -> setEntityId ( $ identifier ) ; $ accessControl -> setEntityClass ( $ type ) ; $ this -> objectManager -> persist ( $ accessControl ) ; } } $ this -> objectManager -> flush ( ) ; }
Sets the permissions for the object with the given class and id for the given security identity .
11,014
public function getPermissions ( $ type , $ identifier ) { $ accessControls = $ this -> accessControlRepository -> findByTypeAndId ( $ type , $ identifier ) ; $ permissions = [ ] ; foreach ( $ accessControls as $ accessControl ) { $ permissions [ $ accessControl -> getRole ( ) -> getId ( ) ] = $ this -> maskConverter -> convertPermissionsToArray ( $ accessControl -> getPermissions ( ) ) ; } return $ permissions ; }
Returns the permissions for all security identities .
11,015
public function getAction ( $ roleId , $ key ) { $ settingValue = $ this -> get ( 'sulu.repository.role_setting' ) -> findSettingValue ( $ roleId , $ key ) ; return $ this -> handleView ( $ this -> view ( $ settingValue ) ) ; }
Returns value for given role - setting .
11,016
public function putAction ( Request $ request , $ roleId , $ key ) { $ entityManager = $ this -> get ( 'doctrine.orm.entity_manager' ) ; $ repository = $ this -> get ( 'sulu.repository.role_setting' ) ; $ setting = $ repository -> findSetting ( $ roleId , $ key ) ; if ( ! $ setting ) { $ setting = $ repository -> createNew ( ) ; } $ setting -> setKey ( $ key ) ; $ setting -> setValue ( $ request -> get ( 'value' , [ ] ) ) ; $ setting -> setRole ( $ entityManager -> getReference ( Role :: class , $ roleId ) ) ; $ entityManager -> persist ( $ setting ) ; $ entityManager -> flush ( ) ; return $ this -> handleView ( $ this -> view ( $ setting -> getValue ( ) ) ) ; }
Save role - setting with value from request body .
11,017
protected function getClassMappingConfiguration ( $ className ) { if ( array_key_exists ( $ className , $ this -> mappings ) ) { return [ 'className' => $ className , 'mapping' => $ this -> mappings [ $ className ] , ] ; } $ reflection = new \ ReflectionClass ( $ className ) ; while ( $ reflection = $ reflection -> getParentClass ( ) ) { if ( array_key_exists ( $ reflection -> getName ( ) , $ this -> mappings ) ) { return [ 'className' => $ reflection -> getName ( ) , 'mapping' => $ this -> mappings [ $ reflection -> getName ( ) ] , ] ; } } throw new MissingClassMappingConfigurationException ( $ className , array_keys ( $ this -> mappings ) ) ; }
Get class mapping configuration by class name or inheritance chain .
11,018
public function cgetAction ( Request $ request ) { if ( 'true' == $ request -> get ( 'flat' ) ) { $ restHelper = $ this -> get ( 'sulu_core.doctrine_rest_helper' ) ; $ factory = $ this -> get ( 'sulu_core.doctrine_list_builder_factory' ) ; $ listBuilder = $ factory -> create ( $ this -> container -> getParameter ( 'sulu.model.role.class' ) ) ; $ restHelper -> initializeListBuilder ( $ listBuilder , $ this -> getFieldDescriptors ( ) ) ; $ list = new ListRepresentation ( $ listBuilder -> execute ( ) , static :: $ entityKey , 'get_roles' , $ request -> query -> all ( ) , $ listBuilder -> getCurrentPage ( ) , $ listBuilder -> getLimit ( ) , $ listBuilder -> count ( ) ) ; } else { $ roles = $ this -> getRoleRepository ( ) -> findAllRoles ( ) ; $ convertedRoles = [ ] ; if ( null != $ roles ) { foreach ( $ roles as $ role ) { array_push ( $ convertedRoles , $ this -> convertRole ( $ role ) ) ; } } $ list = new CollectionRepresentation ( $ convertedRoles , static :: $ entityKey ) ; } $ view = $ this -> view ( $ list , 200 ) ; return $ this -> handleView ( $ view ) ; }
returns all roles .
11,019
public function getAction ( $ id ) { $ find = function ( $ id ) { $ role = $ this -> getRoleRepository ( ) -> findRoleById ( $ id ) ; return $ this -> convertRole ( $ role ) ; } ; $ view = $ this -> responseGetById ( $ id , $ find ) ; return $ this -> handleView ( $ view ) ; }
Returns the role with the given id .
11,020
public function postAction ( Request $ request ) { $ name = $ request -> get ( 'name' ) ; $ system = $ request -> get ( 'system' ) ; try { if ( null === $ name ) { throw new InvalidArgumentException ( 'Role' , 'name' ) ; } if ( null === $ system ) { throw new InvalidArgumentException ( 'Role' , 'name' ) ; } $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ role = $ this -> getRoleRepository ( ) -> createNew ( ) ; $ role -> setName ( $ name ) ; $ role -> setSystem ( $ system ) ; $ permissions = $ request -> get ( 'permissions' ) ; if ( ! empty ( $ permissions ) ) { foreach ( $ permissions as $ permissionData ) { $ this -> addPermission ( $ role , $ permissionData ) ; } } $ securityTypeData = $ request -> get ( 'securityType' ) ; if ( $ this -> checkSecurityTypeData ( $ securityTypeData ) ) { $ this -> setSecurityType ( $ role , $ securityTypeData ) ; } try { $ em -> persist ( $ role ) ; $ em -> flush ( ) ; $ view = $ this -> view ( $ this -> convertRole ( $ role ) , 200 ) ; } catch ( DoctrineUniqueConstraintViolationException $ ex ) { throw new SuluUniqueConstraintViolationException ( 'name' , 'SuluSecurityBudle:Role' ) ; } } catch ( RestException $ ex ) { $ view = $ this -> view ( $ ex -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; }
Creates a new role with the given data .
11,021
public function putAction ( Request $ request , $ id ) { $ role = $ this -> getRoleRepository ( ) -> findRoleById ( $ id ) ; try { if ( ! $ role ) { throw new EntityNotFoundException ( $ this -> getRoleRepository ( ) -> getClassName ( ) , $ id ) ; } else { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ name = $ request -> get ( 'name' ) ; $ role -> setName ( $ name ) ; $ role -> setSystem ( $ request -> get ( 'system' ) ) ; if ( ! $ this -> processPermissions ( $ role , $ request -> get ( 'permissions' , [ ] ) ) ) { throw new RestException ( 'Could not update dependencies!' ) ; } $ securityTypeData = $ request -> get ( 'securityType' ) ; if ( $ this -> checkSecurityTypeData ( $ securityTypeData ) ) { $ this -> setSecurityType ( $ role , $ securityTypeData ) ; } else { $ role -> setSecurityType ( null ) ; } $ em -> flush ( ) ; $ view = $ this -> view ( $ this -> convertRole ( $ role ) , 200 ) ; } } catch ( EntityNotFoundException $ enfe ) { $ view = $ this -> view ( $ enfe -> toArray ( ) , 404 ) ; } catch ( DoctrineUniqueConstraintViolationException $ e ) { throw new RoleNameAlreadyExistsException ( $ name ) ; } catch ( RestException $ re ) { $ view = $ this -> view ( $ re -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; }
Updates the role with the given id and the data given by the request .
11,022
public function deleteAction ( $ id ) { $ delete = function ( $ id ) { $ role = $ this -> getRoleRepository ( ) -> findRoleById ( $ id ) ; if ( ! $ role ) { throw new EntityNotFoundException ( $ this -> getRoleRepository ( ) -> getClassName ( ) , $ id ) ; } $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> remove ( $ role ) ; $ em -> flush ( ) ; } ; $ view = $ this -> responseDelete ( $ id , $ delete ) ; return $ this -> handleView ( $ view ) ; }
Deletes the role with the given id .
11,023
protected function processPermissions ( RoleInterface $ role , $ permissions ) { $ restHelper = $ this -> get ( 'sulu_core.doctrine_rest_helper' ) ; $ get = function ( $ entity ) { return $ entity -> getId ( ) ; } ; $ delete = function ( $ permission ) { $ this -> getDoctrine ( ) -> getManager ( ) -> remove ( $ permission ) ; } ; $ update = function ( $ permission , $ permissionData ) { return $ this -> updatePermission ( $ permission , $ permissionData ) ; } ; $ add = function ( $ permission ) use ( $ role ) { return $ this -> addPermission ( $ role , $ permission ) ; } ; return $ restHelper -> processSubEntities ( $ role -> getPermissions ( ) , $ permissions , $ get , $ add , $ update , $ delete ) ; }
Process all permissions from request .
11,024
protected function addPermission ( RoleInterface $ role , $ permissionData ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ alreadyContains = false ; if ( isset ( $ permissionData [ 'id' ] ) ) { $ permission = $ em -> getRepository ( static :: ENTITY_NAME_PERMISSION ) -> find ( $ permissionData [ 'id' ] ) ; if ( ! $ permission ) { throw new EntityNotFoundException ( static :: ENTITY_NAME_PERMISSION , $ permissionData [ 'id' ] ) ; } $ alreadyContains = $ role -> getPermissions ( ) -> contains ( $ permission ) ; } else { $ permission = new Permission ( ) ; $ permission -> setContext ( $ permissionData [ 'context' ] ) ; $ permission -> setPermissions ( $ this -> get ( 'sulu_security.mask_converter' ) -> convertPermissionsToNumber ( $ permissionData [ 'permissions' ] ) ) ; } if ( false === $ alreadyContains ) { $ permission -> setRole ( $ role ) ; $ em -> persist ( $ permission ) ; $ role -> addPermission ( $ permission ) ; } return true ; }
Adds a permission to the given role .
11,025
private function updatePermission ( Permission $ permission , $ permissionData ) { $ permission -> setContext ( $ permissionData [ 'context' ] ) ; $ permission -> setPermissions ( $ this -> get ( 'sulu_security.mask_converter' ) -> convertPermissionsToNumber ( $ permissionData [ 'permissions' ] ) ) ; return true ; }
Updates an already existing permission .
11,026
protected function convertRole ( RoleInterface $ role ) { $ roleData [ 'id' ] = $ role -> getId ( ) ; $ roleData [ 'name' ] = $ role -> getName ( ) ; $ roleData [ 'identifier' ] = $ role -> getIdentifier ( ) ; $ roleData [ 'system' ] = $ role -> getSystem ( ) ; $ roleData [ 'permissions' ] = [ ] ; $ permissions = $ role -> getPermissions ( ) ; if ( ! empty ( $ permissions ) ) { foreach ( $ permissions as $ permission ) { $ roleData [ 'permissions' ] [ ] = [ 'id' => $ permission -> getId ( ) , 'context' => $ permission -> getContext ( ) , 'module' => $ permission -> getModule ( ) , 'permissions' => $ this -> get ( 'sulu_security.mask_converter' ) -> convertPermissionsToArray ( $ permission -> getPermissions ( ) ) , ] ; } } $ securityType = $ role -> getSecurityType ( ) ; if ( $ securityType ) { $ roleData [ 'securityType' ] = [ 'id' => $ securityType -> getId ( ) , 'name' => $ securityType -> getName ( ) , ] ; } return $ roleData ; }
Converts a role object into an array for the rest service .
11,027
private function setSecurityType ( $ role , $ securityTypeData ) { $ securityType = $ this -> getDoctrine ( ) -> getRepository ( 'SuluSecurityBundle:SecurityType' ) -> findSecurityTypeById ( $ securityTypeData [ 'id' ] ) ; if ( ! $ securityType ) { throw new EntityNotFoundException ( 'SuluSecurityBundle:SecurityType' , $ securityTypeData [ 'id' ] ) ; } $ role -> setSecurityType ( $ securityType ) ; }
Sets the securityType from the given data to the role .
11,028
private function buildSelectForStructures ( $ locale , $ structures , & $ names ) { $ result = '' ; foreach ( $ structures as $ structure ) { $ result .= $ this -> buildSelectForStructure ( $ locale , $ structure , $ names ) ; } return $ result ; }
Returns select statement with all url and title properties .
11,029
private function buildSelectForStructure ( $ locale , StructureInterface $ structure , & $ names ) { $ nodeNameProperty = $ structure -> getProperty ( 'title' ) ; $ result = '' ; $ name = $ this -> getTranslatedProperty ( $ nodeNameProperty , $ locale ) -> getName ( ) ; if ( ! in_array ( $ name , $ names ) ) { $ names [ ] = $ name ; $ result .= ', ' . $ this -> buildSelector ( $ name ) ; } if ( $ structure -> hasTag ( 'sulu.rlp' ) ) { $ urlProperty = $ structure -> getPropertyByTagName ( 'sulu.rlp' ) ; $ name = $ this -> getTranslatedProperty ( $ urlProperty , $ locale ) -> getName ( ) ; if ( 'resource_locator' !== $ urlProperty -> getContentTypeName ( ) && ! in_array ( $ name , $ names ) ) { $ names [ ] = $ name ; $ result .= ', ' . $ this -> buildSelector ( $ name ) ; } } return $ result ; }
Returns select of a single structure with title and url selector .
11,030
private function buildSelectorForExcerpt ( $ locale , & $ additionalFields ) { $ excerptStructure = $ this -> structureManager -> getStructure ( 'excerpt' ) ; $ extension = $ this -> extensionManager -> getExtension ( '' , 'excerpt' ) ; foreach ( $ excerptStructure -> getProperties ( true ) as $ property ) { $ additionalFields [ $ locale ] [ ] = [ 'extension' => $ extension , 'target' => 'excerpt' , 'property' => $ property -> getName ( ) , 'name' => $ property -> getName ( ) , ] ; } }
Returns a select statement for excerpt data .
11,031
public function unsetMain ( $ arrayCollection ) { if ( $ arrayCollection && ! $ arrayCollection -> isEmpty ( ) ) { return $ arrayCollection -> forAll ( function ( $ index , $ entry ) { if ( true === $ entry -> getMain ( ) ) { $ entry -> setMain ( false ) ; return false ; } return true ; } ) ; } }
unsets main of all elements of an ArrayCollection | PersistanceCollection .
11,032
public function setMainForCollection ( $ arrayCollection ) { if ( $ arrayCollection && ! $ arrayCollection -> isEmpty ( ) && ! $ this -> hasMain ( $ arrayCollection ) ) { $ arrayCollection -> first ( ) -> setMain ( true ) ; } }
sets the first element to main if none is set .
11,033
private function hasMain ( $ arrayCollection , & $ mainEntity = null ) { if ( $ arrayCollection && ! $ arrayCollection -> isEmpty ( ) ) { return $ arrayCollection -> exists ( function ( $ index , $ entity ) { $ mainEntity = $ entity ; return true === $ entity -> getMain ( ) ; } ) ; } return false ; }
checks if a collection for main attribute .
11,034
public function setMainEmail ( $ entity ) { if ( $ entity -> getEmails ( ) -> isEmpty ( ) ) { $ entity -> setMainEmail ( null ) ; } else { $ entity -> setMainEmail ( $ entity -> getEmails ( ) -> first ( ) -> getEmail ( ) ) ; } }
sets Entity s Main - Email .
11,035
public function setMainPhone ( $ entity ) { if ( $ entity -> getPhones ( ) -> isEmpty ( ) ) { $ entity -> setMainPhone ( null ) ; } else { $ entity -> setMainPhone ( $ entity -> getPhones ( ) -> first ( ) -> getPhone ( ) ) ; } }
sets Entity s Main - Phone .
11,036
public function setMainFax ( $ entity ) { if ( $ entity -> getFaxes ( ) -> isEmpty ( ) ) { $ entity -> setMainFax ( null ) ; } else { $ entity -> setMainFax ( $ entity -> getFaxes ( ) -> first ( ) -> getFax ( ) ) ; } }
sets Entity s Main - Fax .
11,037
public function setMainUrl ( $ entity ) { if ( $ entity -> getUrls ( ) -> isEmpty ( ) ) { $ entity -> setMainUrl ( null ) ; } else { $ entity -> setMainUrl ( $ entity -> getUrls ( ) -> first ( ) -> getUrl ( ) ) ; } }
sets Entity s Main - Url .
11,038
public function getAccounContact ( AccountInterface $ account , Contact $ contact ) { foreach ( $ contact -> getAccountContacts ( ) as $ accountContact ) { if ( $ accountContact -> getAccount ( ) === $ account ) { return $ accountContact ; } } return ; }
Returns AccountContact relation if exists .
11,039
public function getMainAccountContact ( $ contact ) { foreach ( $ contact -> getAccountContacts ( ) as $ accountContact ) { if ( $ accountContact -> getMain ( ) ) { return $ accountContact ; } } return false ; }
returns the main account - contact relation .
11,040
public function createMainAccountContact ( Contact $ contact , AccountInterface $ account , $ position = null ) { $ accountContact = new AccountContact ( ) ; $ accountContact -> setAccount ( $ account ) ; $ accountContact -> setContact ( $ contact ) ; $ accountContact -> setMain ( true ) ; $ this -> em -> persist ( $ accountContact ) ; $ contact -> addAccountContact ( $ accountContact ) ; $ accountContact -> setPosition ( $ position ) ; return $ accountContact ; }
creates a new main Account Contacts relation .
11,041
public function deleteAllRelations ( $ entity ) { $ this -> deleteNotes ( $ entity ) ; $ this -> deleteAddresses ( $ entity ) ; $ this -> deleteEmails ( $ entity ) ; $ this -> deleteFaxes ( $ entity ) ; $ this -> deleteSocialMediaProfiles ( $ entity ) ; $ this -> deletePhones ( $ entity ) ; $ this -> deleteUrls ( $ entity ) ; }
clears all relational data from entity and deletes it .
11,042
public function deleteAddresses ( $ entity ) { if ( $ entity -> getAccountAddresses ( ) ) { foreach ( $ entity -> getAccountAddresses ( ) as $ accountAddresses ) { $ this -> em -> remove ( $ accountAddresses -> getAddress ( ) ) ; $ this -> em -> remove ( $ accountAddresses ) ; } } }
deletes all addresses that are assigned to entity .
11,043
public function getDeliveryAddress ( $ entity , $ force = false ) { $ conditionCallback = function ( $ address ) { return $ address -> getDeliveryAddress ( ) ; } ; return $ this -> getAddressByCondition ( $ entity , $ conditionCallback , $ force ) ; }
Returns the delivery address .
11,044
public function contactIsEmployeeOfAccount ( $ contact , $ account ) { if ( $ contact -> getAccountContacts ( ) && ! $ contact -> getAccountContacts ( ) -> isEmpty ( ) ) { foreach ( $ contact -> getAccountContacts ( ) as $ accountContact ) { if ( $ accountContact -> getAccount ( ) -> getId ( ) === $ account -> getId ( ) ) { return true ; } } } return false ; }
checks if an account is employee of a company .
11,045
private function getAddresses ( $ entity ) { if ( $ entity instanceof AccountInterface ) { return $ entity -> getAccountAddresses ( ) ; } elseif ( $ entity instanceof Contact ) { return $ entity -> getContactAddresses ( ) ; } return ; }
returns addresses from account or contact .
11,046
public function getAddressByCondition ( $ entity , callable $ conditionCallback , $ force = false ) { $ addresses = $ this -> getAddresses ( $ entity ) ; $ address = null ; $ main = null ; if ( ! is_null ( $ addresses ) ) { foreach ( $ addresses as $ address ) { if ( $ conditionCallback ( $ address -> getAddress ( ) ) ) { return $ address -> getAddress ( ) ; } if ( $ address -> getMain ( ) ) { $ main = $ address -> getAddress ( ) ; } } if ( $ force ) { if ( null === $ main && $ addresses -> first ( ) ) { return $ addresses -> first ( ) -> getAddress ( ) ; } } } return $ main ; }
Returns an address by callback - condition .
11,047
public function addNewContactRelations ( $ contact , $ data ) { $ urls = $ this -> getProperty ( $ data , 'urls' ) ; if ( ! empty ( $ urls ) ) { foreach ( $ urls as $ urlData ) { $ this -> addUrl ( $ contact , $ urlData ) ; } $ this -> setMainUrl ( $ contact ) ; } $ faxes = $ this -> getProperty ( $ data , 'faxes' ) ; if ( ! empty ( $ faxes ) ) { foreach ( $ faxes as $ faxData ) { $ this -> addFax ( $ contact , $ faxData ) ; } $ this -> setMainFax ( $ contact ) ; } $ socialMediaProfiles = $ this -> getProperty ( $ data , 'socialMediaProfiles' ) ; if ( ! empty ( $ socialMediaProfiles ) ) { foreach ( $ socialMediaProfiles as $ socialMediaProfileData ) { $ this -> addSocialMediaProfile ( $ contact , $ socialMediaProfileData ) ; } } $ emails = $ this -> getProperty ( $ data , 'emails' ) ; if ( ! empty ( $ emails ) ) { foreach ( $ emails as $ emailData ) { $ this -> addEmail ( $ contact , $ emailData ) ; } $ this -> setMainEmail ( $ contact ) ; } $ phones = $ this -> getProperty ( $ data , 'phones' ) ; if ( ! empty ( $ phones ) ) { foreach ( $ phones as $ phoneData ) { $ this -> addPhone ( $ contact , $ phoneData ) ; } $ this -> setMainPhone ( $ contact ) ; } $ addresses = $ this -> getProperty ( $ data , 'addresses' ) ; if ( ! empty ( $ addresses ) ) { foreach ( $ addresses as $ addressData ) { $ address = $ this -> createAddress ( $ addressData , $ isMain ) ; $ this -> addAddress ( $ contact , $ address , $ isMain ) ; } } $ this -> setMainForCollection ( $ this -> getAddressRelations ( $ contact ) ) ; $ notes = $ this -> getProperty ( $ data , 'notes' ) ; if ( ! empty ( $ notes ) ) { foreach ( $ notes as $ noteData ) { $ this -> addNote ( $ contact , $ noteData ) ; } } $ tags = $ this -> getProperty ( $ data , 'tags' ) ; if ( ! empty ( $ tags ) ) { foreach ( $ tags as $ tag ) { $ this -> addTag ( $ contact , $ tag ) ; } } if ( null !== $ this -> getProperty ( $ data , 'bankAccounts' ) ) { $ this -> processBankAccounts ( $ contact , $ this -> getProperty ( $ data , 'bankAccounts' , [ ] ) ) ; } }
adds new relations .
11,048
public function processEmails ( $ contact , $ emails ) { $ get = function ( $ email ) { return $ email -> getId ( ) ; } ; $ delete = function ( $ email ) use ( $ contact ) { return $ contact -> removeEmail ( $ email ) ; } ; $ update = function ( $ email , $ matchedEntry ) { return $ this -> updateEmail ( $ email , $ matchedEntry ) ; } ; $ add = function ( $ email ) use ( $ contact ) { return $ this -> addEmail ( $ contact , $ email ) ; } ; $ entities = $ contact -> getEmails ( ) ; $ result = $ this -> processSubEntities ( $ entities , $ emails , $ get , $ add , $ update , $ delete ) ; $ this -> resetIndexOfSubentites ( $ entities ) ; $ this -> setMainEmail ( $ contact ) ; return $ result ; }
Process all emails from request .
11,049
protected function addEmail ( $ contact , $ emailData ) { $ success = true ; $ emailType = $ this -> em -> getRepository ( self :: $ emailTypeEntityName ) -> find ( $ emailData [ 'emailType' ] [ 'id' ] ) ; if ( isset ( $ emailData [ 'id' ] ) ) { throw new EntityIdAlreadySetException ( self :: $ emailEntityName , $ emailData [ 'id' ] ) ; } elseif ( ! $ emailType ) { throw new EntityNotFoundException ( self :: $ emailTypeEntityName , $ emailData [ 'emailType' ] [ 'id' ] ) ; } else { $ email = new Email ( ) ; $ email -> setEmail ( $ emailData [ 'email' ] ) ; $ email -> setEmailType ( $ emailType ) ; $ this -> em -> persist ( $ email ) ; $ contact -> addEmail ( $ email ) ; } return $ success ; }
Adds a new email to the given contact and persist it with the given object manager .
11,050
protected function updateEmail ( Email $ email , $ entry ) { $ success = true ; $ emailType = $ this -> em -> getRepository ( self :: $ emailTypeEntityName ) -> find ( $ entry [ 'emailType' ] [ 'id' ] ) ; if ( ! $ emailType ) { throw new EntityNotFoundException ( self :: $ emailTypeEntityName , $ entry [ 'emailType' ] [ 'id' ] ) ; } else { $ email -> setEmail ( $ entry [ 'email' ] ) ; $ email -> setEmailType ( $ emailType ) ; } return $ success ; }
Updates the given email address .
11,051
public function processUrls ( $ contact , $ urls ) { $ get = function ( $ url ) { return $ url -> getId ( ) ; } ; $ delete = function ( $ url ) use ( $ contact ) { return $ contact -> removeUrl ( $ url ) ; } ; $ update = function ( $ url , $ matchedEntry ) { return $ this -> updateUrl ( $ url , $ matchedEntry ) ; } ; $ add = function ( $ url ) use ( $ contact ) { return $ this -> addUrl ( $ contact , $ url ) ; } ; $ entities = $ contact -> getUrls ( ) ; $ result = $ this -> processSubEntities ( $ entities , $ urls , $ get , $ add , $ update , $ delete ) ; $ this -> resetIndexOfSubentites ( $ entities ) ; $ this -> setMainUrl ( $ contact ) ; return $ result ; }
Process all urls of request .
11,052
public function processCategories ( $ contact , $ categoryIds ) { $ contact -> getCategories ( ) -> clear ( ) ; if ( ! $ categoryIds ) { return true ; } foreach ( $ categoryIds as $ categoryId ) { $ category = $ this -> em -> getRepository ( self :: $ categoryEntityName ) -> find ( $ categoryId ) ; if ( ! $ category ) { throw new EntityNotFoundException ( self :: $ categoryEntityName , $ categoryId ) ; } $ contact -> addCategory ( $ category ) ; } return true ; }
Process all categories of request .
11,053
protected function addUrl ( $ contact , $ data ) { $ success = true ; $ urlType = $ this -> em -> getRepository ( self :: $ urlTypeEntityName ) -> find ( $ data [ 'urlType' ] [ 'id' ] ) ; if ( isset ( $ data [ 'id' ] ) ) { throw new EntityIdAlreadySetException ( self :: $ urlEntityName , $ data [ 'id' ] ) ; } elseif ( ! $ urlType ) { throw new EntityNotFoundException ( self :: $ urlTypeEntityName , $ data [ 'urlType' ] [ 'id' ] ) ; } else { $ url = new Url ( ) ; $ url -> setUrl ( $ data [ 'url' ] ) ; $ url -> setUrlType ( $ urlType ) ; $ this -> em -> persist ( $ url ) ; $ contact -> addUrl ( $ url ) ; } return $ success ; }
Adds a new tag to the given contact .
11,054
public function processPhones ( $ contact , $ phones ) { $ get = function ( $ phone ) { return $ phone -> getId ( ) ; } ; $ delete = function ( $ phone ) use ( $ contact ) { return $ contact -> removePhone ( $ phone ) ; } ; $ update = function ( $ phone , $ matchedEntry ) { return $ this -> updatePhone ( $ phone , $ matchedEntry ) ; } ; $ add = function ( $ phone ) use ( $ contact ) { return $ this -> addPhone ( $ contact , $ phone ) ; } ; $ entities = $ contact -> getPhones ( ) ; $ result = $ this -> processSubEntities ( $ entities , $ phones , $ get , $ add , $ update , $ delete ) ; $ this -> resetIndexOfSubentites ( $ entities ) ; $ this -> setMainPhone ( $ contact ) ; return $ result ; }
Process all phones from request .
11,055
protected function addPhone ( $ contact , $ phoneData ) { $ success = true ; $ phoneType = $ this -> em -> getRepository ( self :: $ phoneTypeEntityName ) -> find ( $ phoneData [ 'phoneType' ] [ 'id' ] ) ; if ( isset ( $ phoneData [ 'id' ] ) ) { throw new EntityIdAlreadySetException ( self :: $ phoneEntityName , $ phoneData [ 'id' ] ) ; } elseif ( ! $ phoneType ) { throw new EntityNotFoundException ( self :: $ phoneTypeEntityName , $ phoneData [ 'phoneType' ] [ 'id' ] ) ; } else { $ phone = new Phone ( ) ; $ phone -> setPhone ( $ phoneData [ 'phone' ] ) ; $ phone -> setPhoneType ( $ phoneType ) ; $ this -> em -> persist ( $ phone ) ; $ contact -> addPhone ( $ phone ) ; } return $ success ; }
Add a new phone to the given contact and persist it with the given object manager .
11,056
protected function updatePhone ( Phone $ phone , $ entry ) { $ success = true ; $ phoneType = $ this -> em -> getRepository ( self :: $ phoneTypeEntityName ) -> find ( $ entry [ 'phoneType' ] [ 'id' ] ) ; if ( ! $ phoneType ) { throw new EntityNotFoundException ( self :: $ phoneTypeEntityName , $ entry [ 'phoneType' ] [ 'id' ] ) ; } else { $ phone -> setPhone ( $ entry [ 'phone' ] ) ; $ phone -> setPhoneType ( $ phoneType ) ; } return $ success ; }
Updates the given phone .
11,057
protected function getBooleanValue ( $ value ) { if ( is_string ( $ value ) ) { return 'true' === $ value ? true : false ; } elseif ( is_bool ( $ value ) ) { return $ value ; } elseif ( is_numeric ( $ value ) ) { return 1 === $ value ? true : false ; } }
Checks if a value is a boolean and converts it if necessary and returns it .
11,058
public function processNotes ( $ contact , $ notes ) { $ get = function ( $ note ) { return $ note -> getId ( ) ; } ; $ delete = function ( $ note ) use ( $ contact ) { $ contact -> removeNote ( $ note ) ; return true ; } ; $ update = function ( $ note , $ matchedEntry ) { return $ this -> updateNote ( $ note , $ matchedEntry ) ; } ; $ add = function ( $ note ) use ( $ contact ) { return $ this -> addNote ( $ contact , $ note ) ; } ; $ entities = $ contact -> getNotes ( ) ; $ result = $ this -> processSubEntities ( $ entities , $ notes , $ get , $ add , $ update , $ delete ) ; $ this -> resetIndexOfSubentites ( $ entities ) ; return $ result ; }
Process all notes from request .
11,059
public function processTags ( $ contact , $ tags ) { $ get = function ( $ tag ) { return $ tag -> getId ( ) ; } ; $ delete = function ( $ tag ) use ( $ contact ) { return $ contact -> removeTag ( $ tag ) ; } ; $ update = function ( ) { return true ; } ; $ add = function ( $ tag ) use ( $ contact ) { return $ this -> addTag ( $ contact , $ tag ) ; } ; $ entities = $ contact -> getTags ( ) ; $ result = $ this -> processSubEntities ( $ entities , $ tags , $ get , $ add , $ update , $ delete ) ; $ this -> resetIndexOfSubentites ( $ entities ) ; return $ result ; }
Process all tags of request .
11,060
protected function addTag ( $ contact , $ data ) { $ success = true ; $ resolvedTag = $ this -> getTagManager ( ) -> findByName ( $ data ) ; $ contact -> addTag ( $ resolvedTag ) ; return $ success ; }
Adds a new tag to the given contact and persist it with the given object manager .
11,061
public function processBankAccounts ( $ contact , $ bankAccounts ) { $ get = function ( $ bankAccount ) { return $ bankAccount -> getId ( ) ; } ; $ delete = function ( $ bankAccounts ) use ( $ contact ) { $ contact -> removeBankAccount ( $ bankAccounts ) ; return true ; } ; $ update = function ( $ bankAccounts , $ matchedEntry ) { return $ this -> updateBankAccount ( $ bankAccounts , $ matchedEntry ) ; } ; $ add = function ( $ bankAccounts ) use ( $ contact ) { return $ this -> addBankAccount ( $ contact , $ bankAccounts ) ; } ; $ entities = $ contact -> getBankAccounts ( ) ; $ result = $ this -> processSubEntities ( $ entities , $ bankAccounts , $ get , $ add , $ update , $ delete ) ; $ this -> resetIndexOfSubentites ( $ entities ) ; return $ result ; }
Process all bankAccounts of a request .
11,062
public function processAddresses ( $ contact , $ addresses ) { $ getAddressId = function ( $ addressRelation ) { return $ addressRelation -> getAddress ( ) -> getId ( ) ; } ; $ delete = function ( $ addressRelation ) use ( $ contact ) { $ this -> removeAddressRelation ( $ contact , $ addressRelation ) ; return true ; } ; $ update = function ( $ addressRelation , $ matchedEntry ) use ( $ contact ) { $ address = $ addressRelation -> getAddress ( ) ; $ result = $ this -> updateAddress ( $ address , $ matchedEntry , $ isMain ) ; if ( $ isMain ) { $ this -> unsetMain ( $ this -> getAddressRelations ( $ contact ) ) ; } $ addressRelation -> setMain ( $ isMain ) ; return $ result ; } ; $ add = function ( $ addressData ) use ( $ contact ) { $ address = $ this -> createAddress ( $ addressData , $ isMain ) ; $ this -> addAddress ( $ contact , $ address , $ isMain ) ; return true ; } ; $ entities = $ this -> getAddressRelations ( $ contact ) ; $ result = $ this -> processSubEntities ( $ entities , $ addresses , $ getAddressId , $ add , $ update , $ delete ) ; $ this -> resetIndexOfSubentites ( $ entities ) ; $ this -> checkAndSetMainAddress ( $ this -> getAddressRelations ( $ contact ) ) ; return $ result ; }
Process all addresses from request .
11,063
public function handleHydrate ( HydrateEvent $ event ) { $ document = $ event -> getDocument ( ) ; if ( ! $ document instanceof RouteBehavior ) { return ; } $ document -> setHistory ( $ event -> getNode ( ) -> getPropertyValue ( self :: NODE_HISTORY_FIELD ) ) ; }
Writes the history status of the node to the document .
11,064
public function handleSetNodeOnPersist ( PersistEvent $ event ) { $ document = $ event -> getDocument ( ) ; $ options = $ event -> getOptions ( ) ; if ( ! $ document instanceof RouteBehavior || ! array_key_exists ( 'path' , $ options ) ) { return ; } $ parentPath = PathHelper :: getParentPath ( $ options [ 'path' ] ) ; $ parentNode = $ this -> nodeManager -> createPath ( $ parentPath ) ; $ nodeName = PathHelper :: getNodeName ( $ options [ 'path' ] ) ; if ( ! $ parentNode -> hasNode ( $ nodeName ) ) { return ; } $ node = $ parentNode -> getNode ( $ nodeName ) ; if ( $ node -> hasProperty ( self :: NODE_HISTORY_FIELD ) ) { return ; } $ event -> setNode ( $ node ) ; $ event -> setParentNode ( $ parentNode ) ; }
Receives node for route and overwrite when the node is empty .
11,065
public function handlePersist ( PersistEvent $ event ) { $ document = $ event -> getDocument ( ) ; if ( ! $ document instanceof RouteBehavior ) { return ; } $ node = $ event -> getNode ( ) ; $ node -> setProperty ( self :: NODE_HISTORY_FIELD , $ document -> isHistory ( ) ) ; $ targetDocument = $ document -> getTargetDocument ( ) ; if ( $ targetDocument instanceof HomeDocument || ! $ targetDocument instanceof WebspaceBehavior || ! $ targetDocument instanceof ResourceSegmentBehavior ) { return ; } $ webspaceKey = $ targetDocument -> getWebspaceName ( ) ; $ locale = $ this -> documentInspector -> getLocale ( $ document ) ; $ routePath = $ this -> sessionManager -> getRoutePath ( $ webspaceKey , $ locale , null ) . $ targetDocument -> getResourceSegment ( ) ; $ documentPath = $ this -> documentInspector -> getPath ( $ document ) ; if ( $ documentPath && $ documentPath != $ routePath ) { $ newRouteDocument = $ this -> documentManager -> create ( 'route' ) ; $ newRouteDocument -> setTargetDocument ( $ targetDocument ) ; $ this -> documentManager -> persist ( $ newRouteDocument , $ locale , [ 'path' => $ routePath , 'auto_create' => true , ] ) ; $ this -> documentManager -> publish ( $ newRouteDocument , $ locale ) ; $ this -> changeOldPathToHistoryRoutes ( $ document , $ newRouteDocument ) ; } }
Updates the route for the given document and creates history routes if necessary .
11,066
public function handleRemove ( RemoveEvent $ event ) { $ document = $ event -> getDocument ( ) ; if ( ! $ document instanceof RouteBehavior ) { return ; } $ this -> recursivelyRemoveRoutes ( $ document ) ; }
Removes the routes for the given document and removes history routes if necessary .
11,067
public function handlePublish ( PublishEvent $ event ) { $ document = $ event -> getDocument ( ) ; if ( ! $ document instanceof RouteBehavior ) { return ; } $ event -> getNode ( ) -> setProperty ( self :: NODE_HISTORY_FIELD , $ document -> isHistory ( ) ) ; }
Handles the history field for the route on publish .
11,068
private function recursivelyRemoveRoutes ( RouteBehavior $ document ) { $ referrers = $ this -> documentInspector -> getReferrers ( $ document ) ; foreach ( $ referrers as $ referrer ) { if ( ! $ referrer instanceof RouteBehavior ) { continue ; } $ this -> recursivelyRemoveRoutes ( $ referrer ) ; $ this -> documentManager -> remove ( $ referrer ) ; } }
Remove given Route and his history .
11,069
private function changeOldPathToHistoryRoutes ( RouteBehavior $ oldDocument , RouteBehavior $ newDocument ) { $ oldDocument -> setTargetDocument ( $ newDocument ) ; $ oldDocument -> setHistory ( true ) ; $ oldRouteNode = $ this -> documentInspector -> getNode ( $ oldDocument ) ; $ oldRouteNode -> setProperty ( self :: NODE_HISTORY_FIELD , true ) ; foreach ( $ this -> documentInspector -> getReferrers ( $ oldDocument ) as $ referrer ) { if ( $ referrer instanceof RouteBehavior ) { $ referrer -> setTargetDocument ( $ newDocument ) ; $ referrer -> setHistory ( true ) ; $ this -> documentManager -> persist ( $ referrer , null , [ 'path' => $ this -> documentInspector -> getPath ( $ referrer ) , ] ) ; $ this -> documentManager -> publish ( $ referrer , null ) ; } } }
Changes the old route to a history route and redirect to the new route .
11,070
public function getData ( ) { if ( null === $ this -> data ) { $ this -> data = $ this -> loadData ( ) ; } return $ this -> data ; }
Lazy loads the data based on the filter criteria from the config .
11,071
private function loadData ( ) { $ result = [ ] ; if ( null !== $ this -> ids && count ( $ this -> ids ) > 0 ) { $ this -> contentQueryBuilder -> init ( [ 'ids' => $ this -> ids , 'properties' => ( isset ( $ this -> params [ 'properties' ] ) ? $ this -> params [ 'properties' ] -> getValue ( ) : [ ] ) , 'published' => ! $ this -> showDrafts , ] ) ; $ pages = $ this -> contentQueryExecutor -> execute ( $ this -> webspaceKey , [ $ this -> languageCode ] , $ this -> contentQueryBuilder ) ; $ map = [ ] ; foreach ( $ pages as $ page ) { $ map [ $ page [ 'uuid' ] ] = $ page ; } foreach ( $ this -> ids as $ id ) { if ( isset ( $ map [ $ id ] ) ) { $ result [ ] = $ map [ $ id ] ; } } } return $ result ; }
lazy load data .
11,072
private function getSuluVersion ( $ dir ) { $ version = '_._._' ; $ composerFile = new SplFileInfo ( $ dir . '/composer.lock' , '' , '' ) ; if ( ! $ composerFile -> isFile ( ) ) { return $ version ; } $ composer = json_decode ( $ composerFile -> getContents ( ) , true ) ; foreach ( $ composer [ 'packages' ] as $ package ) { if ( 'sulu/sulu' === $ package [ 'name' ] ) { return $ package [ 'version' ] ; } } return $ version ; }
Read composer . lock file and return version of sulu .
11,073
private function getAppVersion ( $ dir ) { $ version = null ; $ composerFile = new SplFileInfo ( $ dir . '/composer.json' , '' , '' ) ; if ( ! $ composerFile -> isFile ( ) ) { return $ version ; } $ composerJson = json_decode ( $ composerFile -> getContents ( ) , true ) ; if ( ! array_key_exists ( 'version' , $ composerJson ) ) { return $ version ; } return $ composerJson [ 'version' ] ; }
Read composer . json file and return version of app .
11,074
private function resolveOptions ( $ string , array $ options ) { foreach ( $ options as $ key => $ value ) { $ string = str_replace ( ':' . $ key , $ value , $ string ) ; } return $ string ; }
Resolves options for string .
11,075
public function postAction ( $ id , Request $ request ) { try { $ mediaManager = $ this -> getMediaManager ( ) ; $ systemCollectionManager = $ this -> get ( 'sulu_media.system_collections.manager' ) ; $ locale = $ this -> getLocale ( $ request ) ; $ media = $ mediaManager -> getById ( $ id , $ locale ) ; $ mediaEntity = $ media -> getEntity ( ) ; $ data = $ this -> getData ( $ request , false ) ; unset ( $ data [ 'id' ] ) ; if ( null !== $ mediaEntity -> getPreviewImage ( ) ) { $ data [ 'id' ] = $ mediaEntity -> getPreviewImage ( ) -> getId ( ) ; } $ data [ 'collection' ] = $ systemCollectionManager -> getSystemCollection ( 'sulu_media.preview_image' ) ; $ data [ 'locale' ] = $ locale ; $ data [ 'title' ] = $ media -> getTitle ( ) ; $ uploadedFile = $ this -> getUploadedFile ( $ request , 'previewImage' ) ; $ previewImage = $ mediaManager -> save ( $ uploadedFile , $ data , $ this -> getUser ( ) -> getId ( ) ) ; $ mediaEntity -> setPreviewImage ( $ previewImage -> getEntity ( ) ) ; $ this -> getDoctrine ( ) -> getManager ( ) -> flush ( ) ; $ view = $ this -> view ( $ previewImage , 200 ) ; } catch ( MediaNotFoundException $ e ) { $ view = $ this -> view ( $ e -> toArray ( ) , 404 ) ; } catch ( MediaException $ e ) { $ view = $ this -> view ( $ e -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; }
Creates a new preview image and saves it to the provided media .
11,076
public function deleteAction ( $ id , Request $ request ) { try { $ mediaManager = $ this -> getMediaManager ( ) ; $ locale = $ this -> getLocale ( $ request ) ; $ media = $ mediaManager -> getById ( $ id , $ locale ) ; $ mediaEntity = $ media -> getEntity ( ) ; if ( null !== $ mediaEntity -> getPreviewImage ( ) ) { $ oldPreviewImageId = $ mediaEntity -> getPreviewImage ( ) -> getId ( ) ; $ mediaEntity -> setPreviewImage ( null ) ; $ mediaManager -> delete ( $ oldPreviewImageId ) ; } $ view = $ this -> view ( null , 204 ) ; } catch ( MediaNotFoundException $ e ) { $ view = $ this -> view ( $ e -> toArray ( ) , 404 ) ; } catch ( MediaException $ e ) { $ view = $ this -> view ( $ e -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; }
Removes current preview image and sets default video thumbnail .
11,077
public function find ( $ prefix = 'u' ) { $ selectFromDQL = $ this -> getSelectFrom ( $ prefix ) ; $ whereDQL = $ this -> getWhere ( $ prefix ) ; if ( true != $ this -> countQuery ) { $ orderDQL = $ this -> getOrderBy ( $ prefix ) ; } else { $ orderDQL = '' ; } $ dql = sprintf ( '%s %s %s' , $ selectFromDQL , $ whereDQL , $ orderDQL ) ; return $ dql ; }
Searches Entity by filter for fields pagination and sorted by a column .
11,078
public function justCount ( $ countAttribute = 'u.id' , $ alias = 'totalcount' ) { $ this -> countQuery = true ; $ this -> replaceSelect = 'COUNT(' . $ countAttribute . ') as ' . $ alias ; }
just return count .
11,079
private function getSelectFrom ( $ prefix = 'u' ) { $ this -> joins = '' ; $ this -> prefixes = [ $ prefix ] ; $ fieldsWhere = array_merge ( ( null != $ this -> fields ) ? $ this -> fields : [ ] , array_keys ( $ this -> where ) ) ; $ fieldsWhere = array_merge ( $ fieldsWhere , $ this -> searchTextFields , $ this -> searchNumberFields ) ; if ( null != $ fieldsWhere && count ( $ fieldsWhere ) >= 0 ) { foreach ( $ fieldsWhere as $ field ) { $ this -> performSelectFromField ( $ field , $ prefix ) ; } } if ( true === $ this -> countQuery ) { $ this -> select = $ this -> replaceSelect ; } elseif ( 0 == strlen ( $ this -> select ) ) { $ this -> select = $ prefix ; } $ dql = 'SELECT %s FROM %s %s %s' ; return sprintf ( $ dql , $ this -> select , $ this -> entityName , $ prefix , $ this -> joins ) ; }
Create a Select ... From ... Statement for given fields with joins .
11,080
private function performSelectFromField ( $ field , $ prefix = 'u' ) { $ fieldParts = explode ( '_' , $ field ) ; $ realFieldName = $ field ; if ( preg_match ( '/^(.*)\[(\d+)\]$/' , $ fieldParts [ 0 ] , $ regresult ) ) { $ fieldParts [ 0 ] = $ regresult [ 1 ] ; $ realFieldName = implode ( '_' , $ fieldParts ) ; $ this -> relationalFilters [ $ realFieldName ] = $ regresult [ 2 ] ; } if ( count ( $ fieldParts ) >= 2 && $ this -> isRelation ( $ fieldParts [ 0 ] ) ) { $ this -> joins .= $ this -> generateJoins ( $ fieldParts , $ prefix ) ; if ( in_array ( $ field , $ this -> fields ) ) { $ i = count ( $ fieldParts ) - 1 ; $ parent = $ fieldParts [ $ i - 1 ] ; $ tempField = $ fieldParts [ $ i ] ; $ alias = $ realFieldName ; $ this -> addToSelect ( $ parent , $ tempField , $ alias ) ; } } elseif ( in_array ( $ field , $ this -> fields ) && in_array ( $ field , $ this -> fieldNames ) ) { $ this -> addToSelect ( $ prefix , $ field ) ; } }
solves the relations for a single field and generate dql for select and joins .
11,081
private function generateJoinCondition ( $ field ) { if ( ! array_key_exists ( $ field , $ this -> joinConditions ) ) { return '' ; } $ format = ' WITH %s' ; return sprintf ( $ format , $ this -> joinConditions [ $ field ] ) ; }
generates the join condition .
11,082
private function getWhere ( $ prefix ) { $ result = '' ; if ( count ( $ this -> where ) > 0 || count ( $ this -> searchFields ) > 0 ) { $ wheres = [ ] ; $ searches = [ ] ; $ whereKeys = array_keys ( $ this -> where ) ; $ fields = array_unique ( array_merge ( $ whereKeys , $ this -> searchFields ) ) ; foreach ( $ fields as $ key ) { $ keys = explode ( '_' , $ key ) ; $ prefixActual = $ prefix ; if ( 1 == count ( $ keys ) ) { $ col = $ keys [ 0 ] ; } else { $ i = count ( $ keys ) ; $ prefixActual = $ keys [ $ i - 2 ] ; $ col = $ keys [ $ i - 1 ] ; } if ( in_array ( $ key , $ whereKeys ) ) { $ wheres [ ] = $ prefixActual . '.' . $ col . ' = ' . $ this -> where [ $ key ] ; } if ( in_array ( $ key , $ this -> searchFields ) ) { $ comparator = '=' ; $ search = ':strictSearch' ; if ( in_array ( $ key , $ this -> searchTextFields ) ) { $ comparator = 'LIKE' ; $ search = ':search' ; } $ searches [ ] = $ prefixActual . '.' . $ col . ' ' . $ comparator . ' ' . $ search ; } } if ( ! empty ( $ wheres ) ) { $ result .= implode ( ' AND ' , $ wheres ) ; } if ( ! empty ( $ searches ) ) { if ( '' != $ result ) { $ result .= ' AND ' ; } $ result .= '(' . implode ( ' OR ' , $ searches ) . ')' ; } $ result = 'WHERE ' . $ result ; } return $ result ; }
Get DQL for Where clause .
11,083
private function getOrderBy ( $ prefix ) { $ result = '' ; if ( null != $ this -> sorting && count ( $ this -> sorting ) > 0 ) { $ orderBy = '' ; foreach ( $ this -> sorting as $ col => $ dir ) { if ( strlen ( $ orderBy ) > 0 ) { $ orderBy .= ', ' ; } $ orderBy .= $ prefix . '.' . $ col . ' ' . $ dir ; } $ result .= ' ORDER BY ' . $ orderBy ; } return $ result ; }
Get DQL for Sorting .
11,084
public function setPhoneType ( \ Sulu \ Bundle \ ContactBundle \ Entity \ PhoneType $ phoneType ) { $ this -> phoneType = $ phoneType ; return $ this ; }
Set phoneType .
11,085
public function import ( $ locale , $ filePath , OutputInterface $ output = null , $ format = '1.2.xliff' ) { $ parsedDataList = $ this -> getParser ( $ format ) -> parse ( $ filePath , $ locale ) ; $ failedImports = [ ] ; $ importedCounter = 0 ; $ successCounter = 0 ; if ( null === $ output ) { $ output = new NullOutput ( ) ; } $ progress = new ProgressBar ( $ output , count ( $ parsedDataList ) ) ; $ progress -> setFormat ( ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%' ) ; $ progress -> start ( ) ; foreach ( $ parsedDataList as $ parsedData ) { ++ $ importedCounter ; if ( ! $ this -> importDocument ( $ parsedData , $ locale , $ format ) ) { $ failedImports [ ] = $ parsedData ; } else { ++ $ successCounter ; } $ this -> logger -> info ( sprintf ( 'Document %s/%s' , $ importedCounter , count ( $ parsedDataList ) ) ) ; $ progress -> advance ( ) ; } $ progress -> finish ( ) ; $ return = new \ stdClass ( ) ; $ return -> count = $ importedCounter ; $ return -> fails = count ( $ failedImports ) ; $ return -> successes = $ successCounter ; $ return -> failed = $ failedImports ; $ return -> exceptionStore = $ this -> exceptionStore ; return $ return ; }
Import Snippet by given XLIFF - File .
11,086
private function getCountries ( ) { $ countries = [ ] ; foreach ( Intl :: getRegionBundle ( ) -> getCountryNames ( ) as $ countryCode => $ countryName ) { $ countries [ strtolower ( $ countryCode ) ] = new PropertyParameter ( strtolower ( $ countryCode ) , $ countryName ) ; } return $ countries ; }
Returns array of countries with the country - code as array key .
11,087
public function addValue ( \ Sulu \ Bundle \ ResourceBundle \ Entity \ OperatorValue $ values ) { $ this -> values [ ] = $ values ; return $ this ; }
Add values .
11,088
public function removeValue ( \ Sulu \ Bundle \ ResourceBundle \ Entity \ OperatorValue $ values ) { $ this -> values -> removeElement ( $ values ) ; }
Remove values .
11,089
private function encodePassword ( $ user , $ password , $ salt ) { $ encoder = $ this -> encoderFactory -> getEncoder ( $ user ) ; return $ encoder -> encodePassword ( $ password , $ salt ) ; }
Encodes the given password for the given password with he given salt and returns the result .
11,090
private function getRoleNames ( ) { $ roleNames = $ this -> roleRepository -> getRoleNames ( ) ; if ( empty ( $ roleNames ) ) { throw new \ RuntimeException ( sprintf ( 'The system currently has no roles. Use the "sulu:security:role:create" command to create roles.' ) ) ; } return $ roleNames ; }
Return the names of all the roles .
11,091
public function getAction ( $ id , Request $ request ) { if ( $ this -> getBooleanRequestParameter ( $ request , 'tree' , false , false ) ) { $ collections = $ this -> getCollectionManager ( ) -> getTreeById ( $ id , $ this -> getRequestParameter ( $ request , 'locale' , true ) ) ; return $ this -> handleView ( $ this -> view ( new CollectionRepresentation ( $ collections , 'collections' ) ) ) ; } try { $ locale = $ this -> getRequestParameter ( $ request , 'locale' , true ) ; $ depth = intval ( $ request -> get ( 'depth' , 0 ) ) ; $ breadcrumb = $ this -> getBooleanRequestParameter ( $ request , 'breadcrumb' , false , false ) ; $ children = $ this -> getBooleanRequestParameter ( $ request , 'children' , false , false ) ; $ collectionManager = $ this -> getCollectionManager ( ) ; $ listRestHelper = $ this -> get ( 'sulu_core.list_rest_helper' ) ; $ limit = $ request -> get ( 'limit' , null ) ; $ offset = $ this -> getOffset ( $ request , $ limit ) ; $ search = $ listRestHelper -> getSearchPattern ( ) ; $ sortBy = $ request -> get ( 'sortBy' ) ; $ sortOrder = $ request -> get ( 'sortOrder' , 'ASC' ) ; $ filter = [ 'limit' => $ limit , 'offset' => $ offset , 'search' => $ search , ] ; $ view = $ this -> responseGetById ( $ id , function ( $ id ) use ( $ locale , $ collectionManager , $ depth , $ breadcrumb , $ filter , $ sortBy , $ sortOrder , $ children ) { $ collection = $ collectionManager -> getById ( $ id , $ locale , $ depth , $ breadcrumb , $ filter , null !== $ sortBy ? [ $ sortBy => $ sortOrder ] : [ ] , $ children ) ; if ( SystemCollectionManagerInterface :: COLLECTION_TYPE === $ collection -> getType ( ) -> getKey ( ) ) { $ this -> get ( 'sulu_security.security_checker' ) -> checkPermission ( 'sulu.media.system_collections' , PermissionTypes :: VIEW ) ; } return $ collection ; } ) ; } catch ( CollectionNotFoundException $ cnf ) { $ view = $ this -> view ( $ cnf -> toArray ( ) , 404 ) ; } catch ( MediaException $ e ) { $ view = $ this -> view ( $ e -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; }
Shows a single collection with the given id .
11,092
public function cgetAction ( Request $ request ) { try { $ listRestHelper = $ this -> get ( 'sulu_core.list_rest_helper' ) ; $ securityChecker = $ this -> get ( 'sulu_security.security_checker' ) ; $ flat = $ this -> getBooleanRequestParameter ( $ request , 'flat' , false ) ; $ depth = $ request -> get ( 'depth' , 0 ) ; $ parentId = $ request -> get ( 'parentId' , null ) ; $ limit = $ request -> get ( 'limit' , null ) ; $ offset = $ this -> getOffset ( $ request , $ limit ) ; $ search = $ listRestHelper -> getSearchPattern ( ) ; $ sortBy = $ request -> get ( 'sortBy' ) ; $ sortOrder = $ request -> get ( 'sortOrder' , 'ASC' ) ; $ includeRoot = $ this -> getBooleanRequestParameter ( $ request , 'includeRoot' , false , false ) ; $ collectionManager = $ this -> getCollectionManager ( ) ; if ( 'root' === $ parentId ) { $ includeRoot = false ; $ parentId = null ; } if ( $ flat ) { $ collections = $ collectionManager -> get ( $ this -> getRequestParameter ( $ request , 'locale' , true ) , [ 'depth' => $ depth , 'parent' => $ parentId , ] , $ limit , $ offset , null !== $ sortBy ? [ $ sortBy => $ sortOrder ] : [ ] ) ; } else { $ collections = $ collectionManager -> getTree ( $ this -> getRequestParameter ( $ request , 'locale' , true ) , $ offset , $ limit , $ search , $ depth , null !== $ sortBy ? [ $ sortBy => $ sortOrder ] : [ ] , $ securityChecker -> hasPermission ( 'sulu.media.system_collections' , 'view' ) ) ; } if ( $ includeRoot && ! $ parentId ) { $ collections = [ new RootCollection ( $ this -> get ( 'translator' ) -> trans ( 'sulu_media.all_collections' , [ ] , 'admin' ) , $ collections ) , ] ; } $ all = $ collectionManager -> getCount ( ) ; $ list = new ListRepresentation ( $ collections , self :: $ entityKey , 'get_collections' , $ request -> query -> all ( ) , $ listRestHelper -> getPage ( ) , $ listRestHelper -> getLimit ( ) , $ all ) ; $ view = $ this -> view ( $ list , 200 ) ; } catch ( CollectionNotFoundException $ cnf ) { $ view = $ this -> view ( $ cnf -> toArray ( ) , 404 ) ; } catch ( MediaException $ me ) { $ view = $ this -> view ( $ me -> toArray ( ) , 400 ) ; } return $ this -> handleView ( $ view ) ; }
lists all collections .
11,093
public function deleteAction ( $ id ) { $ delete = function ( $ id ) { try { $ collectionManager = $ this -> getCollectionManager ( ) ; $ collectionManager -> delete ( $ id ) ; } catch ( CollectionNotFoundException $ cnf ) { throw new EntityNotFoundException ( self :: $ entityName , $ id ) ; } catch ( MediaException $ me ) { throw new RestException ( $ me -> getMessage ( ) , $ me -> getCode ( ) ) ; } } ; $ view = $ this -> responseDelete ( $ id , $ delete ) ; return $ this -> handleView ( $ view ) ; }
Delete a collection with the given id .
11,094
protected function moveEntity ( $ id , Request $ request ) { $ destinationId = $ this -> getRequestParameter ( $ request , 'destination' ) ; $ locale = $ this -> getRequestParameter ( $ request , 'locale' , true ) ; $ collection = $ this -> getCollectionManager ( ) -> move ( $ id , $ locale , $ destinationId ) ; $ view = $ this -> view ( $ collection ) ; return $ this -> handleView ( $ view ) ; }
Moves an entity into another one .
11,095
private function assertExists ( $ type ) { if ( ! isset ( $ this -> typePaths [ $ type ] ) ) { throw new Exception \ DocumentTypeNotFoundException ( sprintf ( 'Structure path for document type "%s" is not mapped. Mapped structure types: "%s"' , $ type , implode ( '", "' , array_keys ( $ this -> typePaths ) ) ) ) ; } }
Assert type exists .
11,096
private function getPaths ( $ type ) { $ typeConfigs = $ this -> typePaths [ $ type ] ; $ paths = [ ] ; foreach ( $ typeConfigs as $ typeConfig ) { $ paths [ ] = $ typeConfig [ 'path' ] ; } return $ paths ; }
Get the paths from the type path configuration .
11,097
private function getCategoryQuery ( ) { return $ this -> createQueryBuilder ( 'category' ) -> leftJoin ( 'category.meta' , 'categoryMeta' ) -> leftJoin ( 'category.translations' , 'categoryTranslations' ) -> leftJoin ( 'categoryTranslations.keywords' , 'categoryKeywords' ) -> leftJoin ( 'category.parent' , 'categoryParent' ) -> leftJoin ( 'category.children' , 'categoryChildren' ) -> addSelect ( 'categoryMeta' ) -> addSelect ( 'categoryTranslations' ) -> addSelect ( 'categoryKeywords' ) -> addSelect ( 'categoryParent' ) -> addSelect ( 'categoryChildren' ) ; }
Returns the general part of the query .
11,098
protected function getOperatorQuery ( $ locale ) { $ qb = $ this -> createQueryBuilder ( 'operator' ) -> addSelect ( 'operatorValues' ) -> addSelect ( 'translations' ) -> addSelect ( 'operatorValueTranslations' ) -> leftJoin ( 'operator.translations' , 'translations' , 'WITH' , 'translations.locale = :locale' ) -> leftJoin ( 'operator.values' , 'operatorValues' ) -> leftJoin ( 'operatorValues.translations' , 'operatorValueTranslations' , 'WITH' , 'operatorValueTranslations.locale = :locale' ) -> setParameter ( 'locale' , $ locale ) ; return $ qb ; }
Returns the query for operators .
11,099
public function postGenerateSchemaTable ( GenerateSchemaTableEventArgs $ args ) { $ classMetadata = $ args -> getClassMetadata ( ) ; $ table = $ args -> getClassTable ( ) ; foreach ( $ classMetadata -> getFieldNames ( ) as $ fieldName ) { $ mapping = $ classMetadata -> getFieldMapping ( $ fieldName ) ; if ( ! isset ( $ mapping [ 'options' ] [ 'references' ] ) ) { continue ; } $ referencesOptions = $ mapping [ 'options' ] [ 'references' ] ; $ unknownOptions = array_diff_key ( $ referencesOptions , array_flip ( self :: $ knownOptions ) ) ; if ( count ( $ unknownOptions ) > 0 ) { throw new RuntimeException ( sprintf ( 'Unknown options "%s" in the "references" option in the Doctrine schema of %s::%s.' , implode ( '", "' , array_keys ( $ unknownOptions ) ) , $ classMetadata -> getReflectionClass ( ) -> getName ( ) , $ fieldName ) ) ; } if ( ! isset ( $ referencesOptions [ 'entity' ] ) ) { throw new RuntimeException ( sprintf ( 'Missing option "entity" in the "references" option in the Doctrine schema of %s::%s.' , $ classMetadata -> getReflectionClass ( ) -> getName ( ) , $ fieldName ) ) ; } if ( ! isset ( $ referencesOptions [ 'field' ] ) ) { throw new RuntimeException ( sprintf ( 'Missing option "field" in the "references" option in the Doctrine schema of %s::%s.' , $ classMetadata -> getReflectionClass ( ) -> getName ( ) , $ fieldName ) ) ; } $ localColumnName = $ classMetadata -> getColumnName ( $ fieldName ) ; $ foreignClassMetadata = $ this -> managerRegistry -> getManagerForClass ( $ referencesOptions [ 'entity' ] ) -> getClassMetadata ( $ referencesOptions [ 'entity' ] ) ; $ foreignTable = $ foreignClassMetadata -> getTableName ( ) ; $ foreignColumnName = $ foreignClassMetadata -> getColumnName ( $ referencesOptions [ 'field' ] ) ; $ options = [ ] ; if ( isset ( $ referencesOptions [ 'onDelete' ] ) ) { $ options [ 'onDelete' ] = $ referencesOptions [ 'onDelete' ] ; } if ( isset ( $ referencesOptions [ 'onUpdate' ] ) ) { $ options [ 'onUpdate' ] = $ referencesOptions [ 'onUpdate' ] ; } $ table -> addForeignKeyConstraint ( $ foreignTable , [ $ localColumnName ] , [ $ foreignColumnName ] , $ options ) ; } }
Parses the mapping and adds foreign - key constraints for each references option found .