Passed
Pull Request — master (#18)
by Michael
02:59
created

Log   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 30
c 0
b 0
f 0
dl 0
loc 85
rs 10
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A hasVoted() 0 8 1
A getStaticLogHandler() 0 11 2
A deleteByOptionId() 0 9 1
A deleteByPollId() 0 8 1
1
<?php
2
3
namespace XoopsModules\Xoopspoll;
4
5
/*
6
               XOOPS - PHP Content Management System
7
                   Copyright (c) 2000-2020 XOOPS.org
8
                      <https://xoops.org>
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; either version 2 of the License, or
12
 (at your option) any later version.
13
14
 You may not change or alter any portion of this comment or credits
15
 of supporting developers from this source code or any supporting
16
 source code which is considered copyrighted (c) material of the
17
 original comment or credit authors.
18
19
 This program is distributed in the hope that it will be useful,
20
 but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 GNU General Public License for more details.
23
24
 You should have received a copy of the GNU General Public License
25
 along with this program; if not, write to the Free Software
26
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
27
*/
28
29
/**
30
 * Log class for the XoopsPoll Module
31
 *
32
 * @copyright ::  {@link https://xoops.org/ XOOPS Project}
33
 * @license   ::  {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
34
 * @package   ::  xoopspoll
35
 * @subpackage::  class
36
 * @since     ::  1.40
37
 * @author    ::  {@link http://www.myweb.ne.jp/ Kazumi Ono (AKA onokazu)}
38
 **/
39
40
use XoopsModules\Xoopspoll\{
41
    Helper
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, XoopsModules\Xoopspoll\Helper. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
42
};
43
44
45
46
/**
47
 * Log() class definition for Log Objects
48
 * @author:: zyspec <[email protected]>
49
 * @uses  ::   xoops_getModuleHandler poll module handler for class use
50
 */
51
class Log extends \XoopsObject
52
{
53
    //  class Log extends \XoopsObject {
54
    //    var $db;
55
56
    /**
57
     * Constructor
58
     * @param null $id
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $id is correct as it would always require null to be passed?
Loading history...
59
     */
60
    public function __construct($id = null)
61
    {
62
        parent::__construct();
63
        $this->initVar('log_id', \XOBJ_DTYPE_INT, 0);
64
        $this->initVar('poll_id', \XOBJ_DTYPE_INT, null, true);
65
        $this->initVar('option_id', \XOBJ_DTYPE_INT, null, true);
66
        $this->initVar('ip', \XOBJ_DTYPE_OTHER, null);
67
        $this->initVar('user_id', \XOBJ_DTYPE_INT, 0);
68
        $this->initVar('time', \XOBJ_DTYPE_INT, null);
69
        if (!empty($id) && \is_array($id)) {
70
            $this->assignVars($id);
71
        }
72
    }
73
74
75
    /**
76
     * The following method is provided for backward compatibility with newbb
77
     * @param int $pid
78
     * @return mixed
79
     * @deprecated since Xoopspoll 1.40, please use LogHandler & Log
80
     */
81
    public static function deleteByPollId($pid)
82
    {
83
        $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1);
84
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated since Xoopspoll 1.40, please use Log and LogHandler methods instead.' . " Called from {$trace[0]['file']}line {$trace[0]['line']}");
85
        $slogHandler = self::getStaticLogHandler();
86
        $criteria    = new \Criteria('poll_id', (int)$pid, '=');
87
88
        return $slogHandler->deleteAll($criteria);
89
    }
90
91
    /**
92
     * @param $opt_id
93
     * @return mixed
94
     */
95
    public static function deleteByOptionId($opt_id)
96
    {
97
        $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1);
98
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated since Xoopspoll 1.40, please use Log and LogHandler methods instead.' . " Called from {$trace[0]['file']}line {$trace[0]['line']}");
99
100
        $slogHandler = self::getStaticLogHandler();
101
        $criteria    = new \Criteria('option_id', (int)$opt_id, '=');
102
103
        return $slogHandler->deleteAll($criteria);
104
    }
105
106
    /**
107
     * @param $pid
108
     * @param $ip
109
     * @param $uid
110
     * @return mixed
111
     */
112
    public static function hasVoted($pid, $ip, $uid)
113
    {
114
        $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1);
115
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated since Xoopspoll 1.40, please use Log and LogHandler methods instead.' . " Called from {$trace[0]['file']}line {$trace[0]['line']}");
116
117
        $slogHandler = self::getStaticLogHandler();
118
119
        return $slogHandler->hasVoted($pid, $ip, $uid);
120
    }
121
122
    /**
123
     * @return bool
124
     */
125
    private static function getStaticLogHandler()
126
    {
127
        static $log_h;
128
        $trace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 1);
129
        $GLOBALS['xoopsLogger']->addDeprecated(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated since Xoopspoll 1.40, please use Log and LogHandler methods instead.' . " Called from {$trace[0]['file']}line {$trace[0]['line']}");
130
131
        if (!isset($log_h)) {
132
            $log_h = Helper::getInstance()->getHandler('Log');
133
        }
134
135
        return $log_h;
136
    }
137
138
    /**#@-*/
139
}
140