source: trunk/admin/rating.php @ 27558

Last change on this file since 27558 was 26900, checked in by rvelices, 11 years ago

admin rating user improvements

  • add last rate date for user
  • add consensus deviation but only based on the best rated photos (e.g. how much this user tries to change the best rated photos)
  • Property svn:eol-style set to LF
File size: 7.1 KB
RevLine 
[1056]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[26461]5// | Copyright(C) 2008-2014 Piwigo Team                  http://piwigo.org |
[2297]6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
[1056]23
24if (!defined('PHPWG_ROOT_PATH'))
25{
26  die ("Hacking attempt!");
27}
28
[1072]29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
[1056]30
31// +-----------------------------------------------------------------------+
[1072]32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
34check_status(ACCESS_ADMINISTRATOR);
35
[12624]36
37include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
38$tabsheet = new tabsheet();
[16925]39$tabsheet->set_id('rating');
[12624]40$tabsheet->select('rating');
41$tabsheet->assign();
42
[1072]43// +-----------------------------------------------------------------------+
[1056]44// |                            initialization                             |
45// +-----------------------------------------------------------------------+
46if (isset($_GET['start']) and is_numeric($_GET['start']))
47{
48  $start = $_GET['start'];
49}
50else
51{
52  $start = 0;
53}
54
55$elements_per_page=10;
56if (isset($_GET['display']) and is_numeric($_GET['display']))
57{
58  $elements_per_page = $_GET['display'];
59}
60
61$order_by_index=0;
62if (isset($_GET['order_by']) and is_numeric($_GET['order_by']))
63{
64  $order_by_index = $_GET['order_by'];
65}
66
[1211]67$page['user_filter'] = '';
68if (isset($_GET['users']))
[1056]69{
[1211]70  if ($_GET['users'] == 'user')
[1056]71  {
[1211]72    $page['user_filter'] = ' AND r.user_id <> '.$conf['guest_id'];
[1056]73  }
[1211]74  elseif ($_GET['users'] == 'guest')
[1056]75  {
[1211]76    $page['user_filter'] = ' AND r.user_id = '.$conf['guest_id'];
[1056]77  }
78}
79
80$users = array();
81$query = '
82SELECT '.$conf['user_fields']['username'].' as username, '.$conf['user_fields']['id'].' as id
83  FROM '.USERS_TABLE.'
84;';
85$result = pwg_query($query);
[4325]86while ($row = pwg_db_fetch_assoc($result))
[1056]87{
[4304]88  $users[$row['id']]=stripslashes($row['username']);
[1056]89}
90
91
[11827]92$query = 'SELECT COUNT(DISTINCT(r.element_id))
93FROM '.RATE_TABLE.' AS r
94WHERE 1=1'. $page['user_filter'];
[4325]95list($nb_images) = pwg_db_fetch_row(pwg_query($query));
[1056]96
97
98// +-----------------------------------------------------------------------+
99// |                             template init                             |
100// +-----------------------------------------------------------------------+
101
[2530]102$template->set_filename('rating', 'rating.tpl');
[1056]103
[2223]104$template->assign(
[1084]105  array(
[3172]106    'navbar' => create_navigation_bar(
[1084]107      PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start','del')),
108      $nb_images,
109      $start,
[1090]110      $elements_per_page
[2223]111      ),
[1056]112    'F_ACTION' => PHPWG_ROOT_PATH.'admin.php',
113    'DISPLAY' => $elements_per_page,
[2223]114    'NB_ELEMENTS' => $nb_images,
[1056]115    )
116  );
117
[2223]118
119
[1056]120$available_order_by= array(
121    array(l10n('Rate date'), 'recently_rated DESC'),
[12528]122    array(l10n('Rating score'), 'score DESC'),
[11827]123    array(l10n('Average rate'), 'avg_rates DESC'),
[1059]124    array(l10n('Number of rates'), 'nb_rates DESC'),
125    array(l10n('Sum of rates'), 'sum_rates DESC'),
126    array(l10n('File name'), 'file DESC'),
[1056]127    array(l10n('Creation date'), 'date_creation DESC'),
[1059]128    array(l10n('Post date'), 'date_available DESC'),
[1056]129  );
130
131for ($i=0; $i<count($available_order_by); $i++)
132{
[2223]133  $template->append(
134    'order_by_options',
135    $available_order_by[$i][0]
[1056]136    );
137}
[2223]138$template->assign('order_by_options_selected', array($order_by_index) );
[1056]139
[2223]140
[1211]141$user_options = array(
[2223]142  'all'   => l10n('all'),
143  'user'  => l10n('Users'),
144  'guest' => l10n('Guests'),
[1211]145  );
146
[2223]147$template->assign('user_options', $user_options );
148$template->assign('user_options_selected', array(@$_GET['users']) );
[1211]149
[2223]150
[1064]151$query = '
152SELECT i.id,
[12528]153    i.path,
154    i.file,
[12797]155    i.representative_ext,
[12528]156    i.rating_score       AS score,
157    MAX(r.date)          AS recently_rated,
158    ROUND(AVG(r.rate),2) AS avg_rates,
159    COUNT(r.rate)        AS nb_rates,
160    SUM(r.rate)          AS sum_rates
[1064]161  FROM '.RATE_TABLE.' AS r
162    LEFT JOIN '.IMAGES_TABLE.' AS i ON r.element_id = i.id
[1211]163  WHERE 1 = 1 ' . $page['user_filter'] . '
[6607]164  GROUP BY i.id,
165        i.path,
166        i.file,
[12796]167        i.representative_ext,
[11893]168        i.rating_score,
[6607]169        r.element_id
[1064]170  ORDER BY ' . $available_order_by[$order_by_index][1] .'
[4334]171  LIMIT '.$elements_per_page.' OFFSET '.$start.'
[1064]172;';
[1056]173
174$images = array();
175$result = pwg_query($query);
[4325]176while ($row = pwg_db_fetch_assoc($result))
[1056]177{
[25018]178  $images[] = $row;
[1056]179}
180
[2223]181$template->assign( 'images', array() );
[1056]182foreach ($images as $image)
183{
[12796]184  $thumbnail_src = DerivativeImage::thumb_url($image);
[1056]185
[13077]186  $image_url = get_root_url().'admin.php?page=photo-'.$image['id'];
[1059]187
[1056]188  $query = 'SELECT *
189FROM '.RATE_TABLE.' AS r
190WHERE r.element_id='.$image['id'] . '
191ORDER BY date DESC;';
192  $result = pwg_query($query);
[4325]193  $nb_rates = pwg_db_num_rows($result);
[1056]194
[2223]195  $tpl_image = 
[26837]196    array(
197      'id' => $image['id'],
198      'U_THUMB' => $thumbnail_src,
199      'U_URL' => $image_url,
200      'SCORE_RATE' => $image['score'],
[11827]201       'AVG_RATE' => $image['avg_rates'],
[1056]202       'SUM_RATE' => $image['sum_rates'],
[2223]203       'NB_RATES' => (int)$image['nb_rates'],
204       'NB_RATES_TOTAL' => (int)$nb_rates,
[1056]205       'FILE' => $image['file'],
[2223]206       'rates'  => array()
[1056]207   );
208
[4325]209  while ($row = pwg_db_fetch_assoc($result))
[1056]210  {
211    if ( isset($users[$row['user_id']]) )
212    {
[2475]213      $user_rate = $users[$row['user_id']];
[1056]214    }
215    else
216    {
[2475]217      $user_rate = '? '. $row['user_id'];
[1056]218    }
219    if ( strlen($row['anonymous_id'])>0 )
220    {
[2475]221      $user_rate .= '('.$row['anonymous_id'].')';
[1056]222    }
[1059]223
[26837]224    $row['USER'] = $user_rate;
225    $tpl_image['rates'][] = $row;
[1056]226  }
[2223]227  $template->append( 'images', $tpl_image );
[1056]228}
[2223]229
[1056]230// +-----------------------------------------------------------------------+
231// |                           sending html code                           |
232// +-----------------------------------------------------------------------+
233$template->assign_var_from_handle('ADMIN_CONTENT', 'rating');
[6402]234?>
Note: See TracBrowser for help on using the repository browser.