Changeset 4368 for extensions/ConcoursPhoto/include
- Timestamp:
- Nov 26, 2009, 12:57:43 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/ConcoursPhoto/include/Concours.class.php
r4260 r4368 163 163 `end_date`, 164 164 `category`, 165 `groups`) 165 `groups`, 166 `method` 167 ) 166 168 VALUES (".($concours_id !== NULL ? $concours_id : $this->concours_id).", now(), 167 169 \"".$this->concours_infos['name']."\", \"".$this->concours_infos['descr']."\", 168 170 \"".$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 );"; 170 174 if (pwg_query($query) != null) 171 175 return true; … … 191 195 end_date = \"".$this->concours_infos['end_date']."\", 192 196 category = ".$this->concours_infos['category'].", 193 groups = ".$this->concours_infos['groups']." 197 groups = ".$this->concours_infos['groups'].", 198 method = ".$this->concours_infos['method']." 199 194 200 WHERE id = ".($concours_id !== NULL ? $concours_id : $this->concours_id)." 195 201 ;"; … … 205 211 } 206 212 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 207 236 // delete concours from db (and all sub informations such as details, vote and result 208 237 function delete_concours($concours_id = null) … … 583 612 } 584 613 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 585 633 586 634 // After concours is completed (closed date is passed), generate the result and store it to DB … … 594 642 if ($this->is_closed($concours_id) AND ! $this->is_result_present($concours_id)) 595 643 { 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 596 648 $user_id = array(); 597 649 // vars not initialized … … 646 698 // update database and store result into RESULT table 647 699 // note = global note 700 $IMGmoyenne = 0; 648 701 foreach ($global_note as $id => $val) 702 // id contains the image id 649 703 { 650 $query = 'INSERT INTO ' . CONCOURS_RESULT_TABLE .'(`id_concours`, `img_id`, `date` , `note` ) 704 if ($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` ) 651 708 VALUES ('.($concours_id !== null ? $concours_id : $this->concours_id ) 652 709 .', '.$id 653 710 .', now() ' 654 711 .', '.$val 712 .', '.$IMGmoyenne 713 .', '.(isset($nbvotes[$id]) ? $nbvotes[$id] : 0) 655 714 .');'; 656 715 $result = pwg_query($query); … … 1221 1280 function generate_csv($concours_id = NULL) 1222 1281 { 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 1225 1287 // 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' 1227 1289 .' FROM ' .CONCOURS_RESULT_TABLE 1290 .' INNER JOIN ' . CONCOURS.' AS CONC on CONC.id = id_concours' 1228 1291 .' 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 .=';'; 1232 1300 1233 1301 $result = pwg_query($query); … … 1236 1304 while ($row = mysql_fetch_assoc($result)) 1237 1305 { 1238 $file .= $rang.', '1306 $file .= ($row['nbvotant'] != 0 ? $rang : 'N/A').', ' 1239 1307 .$row['id_concours'].', ' 1308 .$row['method'].', ' 1240 1309 .$row['img_id'].', ' 1241 1310 .$row['name'].', ' … … 1243 1312 .$row['date'].', ' 1244 1313 .$row['note'].', ' 1314 .$row['moyenne'].', ' 1315 .$row['nbvotant'].', ' 1245 1316 .($row['datas'] != null ? $row['datas'] : '') 1246 1317 ."\r\n"; … … 1306 1377 1307 1378 // 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," 1309 1380 .$users_criteria 1310 1381 ."\r\n"; 1311 1382 1312 1383 // 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 1314 1390 .' GROUP BY img_id ' 1315 1391 .';'; … … 1322 1398 $nbvotes[$row['img_id']] = $row['NBVOTE']; 1323 1399 } 1400 */ 1324 1401 /* 1325 1402 foreach ($nbvotes as $id=>$val) … … 1329 1406 */ 1330 1407 // 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' 1332 1411 .' FROM ' .CONCOURS_RESULT_TABLE 1412 .' INNER JOIN ' . CONCOURS_TABLE.' AS CONC on CONC.id = id_concours' 1333 1413 .' 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 1423 if ($this->debug) echo $query; 1338 1424 $result = pwg_query($query); 1339 // echo $query;1340 1425 // For each images 1341 1426 $rang = 1; 1342 1427 while ($row = mysql_fetch_assoc($result)) 1343 1428 { 1344 $file .= $rang.', '1429 $file .= ($row['nbvotant'] != 0 ? $rang : 'N/A').', ' 1345 1430 .$row['id_concours'].', ' 1431 .$row['method'].', ' 1346 1432 .str_replace(",", "",$this->concours_infos['name']).', ' 1347 1433 .$this->concours_infos['begin_date'].', ' … … 1354 1440 .$row['author'].', ' 1355 1441 .$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).', ' 1357 1445 .($row['datas'] != null ? $row['datas'] : '') 1358 1446 ; … … 1398 1486 $rang ++; 1399 1487 } 1400 //echo $file;1488 if ($this->debug) echo $file; 1401 1489 return $file; 1402 1490 … … 1433 1521 ;"; 1434 1522 pwg_query($query); 1435 //echo $query;1523 if ($this->debug) echo $query; 1436 1524 1437 1525 return $filename; … … 1446 1534 .' WHERE id_concours = '.($concours_id !== null ? $concours_id : $this->concours_id ) 1447 1535 .';'; 1448 $row = mysql_fetch_assoc(pwg_query($query)); 1449 if ($row) 1450 return $row['file_name']; 1451 else 1452 return false; 1453 1536 if ($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 } 1454 1546 } 1455 1547 … … 1602 1694 { 1603 1695 1604 global $page ;1696 global $page, $user; 1605 1697 $this->get_user_groups(); 1606 1698 … … 1638 1730 { 1639 1731 1640 foreach($tpl_var as $cle=>$valeur) { 1641 { 1642 $tpl_var[$cle]['NAME'] = $tpl_var[$cle]['NAME'].'<br> '.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> '.l10n('thumbnail_global_note').' : '.$this->get_img_globalnote_user($tpl_var[$cle]['ID'], $concours['id']); 1738 } 1644 1739 } 1645 1740 }
Note: See TracChangeset
for help on using the changeset viewer.