示例#1
0
 /**
  * Export blocks to XML structure
  *
  * @param  array              $location_ids
  * @param  array              $params
  * @param  string             $lang_code
  * @return ExSimpleXmlElement
  */
 public function export($layout_id, $location_ids = array(), $params = array(), $lang_code = DESCR_SL)
 {
     /* Exclude unnecessary fields*/
     $except_location_fields = array('location_id', 'company_id');
     $except_container_fields = array('container_id', 'location_id', 'dispatch', 'is_default', 'company_id', 'default');
     $except_grid_fields = array('container_id', 'location_id', 'position', 'grid_id', 'parent_id', 'order', 'children');
     $except_layout_fields = array('layout_id', 'theme_name', 'company_id');
     $except_location_fields = array_flip($except_location_fields);
     $except_container_fields = array_flip($except_container_fields);
     $except_grid_fields = array_flip($except_grid_fields);
     $except_layout_fields = array_flip($except_layout_fields);
     $layout_data = Layout::instance($this->_company_id)->get($layout_id);
     $layout_data = array_diff_key($layout_data, $except_layout_fields);
     $xml_root = new ExSimpleXmlElement('<block_scheme></block_scheme>');
     $xml_root->addAttribute('scheme', '1.0');
     $settings = $xml_root->addChild('settings');
     $settings->addChild('default_language', $lang_code);
     $layout_xml = $xml_root->addChild('layout');
     foreach ($layout_data as $field_name => $field_value) {
         $layout_xml->addChild($field_name, $field_value);
     }
     if (empty($location_ids)) {
         $location_ids = Location::instance($this->_layout_id)->getList(array(), $lang_code);
         $location_ids = array_keys($location_ids);
     }
     foreach ($location_ids as $location_id) {
         $location = Location::instance($this->_layout_id)->getById($location_id);
         $containers = Container::getList(array('location_id' => $location_id));
         $xml_location = $xml_root->addChild('location');
         $location = array_diff_key($location, $except_location_fields);
         foreach ($location as $attr => $value) {
             $xml_location->addAttribute($attr, $value);
         }
         $xml_containers = $xml_location->addChild('containers');
         $xml_translations = $xml_location->addChild('translations');
         $translations = Location::instance($this->_layout_id)->getAllDescriptions($location_id);
         foreach ($translations as $translation) {
             if ($translation['lang_code'] == $lang_code) {
                 // We do not needed default language
                 continue;
             }
             $xml_translation = $xml_translations->addChild('translation');
             $xml_translation->addChildCData('meta_keywords', $translation['meta_keywords']);
             $xml_translation->addChildCData('page_title', $translation['title']);
             $xml_translation->addChildCData('meta_description', $translation['meta_description']);
             $xml_translation->addChild('name', $translation['name']);
             $xml_translation->addAttribute('lang_code', $translation['lang_code']);
         }
         unset($xml_translations);
         foreach ($containers as $position => $container) {
             $grids = Grid::getList(array('container_ids' => $container['container_id']));
             $xml_container = $xml_containers->addChild('container');
             foreach ($container as $attr => $value) {
                 $xml_container->addAttribute($attr, $value);
             }
             if (!empty($grids) && isset($grids[$container['container_id']])) {
                 $grids = $grids[$container['container_id']];
                 $grids = fn_build_hierarchic_tree($grids, 'grid_id');
                 $container = array_diff_key($container, $except_container_fields);
                 $this->_buildGridStructure($xml_container, $grids, $except_grid_fields, $lang_code);
             }
         }
     }
     return $xml_root->asXML();
 }