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

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

[extensions] Contest Results

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