Example #1
0
 /**
  * This method build widgetmaps relativly to given view and it's templates.
  *
  * @param View          $view
  * @param EntityManager $em
  * @param bool          $updatePage
  *
  * @return array
  */
 public function build(View $view, EntityManager $em = null, $updatePage = true)
 {
     $widgetMaps = [];
     // populate a $widgetmaps array with widgetmaps of given view + widgetmaps of it's templates
     if ($view->getWidgetMaps()) {
         $widgetMaps = $view->getWidgetMaps()->toArray();
     }
     $template = clone $view;
     $builtWidgetMap = [];
     while (null !== ($template = $template->getTemplate())) {
         if ($template->getWidgetMaps()) {
             foreach ($template->getWidgetMaps()->toArray() as $item) {
                 $widgetMaps[] = $item;
             }
         }
     }
     $slots = $this->removeOverwritedWidgetMaps($widgetMaps);
     $this->removeDeletedWidgetMaps($slots);
     foreach ($slots as $slot => $widgetMaps) {
         $mainWidgetMap = null;
         $builtWidgetMap[$slot] = [];
         $rootWidgetMap = $this->findRootWidgetMap($widgetMaps);
         if ($rootWidgetMap) {
             $builtWidgetMap[$slot][] = $rootWidgetMap;
             $builtWidgetMap = $this->orderizeWidgetMap($rootWidgetMap, $builtWidgetMap, $slot, $widgetMaps, $view);
         }
     }
     if ($updatePage) {
         $view->setBuiltWidgetMap($builtWidgetMap);
     }
     return $builtWidgetMap;
 }