/
MantisBugRelationshipData.class.php
155 lines (134 loc) · 3.29 KB
/
MantisBugRelationshipData.class.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* MantisBT - A PHP based bugtracking system
*
* MantisBT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* MantisBT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright Copyright 2002 MantisBT Team - mantisbt-dev@lists.sourceforge.net
*/
/**
* RelationshipData Structure Definition
* @package MantisBT
* @subpackage classes
*/
class MantisBugRelationshipData {
/**
* Relationship id
*/
protected $id;
/**
* Source Bug id
*/
protected $src_bug_id = null;
/**
* Destination Bug id
*/
protected $dest_bug_id = null;
/**
* Type
*/
protected $type = null;
/**
* Source project id
*/
protected $src_project_id;
/**
* Destination project id
*/
protected $dest_project_id;
/**
* Constructor
* @param int $p_id id
*/
function MantisBugRelationshipData( $p_id = 0 ) {
if( $p_id ) {
$this->id = intval($p_id);
}
}
/**
* overloaded function
* @private
* @param string $p_name property name
* @param string $p_value value
*/
public function __set($p_name, $p_value) {
switch ($p_name) {
// integer types
case 'id':
case 'src_bug_id':
case 'src_project_id':
case 'dest_bug_id':
case 'dest_project_id':
case 'type':
$p_value = (int)$p_value;
break;
}
$this->{$p_name} = $p_value;
}
/**
* overloaded function
* @private
* @param string $p_name property name
*/
public function __get($p_name) {
return $this->{$p_name};
}
/**
* overloaded function
* @private
* @param string $p_name property name
* @return bool
*/
public function __isset($p_name) {
return isset( $this->{$p_name} );
}
/**
* validate current object for database insert/update
* @throws MantisBT\Exception\Field\EmptyField
*/
function validate() {
if( $this->src_bug_id=== null || $this->dest_bug_id === null || $this->type === null ) {
throw new MantisBT\Exception\Field\EmptyField();
}
}
/**
* Insert a new bug into the database
* @return int integer representing the bug id that was created
* @access public
* @uses database_api.php
*/
function create() {
self::validate( true );
$query = "INSERT INTO {bug_relationship}
( source_bug_id, destination_bug_id, relationship_type )
VALUES
( %d,%d,%d)";
$result = db_query( $query, array( $this->src_bug_id, $this->dest_bug_id, $this->type ) );
$this->id = db_insert_id( '{bug_relationship}' );
return $this->id;
}
/**
* Update an object from the given data structure
* @return bool (always true)
* @access public
*/
function update() {
self::validate();
$query = "UPDATE {bug_relationship}
SET source_bug_id=%d, destination_bug_id=%d, relationship_type=%d
WHERE id=%d";
$result = db_query( $query, array( $this->src_bug_id, $this->dest_bug_id, $this->type, $this->id ) );
return true;
}
}