1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* // @todo could probably extend ModuleHandler, and therefore not need the |
4
|
|
|
* constant pointing to the modules. |
5
|
|
|
@package Intraface_IntranetMaintenance |
6
|
|
|
*/ |
7
|
|
|
class ModuleMaintenance |
8
|
|
|
{ |
9
|
|
|
private $id; |
10
|
|
|
private $db; |
11
|
|
|
private $value; |
12
|
|
|
public $error; |
13
|
|
|
private $sub_access; |
14
|
|
|
|
15
|
22 |
|
public function __construct($id = 0) |
16
|
|
|
{ |
17
|
22 |
|
$this->id = intval($id); |
18
|
22 |
|
$this->db = MDB2::singleton(DB_DSN); |
19
|
22 |
|
if (PEAR::isError($this->db)) { |
20
|
|
|
throw new Exception("Error in creating db: ".$this->db->getUserInfo()); |
21
|
|
|
} |
22
|
|
|
|
23
|
22 |
|
$this->error = new Intraface_Error; |
24
|
22 |
|
$this->value = array(); |
25
|
|
|
|
26
|
22 |
|
$this->load(); |
27
|
22 |
|
} |
28
|
|
|
|
29
|
1 |
|
static function factory($name) |
30
|
|
|
{ |
31
|
1 |
|
$gateway = new Intraface_ModuleGateway(MDB2::singleton(DB_DSN)); |
32
|
1 |
|
return $gateway->findByName($name); |
33
|
|
|
} |
34
|
|
|
|
35
|
22 |
|
private function load() |
36
|
|
|
{ |
37
|
|
|
// Starter med at nustille |
38
|
22 |
|
$this->value = array(); |
39
|
22 |
|
$this->sub_access; |
40
|
22 |
|
if ($this->id != 0) { |
41
|
1 |
|
$result = $this->db->query("SELECT * FROM module WHERE id = ".$this->id); |
42
|
1 |
|
if (PEAR::isError($result)) { |
43
|
|
|
throw new Exception("Error in query: ".$result->getUserInfo()); |
44
|
|
|
} |
45
|
|
|
|
46
|
1 |
|
if ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) { |
47
|
1 |
|
$this->value = $row; |
48
|
|
|
|
49
|
|
|
// $this->sub_access = new SubAccessMaintenance($this); |
|
|
|
|
50
|
|
|
|
51
|
1 |
|
$j = 0; |
|
|
|
|
52
|
1 |
|
$result_sub_access = $this->db->query("SELECT id, name, description FROM module_sub_access WHERE active = 1 AND module_id = ".$row["id"]." ORDER BY description"); |
53
|
1 |
|
if (PEAR::isError($result_sub_access)) { |
54
|
|
|
throw new Exception("Error in query: ".$result_sub_access->getUserInfo()); |
55
|
|
|
} |
56
|
1 |
|
$i = 0; |
57
|
1 |
|
$this->value["sub_access"] = array(); |
58
|
1 |
|
while ($row = $result_sub_access->fetchRow(MDB2_FETCHMODE_ASSOC)) { |
59
|
1 |
|
$this->value["sub_access"][$i] = $row; |
60
|
1 |
|
$i++; |
61
|
1 |
|
} |
62
|
1 |
|
} |
63
|
1 |
|
} |
64
|
22 |
|
} |
65
|
|
|
|
66
|
1 |
|
public function registerModule($module_name) |
67
|
|
|
{ |
68
|
1 |
|
$gateway = new Intraface_ModuleGateway(MDB2::singleton(DB_DSN)); |
69
|
1 |
|
return $gateway->registerByName($module_name); |
70
|
|
|
} |
71
|
|
|
|
72
|
19 |
|
public function register() |
73
|
|
|
{ |
74
|
19 |
|
$gateway = new Intraface_ModuleGateway(MDB2::singleton(DB_DSN)); |
75
|
19 |
|
return $gateway->registerAll(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function get($key = '') |
79
|
|
|
{ |
80
|
|
|
if (!empty($key)) { |
81
|
|
|
return($this->value[$key]); |
82
|
|
|
} else { |
83
|
|
|
return $this->value; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
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.