Changeset 4368 for extensions


Ignore:
Timestamp:
Nov 26, 2009, 12:57:43 AM (14 years ago)
Author:
tiico
Message:

[ConcoursPhoto] Correct some bug, update database and add audit page (Need to be completed)

Location:
extensions/ConcoursPhoto
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • extensions/ConcoursPhoto/CHANGELOG

    r4310 r4368  
    22-
    33
    4 _______________
     4______________
    55
    66Version 1.0.x
    77-------------
     81.1.0   - Add datas "moyenne" and "nbvotant" in database concours_result. Export theses datas in csv.
     9                - add method of rank calculation in a concours (in database).
     10                - generate the result (export) with the method (moyenne or sum)
    8111.0.0 --> First public release
    912_______________
  • extensions/ConcoursPhoto/admin/add_concours.php

    r4141 r4368  
    3030load_language('plugin.lang', CONCOURS_PATH);
    3131
     32$method_list = array(l10n('concours_method1'), l10n ('concours_method2') );
    3233
    3334       
     
    7374if (isset($_POST['submit']))
    7475{
     76
     77        $concours->concours_infos['method'] = $_POST['concours_method'];
     78
    7579        if ($action == "modify_crit")
    7680                redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php');
    7781
    7882        if ($action == "edit")
     83        {
     84                if ($concours->is_closed($concours_id) AND ! $concours->is_result_present($concours_id))
     85                        $concours->update_concoursfield("method", $concours_id);
     86       
    7987                redirect(PHPWG_ROOT_PATH.'admin.php?page=plugin&section=' . CONCOURS_DIR . '%2Fadmin%2Fadmin.php');
     88        }
    8089
    8190// Step 1 : action = modify
     
    108117        $concours->concours_infos['category'] = $_POST['cat_selection'];
    109118       
     119
     120
    110121        switch($action)
    111122        {
     
    340351$template->assign(array('month_list' => $month_list));
    341352
     353// Add method list to
     354$i=1;
     355foreach ( $method_list as $order ) //on parcours le tableau
     356{
     357        $template->append('concours_method',
     358                array(  'ID' => $i,
     359                                'NAME' => $order,
     360                                'SELECTED' => (isset($concours->concours_infos['method']) && $concours->concours_infos['method'] == $i ? 'selected' : '')));
     361        $i++;   
     362}
     363
     364if ($concours->is_closed($concours_id) AND !$concours->is_result_present($concours_id))
     365        $template->append('result_not_generated', true);
     366
    342367
    343368// Groups selection
  • extensions/ConcoursPhoto/admin/admin.php

    r3905 r4368  
    3535               $my_base_url.'&tab=params');
    3636
     37$tabsheet->add('audit',
     38               l10n('concours_audit'),
     39               $my_base_url.'&tab=audit');
     40
    3741$tabsheet->select($page['tab']);
    3842$tabsheet->assign();
  • extensions/ConcoursPhoto/admin/functions.inc.php

    r3905 r4368  
    9797                FROM ' . CONCOURS_TABLE .'
    9898                WHERE time_to_sec(TIMEDIFF(begin_date, now())) > 0
     99                ORDER BY id
    99100                ;';
    100101
     
    118119                WHERE time_to_sec(TIMEDIFF(begin_date, now())) < 0
    119120                AND time_to_sec(TIMEDIFF(now(), end_date)) < 0
     121                ORDER BY id
    120122                ;';
    121123
     
    137139                SELECT *
    138140                FROM ' . CONCOURS_TABLE .'
    139                 WHERE time_to_sec(TIMEDIFF(now(), end_date)) > 0 '
     141                WHERE time_to_sec(TIMEDIFF(now(), end_date)) > 0
     142                ORDER BY id
     143               
     144                '
    140145//              .'AND id != 0'
    141146                .';';
  • extensions/ConcoursPhoto/admin/manage.php

    r3905 r4368  
    4242
    4343    'U_EDIT' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&amp;concours=' . $concours['id'].'&amp;action=modify',
     44    'U_AUDIT' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Faudit.php&amp;concours=' . $concours['id'],
    4445    'U_DELETE' => !is_adviser() ? PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&amp;concours=' . $concours['id'].'&amp;action=del': '',
    4546  ));
     
    6162
    6263                'U_EDIT' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&amp;concours=' . $concours['id'].'&amp;action=edit',
     64        'U_AUDIT' => PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Faudit.php&amp;concours=' . $concours['id'],
    6365                'U_DELETE' => !is_adviser() ? PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&amp;concours=' . $concours['id'].'&amp;action=del' : '',
    6466                'U_RESULT' => (!is_adviser() and !has_result($concours['id']) )? PHPWG_ROOT_PATH . 'admin.php?page=plugin&amp;section=' . CONCOURS_DIR . '%2Fadmin%2Fadd_concours.php&amp;concours=' . $concours['id'].'&amp;action=result' : '',
  • extensions/ConcoursPhoto/admin/template/add_concours.tpl

    r4141 r4368  
    5151            <b>{$END_DAY_SELECTED} / {$END_MONTH_SELECTED} / {$END_YEAR} - {$END_HOUR} : {$END_MIN}</b>
    5252          </td>
     53        </tr>
     54                <tr>
     55                        <td><b>{'concours_method'|@translate} &nbsp;&nbsp;</b></td>
     56                        <td colspan = "3">             
     57                                <select name="concours_method" {if !isset($result_not_generated)}disabled="disabled"{/if}>
     58                                {foreach from=$concours_method item=concours_method}
     59                                        <option value="{$concours_method.ID}" {$concours_method.SELECTED}>{$concours_method.NAME}</option>
     60                                {/foreach}
     61                                </select>
     62                        </td>
     63                       
    5364        </tr>
    5465               
     
    6273                        </select>
    6374                        </td>
    64         </tr>
     75                </tr>
    6576{else}
    6677                <tr>
     
    142153        </tr>
    143154
     155                <tr>
     156                        <td><b>{'concours_method'|@translate} &nbsp;&nbsp;</b></td>
     157                        <td colspan = "3">             
     158                                <select name="concours_method">
     159                                {foreach from=$concours_method item=concours_method}
     160                                        <option value="{$concours_method.ID}" {$concours_method.SELECTED}>{$concours_method.NAME}</option>
     161                                {/foreach}
     162                                </select>
     163                        </td>
     164                       
     165        </tr>
    144166        <tr><td colspan="4"><br></td></tr>
    145167
     
    153175                        </select>
    154176                        </td>
    155         </tr>
     177                </tr>
    156178{/if}
    157179                </table>
  • extensions/ConcoursPhoto/admin/template/manage.tpl

    r3905 r4368  
    1313                 <table border="1">
    1414                        <tr>
    15                                 <th><b>{'concours_id'|@translate}</b></th>
     15                                <th><b>{'concours_id2'|@translate}</b></th>
    1616                                <th><b>{'concours_name'|@translate}</b></th>
    1717                                <th><b>{'concours_create_date'|@translate}</b></th>
     
    4141                 <table border="1">
    4242                        <tr>
    43                                 <th><b>{'concours_id'|@translate}</b></th>
     43                                <th><b>{'concours_id2'|@translate}</b></th>
    4444                                <th><b>{'concours_name'|@translate}</b></th>
    4545                                <th><b>{'concours_create_date'|@translate}</b></th>
     
    5252                        <tr>
    5353                                <td>{$active_concours.ID}</td>         
    54                                 <td>{$active_concours.NAME}</td>               
     54                                <td><a href="{$prepared_concours.U_AUDIT}" title="{'concours_audit1'|@translate}">{$active_concours.NAME}</a></td>             
    5555                                <td>{$active_concours.CREATE_DATE}</td>         
    5656                                <td>{$active_concours.DESC}</td>               
     
    6969                 <table border="1">
    7070                        <tr>
    71                                 <th><b>{'concours_id'|@translate}</b></th>
     71                                <th><b>{'concours_id2'|@translate}</b></th>
    7272                                <th><b>{'concours_name'|@translate}</b></th>
    7373                                <th><b>{'concours_create_date'|@translate}</b></th>
     
    8080                        <tr>
    8181                                <td>{$closed_concours.ID}</td>         
    82                                 <td>{$closed_concours.NAME}</td>               
     82                                <td><a href="{$closed_concours.U_AUDIT}" title="{'concours_audit1'|@translate}">{$closed_concours.NAME}</a></td>               
    8383                                <td>{$closed_concours.CREATE_DATE}</td>         
    8484                                <td>{$closed_concours.DESC}</td>               
  • extensions/ConcoursPhoto/include/Concours.class.php

    r4260 r4368  
    163163                                                `end_date`,
    164164                                                `category`,
    165                                                 `groups`)
     165                                                `groups`,
     166                                                `method`
     167                                                )
    166168                                        VALUES (".($concours_id !== NULL ? $concours_id : $this->concours_id).", now(),
    167169                                                        \"".$this->concours_infos['name']."\", \"".$this->concours_infos['descr']."\",
    168170                                                        \"".$this->concours_infos['begin_date']."\", \"".$this->concours_infos['end_date']."\",
    169                                                         ".$this->concours_infos['category'].", ".$this->concours_infos['groups'].");";
     171                                                        ".$this->concours_infos['category'].", ".$this->concours_infos['groups'].",
     172                                                        ".$this->concours_infos['method']."
     173                                                        );";
    170174                        if (pwg_query($query) != null)
    171175                                return true;
     
    191195                                                end_date = \"".$this->concours_infos['end_date']."\",
    192196                                                category = ".$this->concours_infos['category'].",
    193                                                 groups = ".$this->concours_infos['groups']."
     197                                                groups = ".$this->concours_infos['groups'].",
     198                                                method = ".$this->concours_infos['method']."
     199                                               
    194200                                                WHERE id = ".($concours_id !== NULL ? $concours_id : $this->concours_id)."
    195201                                                ;";
     
    205211        }
    206212       
     213        // update field on database for a concours_id
     214        function update_concoursfield($field_id, $concours_id = null)
     215        {
     216                if ($concours_id!== null or $this->concours_id !== null)
     217                {
     218
     219                        $query = "UPDATE " . CONCOURS_TABLE . "
     220                                                SET
     221                                                " . $field_id." = ". $this->concours_infos[$field_id] . "
     222                                               
     223                                                WHERE id = ".($concours_id !== NULL ? $concours_id : $this->concours_id)."
     224                                                ;";
     225                        pwg_query($query);
     226                        if (pwg_query($query) != null)
     227                                return true;
     228                        else
     229                                return false;
     230                }
     231                else           
     232                        return false;
     233       
     234        }
     235
    207236        // delete concours from db (and all sub informations such as details, vote and result
    208237        function delete_concours($concours_id = null)
     
    583612        }
    584613       
     614        // function to return the number of votes for a concours by images
     615        function nb_votes_by_img($concours_id = NULL)
     616        {
     617               
     618                // nb of users who vote for each image (for a selected concours
     619                $query = 'SELECT img_id, COUNT(DISTINCT user_id) AS NBVOTE FROM ' . CONCOURS_DATA_TABLE
     620                .' WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id )
     621                .' GROUP BY img_id '
     622                .';';
     623                               
     624                $result = pwg_query($query);
     625                $nbvotes = array();
     626                while ($row = mysql_fetch_assoc($result))
     627                {
     628                        $nbvotes[$row['img_id']] = $row['NBVOTE'];
     629                }
     630                return $nbvotes;
     631        }
     632               
    585633       
    586634        // After concours is completed (closed date is passed), generate the result and store it to DB
     
    594642                        if ($this->is_closed($concours_id) AND ! $this->is_result_present($concours_id))
    595643                        {
     644                       
     645                                // array with the number of vote by image for the concours. Needed for the moyenne
     646                                $nbvotes = $this->nb_votes_by_img($concours_id);
     647                               
    596648                                $user_id = array();
    597649                                // vars not initialized
     
    646698                                // update database and store result into RESULT table
    647699                                // note = global note
     700                                $IMGmoyenne = 0;
    648701                                foreach ($global_note as $id => $val)
     702                                // id contains the image id
    649703                                {
    650                                         $query = 'INSERT INTO  ' . CONCOURS_RESULT_TABLE .'(`id_concours`, `img_id`, `date` , `note` )
     704if ($this->debug)               echo $nbvotes[$id];
     705                                        $IMGmoyenne = (isset($nbvotes[$id]) && $nbvotes[$id] != 0 ? $val/$nbvotes[$id] : 0);
     706                                       
     707                                        $query = 'INSERT INTO  ' . CONCOURS_RESULT_TABLE .'(`id_concours`, `img_id`, `date` , `note`, `moyenne`, `nbvotant` )
    651708                                                        VALUES ('.($concours_id !== null ? $concours_id : $this->concours_id )
    652709                                                                         .', '.$id
    653710                                                                         .', now() '
    654711                                                                         .', '.$val
     712                                                                         .', '.$IMGmoyenne
     713                                                                         .', '.(isset($nbvotes[$id]) ? $nbvotes[$id] : 0)
    655714                                                                         .');';
    656715                                $result = pwg_query($query);
     
    12211280        function generate_csv($concours_id = NULL)
    12221281        {
    1223                 $file = "rang, id_concours, img_id, img_name, img_file, date, note, datas\r\n";
    1224 
     1282                $file = "rang, id_concours,method, img_id, img_name, img_file, date, note, moyenne, nbvotant, datas\r\n";
     1283
     1284                if (!(isset($this->concours_info['method'])))
     1285                        $this->concours_info['method'] = 1;
     1286                       
    12251287                // recover all img_id from the category
    1226                 $query = 'SELECT id_concours, img_id, IMG.name, IMG.file, date, note, datas'
     1288                $query = 'SELECT id_concours,method, img_id, IMG.name, IMG.file, date, note, moyenne, nbvotant, datas'
    12271289                .' FROM ' .CONCOURS_RESULT_TABLE
     1290                .' INNER JOIN ' . CONCOURS.' AS CONC on CONC.id = id_concours'
    12281291                .' INNER JOIN ' . IMAGES_TABLE.' AS IMG on IMG.id = img_id'
    1229                 .' WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id )
    1230                 .' ORDER BY note DESC'
    1231                 .';';
     1292                .' WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id );
     1293               
     1294                if ($this->concours_info['method'] == 1)        // total
     1295                        $query .= ' ORDER BY note DESC';
     1296                elseif ($this->concours_info['method'] == 2)    // moyenne
     1297                        $query .= ' ORDER BY moyenne DESC';
     1298               
     1299                $query .=';';
    12321300               
    12331301                $result = pwg_query($query);
     
    12361304                while ($row = mysql_fetch_assoc($result))
    12371305                {
    1238                         $file .= $rang.', '
     1306                        $file .= ($row['nbvotant'] != 0 ? $rang : 'N/A').', '
    12391307                                        .$row['id_concours'].', '
     1308                                        .$row['method'].', '
    12401309                                        .$row['img_id'].', '
    12411310                                        .$row['name'].', '
     
    12431312                                        .$row['date'].', '
    12441313                                        .$row['note'].', '
     1314                                        .$row['moyenne'].', '
     1315                                        .$row['nbvotant'].', '
    12451316                                        .($row['datas'] != null ? $row['datas'] : '')
    12461317                                        ."\r\n";
     
    13061377               
    13071378                // All informations in csv format
    1308                 $file = "rang, id_concours, nom_concours, date_debut, date_fin, date_export, img_id, img_name, img_file, img_author, note, nbvotant, datas,"
     1379                $file = "rang, id_concours, method, nom_concours, date_debut, date_fin, date_export, img_id, img_name, img_file, img_author, note, moyenne, nbvotant, datas,"
    13091380                .$users_criteria
    13101381                ."\r\n";
    13111382
    13121383                // nb of users who vote for each image
    1313                 $query = 'SELECT img_id, COUNT(DISTINCT user_id) AS NBVOTE FROM ' . CONCOURS_DATA_TABLE
     1384
     1385        // NOT NEEDED, INFO STORE IN DATABASE 'RESULT'
     1386                $nbvotes = $this->nb_votes_by_img($concours_id);
     1387
     1388               
     1389                /*              $query = 'SELECT img_id, COUNT(DISTINCT user_id) AS NBVOTE FROM ' . CONCOURS_DATA_TABLE
    13141390                .' GROUP BY img_id '
    13151391                .';';
     
    13221398                        $nbvotes[$row['img_id']] = $row['NBVOTE'];
    13231399                }
     1400*/             
    13241401/*             
    13251402                foreach ($nbvotes as $id=>$val)
     
    13291406*/             
    13301407                // recover all img_id from the category
    1331                 $query = 'SELECT id_concours, img_id, IMG.name, IMG.file, IMG.author, date, note, datas, comment'
     1408                if (!(isset($this->concours_info['method'])))
     1409                        $this->concours_info['method'] = 1;
     1410                $query = 'SELECT id_concours, method, img_id, IMG.name, IMG.file, IMG.author, date, note, moyenne, nbvotant, datas, comment'
    13321411                .' FROM ' .CONCOURS_RESULT_TABLE
     1412                .' INNER JOIN ' . CONCOURS_TABLE.' AS CONC on CONC.id = id_concours'
    13331413                .' INNER JOIN ' . IMAGES_TABLE.' AS IMG on IMG.id = img_id'
    1334                 .' WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id )
    1335                 .' ORDER BY note DESC'
    1336                 .';';
    1337                
     1414                .' WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id );
     1415               
     1416                if ($this->concours_info['method'] == 1)        // total
     1417                        $query .= ' ORDER BY note DESC';
     1418                elseif ($this->concours_info['method'] == 2)    // moyenne
     1419                        $query .= ' ORDER BY moyenne DESC';
     1420               
     1421                $query .=';';
     1422               
     1423if ($this->debug)               echo $query;
    13381424                $result = pwg_query($query);
    1339 //              echo $query;
    13401425                // For each images
    13411426                $rang = 1;
    13421427                while ($row = mysql_fetch_assoc($result))
    13431428                {
    1344                         $file .= $rang.', '
     1429                        $file .= ($row['nbvotant'] != 0 ? $rang : 'N/A').', '
    13451430                                        .$row['id_concours'].', '
     1431                                        .$row['method'].', '
    13461432                                        .str_replace(",", "",$this->concours_infos['name']).', '
    13471433                                        .$this->concours_infos['begin_date'].', '
     
    13541440                                        .$row['author'].', '
    13551441                                        .$row['note'].', '
    1356                                         .(isset($nbvotes[$row['img_id']]) ? $nbvotes[$row['img_id']] : 0).', '
     1442                                        .$row['moyenne'].', '
     1443                                        .$row['nbvotant'].', '
     1444//                                      .(isset($nbvotes[$row['img_id']]) ? $nbvotes[$row['img_id']] : 0).', '
    13571445                                        .($row['datas'] != null ? $row['datas'] : '')
    13581446                                        ;
     
    13981486                        $rang ++;
    13991487                }
    1400 //              echo $file;
     1488if ($this->debug)               echo $file;
    14011489                return $file;
    14021490       
     
    14331521                                                ;";
    14341522                        pwg_query($query);
    1435         //              echo $query;
     1523if ($this->debug)               echo $query;
    14361524                       
    14371525                        return $filename;
     
    14461534                .' WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id )
    14471535                .';';
    1448                 $row = mysql_fetch_assoc(pwg_query($query));
    1449                 if ($row)
    1450                         return $row['file_name'];
    1451                 else
    1452                         return false;
    1453        
     1536if ($this->debug)       echo $query;
     1537                $result = pwg_query($query);
     1538                if ($result)
     1539                {
     1540                        $row = mysql_fetch_assoc($result);             
     1541                        if ($row)
     1542                                return $row['file_name'];
     1543                        else
     1544                                return false;
     1545                }
    14541546        }
    14551547
     
    16021694  {
    16031695
    1604         global $page;
     1696        global $page, $user;
    16051697        $this->get_user_groups();
    16061698
     
    16381730            {
    16391731
    1640                 foreach($tpl_var as $cle=>$valeur) {
    1641                 {
    1642                   $tpl_var[$cle]['NAME'] = $tpl_var[$cle]['NAME'].'<br>&nbsp;'.l10n('thumbnail_global_note').' : '.$this->get_img_globalnote_user($tpl_var[$cle]['ID'], $concours['id']);
    1643                   }
     1732                foreach($tpl_var as $cle=>$valeur)
     1733                                {
     1734                                        // show only if the author is not the active user
     1735                                        if ($tpl_var[$cle]['FILE_AUTHOR'] != $user['username'])
     1736                                        {
     1737                                                $tpl_var[$cle]['NAME'] = $tpl_var[$cle]['NAME'].'<br>&nbsp;'.l10n('thumbnail_global_note').' : '.$this->get_img_globalnote_user($tpl_var[$cle]['ID'], $concours['id']);
     1738                                        }
    16441739                }
    16451740            }
  • extensions/ConcoursPhoto/language/fr_FR/plugin.lang.php

    r4260 r4368  
    1313$lang['concours_add']                                   = 'Ajouter un concours';
    1414$lang['concours_id']                                    = 'Identifiant';
     15$lang['concours_id2']                                   = 'Id.';
    1516$lang['concours_name']                                  = 'Nom';
    1617$lang['concours_descr']                                 = 'Description';
     
    7374$lang['concours_thumb_note'] = 'Ajouter la note globale sous les miniatures';
    7475$lang['concours_global_user_note']  =   'Total enregistré';
     76
     77
     78$lang['concours_activ_from'] = 'Concours actif de ';
     79$lang['concours_activ_to'] = ' à ';
     80$lang['concours_method'] = 'Méthode de calcul du classement';
     81$lang['concours_method1'] = 'Somme des notes';
     82$lang['concours_method2'] = 'Moyenne des notes';
     83
     84$lang['concours_note'] = 'Note globale';
     85$lang['concours_moyenne'] = 'Moyenne';
     86$lang['concours_nbvotant'] = 'Nombre de votant';
     87$lang['concours_usernote'] = 'Votre note';
     88$lang['concours_infos'] = 'Information sur le concours';
     89$lang['concours_audit'] = 'Audit';
     90$lang['concours_audit1'] = 'Auditer le concours';
     91$lang['concours_author'] = 'Auteur';
     92
    7593?>
  • extensions/ConcoursPhoto/main.inc.php

    r4310 r4368  
    22/*
    33 * Plugin Name: ConcoursPhoto
    4  * Version: 1.0.0
     4 * Version: 1.1.0
    55 * Description: Concours de photo paramétrable
    66 * Plugin URI: http://piwigo.org/ext/extension_view.php?eid=323
  • extensions/ConcoursPhoto/maintain.inc.php

    r3905 r4368  
    2626                                `category` smallint(5) default NULL,
    2727                                `groups` varchar(255) default NULL,
     28                                `method` smallint(5) default 1 NOT NULL,
    2829                               
    2930                                PRIMARY KEY  (`id`)
     
    7071                                `datas` longtext default NULL,
    7172                                `file_name` longtext default NULL,
     73                                `moyenne` float default 0,
     74                                `nbvotant` smallint(5) default 0,
     75                               
    7276                                PRIMARY KEY  (`img_id`),
    7377                                FOREIGN KEY (`id_concours`) REFERENCES ' . $prefixeTable . 'concours(id)                               
     
    184188  global $prefixeTable;
    185189
     190  // Check if upgrade is needed
     191  $query = 'SHOW FULL COLUMNS FROM ' . $prefixeTable . 'concours_result;';
     192  $result = array_from_query($query, 'Field');
     193  if (count($result) < 7)       // only 6 datas on previous database
     194  {
     195    upgrade_concours_from_100();
     196  }
     197 
    186198}
    187199
     
    204216}
    205217
     218// Add new parameter in database in version 2.0.0:
     219// - moy : moyenne of global note with all participant
     220// - nbvotant : nb of vote for an image
     221// - method = type of rank calculation (1-> total; 2-> moyenne)
     222function upgrade_concours_from_100()
     223{
     224        global $prefixeTable;
     225        // Add new parameters
     226        $query = 'ALTER TABLE ' . $prefixeTable . 'concours_result
     227        ADD `moyenne` float default 0 AFTER `note`,
     228        ADD `nbvotant` smallint(5) default 0 AFTER `moyenne`
     229        ;';
     230
     231        pwg_query($query);
     232       
     233        // TODO : Recalcul the moyenne and the nb of participation if the table still exist for the selected concours
     234
     235        $query = 'ALTER TABLE ' . $prefixeTable . 'concours
     236        ADD     `method` smallint(5) default 1 NOT NULL
     237        ;';
     238
     239        pwg_query($query);
     240 
     241}
    206242
    207243?>
  • extensions/ConcoursPhoto/publish.php

    r3905 r4368  
    1313$concours = new Concours($id_concours);
    1414
     15                $template->assign( 'CONCOURS', array(
     16                                'ID'    => $concours->concours_infos['id'],
     17                                'NAME'  => $concours->concours_infos['name'],
     18                                'DESCR' => $concours->concours_infos['descr'],
     19                                'BEGIN_DATE'    => $concours->concours_infos['begin_date'],
     20                                'END_DATE'      => $concours->concours_infos['end_date'],
     21                                'METHOD'        => l10n("concours_method".$concours->concours_infos['method'])
     22                                ));
     23
     24
    1525$category = $concours->concours_infos['category'];
    1626
    17 $query = 'SELECT DISTINCT(img.id), img.name, img.file, img.path, img.tn_ext,
    18                   ic.category_id, cat.name AS catname, conc.note'
     27$query = 'SELECT DISTINCT(img.id), img.name, img.file, img.path, img.tn_ext,img.author,
     28                  ic.category_id, cat.name AS catname, conc.note, conc.moyenne, conc.nbvotant'
    1929                .' FROM ' . IMAGES_TABLE.' AS img'
    2030                .' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON img.id = ic.image_id'
     
    6070                        'name'  => $row['name'],
    6171                        'file'  => $row['file'],
     72                        'author'        => $row['author'],
    6273                        'rang'  => $rang,
    6374                        'thumb' => get_thumbnail_url($row),
    6475                        'url'   => $url,
    65                         'note'  => ($row['note'] == 0 ? 'N/A' :$row['note'])
     76                        'note'  => ($row['note'] == 0 ? 'N/A' :$row['note']),
     77                        'moyenne'       => ($row['moyenne'] == 0 ? 'N/A' :$row['moyenne']),
     78                        'nbvotant'      => $row['nbvotant'],
     79                        'usernote'      => $concours->get_img_globalnote_user($row['id'])
     80                       
    6681                ));
    6782        $rang ++;
  • extensions/ConcoursPhoto/template/result.tpl

    r3905 r4368  
    11<div class="concours">
     2        <fieldset>
     3                <legend>{'concours_infos'|@translate}</legend>
     4        <table align="left">
     5                        <td >
     6                                {'concours_name'|@translate} : <b>{$CONCOURS.NAME}</b>
     7                                <br>{'concours_descr'|@translate} : <b>{$CONCOURS.DESCR}</b>
     8                                <br>{'concours_activ_from'|@translate} <b>{$CONCOURS.BEGIN_DATE}</b> {'concours_activ_to'|@translate} <b>{$CONCOURS.END_DATE}</b>
     9                                <br>{'concours_method'|@translate} : <b>{$CONCOURS.METHOD}</b>
     10                        </td>
     11                </tr>
     12        </table>
     13        </fieldset>
    214        <fieldset>
    315                <legend>{'concours_result_page'|@translate}</legend>
     
    618                 {foreach from=$concours_note item=concours_note}
    719                        <tr>
    8                                 <td><b><i> ({$concours_note.rang}{if $concours_note.rang == 1}{'concours_1st'|@translate}
     20                                <td><b><i> {if $concours_note.nbvotant != 0}
     21                            ({$concours_note.rang}{if $concours_note.rang == 1}{'concours_1st'|@translate}
    922                                                                                                 {elseif $concours_note.rang == 2}{'concours_2nd'|@translate}
    1023                                                                                                 {elseif $concours_note.rang == 3}{'concours_3rd'|@translate}
    1124                                                                                                 {else}{'concours_4th'|@translate}{/if}
    12                                                         )&nbsp;&nbsp;</i></b></td>
     25                                                        )
     26                            {else}(N/A){/if}&nbsp;&nbsp;</i></b></td>
    1327                                <td><b>Photo {$concours_note.img_id}&nbsp;&nbsp;</b></td>               
    1428                                <td>
     
    1630                                        <img class="thumbnail" src="{$concours_note.thumb}" alt="{$concours_note.name}" title="{$concours_note.name}"/>
    1731                                        </a>
     32                    <br><u>{'concours_author'|@translate}</u> : {$concours_note.author}</center>
    1833                                </td>
    19                                 <td><i>Note : {$concours_note.note}&nbsp;&nbsp;</i></td>
     34                                <td>
     35                                <fieldset>
     36                                        <i>{'concours_note'|@translate} : <b>{$concours_note.note}</b>&nbsp;&nbsp;</i>
     37                                        <br><i>{'concours_moyenne'|@translate} : <b>{$concours_note.moyenne}</b>&nbsp;&nbsp;</i>
     38                                        <br><i>{'concours_nbvotant'|@translate} : {$concours_note.nbvotant}&nbsp;&nbsp;</i>
     39                                        <br>
     40                                        <br>{'concours_usernote'|@translate} : <b>{$concours_note.usernote}</b>&nbsp;&nbsp;
     41                                </fieldset>
     42                                </td>
    2043                                {if $concours_note.rang > 3}
    2144                                <td>&nbsp;</td>
     
    2447                                {/if}
    2548                        </tr>
     49                <tr><td colspan="2"></td>
     50                <td ><hr></td>
     51                <td colspan="2"></td>
     52            </tr>
     53
    2654                {/foreach}
    2755
Note: See TracChangeset for help on using the changeset viewer.