idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
27,600
public function newAction ( Blog $ blog ) { try { $ article = new Article ( ) ; $ article -> setBlog ( $ blog ) ; $ form = $ this -> createForm ( ArticleType :: class , $ article ) ; return new JsonResponse ( [ 'html' => $ this -> container -> get ( 'templating' ) -> render ( 'VictoireBlogBundle:Article:new.html.twig' , [ 'form' => $ form -> createView ( ) , 'blogId' => $ blog -> getId ( ) , ] ) , ] ) ; } catch ( NoResultException $ e ) { return new JsonResponse ( [ 'success' => false , 'message' => $ e -> getMessage ( ) , ] ) ; } }
Display a form to create a new Blog Article .
27,601
public function newPostAction ( Request $ request , Blog $ blog ) { $ article = new Article ( ) ; $ article -> setBlog ( $ blog ) ; $ form = $ this -> createForm ( ArticleType :: class , $ article ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ page = $ this -> get ( 'victoire_blog.manager.article' ) -> create ( $ article , $ this -> getUser ( ) ) ; $ dispatcher = $ this -> get ( 'event_dispatcher' ) ; $ event = new ArticleEvent ( $ article ) ; $ dispatcher -> dispatch ( VictoireBlogEvents :: CREATE_ARTICLE , $ event ) ; if ( null === $ response = $ event -> getResponse ( ) ) { $ response = new JsonResponse ( [ 'success' => true , 'url' => $ this -> generateUrl ( 'victoire_core_page_show' , [ '_locale' => $ request -> getLocale ( ) , 'url' => $ page -> getUrl ( ) , ] ) , ] ) ; } return $ response ; } return new JsonResponse ( [ 'success' => false , 'message' => $ this -> container -> get ( 'victoire_form.error_helper' ) -> getRecursiveReadableErrors ( $ form ) , 'html' => $ this -> container -> get ( 'templating' ) -> render ( 'VictoireBlogBundle:Article:new.html.twig' , [ 'form' => $ form -> createView ( ) , 'blogId' => $ blog -> getId ( ) , ] ) , ] ) ; }
Create a new Blog Article .
27,602
public function settingsAction ( Request $ request , Article $ article ) { $ form = $ this -> createForm ( ArticleSettingsType :: class , $ article ) ; $ form -> handleRequest ( $ request ) ; $ response = $ this -> getNotPersistedSettingsResponse ( $ form , $ article , $ request -> query -> get ( 'novalidate' , false ) ) ; return new JsonResponse ( $ response ) ; }
Display a form to edit Blog Article settings .
27,603
public function settingsPostAction ( Request $ request , Article $ article ) { $ form = $ this -> createForm ( ArticleSettingsType :: class , $ article ) ; $ form -> handleRequest ( $ request ) ; $ novalidate = $ request -> query -> get ( 'novalidate' , false ) ; if ( $ novalidate === false && $ form -> isValid ( ) ) { $ page = $ this -> get ( 'victoire_blog.manager.article' ) -> updateSettings ( $ article , $ this -> getUser ( ) ) ; $ response = [ 'success' => true , 'url' => $ this -> generateUrl ( 'victoire_core_page_show' , [ '_locale' => $ page -> getCurrentLocale ( ) , 'url' => $ page -> getReference ( ) -> getUrl ( ) , ] ) , ] ; } else { $ response = $ this -> getNotPersistedSettingsResponse ( $ form , $ article , $ novalidate ) ; } return new JsonResponse ( $ response ) ; }
Save Blog Article settings .
27,604
public function deleteAction ( Article $ article ) { $ blogViewReference = $ this -> container -> get ( 'victoire_view_reference.repository' ) -> getOneReferenceByParameters ( [ 'viewId' => $ article -> getBlog ( ) -> getId ( ) ] ) ; $ this -> get ( 'victoire_blog.manager.article' ) -> delete ( $ article ) ; $ message = $ this -> get ( 'translator' ) -> trans ( 'victoire.blog.article.delete.success' , [ ] , 'victoire' ) ; $ this -> congrat ( $ message ) ; $ response = [ 'success' => true , 'url' => $ this -> generateUrl ( 'victoire_core_page_show' , [ 'url' => $ blogViewReference -> getUrl ( ) , ] ) , 'message' => $ message , ] ; return new JsonResponse ( $ response ) ; }
Delete a Blog Article .
27,605
public function getAllForView ( View $ view ) { $ widgetMapsIdsToSearch = [ ] ; foreach ( $ view -> getBuiltWidgetMap ( ) as $ widgetMaps ) { foreach ( $ widgetMaps as $ widgetMap ) { $ widgetMapsIdsToSearch [ ] = $ widgetMap -> getId ( ) ; } } return $ this -> createQueryBuilder ( 'widget' ) -> join ( 'widget.widgetMap' , 'widgetMap' ) -> andWhere ( 'widgetMap.id IN (:widgetMapsIds)' ) -> setParameter ( 'widgetMapsIds' , $ widgetMapsIdsToSearch ) ; }
Get all Widgets for a given View .
27,606
public function findAllWidgetsForView ( View $ view ) { $ qb = $ this -> getAllForView ( $ view ) ; return $ qb -> getQuery ( ) -> getResult ( ) ; }
Find all Widgets for a given View .
27,607
private function endsWith ( $ str , $ sub ) { return substr ( $ str , strlen ( $ str ) - strlen ( $ sub ) ) === $ sub ; }
String helper .
27,608
public function findReferenceByView ( View $ view ) { $ referenceId = ViewReferenceHelper :: generateViewReferenceId ( $ view ) ; $ reference = $ this -> getOneReferenceByParameters ( [ 'id' => $ referenceId ] , false ) ; $ transformer = $ this -> transformer -> getViewReferenceTransformer ( ( string ) $ reference [ 'viewNamespace' ] , 'array' ) ; return $ transformer -> transform ( $ reference ) ; }
This method return a ViewReference for a View .
27,609
public function getReferencesByParameters ( array $ parameters , $ transform = true , $ keepChildren = false , $ type = null ) { $ viewsReferences = [ ] ; $ refsId = $ this -> repository -> getAllBy ( $ parameters , $ type ) ; $ references = $ this -> repository -> getResults ( $ refsId ) ; foreach ( $ references as $ reference ) { if ( $ transform === true ) { $ transformViewReferenceFn = function ( $ parentViewReference ) use ( & $ transformViewReferenceFn , $ keepChildren ) { $ transformer = ViewReferenceManager :: findTransformerFromElement ( $ parentViewReference ) ; $ reference = $ transformer -> transform ( $ parentViewReference ) ; if ( $ keepChildren ) { foreach ( $ this -> repository -> getChildren ( $ parentViewReference [ 'id' ] ) as $ child ) { $ reference -> addChild ( $ transformViewReferenceFn ( $ this -> repository -> findById ( $ child ) ) ) ; } } return $ reference ; } ; $ reference = $ transformViewReferenceFn ( $ reference ) ; } $ viewsReferences [ ] = $ reference ; } return $ viewsReferences ; }
Get references matching with parameters .
27,610
public function getOneReferenceByParameters ( array $ parameters , $ transform = true , $ keepChildren = false ) { $ result = $ this -> getReferencesByParameters ( $ parameters , $ transform , $ keepChildren ) ; if ( count ( $ result ) ) { return $ result [ 0 ] ; } }
Get first reference matching with parameters .
27,611
public function switchModeAction ( $ mode ) { $ session = $ this -> get ( 'session' ) ; $ session -> set ( 'victoire.edit_mode' , $ mode ) ; return new JsonResponse ( [ 'response' => true ] ) ; }
Method used to change of edit mode .
27,612
protected function addHomepageRedirection ( & $ collection ) { $ route = new Route ( '/' , [ '_controller' => 'FrameworkBundle:Redirect:urlRedirect' , 'path' => '/' . $ this -> localeResolver -> defaultLocale , 'permanent' => true , ] ) ; $ collection -> add ( 'victoire_redirect_homepage' , $ route ) ; }
Add a homepage redirection route to the collection .
27,613
protected function render ( $ template , $ parameters ) { $ twig = $ this -> templating ; $ twig -> setLoader ( new \ Twig_Loader_Filesystem ( $ this -> skeletonDirs ) ) ; return $ twig -> render ( $ template , $ parameters ) ; }
write WidgetBundle files .
27,614
public function getWidgets ( ) { if ( $ this -> widgets === null || ! array_key_exists ( 'value' , $ this -> widgets ) ) { return ; } if ( count ( $ this -> widgets [ 'value' ] ) > 1 ) { return $ this -> widgets [ 'value' ] ; } else { return [ $ this -> widgets [ 'value' ] ] ; } }
Get widgets associated to this businessEntity .
27,615
public function initBottomLeftNavbar ( ) { $ this -> bottomLeftNavbar = $ this -> factory -> createItem ( 'root' , [ 'childrenAttributes' => [ 'id' => 'v-footer-navbar-bottom-left' , ] , ] ) ; $ this -> createDropdownMenuItem ( $ this -> getBottomLeftNavbar ( ) , 'menu.additionals' , [ 'dropdown' => true , 'childrenAttributes' => [ 'class' => 'v-drop v-drop__menu' , 'id' => 'footer-drop-navbar-left' , ] , 'attributes' => [ 'class' => 'vic-dropdown' , 'data-toggle' => 'vic-dropdown' , ] , 'linkAttributes' => [ 'id' => 'v-additionals-drop' , 'class' => 'v-btn v-btn--transparent v-drop-trigger--no-toggle' , 'data-flag' => 'v-drop' , 'data-position' => 'topout leftin' , 'data-droptarget' => '#footer-drop-navbar-left' , ] , 'uri' => '#' , ] , false ) ; return $ this -> bottomLeftNavbar ; }
create bottom left menu defined in the contructor .
27,616
public function createDropdownMenuItem ( ItemInterface $ rootItem , $ title , $ attributes = [ ] , $ caret = true ) { $ options = array_merge ( [ 'dropdown' => true , 'childrenAttributes' => [ 'class' => 'vic-dropdown-menu' , ] , 'attributes' => [ 'class' => 'vic-dropdown' , 'data-toggle' => 'vic-dropdown' , ] , 'linkAttributes' => [ 'class' => 'vic-dropdown-toggle' , 'data-toggle' => 'vic-dropdown' , ] , 'uri' => '#' , ] , $ attributes ) ; $ menu = $ rootItem -> addChild ( $ title , $ options ) -> setExtra ( 'caret' , $ caret ) ; return $ menu ; }
Create the dropdown menu .
27,617
public function getPublishedAt ( ) { if ( $ this -> status == PageStatus :: PUBLISHED && $ this -> publishedAt === null ) { $ this -> setPublishedAt ( $ this -> getCreatedAt ( ) ) ; } return $ this -> publishedAt ; }
Get the published at property .
27,618
public function getCategoryTitle ( ) { $ this -> categoryTitle = $ this -> category ? $ this -> category -> getTitle ( ) : null ; return $ this -> categoryTitle ; }
Get categoryTitle .
27,619
public function getPublishedAtString ( ) { setlocale ( LC_TIME , 'fr_FR' ) ; if ( $ this -> publishedAt ) { return $ this -> publishedAtString = strftime ( '%d %B %Y' , $ this -> publishedAt -> getTimestamp ( ) ) ; } else { return '' ; } }
Get publishedAtString .
27,620
public function setAction ( $ action ) { if ( $ action !== self :: ACTION_CREATE && $ action !== self :: ACTION_OVERWRITE && $ action !== self :: ACTION_DELETE ) { throw new \ Exception ( 'The action of the widget map is not valid. Action: [' . $ action . ']' ) ; } $ this -> action = $ action ; }
Set the action .
27,621
public function getSubstituteForView ( View $ view ) { foreach ( $ this -> getContextualSubstitutes ( ) as $ substitute ) { if ( $ substitute -> getView ( ) === $ view ) { return $ substitute ; } while ( $ template = $ view -> getTemplate ( ) ) { if ( $ substitute -> getView ( ) === $ template ) { return $ substitute ; } } } }
Return substitute if used in View or in one of its inherited Template .
27,622
public function postLoad ( LifecycleEventArgs $ eventArgs ) { $ entity = $ eventArgs -> getEntity ( ) ; if ( $ entity instanceof View ) { $ entity -> setReferences ( [ $ entity -> getCurrentLocale ( ) => new ViewReference ( $ entity -> getId ( ) ) ] ) ; $ viewReferences = $ this -> viewReferenceRepository -> getReferencesByParameters ( [ 'viewId' => $ entity -> getId ( ) , 'templateId' => $ entity -> getId ( ) , ] , true , false , 'OR' ) ; foreach ( $ viewReferences as $ viewReference ) { if ( $ viewReference -> getLocale ( ) === $ entity -> getCurrentLocale ( ) ) { if ( $ entity instanceof WebViewInterface && $ viewReference instanceof ViewReference ) { $ entity -> setReference ( $ viewReference , $ viewReference -> getLocale ( ) ) ; $ entity -> setUrl ( $ viewReference -> getUrl ( ) ) ; } elseif ( $ entity instanceof BusinessTemplate ) { $ entity -> setReferences ( [ $ entity -> getCurrentLocale ( ) => $ this -> viewReferenceBuilder -> buildViewReference ( $ entity , $ eventArgs -> getEntityManager ( ) ) , ] ) ; } } } } }
If entity is a View it will find the ViewReference related to the current view and populate its url .
27,623
public function getHandler ( $ media ) { foreach ( $ this -> handlers as $ handler ) { if ( $ handler -> canHandle ( $ media ) ) { return $ handler ; } } return new FileHandler ( ) ; }
Returns handler to handle the Media item which can handle the item . If no handler is found it returns FileHandler .
27,624
public function getHandlerForType ( $ type ) { foreach ( $ this -> handlers as $ handler ) { if ( $ handler -> getType ( ) == $ type ) { return $ handler ; } } return new FileHandler ( ) ; }
Returns handler to handle the Media item based on the Type . If no handler is found it returns FileHandler .
27,625
public function addTransformer ( DataTransformerInterface $ transformer , $ viewNamespace , $ outputFormat ) { if ( ! array_key_exists ( $ viewNamespace , $ this -> viewsReferenceTransformers ) ) { $ this -> viewsReferenceTransformers [ $ viewNamespace ] = [ ] ; } if ( ! array_key_exists ( $ outputFormat , $ this -> viewsReferenceTransformers [ $ viewNamespace ] ) ) { $ this -> viewsReferenceTransformers [ $ viewNamespace ] [ $ outputFormat ] = null ; } $ this -> viewsReferenceTransformers [ $ viewNamespace ] [ $ outputFormat ] = $ transformer ; }
add a view Manager .
27,626
public function insert ( Widget $ widget , View $ view , $ slotId , $ position , $ widgetReference ) { $ quantum = $ this -> em -> getRepository ( 'VictoireWidgetMapBundle:WidgetMap' ) -> findOneBy ( [ 'view' => $ view , 'slot' => $ slotId , 'position' => $ position , 'parent' => $ widgetReference , 'action' => [ WidgetMap :: ACTION_CREATE , WidgetMap :: ACTION_OVERWRITE , ] , ] ) ; if ( $ quantum ) { $ widget -> setWidgetMap ( $ quantum ) ; $ view -> addWidgetMap ( $ quantum ) ; } else { $ parent = null ; if ( $ widgetReference ) { $ parent = $ this -> em -> getRepository ( 'VictoireWidgetMapBundle:WidgetMap' ) -> find ( $ widgetReference ) ; } $ widgetMapEntry = new WidgetMap ( ) ; $ widgetMapEntry -> setAction ( WidgetMap :: ACTION_CREATE ) ; $ widgetMapEntry -> setSlot ( $ slotId ) ; $ widgetMapEntry -> setPosition ( $ position ) ; $ widgetMapEntry -> setParent ( $ parent ) ; $ widget -> setWidgetMap ( $ widgetMapEntry ) ; $ view -> addWidgetMap ( $ widgetMapEntry ) ; } }
Insert a WidgetMap in a view at given position .
27,627
public function move ( View $ view , $ sortedWidget ) { $ parentWidgetMap = $ this -> em -> getRepository ( 'VictoireWidgetMapBundle:WidgetMap' ) -> find ( ( int ) $ sortedWidget [ 'parentWidgetMap' ] ) ; $ position = $ sortedWidget [ 'position' ] ; $ slot = $ sortedWidget [ 'slot' ] ; $ widgetMap = $ this -> em -> getRepository ( 'VictoireWidgetMapBundle:WidgetMap' ) -> find ( ( int ) $ sortedWidget [ 'widgetMap' ] ) ; $ originalParent = $ widgetMap -> getParent ( ) ; $ originalPosition = $ widgetMap -> getPosition ( ) ; $ children = $ this -> resolver -> getChildren ( $ widgetMap , $ view ) ; $ beforeChild = ! empty ( $ children [ WidgetMap :: POSITION_BEFORE ] ) ? $ children [ WidgetMap :: POSITION_BEFORE ] : null ; $ afterChild = ! empty ( $ children [ WidgetMap :: POSITION_AFTER ] ) ? $ children [ WidgetMap :: POSITION_AFTER ] : null ; $ parentWidgetMapChildren = $ this -> getChildrenByView ( $ parentWidgetMap ) ; $ widgetMap = $ this -> moveWidgetMap ( $ view , $ widgetMap , $ parentWidgetMap , $ position , $ slot ) ; $ this -> moveChildren ( $ view , $ beforeChild , $ afterChild , $ originalParent , $ originalPosition ) ; foreach ( $ parentWidgetMapChildren [ 'views' ] as $ _view ) { if ( $ _view !== $ view ) { if ( isset ( $ parentWidgetMapChildren [ 'before' ] [ $ _view -> getId ( ) ] ) && $ parentWidgetMapChildren [ 'before' ] [ $ _view -> getId ( ) ] -> getPosition ( ) == $ widgetMap -> getPosition ( ) ) { $ parentWidgetMapChildren [ 'before' ] [ $ _view -> getId ( ) ] -> setParent ( $ widgetMap ) ; } if ( isset ( $ parentWidgetMapChildren [ 'after' ] [ $ _view -> getId ( ) ] ) && $ parentWidgetMapChildren [ 'after' ] [ $ _view -> getId ( ) ] -> getPosition ( ) == $ widgetMap -> getPosition ( ) ) { $ parentWidgetMapChildren [ 'after' ] [ $ _view -> getId ( ) ] -> setParent ( $ widgetMap ) ; } } } }
moves a widget in a view .
27,628
public function delete ( View $ view , Widget $ widget ) { $ this -> builder -> build ( $ view ) ; $ widgetMap = $ widget -> getWidgetMap ( ) ; $ slot = $ widgetMap -> getSlot ( ) ; $ originalParent = $ widgetMap -> getParent ( ) ; $ originalPosition = $ widgetMap -> getPosition ( ) ; $ children = $ this -> resolver -> getChildren ( $ widgetMap , $ view ) ; $ beforeChild = ! empty ( $ children [ WidgetMap :: POSITION_BEFORE ] ) ? $ children [ WidgetMap :: POSITION_BEFORE ] : null ; $ afterChild = ! empty ( $ children [ WidgetMap :: POSITION_AFTER ] ) ? $ children [ WidgetMap :: POSITION_AFTER ] : null ; if ( $ widgetMap -> getView ( ) === $ view ) { if ( count ( $ widgetMap -> getAllSubstitutes ( ) ) > 0 ) { foreach ( $ widgetMap -> getAllSubstitutes ( ) as $ substitute ) { if ( $ substitute -> getAction ( ) === WidgetMap :: ACTION_OVERWRITE ) { $ substitute -> setAction ( WidgetMap :: ACTION_CREATE ) ; $ substitute -> setReplaced ( null ) ; } else { $ view -> removeWidgetMap ( $ widgetMap ) ; } } } $ view -> removeWidgetMap ( $ widgetMap ) ; } else { $ replaceWidgetMap = new WidgetMap ( ) ; $ replaceWidgetMap -> setAction ( WidgetMap :: ACTION_DELETE ) ; $ replaceWidgetMap -> addWidget ( $ widget ) ; $ replaceWidgetMap -> setSlot ( $ slot ) ; $ replaceWidgetMap -> setReplaced ( $ widgetMap ) ; $ view -> addWidgetMap ( $ replaceWidgetMap ) ; } $ this -> moveChildren ( $ view , $ beforeChild , $ afterChild , $ originalParent , $ originalPosition ) ; foreach ( $ widgetMap -> getChildren ( ) as $ child ) { if ( $ child -> getView ( ) === $ view || $ child -> getView ( ) -> getTemplate ( ) === $ view ) { $ this -> moveWidgetMap ( $ child -> getView ( ) , $ child , $ originalParent , $ originalPosition ) ; } } }
Delete the widget from the view .
27,629
public function moveChildren ( View $ view , $ beforeChild , $ afterChild , $ originalParent , $ originalPosition ) { if ( $ beforeChild && $ afterChild ) { $ this -> moveWidgetMap ( $ view , $ beforeChild , $ originalParent , $ originalPosition ) ; $ child = $ beforeChild ; while ( $ child -> getChild ( WidgetMap :: POSITION_AFTER ) ) { $ child = $ child -> getChild ( WidgetMap :: POSITION_AFTER ) ; } if ( $ afterChild -> getId ( ) !== $ child -> getId ( ) ) { $ this -> moveWidgetMap ( $ view , $ afterChild , $ child ) ; } } elseif ( $ beforeChild ) { $ this -> moveWidgetMap ( $ view , $ beforeChild , $ originalParent , $ originalPosition ) ; } elseif ( $ afterChild ) { $ this -> moveWidgetMap ( $ view , $ afterChild , $ originalParent , $ originalPosition ) ; } }
If the moved widgetMap has someone at both his before and after arbitrary move UP the before side and find the first place after the before widgetMap hierarchy to place the after widgetMap .
27,630
protected function cloneWidgetMap ( WidgetMap $ widgetMap , View $ view ) { $ originalWidgetMap = $ widgetMap ; $ widgetMap = clone $ widgetMap ; $ widgetMap -> setId ( null ) ; $ widgetMap -> setAction ( WidgetMap :: ACTION_OVERWRITE ) ; $ widgetMap -> setReplaced ( $ originalWidgetMap ) ; $ widgetMap -> setView ( $ view ) ; $ view -> addWidgetMap ( $ widgetMap ) ; $ this -> em -> persist ( $ widgetMap ) ; return $ widgetMap ; }
Create a copy of a WidgetMap in overwrite mode and insert it in the given view .
27,631
protected function moveWidgetMap ( View $ view , WidgetMap $ widgetMap , $ parent = false , $ position = false , $ slot = false ) { if ( $ widgetMap -> getView ( ) !== $ view ) { $ widgetMap = $ this -> cloneWidgetMap ( $ widgetMap , $ view ) ; } if ( $ parent !== false ) { if ( $ oldParent = $ widgetMap -> getParent ( ) ) { $ oldParent -> removeChild ( $ widgetMap ) ; } $ widgetMap -> setParent ( $ parent ) ; if ( $ parent ) { $ parent -> addChild ( $ widgetMap ) ; } } if ( $ position !== false ) { $ widgetMap -> setPosition ( $ position ) ; } if ( $ slot !== false ) { $ widgetMap -> setSlot ( $ slot ) ; } return $ widgetMap ; }
Move given WidgetMap as a child of given parent at given position and slot .
27,632
protected function getChildrenByView ( WidgetMap $ widgetMap ) { $ beforeChilds = $ widgetMap -> getContextualChildren ( WidgetMap :: POSITION_BEFORE ) ; $ afterChilds = $ widgetMap -> getContextualChildren ( WidgetMap :: POSITION_AFTER ) ; $ childrenByView [ 'views' ] = [ ] ; $ childrenByView [ 'before' ] = [ ] ; $ childrenByView [ 'after' ] = [ ] ; foreach ( $ beforeChilds as $ beforeChild ) { $ view = $ beforeChild -> getView ( ) ; $ childrenByView [ 'views' ] [ ] = $ view ; $ childrenByView [ 'before' ] [ $ view -> getId ( ) ] = $ beforeChild ; } foreach ( $ afterChilds as $ afterChild ) { $ view = $ afterChild -> getView ( ) ; $ childrenByView [ 'views' ] [ ] = $ view ; $ childrenByView [ 'after' ] [ $ view -> getId ( ) ] = $ afterChild ; } return $ childrenByView ; }
Find return all the given WidgetMap children for each view where it s related .
27,633
public function showAction ( Request $ request , Widget $ widget , $ viewReferenceId ) { try { $ view = $ this -> get ( 'victoire_page.page_helper' ) -> findPageByParameters ( [ 'id' => $ viewReferenceId ] ) ; $ this -> get ( 'victoire_widget_map.builder' ) -> build ( $ view ) ; $ this -> get ( 'victoire_core.current_view' ) -> setCurrentView ( $ view ) ; $ response = new JsonResponse ( [ 'html' => $ this -> get ( 'victoire_widget.widget_renderer' ) -> render ( $ widget , $ view ) , 'update' => 'vic-widget-' . $ widget -> getId ( ) . '-container' , 'success' => true , ] ) ; } catch ( Exception $ ex ) { $ response = $ this -> getJsonReponseFromException ( $ ex ) ; } return $ response ; }
Show a widget .
27,634
public function apiWidgetsAction ( $ widgetIds , $ viewReferenceId ) { $ view = $ this -> get ( 'victoire_page.page_helper' ) -> findPageByParameters ( [ 'id' => $ viewReferenceId ] ) ; $ response = [ ] ; $ widgets = $ this -> get ( 'doctrine.orm.entity_manager' ) -> getRepository ( 'VictoireWidgetBundle:Widget' ) -> findBy ( [ 'id' => json_decode ( $ widgetIds ) ] ) ; foreach ( $ widgets as $ widget ) { $ response [ $ widget -> getId ( ) ] = $ this -> get ( 'victoire_widget.widget_renderer' ) -> render ( $ widget , $ view ) ; } return new JsonResponse ( $ response ) ; }
API widgets function .
27,635
public function newAction ( Request $ request , $ type , $ viewReference , $ slot = null , $ quantum = 'a' ) { try { $ view = $ this -> getViewByReferenceId ( $ viewReference ) ; if ( ! $ reference = $ this -> get ( 'victoire_view_reference.repository' ) -> getOneReferenceByParameters ( [ 'id' => $ viewReference ] ) ) { $ reference = new ViewReference ( $ viewReference ) ; } $ view -> setReference ( $ reference ) ; $ position = $ request -> query -> has ( 'position' ) ? $ request -> query -> get ( 'position' ) : null ; $ parentWidgetMap = $ request -> query -> has ( 'parentWidgetMap' ) ? $ request -> query -> get ( 'parentWidgetMap' ) : null ; $ widgetData = $ this -> get ( 'victoire_widget.widget_manager' ) -> newWidget ( Widget :: MODE_STATIC , $ type , $ slot , $ view , $ position , $ parentWidgetMap , $ quantum ) ; $ response = new JsonResponse ( [ 'success' => true , 'html' => $ widgetData [ 'html' ] , ] ) ; } catch ( Exception $ ex ) { $ response = $ this -> getJsonReponseFromException ( $ ex ) ; } return $ response ; }
New Widget .
27,636
public function createAction ( $ mode , $ type , $ viewReference , $ slot = null , $ position = null , $ parentWidgetMap = null , $ businessEntityId = null , $ quantum = null ) { try { $ view = $ this -> getViewByReferenceId ( $ viewReference ) ; $ isNewPage = $ view -> getId ( ) === null ? true : false ; if ( ! $ reference = $ this -> get ( 'victoire_view_reference.repository' ) -> getOneReferenceByParameters ( [ 'id' => $ viewReference ] ) ) { $ reference = new ViewReference ( $ viewReference ) ; } $ view -> setReference ( $ reference ) ; $ this -> get ( 'victoire_core.current_view' ) -> setCurrentView ( $ view ) ; $ this -> congrat ( $ this -> get ( 'translator' ) -> trans ( 'victoire.success.message' , [ ] , 'victoire' ) ) ; $ response = $ this -> get ( 'widget_manager' ) -> createWidget ( $ mode , $ type , $ slot , $ view , $ businessEntityId , $ position , $ parentWidgetMap , $ quantum ) ; if ( $ isNewPage ) { $ response = new JsonResponse ( [ 'success' => true , 'redirect' => $ this -> generateUrl ( 'victoire_core_page_show' , [ 'url' => $ reference -> getUrl ( ) , ] ) , ] ) ; } else { $ response = new JsonResponse ( $ response ) ; } } catch ( Exception $ ex ) { $ response = $ this -> getJsonReponseFromException ( $ ex ) ; } return $ response ; }
Create a widget . This action needs 2 routes to handle the presence or not of businessEntityId and parentWidgetMap that are both integers but businessEntityId present only in !static mode .
27,637
public function stylizeAction ( Request $ request , Widget $ widget , $ viewReference , $ quantum = null ) { $ view = $ this -> getViewByReferenceId ( $ viewReference ) ; $ this -> get ( 'victoire_widget_map.builder' ) -> build ( $ view ) ; try { $ widgetView = $ widget -> getWidgetMap ( ) -> getView ( ) ; } catch ( WidgetMapNotFoundException $ e ) { return new JsonResponse ( [ 'success' => false , 'message' => $ e -> getMessage ( ) , ] ) ; } if ( ! $ view instanceof \ Victoire \ Bundle \ TemplateBundle \ Entity \ Template ) { $ widgetViewReference = $ this -> get ( 'victoire_view_reference.repository' ) -> getOneReferenceByParameters ( [ 'viewId' => $ view -> getId ( ) ] ) ; $ widgetView -> setReference ( $ widgetViewReference ) ; } $ this -> get ( 'victoire_core.current_view' ) -> setCurrentView ( $ view ) ; try { $ response = $ this -> get ( 'widget_manager' ) -> editWidgetStyle ( $ request , $ widget , $ view , $ viewReference , $ quantum ) ; $ this -> congrat ( $ this -> get ( 'translator' ) -> trans ( 'victoire.success.message' , [ ] , 'victoire' ) ) ; } catch ( Exception $ ex ) { $ response = $ this -> getJsonReponseFromException ( $ ex ) ; } return $ response ; }
Stylize a widget .
27,638
public function deleteAction ( Widget $ widget , $ viewReference ) { $ view = $ this -> getViewByReferenceId ( $ viewReference ) ; try { $ widgetId = $ widget -> getId ( ) ; $ this -> get ( 'widget_manager' ) -> deleteWidget ( $ widget , $ view ) ; return new JsonResponse ( [ 'success' => true , 'message' => $ this -> get ( 'translator' ) -> trans ( 'victoire_widget.delete.success' , [ ] , 'victoire' ) , 'widgetId' => $ widgetId , ] ) ; } catch ( Exception $ ex ) { return $ this -> getJsonReponseFromException ( $ ex ) ; } }
Delete a Widget .
27,639
public function deleteBulkAction ( Widget $ widget , $ viewReference ) { $ view = $ this -> getViewByReferenceId ( $ viewReference ) ; try { $ widgets = $ widget -> getWidgetMap ( ) -> getWidgets ( ) ; foreach ( $ widgets as $ widget ) { $ this -> get ( 'widget_manager' ) -> deleteWidget ( $ widget , $ view ) ; } return new JsonResponse ( [ 'success' => true , 'message' => $ this -> get ( 'translator' ) -> trans ( 'victoire_widget.delete.success' , [ ] , 'victoire' ) , ] ) ; } catch ( Exception $ ex ) { return $ this -> getJsonReponseFromException ( $ ex ) ; } }
Delete a Widget quantum .
27,640
public function unlinkAction ( $ id , $ viewReference ) { $ view = $ this -> getViewByReferenceId ( $ viewReference ) ; try { $ this -> get ( 'victoire_widget.widget_helper' ) -> deleteById ( $ id ) ; $ this -> get ( 'doctrine.orm.entity_manager' ) -> flush ( ) ; if ( $ view instanceof Template ) { $ redirect = $ this -> generateUrl ( 'victoire_template_show' , [ 'id' => $ view -> getId ( ) ] ) ; } elseif ( $ view instanceof BusinessTemplate ) { $ redirect = $ this -> generateUrl ( 'victoire_business_template_show' , [ 'id' => $ view -> getId ( ) ] ) ; } else { $ viewReference = $ this -> get ( 'victoire_view_reference.repository' ) -> getOneReferenceByParameters ( [ 'viewId' => $ view -> getId ( ) ] ) ; $ redirect = $ this -> generateUrl ( 'victoire_core_page_show' , [ 'url' => $ viewReference -> getUrl ( ) , ] ) ; } return new JsonResponse ( [ 'success' => true , 'redirect' => $ redirect , ] ) ; } catch ( Exception $ ex ) { return $ this -> getJsonReponseFromException ( $ ex ) ; } }
Unlink a Widget by id - > used to unlink an invalid widget after a bad widget unplug .
27,641
protected function getJsonReponseFromException ( Exception $ ex ) { $ authorizationChecker = $ this -> get ( 'security.authorization_checker' ) ; $ logger = $ this -> get ( 'logger' ) ; $ isDebugAllowed = $ authorizationChecker -> isGranted ( 'ROLE_VICTOIRE_PAGE_DEBUG' ) ? true : $ this -> get ( 'kernel' ) -> isDebug ( ) ; $ logger -> error ( $ ex -> getMessage ( ) ) ; $ logger -> error ( $ ex -> getTraceAsString ( ) ) ; if ( $ isDebugAllowed ) { throw $ ex ; } else { $ translator = $ this -> get ( 'translator' ) ; $ message = $ translator -> trans ( 'error_occured' , [ ] , 'victoire' ) ; $ response = new JsonResponse ( [ 'success' => false , 'message' => $ message , ] ) ; } return $ response ; }
Get the json response by the exception and the current user .
27,642
public function isVicLinkActive ( Link $ link ) { return $ this -> request && ( $ this -> request -> getRequestUri ( ) == $ this -> victoireLinkUrl ( $ link -> getParameters ( ) , false ) ) ; }
Check if a given Link is active for current request .
27,643
protected function addAttr ( $ label , $ value , & $ attr ) { if ( ! isset ( $ attr [ $ label ] ) ) { $ attr [ $ label ] = '' ; } else { $ attr [ $ label ] .= ' ' ; } $ attr [ $ label ] .= $ value ; return $ this ; }
Add a given attribute to given attributes .
27,644
public function setBlog ( Blog $ blog ) { $ this -> blog = $ blog ; foreach ( $ this -> children as $ child ) { $ child -> setBlog ( $ blog ) ; } return $ this ; }
Set blog .
27,645
public function reverseTransform ( $ array ) { if ( is_array ( $ array ) && array_key_exists ( 0 , $ array ) ) { $ newIds = [ ] ; $ ids = explode ( ',' , $ array [ 0 ] ) ; $ repo = $ this -> em -> getRepository ( 'VictoireBlogBundle:Tag' ) ; $ objects = $ repo -> findById ( $ ids ) ; foreach ( $ objects as $ object ) { if ( false !== $ key = array_search ( $ object -> getId ( ) , $ ids ) ) { $ newIds [ ] = $ ids [ $ key ] ; unset ( $ ids [ $ key ] ) ; } } $ objectsArray = [ ] ; foreach ( $ ids as $ title ) { if ( $ title !== '' ) { $ object = new Tag ( ) ; $ object -> setTitle ( $ title ) ; $ this -> em -> persist ( $ object ) ; $ objectsArray [ ] = $ object ; } } $ this -> em -> flush ( ) ; foreach ( $ objectsArray as $ objectObj ) { $ newIds [ ] = $ objectObj -> getId ( ) ; } return $ newIds ; } return $ array ; }
String to Tags .
27,646
public function replaceAll ( $ className = null ) { $ out = '' ; if ( ! $ this -> initialized ) { $ out .= $ this -> init ( ) ; } $ _config = $ this -> configSettings ( ) ; $ js = $ this -> returnGlobalEvents ( ) ; if ( empty ( $ _config ) ) { if ( empty ( $ className ) ) { $ js .= 'CKEDITOR.replaceAll();' ; } else { $ js .= "CKEDITOR.replaceAll('" . $ className . "');" ; } } else { $ classDetection = '' ; $ js .= "CKEDITOR.replaceAll( function (textarea, config) {\n" ; if ( ! empty ( $ className ) ) { $ js .= " var classRegex = new RegExp('(?:^| )' + '" . $ className . "' + '(?:$| )');\n" ; $ js .= " if (!classRegex.test(textarea.className))\n" ; $ js .= " return false;\n" ; } $ js .= ' CKEDITOR.tools.extend(config, ' . $ this -> jsEncode ( $ _config ) . ', true);' ; $ js .= '} );' ; } $ out .= $ this -> script ( $ js ) ; if ( ! $ this -> returnOutput ) { echo $ out ; $ out = '' ; } return $ out ; }
Replace all &lt ; textarea&gt ; elements available in the document with editor instances .
27,647
private function ckeditorPath ( ) { if ( ! empty ( $ this -> basePath ) ) { return $ this -> basePath ; } if ( isset ( $ _SERVER [ 'SCRIPT_FILENAME' ] ) ) { $ realPath = dirname ( $ _SERVER [ 'SCRIPT_FILENAME' ] ) ; } else { $ realPath = realpath ( './' ) ; } $ selfPath = dirname ( $ _SERVER [ 'PHP_SELF' ] ) ; $ file = str_replace ( '\\' , '/' , __FILE__ ) ; if ( ! $ selfPath || ! $ realPath || ! $ file ) { return '/ckeditor/' ; } $ documentRoot = substr ( $ realPath , 0 , strlen ( $ realPath ) - strlen ( $ selfPath ) ) ; $ fileUrl = substr ( $ file , strlen ( $ documentRoot ) ) ; $ ckeditorUrl = str_replace ( 'ckeditor_php5.php' , '' , $ fileUrl ) ; return $ ckeditorUrl ; }
Return path to ckeditor . js .
27,648
private function jsEncode ( $ val ) { if ( is_null ( $ val ) ) { return 'null' ; } if ( is_bool ( $ val ) ) { return $ val ? 'true' : 'false' ; } if ( is_int ( $ val ) ) { return $ val ; } if ( is_float ( $ val ) ) { return str_replace ( ',' , '.' , $ val ) ; } if ( is_array ( $ val ) || is_object ( $ val ) ) { if ( is_array ( $ val ) && ( array_keys ( $ val ) === range ( 0 , count ( $ val ) - 1 ) ) ) { return '[' . implode ( ',' , array_map ( [ $ this , 'jsEncode' ] , $ val ) ) . ']' ; } $ temp = [ ] ; foreach ( $ val as $ k => $ v ) { $ temp [ ] = $ this -> jsEncode ( "{$k}" ) . ':' . $ this -> jsEncode ( $ v ) ; } return '{' . implode ( ',' , $ temp ) . '}' ; } if ( strpos ( $ val , '@@' ) === 0 ) { return substr ( $ val , 2 ) ; } if ( strtoupper ( substr ( $ val , 0 , 9 ) ) == 'CKEDITOR.' ) { return $ val ; } return '"' . str_replace ( [ '\\' , '/' , "\n" , "\t" , "\r" , "\x08" , "\x0c" , '"' ] , [ '\\\\' , '\\/' , '\\n' , '\\t' , '\\r' , '\\b' , '\\f' , '\"' ] , $ val ) . '"' ; }
This little function provides a basic JSON support .
27,649
public function getAllAvailableRoles ( $ roleHierarchy ) { $ roles = [ ] ; foreach ( $ roleHierarchy as $ key => $ value ) { if ( is_array ( $ value ) ) { $ roles = array_merge ( $ roles , $ this -> getAllAvailableRoles ( $ value ) ) ; } if ( is_string ( $ key ) ) { $ roles [ ] = $ key ; } if ( is_string ( $ value ) ) { $ roles [ ] = $ value ; } } return $ roles ; }
flatten the array of all roles defined in role_hierarchy .
27,650
public function getWebViewChildren ( $ excludeUnpublished = false ) { $ webViewChildren = [ ] ; foreach ( $ this -> children as $ child ) { if ( ! $ child instanceof BusinessTemplate ) { $ notPublished = $ child -> getStatus ( ) != PageStatus :: PUBLISHED ; $ scheduledDateNotReached = $ child -> getStatus ( ) == PageStatus :: SCHEDULED && $ child -> getPublishedAt ( ) > new \ DateTime ( ) ; if ( $ excludeUnpublished && ( $ notPublished || $ scheduledDateNotReached ) ) { continue ; } $ webViewChildren [ ] = $ child ; } } return $ webViewChildren ; }
Get WebView children . Exclude unpublished or not published yet if asked .
27,651
public function saveBusinessEntity ( BusinessEntity $ businessEntity ) { $ businessEntities = $ this -> cache -> get ( BusinessEntity :: CACHE_CLASSES ) ; $ businessEntities [ $ businessEntity -> getClass ( ) ] = $ businessEntity ; $ this -> cache -> save ( BusinessEntity :: CACHE_CLASSES , $ businessEntities ) ; }
save BusinessEntity .
27,652
public function saveWidgetReceiverProperties ( $ widgetName , $ receiverProperties ) { $ widgets = $ this -> cache -> get ( BusinessEntity :: CACHE_WIDGETS , [ ] ) ; if ( ! array_key_exists ( $ widgetName , $ widgets ) ) { $ widgets [ $ widgetName ] = [ ] ; } $ widgets [ $ widgetName ] [ 'receiverProperties' ] = $ receiverProperties ; $ this -> cache -> save ( BusinessEntity :: CACHE_WIDGETS , $ widgets ) ; }
save Widget .
27,653
public function addWidgetBusinessEntity ( $ widgetName , $ businessEntity ) { $ widgets = $ this -> cache -> get ( BusinessEntity :: CACHE_WIDGETS , [ ] ) ; if ( ! array_key_exists ( $ widgetName , $ widgets ) ) { $ widgets [ $ widgetName ] = [ 'businessEntities' => [ ] ] ; } $ widgets [ $ widgetName ] [ 'businessEntities' ] [ $ businessEntity -> getId ( ) ] = $ businessEntity ; $ this -> cache -> save ( BusinessEntity :: CACHE_WIDGETS , $ widgets ) ; }
add a BusinessEntity For Widget .
27,654
public function resolve ( Request $ request ) { switch ( $ this -> localePattern ) { case self :: PATTERN_DOMAIN : $ locale = $ this -> resolveFromDomain ( $ request ) ; $ request -> setLocale ( $ locale ) ; break ; } return $ request -> getLocale ( ) ; }
set the local depending on patterns it also set the victoire_locale wich is the locale of the application admin .
27,655
protected function createWidgetGenerator ( ) { $ generator = new WidgetGenerator ( $ this -> getContainer ( ) -> get ( 'filesystem' ) ) ; $ generator -> setTemplating ( $ this -> getContainer ( ) -> get ( 'twig' ) ) ; return $ generator ; }
Instanciate a new WidgetGenerator .
27,656
private function parseFields ( $ input ) { if ( is_array ( $ input ) ) { return $ input ; } $ fields = [ ] ; foreach ( explode ( ' ' , $ input ) as $ value ) { $ elements = explode ( ':' , $ value ) ; $ name = $ elements [ 0 ] ; if ( strlen ( $ name ) ) { $ type = isset ( $ elements [ 1 ] ) ? $ elements [ 1 ] : 'string' ; preg_match_all ( '/(.*)\((.*)\)/' , $ type , $ matches ) ; $ type = isset ( $ matches [ 1 ] [ 0 ] ) ? $ matches [ 1 ] [ 0 ] : $ type ; $ length = isset ( $ matches [ 2 ] [ 0 ] ) ? $ matches [ 2 ] [ 0 ] : null ; $ fields [ $ name ] = [ 'fieldName' => $ name , 'type' => $ type , 'length' => $ length ] ; } } return $ fields ; }
transform console s output string fields into an array of fields .
27,657
public function boot ( ) { $ driverChain = $ this -> container -> get ( 'doctrine.orm.entity_manager' ) -> getConfiguration ( ) -> getMetadataDriverImpl ( ) ; $ proxyDriver = $ this -> container -> get ( 'victoire_core.entity_proxy.cache_driver' ) ; $ driverChain -> addDriver ( $ proxyDriver , 'Victoire' ) ; }
Boot the bundle .
27,658
public function showAction ( Request $ request , FlattenException $ exception , DebugLoggerInterface $ logger = null , $ _format = 'html' ) { $ currentContent = $ this -> getAndCleanOutputBuffering ( $ request -> headers -> get ( 'X-Php-Ob-Level' , - 1 ) ) ; $ code = $ exception -> getStatusCode ( ) ; $ uriArray = explode ( '/' , rtrim ( $ request -> getRequestUri ( ) , '/' ) ) ; $ matches = preg_match ( '/^.*(\..*)$/' , array_pop ( $ uriArray ) , $ matches ) ; $ locale = $ request -> getLocale ( ) ; if ( ! in_array ( $ locale , $ this -> availableLocales , true ) ) { $ request -> setLocale ( $ this -> defaultLocale ) ; } if ( $ this -> debug === false && 0 === $ matches ) { $ page = $ this -> em -> getRepository ( 'VictoireTwigBundle:ErrorPage' ) -> findOneByCode ( $ code ) ; if ( $ page ) { return $ this -> forward ( 'VictoireTwigBundle:ErrorPage:show' , [ 'code' => $ page -> getCode ( ) , ] ) ; } } return new Response ( $ this -> twig -> render ( $ this -> findTemplate ( $ request , $ _format , $ code , $ this -> debug ) , [ 'status_code' => $ code , 'status_text' => isset ( Response :: $ statusTexts [ $ code ] ) ? Response :: $ statusTexts [ $ code ] : '' , 'exception' => $ exception , 'logger' => $ logger , 'currentContent' => $ currentContent , ] ) ) ; }
Converts an Exception to a Response to be able to render a Victoire view .
27,659
protected function forward ( $ controller , array $ path = [ ] , array $ query = [ ] ) { $ path [ '_controller' ] = $ controller ; $ subRequest = $ this -> request -> duplicate ( $ query , null , $ path ) ; return $ this -> kernel -> handle ( $ subRequest , HttpKernelInterface :: SUB_REQUEST ) ; }
Forwards the request to another controller .
27,660
public function warm ( View $ viewToWarm , View $ contextualView = null ) { $ widgetMaps = [ ] ; if ( null === $ contextualView ) { $ contextualView = $ viewToWarm ; } foreach ( $ viewToWarm -> getWidgetMaps ( ) as $ _widgetMap ) { $ _widgetMap -> setContextualView ( $ contextualView ) ; $ widgetMaps [ ] = $ _widgetMap ; } if ( $ template = $ viewToWarm -> getTemplate ( ) ) { $ templateWidgetMaps = $ this -> warm ( $ template , $ contextualView ) ; $ widgetMaps = array_merge ( $ widgetMaps , $ templateWidgetMaps ) ; } return $ widgetMaps ; }
Give a contextual View to each WidgetMap used in a View and its Templates .
27,661
protected function execute ( InputInterface $ input , OutputInterface $ output ) { $ force = $ input -> getOption ( 'force' ) ; $ limit = $ input -> getOption ( 'limit' ) ; $ this -> entityManager = $ this -> getContainer ( ) -> get ( 'doctrine.orm.entity_manager' ) ; $ viewCssBuilder = $ this -> getContainer ( ) -> get ( 'victoire_core.view_css_builder' ) ; $ widgetMapBuilder = $ this -> getContainer ( ) -> get ( 'victoire_widget_map.builder' ) ; $ widgetRepo = $ this -> entityManager -> getRepository ( 'Victoire\Bundle\WidgetBundle\Entity\Widget' ) ; $ views = $ this -> getViewsToTreat ( ) ; foreach ( $ views as $ i => $ view ) { if ( ! $ force && $ view -> isCssUpToDate ( ) ) { unset ( $ views [ $ i ] ) ; } } $ limit = ( $ limit && $ limit < count ( $ views ) ) ? $ limit : count ( $ views ) ; $ count = 0 ; if ( count ( $ views ) < 1 ) { $ output -> writeln ( '<info>0 View\'s CSS to regenerate for your options</info>' ) ; return true ; } $ progress = new ProgressBar ( $ output , $ limit ) ; $ progress -> start ( ) ; foreach ( $ views as $ view ) { if ( $ count >= $ limit ) { break ; } if ( $ viewHash = $ view -> getCssHash ( ) ) { $ viewCssBuilder -> removeCssFile ( $ viewHash ) ; } $ view -> changeCssHash ( ) ; $ widgetMapBuilder -> build ( $ view , $ this -> entityManager ) ; $ widgets = $ widgetRepo -> findAllWidgetsForView ( $ view ) ; $ viewCssBuilder -> generateViewCss ( $ view , $ widgets ) ; $ view -> setCssUpToDate ( true ) ; $ this -> entityManager -> persist ( $ view ) ; $ this -> entityManager -> flush ( $ view ) ; $ progress -> advance ( ) ; $ count ++ ; } $ progress -> finish ( ) ; return true ; }
Generate a css file containing all css parameters for all widgets used in each view .
27,662
private function getViewsToTreat ( ) { $ templateRepo = $ this -> entityManager -> getRepository ( 'VictoireTemplateBundle:Template' ) ; $ rootTemplates = $ templateRepo -> getInstance ( ) -> where ( 'template.template IS NULL' ) -> getQuery ( ) -> getResult ( ) ; $ templates = [ ] ; $ recursiveGetTemplates = function ( $ template ) use ( & $ recursiveGetTemplates , & $ templates ) { array_push ( $ templates , $ template ) ; foreach ( $ template -> getInheritors ( ) as $ _template ) { if ( $ _template instanceof Template ) { $ recursiveGetTemplates ( $ _template ) ; } } } ; foreach ( $ rootTemplates as $ rootTemplate ) { $ recursiveGetTemplates ( $ rootTemplate ) ; } $ pageRepo = $ this -> entityManager -> getRepository ( 'VictoirePageBundle:BasePage' ) ; $ pages = $ pageRepo -> findAll ( ) ; $ errorRepo = $ this -> entityManager -> getRepository ( 'VictoireTwigBundle:ErrorPage' ) ; $ errorPages = $ errorRepo -> findAll ( ) ; return array_merge ( $ templates , array_merge ( $ pages , $ errorPages ) ) ; }
Get Templates BasePages and ErrorPages .
27,663
public function postFlush ( PostFlushEventArgs $ eventArgs ) { $ em = $ eventArgs -> getEntityManager ( ) ; foreach ( $ this -> flushedBusinessEntities as $ entity ) { $ businessEntity = $ this -> businessEntityHelper -> findByEntityInstance ( $ entity ) ; $ businessTemplates = $ em -> getRepository ( 'VictoireBusinessPageBundle:BusinessTemplate' ) -> findPagePatternByBusinessEntity ( $ businessEntity ) ; foreach ( $ businessTemplates as $ businessTemplate ) { foreach ( $ businessTemplate -> getTranslations ( ) as $ translation ) { $ businessTemplate -> setCurrentLocale ( $ translation -> getLocale ( ) ) ; if ( $ page = $ em -> getRepository ( 'Victoire\Bundle\BusinessPageBundle\Entity\BusinessPage' ) -> findPageByBusinessEntityAndPattern ( $ businessTemplate , $ entity , $ businessEntity ) ) { $ this -> businessPageBuilder -> updatePageParametersByEntity ( $ page , $ entity ) ; } else { $ page = $ this -> businessPageBuilder -> generateEntityPageFromTemplate ( $ businessTemplate , $ entity , $ em ) ; } if ( $ this -> businessPageHelper -> isEntityAllowed ( $ businessTemplate , $ entity , $ em ) ) { $ event = new ViewReferenceEvent ( $ page ) ; $ this -> dispatcher -> dispatch ( ViewReferenceEvents :: UPDATE_VIEW_REFERENCE , $ event ) ; } } } } foreach ( $ this -> flushedBusinessTemplates as $ entity ) { $ businessEntityId = $ entity -> getBusinessEntityId ( ) ; $ businessEntity = $ this -> businessEntityHelper -> findById ( $ businessEntityId ) ; $ entities = $ this -> businessPageHelper -> getEntitiesAllowed ( $ entity , $ em ) ; foreach ( $ entity -> getTranslations ( ) as $ translation ) { $ entity -> setCurrentLocale ( $ translation -> getLocale ( ) ) ; foreach ( $ entities as $ be ) { if ( $ this -> businessPageHelper -> isEntityAllowed ( $ entity , $ be , $ em ) ) { if ( $ page = $ em -> getRepository ( 'Victoire\Bundle\BusinessPageBundle\Entity\BusinessPage' ) -> findPageByBusinessEntityAndPattern ( $ entity , $ be , $ businessEntity ) ) { $ this -> businessPageBuilder -> updatePageParametersByEntity ( $ page , $ be ) ; } else { $ page = $ this -> businessPageBuilder -> generateEntityPageFromTemplate ( $ entity , $ be , $ em ) ; } $ event = new ViewReferenceEvent ( $ page ) ; $ this -> dispatcher -> dispatch ( ViewReferenceEvents :: UPDATE_VIEW_REFERENCE , $ event ) ; } } } } $ this -> flushedBusinessEntities -> clear ( ) ; $ this -> flushedBusinessTemplates -> clear ( ) ; }
Iterate over inserted BusinessEntities and BusinessTemplates catched by postPersist and dispatch event to generate the needed ViewReferences .
27,664
private function updateViewReference ( LifecycleEventArgs $ eventArgs ) { $ entity = $ eventArgs -> getEntity ( ) ; if ( in_array ( Translation :: class , class_uses ( $ entity ) ) && null !== $ entity -> getTranslatable ( ) ) { $ entity = $ entity -> getTranslatable ( ) ; } if ( $ businessEntity = $ this -> businessEntityHelper -> findByEntityInstance ( $ entity ) ) { $ this -> flushedBusinessEntities -> add ( $ entity ) ; } if ( $ entity instanceof BusinessTemplate ) { $ this -> flushedBusinessTemplates -> add ( $ entity ) ; } }
This method throw an event if needed for a view related to a businessEntity .
27,665
public function getWidgetStaticContent ( Widget $ widget ) { $ reflect = new \ ReflectionClass ( $ widget ) ; $ widgetProperties = $ reflect -> getProperties ( ) ; $ parameters = [ 'widget' => $ widget ] ; $ accessor = PropertyAccess :: createPropertyAccessor ( ) ; foreach ( $ widgetProperties as $ property ) { if ( ! $ property -> isStatic ( ) ) { $ value = $ accessor -> getValue ( $ widget , $ property -> getName ( ) ) ; $ parameters [ $ property -> getName ( ) ] = $ value ; } } return $ parameters ; }
Get the static content of the widget .
27,666
public function getWidgetBusinessEntityContent ( Widget $ widget ) { $ entity = $ widget -> getEntity ( ) ; $ parameters = $ this -> getWidgetStaticContent ( $ widget ) ; $ this -> populateParametersWithWidgetFields ( $ widget , $ entity , $ parameters ) ; return $ parameters ; }
Get the business entity content .
27,667
public function getWidgetQueryContent ( Widget $ widget ) { $ parameters = $ this -> getWidgetStaticContent ( $ widget ) ; $ entity = $ this -> getWidgetQueryBuilder ( $ widget ) -> setMaxResults ( 1 ) -> getQuery ( ) -> getOneOrNullResult ( ) ; $ fields = $ widget -> getFields ( ) ; $ this -> populateParametersWithWidgetFields ( $ widget , $ entity , $ parameters ) ; return $ parameters ; }
Get the content of the widget for the query mode .
27,668
public function getWidgetQueryBuilder ( Widget $ widget ) { $ itemsQueryBuilder = $ this -> queryHelper -> getQueryBuilder ( $ widget , $ this -> entityManager ) ; $ itemsQueryBuilder -> andWhere ( 'main_item.visibleOnFront = true' ) ; return $ this -> queryHelper -> buildWithSubQuery ( $ widget , $ itemsQueryBuilder , $ this -> entityManager ) ; }
Get the widget query result .
27,669
public function buildView ( FormView $ view , FormInterface $ form , array $ options ) { foreach ( $ view -> vars [ 'choices' ] as $ choice ) { $ dataNode = $ choice -> data ; $ level = $ this -> propertyAccessor -> getValue ( $ dataNode , 'lvl' ) ; $ choice -> label = str_repeat ( str_repeat ( '&#160;' , $ level ) , 4 ) . $ choice -> label ; } }
genere le formulaire .
27,670
public function clearAction ( Request $ request ) { if ( ! $ this -> getParameter ( 'kernel.debug' ) ) { throw new AccessDeniedException ( 'You should be in debug mode to access this feature' ) ; } $ this -> get ( 'victoire_widget.widget_cache' ) -> clear ( ) ; return $ this -> redirect ( $ request -> headers -> get ( 'referer' ) ) ; }
Clear the widgetcache .
27,671
public function newAction ( Request $ request , $ isHomepage = false ) { return new JsonResponse ( parent :: newAction ( $ request , $ isHomepage ) ) ; }
Display a form to create a new Page .
27,672
public function settingsAction ( Request $ request , BasePage $ page ) { return new JsonResponse ( parent :: settingsAction ( $ request , $ page ) ) ; }
Display a form to edit Page settings .
27,673
public function settingsPostAction ( Request $ request , BasePage $ page ) { return new JsonResponse ( parent :: settingsPostAction ( $ request , $ page ) ) ; }
Save Page settings .
27,674
public function warm ( EntityManager $ em , View $ view ) { $ this -> em = $ em ; $ widgetRepo = $ this -> em -> getRepository ( 'Victoire\Bundle\WidgetBundle\Entity\Widget' ) ; $ viewWidgets = $ widgetRepo -> findAllWidgetsForView ( $ view ) ; $ this -> injectWidgets ( $ view , $ viewWidgets ) ; $ this -> extractAssociatedEntities ( $ viewWidgets ) ; }
Find all Widgets for current View inject them in WidgetMap and warm associated entities .
27,675
private function injectWidgets ( View $ view , $ viewWidgets ) { $ builtWidgetMap = $ view -> getBuiltWidgetMap ( ) ; foreach ( $ builtWidgetMap as $ slot => $ widgetMaps ) { foreach ( $ widgetMaps as $ i => $ widgetMap ) { foreach ( $ viewWidgets as $ widget ) { if ( $ widget -> getWidgetMap ( ) == $ widgetMap ) { $ builtWidgetMap [ $ slot ] [ $ i ] -> addWidget ( $ widget ) ; $ builtWidgetMap [ $ slot ] [ $ i ] -> getWidgets ( ) -> setDirty ( false ) ; $ builtWidgetMap [ $ slot ] [ $ i ] -> getWidgets ( ) -> setInitialized ( true ) ; continue ; } } } } $ view -> setBuiltWidgetMap ( $ builtWidgetMap ) ; }
Inject Widgets in View s builtWidgetMap .
27,676
private function extractAssociatedEntities ( array $ entities ) { $ linkIds = $ associatedEntities = [ ] ; foreach ( $ entities as $ entity ) { $ reflect = new \ ReflectionClass ( $ entity ) ; $ widgetCached = ( $ entity instanceof Widget && $ this -> widgetHelper -> isCacheEnabled ( $ entity ) ) ; if ( ! $ widgetCached && $ this -> hasLinkTrait ( $ reflect ) && $ entity -> getLink ( ) ) { $ linkIds [ ] = $ entity -> getLink ( ) -> getId ( ) ; } $ metaData = $ this -> em -> getClassMetadata ( get_class ( $ entity ) ) ; foreach ( $ metaData -> getAssociationMappings ( ) as $ association ) { $ targetClass = $ association [ 'targetEntity' ] ; if ( $ targetClass == WidgetMap :: class ) { continue ; } if ( $ metaData -> isSingleValuedAssociation ( $ association [ 'fieldName' ] ) && ! $ widgetCached ) { if ( $ targetEntity = $ this -> accessor -> getValue ( $ entity , $ association [ 'fieldName' ] ) ) { $ associatedEntities [ $ targetClass ] [ 'id' ] [ 'unsorted' ] [ 'entitiesToWarm' ] [ ] = new AssociatedEntityToWarm ( AssociatedEntityToWarm :: TYPE_MANY_TO_ONE , $ entity , $ association [ 'fieldName' ] , $ targetEntity -> getId ( ) ) ; } } elseif ( $ metaData -> isCollectionValuedAssociation ( $ association [ 'fieldName' ] ) ) { if ( ! $ widgetCached || $ targetClass === Criteria :: class ) { if ( $ this -> accessor -> getValue ( $ entity , $ association [ 'fieldName' ] ) ) { $ getter = 'get' . ucwords ( $ association [ 'fieldName' ] ) ; $ entity -> $ getter ( ) -> setDirty ( false ) ; $ entity -> $ getter ( ) -> setInitialized ( true ) ; $ orderByToken = 'unsorted' ; if ( isset ( $ association [ 'orderBy' ] ) ) { $ orderByToken = implode ( $ association [ 'orderBy' ] ) ; $ associatedEntities [ $ targetClass ] [ $ association [ 'mappedBy' ] ] [ $ orderByToken ] [ 'orderBy' ] = $ association [ 'orderBy' ] ; } $ associatedEntities [ $ targetClass ] [ $ association [ 'mappedBy' ] ] [ $ orderByToken ] [ 'entitiesToWarm' ] [ ] = new AssociatedEntityToWarm ( AssociatedEntityToWarm :: TYPE_ONE_TO_MANY , $ entity , $ association [ 'fieldName' ] , $ entity -> getId ( ) ) ; } } } } } $ newEntities = $ this -> setAssociatedEntities ( $ associatedEntities ) ; $ this -> setPagesForLinks ( $ linkIds ) ; if ( $ newEntities ) { $ this -> extractAssociatedEntities ( $ newEntities ) ; } }
Pass through all widgets and associated entities to extract all missing associations store it by repository to group queries by entity type .
27,677
private function setAssociatedEntities ( array $ repositories ) { $ newEntities = [ ] ; foreach ( $ repositories as $ repositoryName => $ findMethods ) { foreach ( $ findMethods as $ findMethod => $ groupedBySortAssociatedEntitiesToWarm ) { foreach ( $ groupedBySortAssociatedEntitiesToWarm as $ orderByToken => $ groupedAssociatedEntitiesToWarm ) { $ associatedEntitiesToWarm = $ groupedAssociatedEntitiesToWarm [ 'entitiesToWarm' ] ; $ idsToSearch = array_map ( function ( $ associatedEntityToWarm ) { return $ associatedEntityToWarm -> getEntityId ( ) ; } , $ associatedEntitiesToWarm ) ; $ orderBy = [ ] ; if ( $ orderByToken !== 'unsorted' ) { foreach ( $ groupedAssociatedEntitiesToWarm [ 'orderBy' ] as $ orderAttribut => $ order ) { $ orderBy [ $ orderAttribut ] = $ order ; } } $ foundEntities = $ this -> em -> getRepository ( $ repositoryName ) -> findBy ( [ $ findMethod => array_values ( $ idsToSearch ) , ] , $ orderBy ) ; foreach ( $ associatedEntitiesToWarm as $ associatedEntityToWarm ) { foreach ( $ foundEntities as $ foundEntity ) { if ( $ associatedEntityToWarm -> getType ( ) === AssociatedEntityToWarm :: TYPE_MANY_TO_ONE && $ foundEntity -> getId ( ) === $ associatedEntityToWarm -> getEntityId ( ) ) { $ inheritorEntity = $ associatedEntityToWarm -> getInheritorEntity ( ) ; $ inheritorPropertyName = $ associatedEntityToWarm -> getInheritorPropertyName ( ) ; $ this -> accessor -> setValue ( $ inheritorEntity , $ inheritorPropertyName , $ foundEntity ) ; continue ; } elseif ( $ associatedEntityToWarm -> getType ( ) === AssociatedEntityToWarm :: TYPE_ONE_TO_MANY && $ this -> accessor -> getValue ( $ foundEntity , $ findMethod ) === $ associatedEntityToWarm -> getInheritorEntity ( ) ) { $ inheritorEntity = $ associatedEntityToWarm -> getInheritorEntity ( ) ; $ inheritorPropertyName = $ associatedEntityToWarm -> getInheritorPropertyName ( ) ; $ getter = 'get' . ucwords ( $ inheritorPropertyName ) ; $ inheritorEntity -> $ getter ( ) -> add ( $ foundEntity ) ; $ inheritorEntity -> $ getter ( ) -> setDirty ( false ) ; $ inheritorEntity -> $ getter ( ) -> setInitialized ( true ) ; $ newEntities [ ] = $ foundEntity ; continue ; } } } } } } return $ newEntities ; }
Set all missing associated entities .
27,678
private function setPagesForLinks ( array $ linkIds ) { $ viewReferences = [ ] ; $ links = $ this -> em -> getRepository ( 'VictoireCoreBundle:Link' ) -> findById ( $ linkIds ) ; foreach ( $ links as $ link ) { if ( $ link -> getParameters ( ) [ 'linkType' ] == 'viewReference' ) { $ viewReference = $ this -> viewReferenceRepository -> getOneReferenceByParameters ( [ 'id' => $ link -> getParameters ( ) [ 'viewReference' ] , 'locale' => $ link -> getParameters ( ) [ 'locale' ] , ] ) ; if ( $ viewReference instanceof ViewReference ) { $ viewReferences [ $ link -> getId ( ) ] = $ viewReference ; } } } $ pages = $ this -> em -> getRepository ( 'VictoireCoreBundle:View' ) -> findByViewReferences ( $ viewReferences ) ; foreach ( $ links as $ link ) { foreach ( $ pages as $ page ) { if ( ! ( $ page instanceof BusinessTemplate ) && $ page -> getReference ( ) && $ link -> getViewReference ( ) == $ page -> getReference ( ) -> getId ( ) ) { $ link -> setViewReferencePage ( $ page ) ; } } } }
Set viewReferencePage for each link .
27,679
private function hasLinkTrait ( \ ReflectionClass $ reflect ) { $ traits = $ reflect -> getTraits ( ) ; foreach ( $ traits as $ trait ) { if ( $ trait -> getName ( ) == LinkTrait :: class ) { return true ; } } if ( $ parentClass = $ reflect -> getParentClass ( ) ) { if ( $ this -> hasLinkTrait ( $ parentClass ) ) { return true ; } } return false ; }
Check if reflection class has LinkTrait .
27,680
public function findOneByCode ( $ code , $ deepMode = false ) { $ page = $ this -> createQueryBuilder ( $ this -> mainAlias ) -> where ( $ this -> mainAlias . '.code = :code' ) -> setParameter ( 'code' , $ code ) -> setMaxResults ( 1 ) -> getQuery ( ) -> getOneOrNullResult ( ) ; if ( ! $ page && $ deepMode ) { $ page = $ this -> findOneByCode ( floor ( $ code / 100 ) * 100 ) ; } return $ page ; }
Get a page according to the given code .
27,681
public function getBusinessEntity ( ) { if ( $ this -> businessEntity === null ) { if ( $ this -> getEntityProxy ( ) !== null ) { $ this -> businessEntity = $ this -> getEntityProxy ( ) -> getEntity ( $ this -> getBusinessEntityId ( ) ) ; return $ this -> businessEntity ; } } return $ this -> businessEntity ; }
Get the business entity .
27,682
public function cmsWidgetUnlinkAction ( $ widgetId , $ view ) { $ viewReference = $ this -> viewReferenceRepository -> getOneReferenceByParameters ( [ 'viewId' => $ view -> getId ( ) ] ) ; if ( ! $ viewReference && $ view -> getId ( ) != '' ) { $ viewReference = new ViewReference ( $ view -> getId ( ) ) ; } elseif ( $ view instanceof VirtualBusinessPage ) { $ viewReference = new ViewReference ( $ view -> getTemplate ( ) -> getId ( ) ) ; } $ view -> setReference ( $ viewReference ) ; return $ this -> widgetRenderer -> renderUnlinkActionByWidgetId ( $ widgetId , $ view ) ; }
render unlink action for a widgetId .
27,683
public function cmsSlotWidgets ( $ slotId , $ slotOptions = [ ] ) { $ currentView = $ this -> currentViewHelper -> getUpdatedCurrentView ( ) ; $ result = '' ; $ slotOptions = $ this -> widgetRenderer -> computeOptions ( $ slotId , $ slotOptions ) ; if ( $ currentView && ! empty ( $ currentView -> getBuiltWidgetMap ( ) [ $ slotId ] ) ) { foreach ( $ currentView -> getBuiltWidgetMap ( ) [ $ slotId ] as $ widgetMap ) { $ widget = null ; try { $ widget = $ this -> widgetResolver -> resolve ( $ widgetMap ) ; if ( $ widget ) { if ( ! $ widgetMap -> isAsynchronous ( ) ) { $ result .= $ this -> cmsWidget ( $ widget ) ; } else { $ result .= $ this -> widgetRenderer -> prepareAsynchronousRender ( $ widget ) ; } } } catch ( \ Exception $ ex ) { $ result .= $ this -> widgetExceptionHandler -> handle ( $ ex , $ currentView , $ widget ) ; } } } $ ngSlotControllerName = 'slot' . $ slotId . 'Controller' ; $ ngInitLoadActions = $ this -> isRoleVictoireGranted ( ) ? sprintf ( 'ng-init=\'%s.init("%s", %s)\'' , $ ngSlotControllerName , $ slotId , json_encode ( $ slotOptions ) ) : '' ; $ result = sprintf ( '<div class="vic-slot" data-name="%s" id="vic-slot-%s" ng-controller="SlotController as %s" %s>%s</div>' , $ slotId , $ slotId , $ ngSlotControllerName , $ ngInitLoadActions , $ result ) ; return $ result ; }
render all widgets in a slot .
27,684
public function cmsWidget ( $ widget ) { $ widget -> setCurrentView ( $ this -> currentViewHelper -> getCurrentView ( ) ) ; try { $ response = $ this -> widgetRenderer -> renderContainer ( $ widget , $ widget -> getCurrentView ( ) ) ; } catch ( \ Exception $ ex ) { $ response = $ this -> widgetExceptionHandler -> handle ( $ ex , $ widget ) ; } return $ response ; }
Render a widget .
27,685
public function hash ( $ value , $ algorithm = 'md5' ) { try { return hash ( $ algorithm , $ value ) ; } catch ( \ Exception $ e ) { error_log ( 'Please check that the ' . $ algorithm . ' does exists because it failed when trying to run. We are expecting a valid algorithm such as md5 or sha512 etc. [' . $ e -> getMessage ( ) . ']' ) ; return $ value ; } }
hash some string with given algorithm .
27,686
public function twigVicDateFormatFilter ( $ value , $ format = 'F j, Y H:i' , $ timezone = null ) { try { $ result = twig_date_format_filter ( $ this -> twig , $ value , $ format , $ timezone ) ; } catch ( \ Exception $ e ) { return $ value ; } return $ result ; }
Converts a date to the given format .
27,687
public function isBusinessEntityAllowed ( $ formEntityName , View $ view ) { $ isBusinessEntityAllowed = false ; if ( $ view instanceof BusinessTemplate || $ view instanceof BusinessPage ) { if ( $ formEntityName === $ view -> getBusinessEntityId ( ) ) { $ isBusinessEntityAllowed = true ; } } return $ isBusinessEntityAllowed ; }
Is the business entity type allowed for the widget and the view context .
27,688
public function setDisableForReceiverProperties ( $ receiverProperties = [ ] ) { foreach ( $ receiverProperties as $ receiverProperty => $ value ) { if ( ! array_key_exists ( $ receiverProperty , $ this -> businessProperties ) ) { $ this -> disable = true ; } } }
Set disable if BusinessEntity dont have all receiverProperties required .
27,689
public function addBusinessProperty ( BusinessProperty $ businessProperty ) { $ type = $ businessProperty -> getType ( ) ; if ( ! isset ( $ this -> businessProperties [ $ type ] ) ) { $ this -> businessProperties [ $ type ] = [ ] ; } $ this -> businessProperties [ $ type ] [ ] = $ businessProperty ; }
Add a business property .
27,690
public function getBusinessPropertiesByType ( $ type ) { $ bp = [ ] ; if ( isset ( $ this -> businessProperties [ $ type ] ) ) { $ bp = $ this -> businessProperties [ $ type ] ; } return $ bp ; }
Get the business properties by type .
27,691
public function getMetadataValue ( $ key ) { return isset ( $ this -> metadata [ $ key ] ) ? $ this -> metadata [ $ key ] : null ; }
Get the specified metadata value .
27,692
public function onRenderPage ( PageRenderEvent $ event ) { $ currentView = $ event -> getCurrentView ( ) ; if ( $ currentView instanceof VirtualBusinessPage ) { $ currentView -> setCssHash ( $ currentView -> getTemplate ( ) -> getCssHash ( ) ) ; } elseif ( ! $ currentView -> getCssHash ( ) || ! $ currentView -> isCssUpToDate ( ) ) { $ currentView -> changeCssHash ( ) ; $ this -> entityManager -> persist ( $ currentView ) ; $ this -> entityManager -> flush ( $ currentView ) ; } }
Generate cssHash and css file for current View if cssHash has not been set yet or is not up to date .
27,693
public function showAction ( ErrorPage $ page ) { $ this -> container -> get ( 'twig' ) -> addGlobal ( 'view' , $ page ) ; $ page -> setReference ( new ViewReference ( $ page -> getId ( ) ) ) ; $ parameters = [ 'view' => $ page , 'id' => $ page -> getId ( ) , 'locale' => $ page -> getCurrentLocale ( ) , ] ; $ this -> get ( 'victoire_widget_map.builder' ) -> build ( $ page ) ; $ this -> get ( 'victoire_widget_map.widget_data_warmer' ) -> warm ( $ this -> get ( 'doctrine.orm.entity_manager' ) , $ page ) ; $ this -> container -> get ( 'victoire_core.current_view' ) -> setCurrentView ( $ page ) ; $ response = $ this -> container -> get ( 'templating' ) -> renderResponse ( 'VictoireCoreBundle:Layout:' . $ page -> getTemplate ( ) -> getLayout ( ) . '.html.twig' , $ parameters ) ; return $ response ; }
Show an error page .
27,694
public function buildViewReference ( View $ view , EntityManager $ em = null ) { $ viewReferenceBuilder = $ this -> viewReferenceBuilderChain -> getViewReferenceBuilder ( $ view ) ; $ viewReference = $ viewReferenceBuilder -> buildReference ( $ view , $ em ) ; return $ viewReference ; }
compute the viewReference relative to a View + entity .
27,695
public function showAction ( Request $ request , $ url = '' ) { $ response = $ this -> get ( 'victoire_page.page_helper' ) -> renderPageByUrl ( $ request -> getUri ( ) , $ url , $ request -> getLocale ( ) , $ request -> isXmlHttpRequest ( ) ? $ request -> query -> get ( 'modalLayout' , null ) : null ) ; return $ response ; }
Find Page from url and render it . Route for this action is defined in RouteLoader .
27,696
public function showByIdAction ( Request $ request , $ viewId , $ entityId = null ) { $ parameters = [ 'viewId' => $ viewId , 'locale' => $ request -> getLocale ( ) , ] ; if ( $ entityId ) { $ parameters [ 'entityId' ] = $ entityId ; } $ page = $ this -> get ( 'victoire_page.page_helper' ) -> findPageByParameters ( $ parameters ) ; return $ this -> redirect ( $ this -> generateUrl ( 'victoire_core_page_show' , array_merge ( [ 'url' => $ page -> getReference ( ) -> getUrl ( ) ] , $ request -> query -> all ( ) ) ) ) ; }
Find url for a View id and optionally an Entity id and redirect to showAction . Route for this action is defined in RouteLoader .
27,697
public function showBusinessPageByIdAction ( Request $ request , $ entityId , $ type ) { $ businessEntityHelper = $ this -> get ( 'victoire_core.helper.queriable_business_entity_helper' ) ; $ businessEntity = $ businessEntityHelper -> findById ( $ type ) ; $ entity = $ businessEntityHelper -> getByBusinessEntityAndId ( $ businessEntity , $ entityId ) ; $ refClass = new \ ReflectionClass ( $ entity ) ; $ templateId = $ this -> get ( 'victoire_business_page.business_page_helper' ) -> guessBestPatternIdForEntity ( $ refClass , $ entityId , $ this -> container -> get ( 'doctrine.orm.entity_manager' ) ) ; $ page = $ this -> get ( 'victoire_page.page_helper' ) -> findPageByParameters ( [ 'viewId' => $ templateId , 'entityId' => $ entityId , 'locale' => $ request -> getLocale ( ) , ] ) ; return $ this -> redirect ( $ this -> generateUrl ( 'victoire_core_page_show' , [ 'url' => $ page -> getReference ( ) -> getUrl ( ) , ] ) ) ; }
Find BusinessPage url for an Entity id and type and redirect to showAction . Route for this action is defined in RouteLoader .
27,698
protected function newAction ( Request $ request , $ isHomepage = false ) { $ page = $ this -> getNewPage ( ) ; if ( $ page instanceof Page ) { $ page -> setHomepage ( $ isHomepage ? $ isHomepage : 0 ) ; } $ form = $ this -> get ( 'form.factory' ) -> create ( $ this -> getNewPageType ( ) , $ page ) ; return [ 'success' => true , 'html' => $ this -> get ( 'templating' ) -> render ( $ this -> getBaseTemplatePath ( ) . ':new.html.twig' , [ 'form' => $ form -> createView ( ) ] ) , ] ; }
Display a form to create a new Blog or Page . Route is defined in inherited controllers .
27,699
protected function newPostAction ( Request $ request ) { $ entityManager = $ this -> get ( 'doctrine.orm.entity_manager' ) ; $ page = $ this -> getNewPage ( ) ; $ form = $ this -> get ( 'form.factory' ) -> create ( $ this -> getNewPageType ( ) , $ page ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ page = $ this -> get ( 'victoire_page.page_helper' ) -> setPosition ( $ page ) ; $ page -> setAuthor ( $ this -> getUser ( ) ) ; $ entityManager -> persist ( $ page ) ; $ entityManager -> flush ( ) ; if ( null !== $ this -> get ( 'victoire_core.helper.business_entity_helper' ) -> findByEntityInstance ( $ page ) ) { $ page = $ this -> get ( 'victoire_business_page.business_page_builder' ) -> generateEntityPageFromTemplate ( $ page -> getTemplate ( ) , $ page , $ entityManager ) ; } $ this -> congrat ( $ this -> get ( 'translator' ) -> trans ( 'victoire_page.create.success' , [ ] , 'victoire' ) ) ; return $ this -> getViewReferenceRedirect ( $ request , $ page ) ; } return [ 'success' => false , 'message' => $ this -> get ( 'victoire_form.error_helper' ) -> getRecursiveReadableErrors ( $ form ) , 'html' => $ this -> get ( 'templating' ) -> render ( $ this -> getBaseTemplatePath ( ) . ':new.html.twig' , [ 'form' => $ form -> createView ( ) ] ) , ] ; }
Create a new Blog or Page . Route is defined in inherited controllers .