示例#1
0
    }
    Tygh::$app['view']->assign('location', $selected_location);
    Tygh::$app['view']->assign('editable_content', $editable_content);
    Tygh::$app['view']->assign('editable_template_name', $editable_template_name);
    Tygh::$app['view']->assign('editable_wrapper', $editable_wrapper);
    Tygh::$app['view']->assign('block', $block_data);
    Tygh::$app['view']->assign('snapping_data', $snapping_data);
    Tygh::$app['view']->assign('block_scheme', $block_scheme);
    if (defined('AJAX_REQUEST')) {
        Tygh::$app['view']->display('views/block_manager/update_block.tpl');
        exit;
    }
} elseif ($mode == 'update_grid') {
    if (!empty($_REQUEST['grid_data']['grid_id'])) {
        // Update existing grid
        $grid = Grid::getById($_REQUEST['grid_data']['grid_id'], DESCR_SL);
        Tygh::$app['view']->assign('grid', $grid);
    }
    Tygh::$app['view']->assign('params', $_REQUEST['grid_data']);
} elseif ($mode == 'update_container') {
    if (!empty($_REQUEST['container_id'])) {
        // Update existing container
        $container = Container::getById($_REQUEST['container_id']);
        Tygh::$app['view']->assign('container', $container);
    }
} elseif ($mode == 'update_location') {
    $location_data = array('dispatch' => '');
    if (!empty($_REQUEST['location'])) {
        $location_data = Location::instance()->getById($_REQUEST['location'], DESCR_SL);
    }
    if (isset($_REQUEST['location_data']['dispatch'])) {
示例#2
0
文件: func.php 项目: arpad9/bygmarket
/**
 * Check if grid belongs to twigmo location
 * @param int $grid_id
 */
function fn_twg_is_twigmo_grid($grid_id)
{
    $grid = Grid::getById($grid_id);
    if (!$grid) {
        return false;
    }
    $container = Container::getById($grid['container_id']);
    return fn_twg_is_twigmo_location($container['location_id']);
}
示例#3
0
 /**
  * Loads location data, containers, grids and blocks
  *
  * @param string $dispatch       URL dispatch (controller.mode.action)
  * @param string $area           Area ('A' for admin or 'C' for custom
  * @param array  $dynamic_object
  * @param int    $location_id
  * @param string $lang_code      2 letters language code
  */
 public function __construct($dispatch, $area, $dynamic_object = array(), $location_id = 0, $lang_code = DESCR_SL)
 {
     Debugger::checkpoint('Start render location');
     // Try to get location for this dispatch
     if ($location_id > 0) {
         $this->_location = Location::instance()->getById($location_id, $lang_code);
     } else {
         $this->_location = Location::instance()->get($dispatch, $dynamic_object, $lang_code);
     }
     $this->_area = $area;
     if (!empty($this->_location)) {
         if (isset($dynamic_object['object_id']) && $dynamic_object['object_id'] > 0) {
             $this->_containers = Container::getListByArea($this->_location['location_id'], 'C');
         } else {
             $this->_containers = Container::getListByArea($this->_location['location_id'], $this->_area);
         }
         $this->_grids = Grid::getList(array('container_ids' => Container::getIds($this->_containers)));
         $blocks = Block::instance()->getList(array('?:bm_snapping.*', '?:bm_blocks.*', '?:bm_blocks_descriptions.*'), Grid::getIds($this->_grids), $dynamic_object, null, null, $lang_code);
         $this->_blocks = $blocks;
         $this->_view = \Tygh::$app['view'];
         $this->_theme = self::_getThemePath($this->_area);
         $this->_dynamic_object_scheme = SchemesManager::getDynamicObject($this->_location['dispatch'], 'C');
     }
 }
示例#4
0
 /**
  * Get blocks for the twigmo homepage
  * @param  string $dispatch        Dispatch of needed location
  * @param  array  $allowed_objects - array of blocks types
  * @return array  blocks
  */
 public static final function getBlocksForLocation($dispatch, $allowed_objects)
 {
     $allowed_page_types = array('T', 'L', 'F');
     $blocks = array();
     $location = Location::instance(fn_twg_get_default_layout_id())->get($dispatch);
     if (!$location) {
         return $blocks;
     }
     $get_cont_params = array('location_id' => $location['location_id']);
     $container = Container::getList($get_cont_params);
     if (!$container or !$container['CONTENT']) {
         return $blocks;
     }
     $grids_params = array('container_ids' => $container['CONTENT']['container_id']);
     $grids = Grid::getList($grids_params);
     if (!$grids) {
         return $blocks;
     }
     $block_grids = Block::instance()->getList(array('?:bm_snapping.*', '?:bm_blocks.*', '?:bm_blocks_descriptions.*'), Grid::getIds($grids));
     $image_params = TwigmoSettings::get('images.catalog');
     foreach ($block_grids as $block_grid) {
         foreach ($block_grid as $block) {
             if ($block['status'] != 'A' or !in_array($block['type'], $allowed_objects)) {
                 continue;
             }
             $block_data = array('block_id' => $block['block_id'], 'title' => $block['name'], 'hide_header' => isset($block['properties']['hide_header']) ? $block['properties']['hide_header'] : 'N', 'user_class' => $block['user_class']);
             $block_scheme = SchemesManager::getBlockScheme($block['type'], array());
             if ($block['type'] == 'html_block') {
                 // Html block
                 if (isset($block['content']['content']) and fn_string_not_empty($block['content']['content'])) {
                     $block_data['html'] = $block['content']['content'];
                 }
             } elseif (!empty($block_scheme['content']) and !empty($block_scheme['content']['items'])) {
                 // Products and categories: get items
                 $template_variable = 'items';
                 $field = $block_scheme['content']['items'];
                 fn_set_hook('render_block_content_pre', $template_variable, $field, $block_scheme, $block);
                 $items = RenderManager::getValue($template_variable, $field, $block_scheme, $block);
                 // Filter pages - only texts, links and forms posible
                 if ($block['type'] == 'pages') {
                     foreach ($items as $item_id => $item) {
                         if (!in_array($item['page_type'], $allowed_page_types)) {
                             unset($items[$item_id]);
                         }
                     }
                 }
                 if (empty($items)) {
                     continue;
                 }
                 $block_data['total_items'] = count($items);
                 // Images
                 if ($block['type'] == 'products' or $block['type'] == 'categories') {
                     $object_type = $block['type'] == 'products' ? 'product' : 'category';
                     foreach ($items as $items_id => $item) {
                         if (!empty($item['main_pair'])) {
                             $main_pair = $item['main_pair'];
                         } else {
                             $main_pair = fn_get_image_pairs($item[$object_type . '_id'], $object_type, 'M', true, true);
                         }
                         if (!empty($main_pair)) {
                             $items[$items_id]['icon'] = TwigmoImage::getApiImageData($main_pair, $object_type, 'icon', $image_params);
                         }
                     }
                 }
                 // Banners properties
                 if ($block['type'] == 'banners') {
                     $rotation = $block['properties']['template'] == 'addons/banners/blocks/carousel.tpl' ? 'Y' : 'N';
                     $block_data['delay'] = $rotation == 'Y' ? $block['properties']['delay'] : 0;
                     $block_data['hide_navigation'] = isset($block['properties']['navigation']) && $block['properties']['navigation'] == 'N' ? 'Y' : 'N';
                 }
                 $block_data[$block['type']] = Api::getAsList($block['type'], $items);
             }
             $blocks[$block['block_id']] = $block_data;
         }
     }
     return $blocks;
 }
示例#5
0
 /**
  * Get blocks by type from given location_id, returns snapping_id and block status
  *
  * @param  string     $block_type  Type of block
  * @param  int        $location_id Location Id
  * @return array|bool Array with snapping_id => block_status
  */
 public function getBlocksByTypeForLocation($block_type, $location_id)
 {
     $blocks = false;
     if (!empty($location_id)) {
         $containers = Container::getListByArea($location_id, 'C');
         $grids = Grid::getList(array('container_ids' => Container::getIds($containers), 'simple' => true));
         $condition = db_quote(' AND ?:bm_blocks.type = ?s', $block_type);
         $condition .= $this->getCompanyCondition('?:bm_blocks.company_id');
         $blocks = db_get_hash_single_array("SELECT ?:bm_snapping.snapping_id, ?:bm_snapping.status " . "FROM ?:bm_snapping " . "LEFT JOIN ?:bm_blocks " . "ON ?:bm_blocks.block_id = ?:bm_snapping.block_id " . "WHERE ?:bm_snapping.grid_id IN (?n) ?p", array('snapping_id', 'status'), Grid::getIds($grids), $condition);
     }
     return $blocks;
 }
示例#6
0
 /**
  * Removes non-default location with containers and grids. Set <i>force_removing</i>
  * to true to remove default location.
  *
  * @param  int  $location_id    Location identifier
  * @param  bool $force_removing Disable default location check
  * @return bool True in success, false otherwise
  */
 public function remove($location_id, $force_removing = false)
 {
     if (!empty($location_id)) {
         $location_data = $this->getById($location_id);
         if (!empty($location_data) && !$location_data['is_default'] || $force_removing) {
             /**
              * Actions before removing location
              * @param int $location_id Location identifier
              * @param bool $force_removing Disable default location check
              * @param $description
              */
             fn_set_hook('remove_location', $location_id, $force_removing);
             db_query('DELETE FROM ?:bm_locations WHERE location_id = ?i', $location_id);
             db_query('DELETE FROM ?:bm_locations_descriptions WHERE location_id = ?i', $location_id);
             Container::removeMissing();
             Grid::removeMissing();
             return true;
         }
     }
     return false;
 }
        fn_get_file(Registry::get('config.dir.layouts') . $file);
    }
} elseif ($mode == 'show_objects') {
    if (!empty($_REQUEST['object_type']) && !empty($_REQUEST['block_id'])) {
        Registry::get('view')->assign('object_type', $_REQUEST['object_type']);
        Registry::get('view')->assign('block_id', $_REQUEST['block_id']);
        Registry::get('view')->assign('object_ids', Block::instance()->getChangedContentsIds($_REQUEST['object_type'], $_REQUEST['block_id']));
        Registry::get('view')->assign('params', array('type' => 'links'));
        Registry::get('view')->assign('dynamic_object_scheme', SchemesManager::getDynamicObjectByType($_REQUEST['object_type']));
    }
} elseif ($mode == 'update_status') {
    $type = empty($_REQUEST['type']) ? 'block' : $_REQUEST['type'];
    if ($type == 'block') {
        Block::instance()->updateStatus($_REQUEST);
    } elseif ($type == 'grid') {
        Grid::update($_REQUEST);
    } elseif ($type == 'container') {
        Container::update($_REQUEST);
    }
    exit;
} elseif ($mode == 'delete_layout') {
    Layout::instance()->delete($_REQUEST['layout_id']);
    return array(CONTROLLER_STATUS_OK, 'block_manager.manage');
} elseif ($mode == 'set_default_layout') {
    if (!empty($_REQUEST['layout_id'])) {
        Layout::instance()->setDefault($_REQUEST['layout_id']);
        fn_set_notification('N', __('notice'), __('text_changes_saved'));
    }
    return array(CONTROLLER_STATUS_OK, 'block_manager.manage');
}
function fn_get_selected_location($params)
示例#8
0
 private function _parseGridStructure(&$xml_node, $container_id, $parent_id = 0)
 {
     foreach ($xml_node->grid as $grid) {
         if (!empty($grid)) {
             $grid_attrs = $this->_getNodeAttrs($grid);
             $grid_attrs['container_id'] = $container_id;
             $grid_attrs['parent_id'] = $parent_id;
             $grid_id = Grid::update($grid_attrs);
             if (isset($grid->grid)) {
                 $this->_parseGridStructure($grid, $container_id, $grid_id);
             }
             if (!empty($grid->blocks)) {
                 $this->_parseBlockStructure($grid_id, $grid->blocks);
             }
         }
     }
 }