source: extensions/ContestResults/include/cr_menubar.php @ 17737

Last change on this file since 17737 was 9975, checked in by mistic100, 13 years ago
  • many corrections
File size: 3.4 KB
RevLine 
[6768]1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4// +-----------------------------------------------------------------------+
[9200]5//                              Triggers
[6768]6// +-----------------------------------------------------------------------+
[9745]7if ($conf['ContestResults']['menubar_mode']['block']) {
[6768]8        add_event_handler('blockmanager_register_blocks', 'CR_register_menubar_blocks');
[9200]9}
[6768]10add_event_handler('blockmanager_apply', 'CR_menubar_apply');
11
12// +-----------------------------------------------------------------------+
13//                              Ajouter un block
14// +-----------------------------------------------------------------------+
[9200]15function CR_register_menubar_blocks($menu_ref_arr) {
[6768]16        $menu = &$menu_ref_arr[0];
[9200]17        if ($menu->get_id() != 'menubar') { return; }
[6768]18        $menu->register_block(new RegisteredBlock('mbContestResults', l10n('Contests'), 'ContestResults'));
19}
20
21// +-----------------------------------------------------------------------+
[9200]22//                              Remplis les block
[6768]23// +-----------------------------------------------------------------------+
[9200]24function CR_menubar_apply($menu_ref_arr) {
[6768]25        global $template, $conf;
26        $menu = &$menu_ref_arr[0];
27       
[9975]28        if (is_string($conf['ContestResults'])) {
29                $conf['ContestResults'] = unserialize($conf['ContestResults']);
30        }
31       
[9200]32        // Block Contest - un nouveau bloc dans le menu
33        if (($block = $menu->get_block('mbContestResults')) != null) {
[6768]34                $data = array();
[9200]35               
[9975]36                // on récupère les concours
[9200]37                $contests = pwg_query("SELECT
38                                id,
39                                name,
40                                visible,
41                                date_begin,
42                                date_end
[6768]43                        FROM " . CR_TABLE_1 . "
[9200]44                        ORDER BY date_begin DESC;");
[6768]45
[9975]46                $m = 0; // compteur pour limiter le nombre de concours affichés
[9745]47                while ($contest = pwg_db_fetch_assoc($contests)) {
48                        $contest = array_merge($contest, get_contest_status($contest['date_begin'],$contest['date_end']));
49                       
50                        if (($contest['visible'] OR is_admin()) AND $m < $conf['ContestResults']['menubar_block']['number']) {
[6768]51                                array_push($data, array(
[9975]52                                        'URL' => CR_PUBLIC . $contest['id'] . '-' . str2url(trigger_event('render_category_name', $contest['name'])),
53                                        'LABEL' => trigger_event('render_category_name', $contest['name']),
[6768]54                                        'DATE' => format_date($contest['date_begin']) . ' - ' . format_date($contest['date_end']),
[9572]55                                        'VISIBLE' => $contest['visible'],
[9745]56                                        'STATUS' => $contest['status'],
[9975]57                                        'DAYS' => $conf['ContestResults']['menubar_block']['display_days'] ? $contest['days'] : null,
[6768]58                                ));
59                        }
[9200]60                        $m++;
[6768]61                }
62
[9200]63                // Finalement on rempli le bloc avec les concours
64                if (!empty($data)) {
[6768]65                        $template->set_template_dir(CR_PATH . 'template/');
66                        $block->set_title('<a href="' . CR_PUBLIC . '">' . l10n('Contests') . '</a>');
67                        $block->template = 'cr_menubar.tpl';
68                        $block->data = $data;
69                }
70        }
71       
[9200]72        // Block Menu - ajout d'un lien dans le bloc Menu
[9745]73        if ($conf['ContestResults']['menubar_mode']['link'] AND $conf['ContestResults']['menubar_link']['menu'] AND ($block = $menu->get_block('mbMenu')) != null) {
[6768]74                array_push($block->data, array(
75                        'URL' => CR_PUBLIC,
76                        'TITLE' => l10n('Contests'),
77                        'NAME' => l10n('Contests')
78                ));
79        }
80       
[9200]81        // Block Specials - ajout d'un lien dans le bloc Specials
[9745]82        if($conf['ContestResults']['menubar_mode']['link'] AND $conf['ContestResults']['menubar_link']['specials'] AND ($block = $menu->get_block('mbSpecials')) != null){
[6768]83                array_push($block->data, array(
84                        'URL' => CR_PUBLIC,
85                        'TITLE' => l10n('Contests'),
86                        'NAME' => l10n('Contests')
87                ));
88        }
89}
90?>
Note: See TracBrowser for help on using the repository browser.