[ Index ] |
PHP Cross Reference of Yamoon 0.9.0 |
[Summary view] [Print] [Text view]
1 <?php 2 3 require_once ('Config.php'); 4 require_once ('Probe.php'); 5 6 /** 7 * Company.php - manage company creation, update and deletes. 8 */ 9 10 class Company { 11 var $config; 12 13 var $name; 14 var $contact; 15 16 /** 17 * Company Constructor 18 * $company = new Company($config, $id); 19 * 20 * param $config Configuration class 21 * param $id When provided, grab all info for that company 22 */ 23 function Company ($config, $id="") { 24 $this->config = $config; 25 if ($id > 0) { 26 $this->id = $id; 27 $rows = $this->config->select("select id, name, contact from companies where id = ?", $id); 28 if (isset($rows[0]) && $rows[0]->id > 0) { 29 $this->name = $rows[0]->name; 30 $this->contact = $rows[0]->contact; 31 } else { 32 error_log("Company not found"); 33 return false; 34 } 35 } 36 return true; 37 } 38 39 /** 40 * Get all probes of this company. 41 * 42 * $probeList = $company->getProbes(); 43 * return $probeList A list of all probes of this company 44 */ 45 function getProbes () { 46 $list = array(); 47 $rows = $this->config->select("select id from probes where company_id = ?", $this->id); 48 if (isset($rows[0]) && $rows[0]->id > 0) { 49 foreach ($rows as $item) 50 array_push($list, new Probe($this->config, $item->id)); 51 } 52 return $list; 53 } 54 55 /** 56 * Get all hosts of this company. 57 * 58 * $probeList = $company->getHosts(); 59 * return $hostList A list of all hosts of this company 60 */ 61 function getHosts () { 62 $list = array(); 63 $rows = $this->config->select("select id from hosts where company_id = ?", $this->id); 64 if (isset($rows[0]) && $rows[0]->id > 0) { 65 foreach ($rows as $item) 66 array_push($list, new Host($this->config, $item->id)); 67 } 68 return $list; 69 } 70 71 /** 72 * Create a new company if there's no host with that name yet. 73 * Construct object first. 74 * $host->create("my company", "myserver.mycompany.com", "127.0.0.1"); 75 * 76 * param $company_id The company this host is part 77 * param $name The hostname 78 * param $ip Its IP, if not provided try to check it 79 * return $id Newly created company's ID 80 */ 81 function create ($name, $contact="") { 82 if ($this->config->select("select id from companies where name = ?", $name)) 83 return false; 84 else { 85 $values = array($name, $contact); 86 $this->config->query("insert into companies values (NULL, ?, ?)", $values); 87 $rows = $this->config->select("select last_insert_id() as id"); 88 $this->id = $rows[0]->id; 89 $this->name = $name; 90 $this->contact = $contact; 91 return $this->id; 92 } 93 } 94 95 /** 96 * Update the current company on the database using the current parameters. 97 * $company->name = "changedname.mycompany.com"; 98 * $company->update() 99 */ 100 function update () { 101 $values = array( $this->name, $this->contact, $this->id ); 102 return $this->config->query("update companies set name = ?, contact = ? where id = ?", $values); 103 } 104 105 /** 106 * Delete the current company and it's probes and hosts. 107 * $company->delete(); 108 */ 109 function delete () { 110 $values = array( $this->id ); 111 $this->config->query("delete from companies where id = ?", $values); 112 foreach ($this->getProbes() as $probe) 113 $probe->delete(); 114 foreach ($this->getHosts() as $host) 115 $host->delete(); 116 } 117 118 /** 119 * Clone the current company and all it's probes and hosts. 120 * $company = new Company($config, $id); 121 * $newCompany = $company->clone(); 122 */ 123 function clone () { 124 $newCompany = new Company($this->config); 125 $newCompany->create($company->name.'-clone', $company->contact); 126 foreach ($this->getProbes() as $probe) { 127 $host = new Host($config); 128 $host->create($this->id, $probe->host->name, $probe->host->ip); 129 $probe = new Probe($config); 130 $probe->create($this->id, $probe->service->id, $host->id); 131 } 132 return $newCompany; 133 } 134 135 /** 136 * Dumper. 137 * $company->dump(); 138 */ 139 function dump () { 140 print "\n################################ Company ".$this->name."'s Dump\n"; 141 print "##\tContact: $this->contact\n"; 142 print "##\tProbes:\n"; 143 foreach ($this->getProbes() as $probe) { 144 $probe->dump(); 145 } 146 print "\n##\tHosts:\n"; 147 foreach ($this->getHosts() as $host) { 148 $host->dump(); 149 } 150 print "\n######### End of company ".$this->name."'s Dump\n"; 151 } 152 } 153 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sat Feb 19 17:29:53 2005 | Cross-referenced by PHPXref 0.6 |