|
1
|
|
|
<?php |
|
2
|
|
|
// |
|
3
|
|
|
// ------------------------------------------------------------------------ // |
|
4
|
|
|
// This program is free software; you can redistribute it and/or modify // |
|
5
|
|
|
// it under the terms of the GNU General Public License as published by // |
|
6
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
|
7
|
|
|
// (at your option) any later version. // |
|
8
|
|
|
// // |
|
9
|
|
|
// You may not change or alter any portion of this comment or credits // |
|
10
|
|
|
// of supporting developers from this source code or any supporting // |
|
11
|
|
|
// source code which is considered copyrighted (c) material of the // |
|
12
|
|
|
// original comment or credit authors. // |
|
13
|
|
|
// // |
|
14
|
|
|
// This program is distributed in the hope that it will be useful, // |
|
15
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
16
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
17
|
|
|
// GNU General Public License for more details. // |
|
18
|
|
|
// // |
|
19
|
|
|
// You should have received a copy of the GNU General Public License // |
|
20
|
|
|
// along with this program; if not, write to the Free Software // |
|
21
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
|
22
|
|
|
// ------------------------------------------------------------------------ // |
|
23
|
|
|
// Author: phppp (D.J., [email protected]) // |
|
24
|
|
|
// URL: http://xoops.org // |
|
25
|
|
|
// Project: Article Project // |
|
26
|
|
|
// ------------------------------------------------------------------------ // |
|
27
|
|
|
|
|
28
|
|
|
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
|
|
|
|
|
|
29
|
|
|
include_once dirname(__DIR__) . '/include/vars.php'; |
|
30
|
|
|
mod_loadFunctions('', $GLOBALS['moddirname']); |
|
31
|
|
|
|
|
32
|
|
|
if (!class_exists('Brate')): |
|
33
|
|
|
/** |
|
34
|
|
|
* Class Brate |
|
35
|
|
|
*/ |
|
36
|
|
|
class Brate extends XoopsObject |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* Brate constructor. |
|
40
|
|
|
* @param null $id |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct($id = null) { |
|
43
|
|
|
// $this->ArtObject(); |
|
|
|
|
|
|
44
|
|
|
$this->table = planet_DB_prefix('rate'); |
|
45
|
|
|
$this->initVar('rate_id', XOBJ_DTYPE_INT, null, false); |
|
46
|
|
|
$this->initVar('art_id', XOBJ_DTYPE_INT, 0, true); |
|
47
|
|
|
$this->initVar('rate_uid', XOBJ_DTYPE_INT, 0); |
|
48
|
|
|
$this->initVar('rate_ip', XOBJ_DTYPE_INT, 0); |
|
49
|
|
|
$this->initVar('rate_rating', XOBJ_DTYPE_INT, 0, true); |
|
50
|
|
|
$this->initVar('rate_time', XOBJ_DTYPE_INT, 0, true); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
endif; |
|
54
|
|
|
|
|
55
|
|
|
planet_parse_class(' |
|
56
|
|
|
class [CLASS_PREFIX]RateHandler extends XoopsPersistableObjectHandler |
|
57
|
|
|
{ |
|
58
|
|
|
/** |
|
59
|
|
|
* Constructor |
|
60
|
|
|
* |
|
61
|
|
|
* @param object $db reference to the {@link XoopsDatabase} object |
|
62
|
|
|
**/ |
|
63
|
|
|
public function __construct(XoopsDatabase $db) { |
|
64
|
|
|
parent::__construct($db, planet_DB_prefix("rate", true), "Brate", "rate_id"); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function &getByArticle($art_id, $criteria = null) |
|
68
|
|
|
{ |
|
69
|
|
|
if (isset($criteria) && is_subclass_of($criteria, "criteriaelement")) { |
|
70
|
|
|
$criteria->add(new Criteria("art_id", (int)($art_id)), "AND"); |
|
71
|
|
|
} else { |
|
72
|
|
|
$criteria = new CriteriaCompo(new Criteria("art_id", (int)($art_id))); |
|
73
|
|
|
} |
|
74
|
|
|
$ret = $this->getAll($criteria); |
|
75
|
|
|
|
|
76
|
|
|
return $ret; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function &getRatingByArticle($art_id, $criteria = null) |
|
80
|
|
|
{ |
|
81
|
|
|
if (isset($criteria) && is_subclass_of($criteria, "criteriaelement")) { |
|
82
|
|
|
$criteria->add(new Criteria("art_id", (int)($art_id)), "AND"); |
|
83
|
|
|
} else { |
|
84
|
|
|
$criteria = new CriteriaCompo(new Criteria("art_id", (int)($art_id))); |
|
85
|
|
|
} |
|
86
|
|
|
$sql = "SELECT COUNT(*) AS rates, SUM(rate_rating) AS rating FROM " . planet_DB_prefix("rate"); |
|
87
|
|
|
$sql .= " ".$criteria->renderWhere(); |
|
88
|
|
|
if ($criteria->getSort() != "") { |
|
89
|
|
|
$sql .= " ORDER BY ".$criteria->getSort()." ".$criteria->getOrder(); |
|
90
|
|
|
} |
|
91
|
|
|
$limit = $criteria->getLimit(); |
|
92
|
|
|
$start = $criteria->getStart(); |
|
93
|
|
|
$result = $this->db->query($sql, $limit, $start); |
|
94
|
|
|
$myrow = $this->db->fetchArray($result); |
|
95
|
|
|
$ret = array("rates"=>$myrow["rates"], "rating"=>$myrow["rating"]); |
|
96
|
|
|
|
|
97
|
|
|
return $ret; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
'); |
|
101
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.