Esempio n. 1
0
 /**
  * undocumented function.
  *
  *
  * @param \Victoire\Bundle\CoreBundle\Entity\View $view
  *
  * @return void
  *
  * @author
  **/
 public function insertWidgetMapInSlot($slotId, WidgetMap $widgetMapEntry, $view)
 {
     //get the slot
     $slot = $view->getSlotById($slotId);
     //test that slot exists
     if ($slot === null) {
         $slot = new Slot();
         $slot->setId($slotId);
         $view->addSlot($slot);
     }
     $slot->addWidgetMap($widgetMapEntry);
     //update the widget map
     $view->updateWidgetMapBySlots();
 }
Esempio n. 2
0
 /**
  * create a widgetMap for the new Widget cloned
  *
  * @return void
  **/
 public function overwriteWidgetMap(Widget $widgetCopy, Widget $widget, View $view)
 {
     //the id of the new widget
     $widgetId = $widgetCopy->getId();
     //the widget slot
     $widgetSlotId = $widget->getSlot();
     //the widget id
     $replacedWidgetId = $widget->getId();
     //get the slot
     $slot = $view->getSlotById($widgetSlotId);
     //there might be no slot yet for the child view
     if ($slot === null) {
         //create a new slot
         $slot = new Slot();
         $slot->setId($widgetSlotId);
         //add the new slot to the view
         $view->addSlot($slot);
     }
     $originalWidgetMap = $slot->getWidgetMapByWidgetId($replacedWidgetId);
     //If widgetmap was not found current view, we dig
     if (!$originalWidgetMap) {
         $watchDog = 100;
         $_view = $view;
         while (!$originalWidgetMap && $watchDog) {
             $_view = $_view->getTemplate();
             $parentSlot = $_view->getSlotById($widgetSlotId);
             if ($parentSlot) {
                 $originalWidgetMap = $parentSlot->getWidgetMapByWidgetId($replacedWidgetId);
             }
             $watchDog--;
         }
         if (0 == $watchDog) {
             throw new \Exception(sprintf("The slot %s doesn't appears to be in any templates WidgetMaps. You should check this manually.", $widgetSlotId));
         }
     }
     //the widget is owned by another view (a parent)
     //so we add a new widget map that indicates we delete this widget
     $widgetMap = new WidgetMap();
     $widgetMap->setAction(WidgetMap::ACTION_OVERWRITE);
     $widgetMap->setReplacedWidgetId($replacedWidgetId);
     $widgetMap->setWidgetId($widgetId);
     $widgetMap->setPosition($originalWidgetMap->getPosition());
     $widgetMap->setAsynchronous($widgetCopy->isAsynchronous());
     $widgetMap->setPositionReference($originalWidgetMap->getPositionReference());
     $slot->addWidgetMap($widgetMap);
 }