/
rateitlog.php
executable file
·71 lines (65 loc) · 1.66 KB
/
rateitlog.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
class RateItLog extends QueryRecord
{
public static function default_fields()
{
return array(
'id' => 0,
'post_id' => 0,
'rating' => 0,
'ip' => 0,
'timestamp' => date( 'Y-m-d H:i:s' ),
);
}
/**
* constructer
*
* @access public
*/
public function __construct( $paramarray = array() )
{
if ( isset( $paramarray['ip'] ) ) {
$paramarray['ip']= sprintf( '%u', ip2long( $paramarray['ip'] ) );
}
// Defaults
$this->fields = array_merge( self::default_fields(), $this->fields );
parent::__construct( $paramarray );
$this->exclude_fields( 'id' );
}
/**
* insert
*
* @access public
* @return boolean
*/
public function insert()
{
$result = parent::insertRecord( DB::table( 'rateit_log' ) );
$this->newfields['id'] = DB::last_insert_id(); // Make sure the id is set in the comment object to match the row id
$this->fields = array_merge($this->fields, $this->newfields);
$this->newfields = array();
return $result;
}
public function __set( $name, $value )
{
switch( $name ) {
case 'ip':
$this->ip = sprintf( '%u', ip2long( $value ) );
break;
}
return parent::__set( $name, $value );
}
public function __get( $name )
{
switch($name) {
case 'ip':
$out = long2ip( parent::__get( $name ) );
break;
default:
$out = parent::__get( $name );
break;
}
return $out;
}
}
?>