예제 #1
0
 public static function add_filter_fieldset(Menu $menu, Template $tpl)
 {
     $tpl_filter = new FileTemplate('admin/menus/filters.tpl');
     $tpl_filter->assign_block_vars('modules', array('ID' => ''));
     foreach (ModulesManager::get_activated_modules_map_sorted_by_localized_name() as $module) {
         $configuration = $module->get_configuration();
         $home_page = $configuration->get_home_page();
         if (!empty($home_page)) {
             $tpl_filter->assign_block_vars('modules', array('ID' => $module->get_id()));
         }
     }
     //Ajout du menu
     if ($menu->get_id() == '') {
         $menu->set_filters(array(new MenuStringFilter('/')));
     }
     // Installed modules
     foreach ($menu->get_filters() as $key => $filter) {
         $filter_pattern = $filter->get_pattern();
         $filter_infos = explode('/', $filter_pattern);
         $module_name = $filter_infos[0];
         $regex = substr(strstr($filter_pattern, '/'), 1);
         $tpl_filter->assign_block_vars('filters', array('ID' => $key, 'FILTER' => $regex));
         $tpl_filter->assign_block_vars('filters.modules', array('ID' => '', 'SELECTED' => $filter_pattern == '/' ? ' selected="selected"' : ''));
         foreach (ModulesManager::get_activated_modules_map_sorted_by_localized_name() as $module) {
             $configuration = $module->get_configuration();
             $home_page = $configuration->get_home_page();
             if (!empty($home_page)) {
                 $tpl_filter->assign_block_vars('filters.modules', array('ID' => $module->get_id(), 'SELECTED' => $module_name == $module->get_id() ? ' selected="selected"' : ''));
             }
         }
     }
     $tpl_filter->add_lang(LangLoader::get('admin-menus-common'));
     $tpl_filter->put_all(array('NBR_FILTER' => $menu->get_id() == '' ? 0 : count($menu->get_filters()) - 1));
     $tpl->put('filters', $tpl_filter);
 }
예제 #2
0
    /**
     * @desc Move a menu into a block and save it. Enable or disable it according to the destination block
     * @param Menu $menu the menu to move
     * @param int $block the destination block
     * @param int $position the destination block position
     * @param bool $save if true, save also the menu
     */
    public static function move(Menu $menu, $block, $position = 0, $save = true)
    {
        if ($menu->get_id() > 0 && $menu->is_enabled()) {
            // Updates the previous block position counter
            // Only for already existing menu that are enabled, not for new ones
            $parameters = array('block' => $menu->get_block(), 'position' => $menu->get_block_position());
            self::$querier->inject('UPDATE ' . DB_TABLE_MENUS . ' SET position=position - 1
				WHERE block=:block AND position > :position', $parameters);
        }
        // Disables the menu if the destination block is the NOT_ENABLED block position
        $menu->enabled($block == Menu::BLOCK_POSITION__NOT_ENABLED ? Menu::MENU_NOT_ENABLED : Menu::MENU_ENABLED);
        // If not enabled, we do not move it so we can restore its position by reactivating it
        if ($menu->is_enabled()) {
            // Moves the menu into the destination block
            $menu->set_block($block);
            // Computes the new block position for the menu
            if (empty($position)) {
                $position_query = self::get_next_position($menu->get_block());
                $menu->set_block_position($position_query);
            }
        }
        if ($save) {
            self::save($menu);
        }
    }
예제 #3
0
 /**
  * 
  * Enter description here ...
  * @param Menu $menu
  */
 public static function save(Menu $menu)
 {
     $dbh = $GLOBALS['dbh'];
     if ($menu->get_id()) {
         // Update
         $data = $dbh->prepare("\n\t\t\t\tUPDATE \n\t\t\t\t\tmenu\n\t\t\t\tSET \n\t\t\t\t\tname=:name, unit=:unit, cost=:cost \n\t\t\t\tWHERE \n\t\t\t\t\tid=:id\n\t\t\t");
         $data->execute(array(':name' => $menu->get_name(), ':unit' => $menu->get_unit(), ':cost' => $menu->get_cost(), ':id' => $menu->get_id()));
     } else {
         // Insert
         $data = $dbh->prepare("\n\t\t\t\tINSERT \n\t\t\t\t\tINTO `menu`(name, unit, cost)\n\t\t\t\tVALUES\n\t\t\t\t\t(:name, :unit, :cost)\n\t\t\t");
         $data->execute(array(':name' => $menu->get_name(), ':unit' => $menu->get_unit(), ':cost' => $menu->get_cost()));
     }
 }