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

Last change on this file since 9788 was 9788, checked in by mistic100, 13 years ago

[extensions] Contest Results

File size: 3.2 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       
[9200]28        // Block Contest - un nouveau bloc dans le menu
29        if (($block = $menu->get_block('mbContestResults')) != null) {
[6768]30                $data = array();
[9200]31               
32                // on récupère les concours
33                $contests = pwg_query("SELECT
34                                id,
35                                name,
36                                visible,
37                                date_begin,
38                                date_end
[6768]39                        FROM " . CR_TABLE_1 . "
[9200]40                        ORDER BY date_begin DESC;");
[6768]41
[9572]42                $m = 0; // compteur pour limiter le nombre de concours affichés
[9745]43                while ($contest = pwg_db_fetch_assoc($contests)) {
44                        $contest = array_merge($contest, get_contest_status($contest['date_begin'],$contest['date_end']));
45                       
46                        if (($contest['visible'] OR is_admin()) AND $m < $conf['ContestResults']['menubar_block']['number']) {
[6768]47                                array_push($data, array(
48                                        'URL' => CR_PUBLIC . $contest['id'] . '-' . str2url(trigger_event('render_CR_content', $contest['name'])),
49                                        'LABEL' => trigger_event('render_CR_content', $contest['name']),
50                                        'DATE' => format_date($contest['date_begin']) . ' - ' . format_date($contest['date_end']),
[9572]51                                        'VISIBLE' => $contest['visible'],
[9745]52                                        'STATUS' => $contest['status'],
53                                        'DAYS' => $contest['days'],
[6768]54                                ));
55                        }
[9200]56                        $m++;
[6768]57                }
58
[9200]59                // Finalement on rempli le bloc avec les concours
60                if (!empty($data)) {
[6768]61                        $template->set_template_dir(CR_PATH . 'template/');
62                        $block->set_title('<a href="' . CR_PUBLIC . '">' . l10n('Contests') . '</a>');
63                        $block->template = 'cr_menubar.tpl';
64                        $block->data = $data;
65                }
66        }
67       
[9200]68        // Block Menu - ajout d'un lien dans le bloc Menu
[9745]69        if ($conf['ContestResults']['menubar_mode']['link'] AND $conf['ContestResults']['menubar_link']['menu'] AND ($block = $menu->get_block('mbMenu')) != null) {
[6768]70                array_push($block->data, array(
71                        'URL' => CR_PUBLIC,
72                        'TITLE' => l10n('Contests'),
73                        'NAME' => l10n('Contests')
74                ));
75        }
76       
[9200]77        // Block Specials - ajout d'un lien dans le bloc Specials
[9745]78        if($conf['ContestResults']['menubar_mode']['link'] AND $conf['ContestResults']['menubar_link']['specials'] AND ($block = $menu->get_block('mbSpecials')) != null){
[6768]79                array_push($block->data, array(
80                        'URL' => CR_PUBLIC,
81                        'TITLE' => l10n('Contests'),
82                        'NAME' => l10n('Contests')
83                ));
84        }
85}
86?>
Note: See TracBrowser for help on using the repository browser.