[ 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 ('Language.php'); 5 6 /** 7 * Service.php - manage service creation, update and deletes. 8 */ 9 10 class Service { 11 var $config; 12 13 var $id; 14 var $name; 15 var $code; 16 var $result; 17 var $quality; 18 var $language; 19 20 /** 21 * Service Constructor 22 * $service = new Service($config, $id); 23 * 24 * param $config Configuration class 25 * param $id When provided, grab all info for that service 26 */ 27 function Service ($config, $id="") { 28 $this->config = $config; 29 if ($id > 0) { 30 $this->id = $id; 31 $rows = $this->config->select("select id, name, code, result, quality, language from services where id = ?", $id); 32 if (isset($rows[0]) && $rows[0]->id > 0) { 33 $this->name = $rows[0]->name; 34 $this->code = $rows[0]->code; 35 $this->result = $rows[0]->result; 36 $this->quality = $rows[0]->quality; 37 $this->language = new Language($this->config, $rows[0]->language); 38 } else { 39 error_log("Service not found"); 40 return false; 41 } 42 } 43 return true; 44 } 45 46 /** 47 * Create a new service if there's no service with that name yet. 48 * Construct object first. 49 * $service->create(); 50 * 51 * param $name The service name 52 * param $language The language ID it's service uses 53 * param $code The code to run 54 * param $result The result regular expression, if match status is UP, else is DOWN 55 * param $quality The quality regular expression, the first match will be the quality 56 * return $id Newly created service's ID 57 */ 58 function create ($name, $language, $code, $result="", $quality="") { 59 if ($this->config->select("select id from services where name = ?", $name)) 60 return false; 61 else { 62 $values = array($name, $code, $result, $quality, $language); 63 $this->config->query("insert into services values (NULL, ?, ?, ?, ?, ?)", $values); 64 $rows = $this->config->select("select last_insert_id() as id"); 65 $this->id = $rows[0]->id; 66 $this->name = $name; 67 $this->language = new Language($this->config, $language); 68 $this->code = $code; 69 $this->result = $result; 70 $this->quality = $quality; 71 return $this->id; 72 } 73 } 74 75 /** 76 * Update the current service on the database using the current parameters. 77 * $service->name = "new service's name"; 78 * $service->update() 79 */ 80 function update () { 81 $values = array( $this->name, $this->code, $this->result, $this->quality, $this->language, $this->id ); 82 return $this->config->query("update services set name = ?, code = ?, result = ?, quality = ?, language = ? where id = ?", $values); 83 } 84 85 /** 86 * Delete the current service IF and only IF there's no probe using it. 87 * $service->delete(); 88 */ 89 function delete () { 90 $values = array( $this->id ); 91 if ($this->config->select("select id from probes where service_id = ?", $values)) 92 return null; 93 return $this->config->query("delete from services where id = ?", $values); 94 } 95 96 /** 97 * Dumper. 98 * $service->dump(); 99 */ 100 function dump () { 101 print "\t\t* Service: $this->name\n"; 102 print "\t\t Code: $this->code\n"; 103 print "\t\t Result: $this->result\n"; 104 print "\t\t Quality: $this->quality\n"; 105 print "\t\t Delay: $this->delay\n"; 106 $this->language->dump(); 107 } 108 } 109 ?>
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 |