Brate   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
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: https://xoops.org                         //
25
// Project: Article Project                                                 //
26
// ------------------------------------------------------------------------ //
27
28
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
29
require_once __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
        {
44
            //            $this->ArtObject();
45
            $this->table = planet_DB_prefix('rate');
46
            $this->initVar('rate_id', XOBJ_DTYPE_INT, null, false);
47
            $this->initVar('art_id', XOBJ_DTYPE_INT, 0, true);
48
            $this->initVar('rate_uid', XOBJ_DTYPE_INT, 0);
49
            $this->initVar('rate_ip', XOBJ_DTYPE_INT, 0);
50
            $this->initVar('rate_rating', XOBJ_DTYPE_INT, 0, true);
51
            $this->initVar('rate_time', XOBJ_DTYPE_INT, 0, true);
52
        }
53
    }
54
endif;
55
56
PlanetUtility::planetParseClass('
57
class [CLASS_PREFIX]RateHandler extends XoopsPersistableObjectHandler
58
{
59
    /**
60
     * Constructor
61
     *
62
     * @param object $db reference to the {@link XoopsDatabase} object
63
     **/
64
    public function __construct(\XoopsDatabase $db) {
65
        parent::__construct($db, planet_DB_prefix("rate", true), "Brate", "rate_id");
66
    }
67
68
    public function &getByArticle($art_id, $criteria = null)
69
    {
70
        if (isset($criteria) && is_subclass_of($criteria, "criteriaelement")) {
71
            $criteria->add(new \Criteria("art_id", (int)($art_id)), "AND");
72
        } else {
73
            $criteria = new \CriteriaCompo(new \Criteria("art_id", (int)($art_id)));
74
        }
75
        $ret = $this->getAll($criteria);
76
77
        return $ret;
78
    }
79
80
    public function &getRatingByArticle($art_id, $criteria = null)
81
    {
82
        if (isset($criteria) && is_subclass_of($criteria, "criteriaelement")) {
83
            $criteria->add(new \Criteria("art_id", (int)($art_id)), "AND");
84
        } else {
85
            $criteria = new \CriteriaCompo(new \Criteria("art_id", (int)($art_id)));
86
        }
87
        $sql = "SELECT COUNT(*) AS rates, SUM(rate_rating) AS rating FROM " . planet_DB_prefix("rate");
88
        $sql .= " ".$criteria->renderWhere();
89
        if ($criteria->getSort() != "") {
90
            $sql .= " ORDER BY ".$criteria->getSort()." ".$criteria->getOrder();
91
        }
92
        $limit = $criteria->getLimit();
93
        $start = $criteria->getStart();
94
        $result = $this->db->query($sql, $limit, $start);
95
        $myrow = $this->db->fetchArray($result);
96
        $ret = array("rates"=>$myrow["rates"], "rating"=>$myrow["rating"]);
97
98
        return $ret;
99
    }
100
}
101
');
102