1
|
|
|
<?php |
|
|
|
|
2
|
|
|
// ------------------------------------------------------------------------ // |
3
|
|
|
// BOOKSHOP - MODULE FOR XOOPS 2 // |
4
|
|
|
// Copyright (c) 2007, 2008 Instant Zero // |
5
|
|
|
// <http://www.instant-zero.com/> // |
6
|
|
|
// ------------------------------------------------------------------------- // |
7
|
|
|
// This program is free software; you can redistribute it and/or modify // |
8
|
|
|
// it under the terms of the GNU General Public License as published by // |
9
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
10
|
|
|
// (at your option) any later version. // |
11
|
|
|
// // |
12
|
|
|
// You may not change or alter any portion of this comment or credits // |
13
|
|
|
// of supporting developers from this source code or any supporting // |
14
|
|
|
// source code which is considered copyrighted (c) material of the // |
15
|
|
|
// original comment or credit authors. // |
16
|
|
|
// // |
17
|
|
|
// This program is distributed in the hope that it will be useful, // |
18
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
19
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
20
|
|
|
// GNU General Public License for more details. // |
21
|
|
|
// // |
22
|
|
|
// You should have received a copy of the GNU General Public License // |
23
|
|
|
// along with this program; if not, write to the Free Software // |
24
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
25
|
|
|
// ------------------------------------------------------------------------ // |
26
|
|
|
|
27
|
|
|
defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
28
|
|
|
|
29
|
|
|
include_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
30
|
|
|
if (!class_exists('Bookshop_XoopsPersistableObjectHandler')) { |
31
|
|
|
include_once XOOPS_ROOT_PATH . '/modules/bookshop/class/PersistableObjectHandler.php'; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Class bookshop_votedata |
36
|
|
|
*/ |
37
|
|
View Code Duplication |
class bookshop_votedata extends Bookshop_Object |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
public function __construct() |
40
|
|
|
{ |
41
|
|
|
$this->initVar('vote_ratingid', XOBJ_DTYPE_INT, null, false); |
42
|
|
|
$this->initVar('vote_book_id', XOBJ_DTYPE_INT, null, false); |
43
|
|
|
$this->initVar('vote_uid', XOBJ_DTYPE_INT, null, false); |
44
|
|
|
$this->initVar('vote_rating', XOBJ_DTYPE_INT, null, false); |
45
|
|
|
$this->initVar('vote_ratinghostname', XOBJ_DTYPE_TXTBOX, null, false); |
46
|
|
|
$this->initVar('vote_ratingtimestamp', XOBJ_DTYPE_INT, null, false); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Class BookshopBookshop_votedataHandler |
52
|
|
|
*/ |
53
|
|
|
class BookshopBookshop_votedataHandler extends Bookshop_XoopsPersistableObjectHandler |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
/** |
56
|
|
|
* @param $db |
57
|
|
|
*/ |
58
|
|
|
public function __construct($db) |
59
|
|
|
{ // Table Classe Id |
60
|
|
|
parent::__construct($db, 'bookshop_votedata', 'bookshop_votedata', 'vote_ratingid'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Renvoie le nombre total de votes pour un livre ainsi que la sommes des votes |
65
|
|
|
* |
66
|
|
|
* @param integer $book_id Identifiant du livre |
67
|
|
|
* @param integer $totalVotes Variable passée par référence et devant contenir le nombre total de votes du livre |
68
|
|
|
* @param integer $sumRating Variable passée par référence et devant contenir le cumul des votes |
69
|
|
|
* @return none Rien |
|
|
|
|
70
|
|
|
*/ |
71
|
|
View Code Duplication |
public function getCountRecordSumRating($book_id, &$totalVotes, &$sumRating) |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
$sql = 'SELECT count( * ) AS cpt, sum( vote_rating ) AS sum_rating FROM ' . $this->table . ' WHERE vote_book_id = ' . (int)$book_id; |
74
|
|
|
$result = $this->db->query($sql); |
75
|
|
|
if (!$result) { |
76
|
|
|
return 0; |
77
|
|
|
} else { |
78
|
|
|
$myrow = $this->db->fetchArray($result); |
79
|
|
|
$totalVotes = $myrow['cpt']; |
80
|
|
|
$sumRating = $myrow['sum_rating']; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Returns the (x) last votes |
86
|
|
|
* |
87
|
|
|
* @param integer $start Starting position |
88
|
|
|
* @param integer $limit count of items to return |
89
|
|
|
* @return array Array of votedata objects |
90
|
|
|
*/ |
91
|
|
|
public function getLastVotes($start = 0, $limit = 0) |
92
|
|
|
{ |
93
|
|
|
$tbl_datas = array(); |
94
|
|
|
$criteria = new Criteria('vote_ratingid', 0, '<>'); |
95
|
|
|
$criteria->setLimit($limit); |
96
|
|
|
$criteria->setStart($start); |
97
|
|
|
$criteria->setSort('vote_ratingtimestamp'); |
98
|
|
|
$criteria->setOrder('DESC'); |
99
|
|
|
$tbl_datas =& $this->getObjects($criteria, true); |
100
|
|
|
|
101
|
|
|
return $tbl_datas; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.