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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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            }
Note: See TracChangeset for help on using the changeset viewer.