Exemple #1
0
 protected function _compileExtendedSubItems($parent, $mainContainer)
 {
     if (!$this->_project->hasChilds($parent)) {
         return array();
     }
     $mainContainerObject = $this->_project->getItemData($mainContainer);
     $eventManager = $this->_project->getEventManager();
     $childs = $this->_project->getChilds($parent);
     $items = array();
     $docked = array();
     $menu = array();
     foreach ($childs as $k => $item) {
         if ($this->_project->hasChilds($item['id'])) {
             $this->_compileExtendedSubItems($item['id'], $mainContainer);
         }
         $itemName = 'me.childObjects.' . $item['id'];
         switch ($item['data']->getClass()) {
             case 'Docked':
                 if (!$this->_project->hasChilds($item['id'])) {
                     continue;
                 }
                 $docked[] = $item['data'];
                 break;
             case 'Menu':
                 if (!$this->_project->hasChilds($item['id'])) {
                     continue;
                 }
                 $menu[] = $item['data'];
                 break;
             default:
                 $items[] = $itemName;
                 break;
         }
         $objectEvents = $eventManager->getObjectEvents($item['id']);
         if (!empty($objectEvents)) {
             $eventsConfig = $item['data']->getConfig()->getEvents()->__toArray();
             foreach ($objectEvents as $event => $config) {
                 if (empty($config['code'])) {
                     continue;
                 }
                 $params = '';
                 if (isset($eventsConfig[$event])) {
                     $params = implode(',', array_keys($eventsConfig[$event]));
                 }
                 if ($event === 'handler') {
                     $item['data']->addListener($event, "function(" . $params . "){\n" . Utils_String::addIndent($config['code'], 2) . "\n}");
                     $item['data']->scope = 'this';
                 } else {
                     $item['data']->addListener($event, "{\n" . Utils_String::addIndent("fn:function(" . $params . "){\n" . Utils_String::addIndent($config['code'], 2) . "\n},\n" . Utils_String::addIndent("scope:this") . "\n}", 2) . "\n");
                 }
             }
         }
         $mainContainerObject->addElement($itemName, $item['data']);
         /**
          * Convert ActionColumn listeners
          */
         if ($item['data']->getClass() === 'Grid') {
             $this->_applycolumnEvents($item['data']);
             $this->_applyFiltersEvents($item['data']->getFiltersFeature());
         }
     }
     if ($parent !== '0') {
         $container = $this->_project->getItemData($parent);
         if (!empty($items)) {
             $container->items = "[\n" . Utils_String::addIndent(implode(",\n", $items), 1) . "\n]\n";
         }
         if (!empty($docked)) {
             $container->dockedItems = implode(',', $docked);
         }
         if (!empty($menu)) {
             $container->menu = implode(',', $menu);
         }
     }
 }