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

Last change on this file since 9788 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: 1.5 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4// Racourcis un texte et ajoute une ellipse
5function CR_cut_string($string, $limit) {
6        include_once(CR_PATH . 'include/cutstring.class.php');
7        if (strlen(str_replace("\r\n", "\n", strip_tags($string))) > $limit) {
8                $output = new HtmlCutString($string, $limit);
9                return ($output->cut()).'...';
10        } else {
11                return $string;
12        }
13}
14
15// Recupère le nom d'un coucours à partir de l'id
16function get_contest_name($id) {
17        $contest = pwg_query("SELECT name FROM " . CR_TABLE_1 . " WHERE id = " . $id . ";");
18        if (pwg_db_num_rows($contest)) {
19                $contest = pwg_db_fetch_assoc($contest);
20                return $contest['name'];
21        } else {
22                return false;
23        }
24}
25
26// Nombre de jours entre deux dates
27function date_diff($date2, $date1) {
28        return ceil((strtotime($date2)-strtotime($date1))/(3600*24));
29}
30
31// Date passée
32function is_date_passed($date) {
33        if (time() > strtotime($date)) {
34                return true;
35        } else {
36                return false;
37        }
38}
39
40// Calcul le status d'un concours
41function get_contest_status($date_begin, $date_end) {
42        if (!is_date_passed($date_begin)) {
43                $contest['status'] = 'pending';
44                $contest['days'] = l10n_dec('CR_%d_days_to_begin', 'CR_%d_days_to_begin', date_diff($date_begin,date('Y-m-d')));
45        } else if (is_date_passed($date_end)) {
46                $contest['status'] = 'finished';
47                $contest['days'] = l10n('CR_finished');
48        } else { 
49                $contest['status'] = 'running';
50                $contest['days'] = l10n_dec('CR_%d_days_to_end', 'CR_%d_days_to_end', date_diff($date_end,date('Y-m-d')));
51        }
52       
53        return $contest;
54}
55?>
Note: See TracBrowser for help on using the repository browser.