From 3d7f906daeb8fa19c944ef1059084625aadd2c25 Mon Sep 17 00:00:00 2001 From: Mark Dintelman Date: Thu, 13 Mar 2014 21:21:53 -0500 Subject: [PATCH 01/11] tb2 --- App/ta2.php | 224 ++++++++++++++++++++++++++++++++++++++++++++ App/ta2test.php | 36 +++++++ Config/database.sql | 10 ++ 3 files changed, 270 insertions(+) create mode 100644 App/ta2.php create mode 100644 App/ta2test.php diff --git a/App/ta2.php b/App/ta2.php new file mode 100644 index 0000000..3a77eb0 --- /dev/null +++ b/App/ta2.php @@ -0,0 +1,224 @@ +"; + $this->db = new \mysqli(\WCS\Config::$dbhost,\WCS\Config::$dbuser,\WCS\Config::$dbpassword,\WCS\Config::$dbdatabase); + if($this->db===NULL){ + die("Error unable to connect to database"); + } + } + + function __destruct() { + if($this->db!=NULL){ + $this->db->close(); + } + } + + public function SetID($ID){ + if(preg_match('/^[0-9]+$/', $ID)){ + $this->workerID=$ID; + RETURN TRUE; + } + RETURN FALSE; + } + + function SetName($name){ + if(preg_match('/^\s*$/',$name)){ + return FALSE; + } + $this->name=$name; + return TRUE; + } + + public function SetSubcell($subcell){ + if(preg_match('/^[0-9]+$/', $subcell)){ + $this->subcell=$subcell; + RETURN TRUE; + } + RETURN FALSE; + } + + public function SetRate($rate){ + if(preg_match('/^[0-9]+$/', $rate)){ + $this->rate=$rate; + RETURN TRUE; + } + RETURN FALSE; + } + public function insert(){ + $stmt=$this->db->prepare("INSERT INTO Workers (workerID,name,subcell,rate) VALUES (?,?,?,?)"); + if($stmt===FALSE){ + error_log("WCS/Workers.insert> stmt:".$this->db->error); + return FALSE; + } + if($stmt->bind_param('isid',$this->workerID,$this->name,$this->subcell,$this->rate)===FALSE){ + error_log("WCS/Workers.insert> bind_param:".$this->db->error); + return FALSE; + } + if($stmt->execute()===FALSE){ + if($this->db->errno==1062){ // Duplicate. + return FALSE; + } + error_log("WCS/Workers.insert> execute:".$this->db->errno." ".$this->db->error); + return FALSE; + } + return TRUE; + } + + public function delete(){ + $stmt=$this->db->prepare("DELETE FROM Workers Where workerID=?"); + if ($stmt===FALSE){ + error_log("WCS/Workers.delete> stmt:" . $this->db->error); + return FALSE; + } + if($stmt->bind_param('i', $this->workerID)===FALSE){ + error_log("WCS/Workers.delete> bind_param:".$this->db->error); + return FALSE; + } + if ($stmt->execute()===FALSE){ + error_log("WCS/Workers.delete> execute:".$this->db->errno." ".$this->db->error); + return FALSE; + } + return TRUE; + } +public function getworkerID() { + $stmt=$this->db->prepare("SELECT DISTINCT workerID FROM Workers ORDER BY workerID"); + if($stmt===FALSE){ + die("prepare error ".$this->db->error); + } + if($stmt->bind_result($ID)===FALSE){ + die("bind error ".$this->db->error); + } + if($stmt->execute()===FALSE){ + die("execute error ".$this->db->error); + } + $workerID=array(); + while($stmt->fetch()){ + $workerID[]=$ID; + + } + return $workerID; + + + } + + public function getname() { + $stmt=$this->db->prepare("SELECT DISTINCT name FROM Workers ORDER BY name"); + if($stmt===FALSE){ + die("prepare error ".$this->db->error); + } + if($stmt->bind_result($name)===FALSE){ + die("bind error ".$this->db->error); + } + if($stmt->execute()===FALSE){ + die("execute error ".$this->db->error); + } + $names=array(); + while($stmt->fetch()){ + $names[]=$name; + + } + return $names; + + + } + + public function getsubcell() { + $stmt=$this->db->prepare("SELECT DISTINCT subcell FROM Workers ORDER BY subcell"); + if($stmt===FALSE){ + die("prepare error ".$this->db->error); + } + if($stmt->bind_result($subcell)===FALSE){ + die("bind error ".$this->db->error); + } + if($stmt->execute()===FALSE){ + die("execute error ".$this->db->error); + } + $subcells=array(); + while($stmt->fetch()){ + $subcells[]=$subcell; + + } + return $subcells; + + + } + public function getrate() { + $stmt=$this->db->prepare("SELECT DISTINCT rate FROM Workers ORDER BY rate"); + if($stmt===FALSE){ + die("prepare error ".$this->db->error); + } + if($stmt->bind_result($rate)===FALSE){ + die("bind error ".$this->db->error); + } + if($stmt->execute()===FALSE){ + die("execute error ".$this->db->error); + } + $rates=array(); + while($stmt->fetch()){ + $rates[]=$rate; + + } + return $rates; + + + } +} + + +$t= new Workers(); +$t->SetID("102"); +$t->SetName("Mark Dintelman"); +$t->SetSubcell("10"); +$t->SetRate("9"); +$t->insert(); +$t->delete(); +$t->insert(); +$t->getworkerID(); + +$t1= new Workers(); +$t1->SetID("102"); +$t1->SetName("Mark Dintelman"); +$t1->SetSubcell("11"); +$t1->SetRate("5"); +$t1->insert(); +$t1->delete(); +$t1->insert(); +$t1->getworkerID(); + +$tt= new Workers(); +$tt->SetID("103"); +$tt->SetName("Max Smith"); +$tt->SetSubcell("11"); +$tt->SetRate("10"); +$tt->insert(); +$tt->delete(); +$tt->insert(); +$tt->getworkerID(); + +$c= new Workers(); +foreach($c->getworkerID() as $id) + echo $id; +foreach($c->getname() as $name) + echo $name; +foreach($c->getsubcell() as $sub) + echo $sub; +foreach($c->getrate() as $r) + echo $r; + + + +?> + diff --git a/App/ta2test.php b/App/ta2test.php new file mode 100644 index 0000000..293a022 --- /dev/null +++ b/App/ta2test.php @@ -0,0 +1,36 @@ +assertTrue($w->SetID("102")); + $this->assertFalse($w->SetID("MARK")); + $this->assertFalse($w->SetName(" ")); + $this->assertTrue($w->SetName("Mark Dintelman")); + $this->assertTrue($w->SetSubcell("10")); + $this->assertFalse($w->SetSubcell("Mark")); + $this->assertTrue($w->SetRate("9")); + $this->assertTrue($w->delete()); + $this->assertTrue($w->insert()); + $this->assertEquals(array("102","103",),$w->getworkerID()); + $this->assertEquals(array("Mark Dintelman","Max Smith"),$w->getname()); + $this->assertEquals(array("10","11"),$w->getsubcell()); + $this->assertEquals(array("9","10"),$w->getrate()); + + + + + + } + +} +if (!defined('PHPUnit_MAIN_METHOD')) { + WorkersTestCase::main(); +} \ No newline at end of file diff --git a/Config/database.sql b/Config/database.sql index bcb8168..54d2328 100644 --- a/Config/database.sql +++ b/Config/database.sql @@ -1,5 +1,15 @@ -- Database Copyright 2014 by WebIS Spring 2014 License Apache 2.0 +-- Worker +DROP TABLE IF EXISTS Workers; +CREATE TABLE Workers ( + workerID integer, + name VARCHAR(128), + subcell integer, + rate double, + PRIMARY KEY (workerID) +); + -- Person DROP TABLE IF EXISTS Person; CREATE TABLE Person ( From 7e3829e8731c0f1433e19cba62ada0a0df7cdcd6 Mon Sep 17 00:00:00 2001 From: Mark Dintelman Date: Thu, 13 Mar 2014 21:23:31 -0500 Subject: [PATCH 02/11] Revert "tb2" This reverts commit 3d7f906daeb8fa19c944ef1059084625aadd2c25. --- App/ta2.php | 224 -------------------------------------------- App/ta2test.php | 36 ------- Config/database.sql | 10 -- 3 files changed, 270 deletions(-) delete mode 100644 App/ta2.php delete mode 100644 App/ta2test.php diff --git a/App/ta2.php b/App/ta2.php deleted file mode 100644 index 3a77eb0..0000000 --- a/App/ta2.php +++ /dev/null @@ -1,224 +0,0 @@ -"; - $this->db = new \mysqli(\WCS\Config::$dbhost,\WCS\Config::$dbuser,\WCS\Config::$dbpassword,\WCS\Config::$dbdatabase); - if($this->db===NULL){ - die("Error unable to connect to database"); - } - } - - function __destruct() { - if($this->db!=NULL){ - $this->db->close(); - } - } - - public function SetID($ID){ - if(preg_match('/^[0-9]+$/', $ID)){ - $this->workerID=$ID; - RETURN TRUE; - } - RETURN FALSE; - } - - function SetName($name){ - if(preg_match('/^\s*$/',$name)){ - return FALSE; - } - $this->name=$name; - return TRUE; - } - - public function SetSubcell($subcell){ - if(preg_match('/^[0-9]+$/', $subcell)){ - $this->subcell=$subcell; - RETURN TRUE; - } - RETURN FALSE; - } - - public function SetRate($rate){ - if(preg_match('/^[0-9]+$/', $rate)){ - $this->rate=$rate; - RETURN TRUE; - } - RETURN FALSE; - } - public function insert(){ - $stmt=$this->db->prepare("INSERT INTO Workers (workerID,name,subcell,rate) VALUES (?,?,?,?)"); - if($stmt===FALSE){ - error_log("WCS/Workers.insert> stmt:".$this->db->error); - return FALSE; - } - if($stmt->bind_param('isid',$this->workerID,$this->name,$this->subcell,$this->rate)===FALSE){ - error_log("WCS/Workers.insert> bind_param:".$this->db->error); - return FALSE; - } - if($stmt->execute()===FALSE){ - if($this->db->errno==1062){ // Duplicate. - return FALSE; - } - error_log("WCS/Workers.insert> execute:".$this->db->errno." ".$this->db->error); - return FALSE; - } - return TRUE; - } - - public function delete(){ - $stmt=$this->db->prepare("DELETE FROM Workers Where workerID=?"); - if ($stmt===FALSE){ - error_log("WCS/Workers.delete> stmt:" . $this->db->error); - return FALSE; - } - if($stmt->bind_param('i', $this->workerID)===FALSE){ - error_log("WCS/Workers.delete> bind_param:".$this->db->error); - return FALSE; - } - if ($stmt->execute()===FALSE){ - error_log("WCS/Workers.delete> execute:".$this->db->errno." ".$this->db->error); - return FALSE; - } - return TRUE; - } -public function getworkerID() { - $stmt=$this->db->prepare("SELECT DISTINCT workerID FROM Workers ORDER BY workerID"); - if($stmt===FALSE){ - die("prepare error ".$this->db->error); - } - if($stmt->bind_result($ID)===FALSE){ - die("bind error ".$this->db->error); - } - if($stmt->execute()===FALSE){ - die("execute error ".$this->db->error); - } - $workerID=array(); - while($stmt->fetch()){ - $workerID[]=$ID; - - } - return $workerID; - - - } - - public function getname() { - $stmt=$this->db->prepare("SELECT DISTINCT name FROM Workers ORDER BY name"); - if($stmt===FALSE){ - die("prepare error ".$this->db->error); - } - if($stmt->bind_result($name)===FALSE){ - die("bind error ".$this->db->error); - } - if($stmt->execute()===FALSE){ - die("execute error ".$this->db->error); - } - $names=array(); - while($stmt->fetch()){ - $names[]=$name; - - } - return $names; - - - } - - public function getsubcell() { - $stmt=$this->db->prepare("SELECT DISTINCT subcell FROM Workers ORDER BY subcell"); - if($stmt===FALSE){ - die("prepare error ".$this->db->error); - } - if($stmt->bind_result($subcell)===FALSE){ - die("bind error ".$this->db->error); - } - if($stmt->execute()===FALSE){ - die("execute error ".$this->db->error); - } - $subcells=array(); - while($stmt->fetch()){ - $subcells[]=$subcell; - - } - return $subcells; - - - } - public function getrate() { - $stmt=$this->db->prepare("SELECT DISTINCT rate FROM Workers ORDER BY rate"); - if($stmt===FALSE){ - die("prepare error ".$this->db->error); - } - if($stmt->bind_result($rate)===FALSE){ - die("bind error ".$this->db->error); - } - if($stmt->execute()===FALSE){ - die("execute error ".$this->db->error); - } - $rates=array(); - while($stmt->fetch()){ - $rates[]=$rate; - - } - return $rates; - - - } -} - - -$t= new Workers(); -$t->SetID("102"); -$t->SetName("Mark Dintelman"); -$t->SetSubcell("10"); -$t->SetRate("9"); -$t->insert(); -$t->delete(); -$t->insert(); -$t->getworkerID(); - -$t1= new Workers(); -$t1->SetID("102"); -$t1->SetName("Mark Dintelman"); -$t1->SetSubcell("11"); -$t1->SetRate("5"); -$t1->insert(); -$t1->delete(); -$t1->insert(); -$t1->getworkerID(); - -$tt= new Workers(); -$tt->SetID("103"); -$tt->SetName("Max Smith"); -$tt->SetSubcell("11"); -$tt->SetRate("10"); -$tt->insert(); -$tt->delete(); -$tt->insert(); -$tt->getworkerID(); - -$c= new Workers(); -foreach($c->getworkerID() as $id) - echo $id; -foreach($c->getname() as $name) - echo $name; -foreach($c->getsubcell() as $sub) - echo $sub; -foreach($c->getrate() as $r) - echo $r; - - - -?> - diff --git a/App/ta2test.php b/App/ta2test.php deleted file mode 100644 index 293a022..0000000 --- a/App/ta2test.php +++ /dev/null @@ -1,36 +0,0 @@ -assertTrue($w->SetID("102")); - $this->assertFalse($w->SetID("MARK")); - $this->assertFalse($w->SetName(" ")); - $this->assertTrue($w->SetName("Mark Dintelman")); - $this->assertTrue($w->SetSubcell("10")); - $this->assertFalse($w->SetSubcell("Mark")); - $this->assertTrue($w->SetRate("9")); - $this->assertTrue($w->delete()); - $this->assertTrue($w->insert()); - $this->assertEquals(array("102","103",),$w->getworkerID()); - $this->assertEquals(array("Mark Dintelman","Max Smith"),$w->getname()); - $this->assertEquals(array("10","11"),$w->getsubcell()); - $this->assertEquals(array("9","10"),$w->getrate()); - - - - - - } - -} -if (!defined('PHPUnit_MAIN_METHOD')) { - WorkersTestCase::main(); -} \ No newline at end of file diff --git a/Config/database.sql b/Config/database.sql index 54d2328..bcb8168 100644 --- a/Config/database.sql +++ b/Config/database.sql @@ -1,15 +1,5 @@ -- Database Copyright 2014 by WebIS Spring 2014 License Apache 2.0 --- Worker -DROP TABLE IF EXISTS Workers; -CREATE TABLE Workers ( - workerID integer, - name VARCHAR(128), - subcell integer, - rate double, - PRIMARY KEY (workerID) -); - -- Person DROP TABLE IF EXISTS Person; CREATE TABLE Person ( From 9c54fc64ce0e1a5b4ede0b96266880118de35176 Mon Sep 17 00:00:00 2001 From: Mark Dintelman Date: Thu, 13 Mar 2014 21:30:24 -0500 Subject: [PATCH 03/11] Revert "Revert "tb2"" This reverts commit 7e3829e8731c0f1433e19cba62ada0a0df7cdcd6. --- App/ta2.php | 224 ++++++++++++++++++++++++++++++++++++++++++++ App/ta2test.php | 36 +++++++ Config/database.sql | 10 ++ 3 files changed, 270 insertions(+) create mode 100644 App/ta2.php create mode 100644 App/ta2test.php diff --git a/App/ta2.php b/App/ta2.php new file mode 100644 index 0000000..3a77eb0 --- /dev/null +++ b/App/ta2.php @@ -0,0 +1,224 @@ +"; + $this->db = new \mysqli(\WCS\Config::$dbhost,\WCS\Config::$dbuser,\WCS\Config::$dbpassword,\WCS\Config::$dbdatabase); + if($this->db===NULL){ + die("Error unable to connect to database"); + } + } + + function __destruct() { + if($this->db!=NULL){ + $this->db->close(); + } + } + + public function SetID($ID){ + if(preg_match('/^[0-9]+$/', $ID)){ + $this->workerID=$ID; + RETURN TRUE; + } + RETURN FALSE; + } + + function SetName($name){ + if(preg_match('/^\s*$/',$name)){ + return FALSE; + } + $this->name=$name; + return TRUE; + } + + public function SetSubcell($subcell){ + if(preg_match('/^[0-9]+$/', $subcell)){ + $this->subcell=$subcell; + RETURN TRUE; + } + RETURN FALSE; + } + + public function SetRate($rate){ + if(preg_match('/^[0-9]+$/', $rate)){ + $this->rate=$rate; + RETURN TRUE; + } + RETURN FALSE; + } + public function insert(){ + $stmt=$this->db->prepare("INSERT INTO Workers (workerID,name,subcell,rate) VALUES (?,?,?,?)"); + if($stmt===FALSE){ + error_log("WCS/Workers.insert> stmt:".$this->db->error); + return FALSE; + } + if($stmt->bind_param('isid',$this->workerID,$this->name,$this->subcell,$this->rate)===FALSE){ + error_log("WCS/Workers.insert> bind_param:".$this->db->error); + return FALSE; + } + if($stmt->execute()===FALSE){ + if($this->db->errno==1062){ // Duplicate. + return FALSE; + } + error_log("WCS/Workers.insert> execute:".$this->db->errno." ".$this->db->error); + return FALSE; + } + return TRUE; + } + + public function delete(){ + $stmt=$this->db->prepare("DELETE FROM Workers Where workerID=?"); + if ($stmt===FALSE){ + error_log("WCS/Workers.delete> stmt:" . $this->db->error); + return FALSE; + } + if($stmt->bind_param('i', $this->workerID)===FALSE){ + error_log("WCS/Workers.delete> bind_param:".$this->db->error); + return FALSE; + } + if ($stmt->execute()===FALSE){ + error_log("WCS/Workers.delete> execute:".$this->db->errno." ".$this->db->error); + return FALSE; + } + return TRUE; + } +public function getworkerID() { + $stmt=$this->db->prepare("SELECT DISTINCT workerID FROM Workers ORDER BY workerID"); + if($stmt===FALSE){ + die("prepare error ".$this->db->error); + } + if($stmt->bind_result($ID)===FALSE){ + die("bind error ".$this->db->error); + } + if($stmt->execute()===FALSE){ + die("execute error ".$this->db->error); + } + $workerID=array(); + while($stmt->fetch()){ + $workerID[]=$ID; + + } + return $workerID; + + + } + + public function getname() { + $stmt=$this->db->prepare("SELECT DISTINCT name FROM Workers ORDER BY name"); + if($stmt===FALSE){ + die("prepare error ".$this->db->error); + } + if($stmt->bind_result($name)===FALSE){ + die("bind error ".$this->db->error); + } + if($stmt->execute()===FALSE){ + die("execute error ".$this->db->error); + } + $names=array(); + while($stmt->fetch()){ + $names[]=$name; + + } + return $names; + + + } + + public function getsubcell() { + $stmt=$this->db->prepare("SELECT DISTINCT subcell FROM Workers ORDER BY subcell"); + if($stmt===FALSE){ + die("prepare error ".$this->db->error); + } + if($stmt->bind_result($subcell)===FALSE){ + die("bind error ".$this->db->error); + } + if($stmt->execute()===FALSE){ + die("execute error ".$this->db->error); + } + $subcells=array(); + while($stmt->fetch()){ + $subcells[]=$subcell; + + } + return $subcells; + + + } + public function getrate() { + $stmt=$this->db->prepare("SELECT DISTINCT rate FROM Workers ORDER BY rate"); + if($stmt===FALSE){ + die("prepare error ".$this->db->error); + } + if($stmt->bind_result($rate)===FALSE){ + die("bind error ".$this->db->error); + } + if($stmt->execute()===FALSE){ + die("execute error ".$this->db->error); + } + $rates=array(); + while($stmt->fetch()){ + $rates[]=$rate; + + } + return $rates; + + + } +} + + +$t= new Workers(); +$t->SetID("102"); +$t->SetName("Mark Dintelman"); +$t->SetSubcell("10"); +$t->SetRate("9"); +$t->insert(); +$t->delete(); +$t->insert(); +$t->getworkerID(); + +$t1= new Workers(); +$t1->SetID("102"); +$t1->SetName("Mark Dintelman"); +$t1->SetSubcell("11"); +$t1->SetRate("5"); +$t1->insert(); +$t1->delete(); +$t1->insert(); +$t1->getworkerID(); + +$tt= new Workers(); +$tt->SetID("103"); +$tt->SetName("Max Smith"); +$tt->SetSubcell("11"); +$tt->SetRate("10"); +$tt->insert(); +$tt->delete(); +$tt->insert(); +$tt->getworkerID(); + +$c= new Workers(); +foreach($c->getworkerID() as $id) + echo $id; +foreach($c->getname() as $name) + echo $name; +foreach($c->getsubcell() as $sub) + echo $sub; +foreach($c->getrate() as $r) + echo $r; + + + +?> + diff --git a/App/ta2test.php b/App/ta2test.php new file mode 100644 index 0000000..293a022 --- /dev/null +++ b/App/ta2test.php @@ -0,0 +1,36 @@ +assertTrue($w->SetID("102")); + $this->assertFalse($w->SetID("MARK")); + $this->assertFalse($w->SetName(" ")); + $this->assertTrue($w->SetName("Mark Dintelman")); + $this->assertTrue($w->SetSubcell("10")); + $this->assertFalse($w->SetSubcell("Mark")); + $this->assertTrue($w->SetRate("9")); + $this->assertTrue($w->delete()); + $this->assertTrue($w->insert()); + $this->assertEquals(array("102","103",),$w->getworkerID()); + $this->assertEquals(array("Mark Dintelman","Max Smith"),$w->getname()); + $this->assertEquals(array("10","11"),$w->getsubcell()); + $this->assertEquals(array("9","10"),$w->getrate()); + + + + + + } + +} +if (!defined('PHPUnit_MAIN_METHOD')) { + WorkersTestCase::main(); +} \ No newline at end of file diff --git a/Config/database.sql b/Config/database.sql index bcb8168..54d2328 100644 --- a/Config/database.sql +++ b/Config/database.sql @@ -1,5 +1,15 @@ -- Database Copyright 2014 by WebIS Spring 2014 License Apache 2.0 +-- Worker +DROP TABLE IF EXISTS Workers; +CREATE TABLE Workers ( + workerID integer, + name VARCHAR(128), + subcell integer, + rate double, + PRIMARY KEY (workerID) +); + -- Person DROP TABLE IF EXISTS Person; CREATE TABLE Person ( From 9d1d8e4759c90ab423d8f534d66fbb230f223a1f Mon Sep 17 00:00:00 2001 From: Mark Dintelman Date: Thu, 27 Mar 2014 14:23:53 -0500 Subject: [PATCH 04/11] Problems with inserting. --- App/ta3.php | 183 ++++++++++++++++++++++++++++++++++++++++++++ App/ta3test.php | 34 ++++++++ Config/database.sql | 10 +++ 3 files changed, 227 insertions(+) create mode 100644 App/ta3.php create mode 100644 App/ta3test.php diff --git a/App/ta3.php b/App/ta3.php new file mode 100644 index 0000000..340ba9e --- /dev/null +++ b/App/ta3.php @@ -0,0 +1,183 @@ +"; + $this->db = new \mysqli(\WCS\Config::$dbhost,\WCS\Config::$dbuser,\WCS\Config::$dbpassword,\WCS\Config::$dbdatabase); + if($this->db===NULL){ + die("Error unable to connect to database"); + } + } + + function __destruct() { + if($this->db!=NULL){ + $this->db->close(); + } + } + + public function SetID($ID){ + if(preg_match('/^[0-9]+$/', $ID)){ + $this->workerID=$ID; + RETURN TRUE; + } + RETURN FALSE; + } + + function SetName($name){ + if(preg_match('/^\s*$/',$name)){ + return FALSE; + } + $this->name=$name; + return TRUE; + } + + public function Setratesub1($subcell1){ + $this->rateSub1=$subcell1; + RETURN TRUE; + + } + + public function SetrateSub2($sub2){ + $this->rateSub2=$sub2; + RETURN TRUE; + } + + public function insert(){ + $stmt=$this->db->prepare("INSERT INTO Workers2 (workerID,name,rateSub1,rateSub2) VALUES (?,?,?,?)"); + if($stmt===FALSE){ + error_log("WCS/Workers2.insert> stmt:".$this->db->error); + return FALSE; + } + if($stmt->bind_param('isdd',$this->workerID,$this->name,$this->rateSub1,$this->rateSub2)===FALSE){ + error_log("WCS/Workers2.insert> bind_param:".$this->db->error); + return FALSE; + } + if($stmt->execute()===FALSE){ + if($this->db->errno==1062){ // Duplicate. + return FALSE; + } + error_log("WCS/Workers2.insert> execute:".$this->db->errno." ".$this->db->error); + return FALSE; + } + return TRUE; + } + + public function delete(){ + $stmt=$this->db->prepare("DELETE FROM Workers2 Where workerID=?"); + if ($stmt===FALSE){ + error_log("WCS/Workers2.delete> stmt:" . $this->db->error); + return FALSE; + } + if($stmt->bind_param('i', $this->workerID)===FALSE){ + error_log("WCS/Workers2.delete> bind_param:".$this->db->error); + return FALSE; + } + if ($stmt->execute()===FALSE){ + error_log("WCS/Workers2.delete> execute:".$this->db->errno." ".$this->db->error); + return FALSE; + } + return TRUE; + } + public function getworkerID() { + $stmt=$this->db->prepare("SELECT DISTINCT workerID FROM Workers2 ORDER BY workerID"); + if($stmt===FALSE){ + die("prepare error ".$this->db->error); + } + if($stmt->bind_result($ID)===FALSE){ + die("bind error ".$this->db->error); + } + if($stmt->execute()===FALSE){ + die("execute error ".$this->db->error); + } + $workerID=array(); + while($stmt->fetch()){ + $workerID[]=$ID; + + } + return $workerID; + + + } + + public function getname() { + $stmt=$this->db->prepare("SELECT DISTINCT name FROM Workers2 ORDER BY name"); + if($stmt===FALSE){ + die("prepare error ".$this->db->error); + } + if($stmt->bind_result($name)===FALSE){ + die("bind error ".$this->db->error); + } + if($stmt->execute()===FALSE){ + die("execute error ".$this->db->error); + } + $names=array(); + while($stmt->fetch()){ + $names[]=$name; + + } + return $names; + + + } + + public function getrateSub1() { + $stmt=$this->db->prepare("SELECT DISTINCT rateSub1 FROM Workers2 ORDER BY rateSub1"); + if($stmt===FALSE){ + die("prepare error ".$this->db->error); + } + if($stmt->bind_result($sub1)===FALSE){ + die("bind error ".$this->db->error); + } + if($stmt->execute()===FALSE){ + die("execute error ".$this->db->error); + } + $ratesub1=array(); + while($stmt->fetch()){ + $rateSub1[]=$sub1; + + } + return $rateSub1; + + + } + public function getrateSub2() { + $stmt=$this->db->prepare("SELECT DISTINCT rateSub2 FROM Workers2 ORDER BY rateSub2"); + if($stmt===FALSE){ + die("prepare error ".$this->db->error); + } + if($stmt->bind_result($sub2)===FALSE){ + die("bind error ".$this->db->error); + } + if($stmt->execute()===FALSE){ + die("execute error ".$this->db->error); + } + $rateSub2=array(); + while($stmt->fetch()){ + $rateSub2[]=$sub2; + + } + return $rateSub2; + + + } +} + + + + + + +?> + diff --git a/App/ta3test.php b/App/ta3test.php new file mode 100644 index 0000000..017636b --- /dev/null +++ b/App/ta3test.php @@ -0,0 +1,34 @@ +assertTrue($w->SetID("102")); + $this->assertFalse($w->SetID("Mark")); + $this->assertFalse($w->SetName(" ")); + $this->assertTrue($w->SetName("Mark Dintelman")); + $this->assertTrue($w->Setratesub1("0.9")); + $this->assertTrue($w->Setratesub2("0.8")); + $this->assertTrue($w->delete()); + $this->assertTrue($w->insert()); + + + + + + + + + } + +} +if (!defined('PHPUnit_MAIN_METHOD')) { + WorkersTestCase::main(); +} \ No newline at end of file diff --git a/Config/database.sql b/Config/database.sql index 54d2328..0464125 100644 --- a/Config/database.sql +++ b/Config/database.sql @@ -1,5 +1,15 @@ -- Database Copyright 2014 by WebIS Spring 2014 License Apache 2.0 +-- Worker2 +DROP TABLE IF EXISTS Workers2; +CREATE TABLE Workers2 ( + workerID integer, + name VARCHAR(128), + rateSub1 double, + rateSub2 double, + PRIMARY KEY (workerID) +); + -- Worker DROP TABLE IF EXISTS Workers; CREATE TABLE Workers ( From 849a1c3927b5429db9f4c7956a463efa274c11be Mon Sep 17 00:00:00 2001 From: Mark Dintelman Date: Sun, 30 Mar 2014 15:27:45 -0500 Subject: [PATCH 05/11] commit changes --- App/ta2.php | 43 ++++--------------------------------------- App/ta3.php | 2 +- App/ta3test.php | 6 +++--- Config/database.sql | 3 +++ 4 files changed, 11 insertions(+), 43 deletions(-) diff --git a/App/ta2.php b/App/ta2.php index 3a77eb0..f993207 100644 --- a/App/ta2.php +++ b/App/ta2.php @@ -156,10 +156,13 @@ public function getsubcell() { } public function getrate() { - $stmt=$this->db->prepare("SELECT DISTINCT rate FROM Workers ORDER BY rate"); + $stmt=$this->db->prepare("SELECT DISTINCT rate FROM Workers WHERE workerID=? AND subcell=?"); if($stmt===FALSE){ die("prepare error ".$this->db->error); } + if($stmt->bind_param('ii',$this->workerID,$this->subcell)===FALSE){ + die("bind error ".$this->db->error); + } if($stmt->bind_result($rate)===FALSE){ die("bind error ".$this->db->error); } @@ -178,45 +181,7 @@ public function getrate() { } -$t= new Workers(); -$t->SetID("102"); -$t->SetName("Mark Dintelman"); -$t->SetSubcell("10"); -$t->SetRate("9"); -$t->insert(); -$t->delete(); -$t->insert(); -$t->getworkerID(); - -$t1= new Workers(); -$t1->SetID("102"); -$t1->SetName("Mark Dintelman"); -$t1->SetSubcell("11"); -$t1->SetRate("5"); -$t1->insert(); -$t1->delete(); -$t1->insert(); -$t1->getworkerID(); - -$tt= new Workers(); -$tt->SetID("103"); -$tt->SetName("Max Smith"); -$tt->SetSubcell("11"); -$tt->SetRate("10"); -$tt->insert(); -$tt->delete(); -$tt->insert(); -$tt->getworkerID(); -$c= new Workers(); -foreach($c->getworkerID() as $id) - echo $id; -foreach($c->getname() as $name) - echo $name; -foreach($c->getsubcell() as $sub) - echo $sub; -foreach($c->getrate() as $r) - echo $r; diff --git a/App/ta3.php b/App/ta3.php index 340ba9e..cbb4196 100644 --- a/App/ta3.php +++ b/App/ta3.php @@ -3,7 +3,7 @@ namespace WCS; require_once 'Work-Cell-Scheduler/Config/global.php'; -class Workers { +class Workers2 { private $db=NULL; diff --git a/App/ta3test.php b/App/ta3test.php index 017636b..ea510a2 100644 --- a/App/ta3test.php +++ b/App/ta3test.php @@ -9,16 +9,16 @@ class WorkersTestCase extends WebIS\Validator { protected static $__CLASS__=__CLASS__; function testworkers(){ - $w= new \WCS\Workers(); + $w= new \WCS\Workers2(); $this->assertTrue($w->SetID("102")); $this->assertFalse($w->SetID("Mark")); $this->assertFalse($w->SetName(" ")); $this->assertTrue($w->SetName("Mark Dintelman")); $this->assertTrue($w->Setratesub1("0.9")); $this->assertTrue($w->Setratesub2("0.8")); - $this->assertTrue($w->delete()); - $this->assertTrue($w->insert()); + $this->assertEquals(array('102'),$w->getworkerID()); + $this->assertEquals(array('0.9'),$w->getrateSub1()); diff --git a/Config/database.sql b/Config/database.sql index 0464125..f39cece 100644 --- a/Config/database.sql +++ b/Config/database.sql @@ -10,6 +10,9 @@ CREATE TABLE Workers2 ( PRIMARY KEY (workerID) ); +INSERT INTO Workers2 (workerID, name, rateSub1, rateSub2) VALUES + (102,'Mark Dintelman',0.9,0.8); + -- Worker DROP TABLE IF EXISTS Workers; CREATE TABLE Workers ( From e74f70eda605ffecacf4fadf79e3fda0a117bd51 Mon Sep 17 00:00:00 2001 From: Mark Dintelman Date: Sun, 30 Mar 2014 17:11:43 -0500 Subject: [PATCH 06/11] commit changes --- App/ta3.php | 113 ++++++++++++++++++++++++++++++++++++++++++++++++ App/ta3test.php | 2 + 2 files changed, 115 insertions(+) diff --git a/App/ta3.php b/App/ta3.php index cbb4196..2e5daf5 100644 --- a/App/ta3.php +++ b/App/ta3.php @@ -3,6 +3,97 @@ namespace WCS; require_once 'Work-Cell-Scheduler/Config/global.php'; + +class Workers2App { + private $workerID=NULL; + + function add(Workers2 $ID){ + $this->workerID=$ID; + return TRUE; + } + + function Apply($p){ + $this->load(); + $this->save(); + echo $this->edit($p); + } + + function get(){ + if($this->workerID===NULL){ + $this->workerID=new Workers2(); + } + if(!$this->workerID->SetID($_REQUEST['workerID'])){ + return FALSE; + } + if(isset($_REQUEST['name']) and !$this->workerID->SetName($_REQUEST['name'])){ + return FALSE; + } + if(isset($_REQUEST['rateSub1']) and !$this->workerID->SetrateSub1($_REQUEST['rateSub1'])){ + return FALSE; + } + if(isset($_REQUEST['rateSub2']) and !$this->workerID->SetrateSub2($_REQUEST['rateSub2'])){ + return FALSE; + } + } + function load(){ + if(!isset($_REQUEST['action'])){ + return FALSE; + } + if($_REQUEST['action']!='Load'){ + return FALSE; + } + $this->get(); + if($this->workerID->getworker()===FALSE){ + return FALSE; + } + return TRUE; + } + + function save(){ + if($this->workerID===NULL){ + $this->workerID=new Workers2(); + } + if(!isset($_REQUEST['action'])){ + return FALSE; + } + if($_REQUEST['action']!='Update'){ + return FALSE; + } + $this->get(); + if($this->workerID->delete()===FALSE){ + print ":Workers2App.save: unable to delete()"; + return FALSE; + } + if($this->workerID->insert()===FALSE){ + print ":Workers2App.save: unable to write()"; + return FALSE; + } + return TRUE; + } + + function edit($action){ + $workerID=htmlspecialchars($this->workerID->getworkerID()); + $name=htmlspecialchars($this->workerID->getname()); + $rateSub1=htmlspecialchars($this->workerID->getrateSub1()); + $rateSub2=htmlspecialchars($this->workerID->getrateSub2()); + return << + + + + + +
WorkerID
Name
SubCell 1
Subcell 2
+ + + +HTML; + } + + +} + + class Workers2 { @@ -172,6 +263,28 @@ public function getrateSub2() { } + + function getworker(){ + $stmt=$this->db->prepare("SELECT name,rateSub1,rateSub2 FROM Workers2 WHERE workerID=?"); + if($stmt===FALSE){ + die("prepare error ".$this->db->error); + } + if($stmt->bind_param('i', $this->workerID)===FALSE){ + error_log("WCS/Workers2.getworker> bind_param:".$this->db->error); + return FALSE; + } + if($stmt->bind_result($this->name,$this->rateSub1,$this->rateSub2)===FALSE){ + die("bind error ".$this->db->error); + } + if($stmt->execute()===FALSE){ + die("execute error ".$this->db->error); + } + if($stmt->fetch()==FALSE){ + $stmt->close(); + return FALSE; + } + return TRUE; + } } diff --git a/App/ta3test.php b/App/ta3test.php index ea510a2..060a172 100644 --- a/App/ta3test.php +++ b/App/ta3test.php @@ -18,7 +18,9 @@ function testworkers(){ $this->assertTrue($w->Setratesub2("0.8")); $this->assertEquals(array('102'),$w->getworkerID()); + $this->assertEquals(array('Mark Dintelman'),$w->getname()); $this->assertEquals(array('0.9'),$w->getrateSub1()); + $this->assertEquals(array('0.8'),$w->getrateSub2()); From d153d29199f9efd204d1e83ee4dc996a6a6bb7b5 Mon Sep 17 00:00:00 2001 From: Mark Dintelman Date: Sun, 30 Mar 2014 17:54:44 -0500 Subject: [PATCH 07/11] commit --- App/ta3.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/App/ta3.php b/App/ta3.php index 2e5daf5..56e9afa 100644 --- a/App/ta3.php +++ b/App/ta3.php @@ -72,10 +72,10 @@ function save(){ } function edit($action){ - $workerID=htmlspecialchars($this->workerID->getworkerID()); - $name=htmlspecialchars($this->workerID->getname()); - $rateSub1=htmlspecialchars($this->workerID->getrateSub1()); - $rateSub2=htmlspecialchars($this->workerID->getrateSub2()); + $workerID=htmlspecialchars($this->workerID->getworkerIDs()); + $name=htmlspecialchars($this->workerID->getnames()); + $rateSub1=htmlspecialchars($this->workerID->getrateSub1s()); + $rateSub2=htmlspecialchars($this->workerID->getrateSub2s()); return << @@ -85,7 +85,7 @@ function edit($action){
Subcell 2
- + HTML; } @@ -125,6 +125,10 @@ public function SetID($ID){ } RETURN FALSE; } + + function getworkerIDs(){ + return $this->workerID; + } function SetName($name){ if(preg_match('/^\s*$/',$name)){ @@ -133,18 +137,30 @@ function SetName($name){ $this->name=$name; return TRUE; } + + function getnames(){ + return $this->name; + } public function Setratesub1($subcell1){ $this->rateSub1=$subcell1; RETURN TRUE; } + + function getrateSub1s(){ + return $this->rateSub1; + } public function SetrateSub2($sub2){ $this->rateSub2=$sub2; RETURN TRUE; } + function getrateSub2s(){ + return $this->rateSub2; + } + public function insert(){ $stmt=$this->db->prepare("INSERT INTO Workers2 (workerID,name,rateSub1,rateSub2) VALUES (?,?,?,?)"); if($stmt===FALSE){ From d5c916847f557fed0effaec1327cfbbcef97d057 Mon Sep 17 00:00:00 2001 From: Mark Dintelman Date: Sun, 30 Mar 2014 19:48:50 -0500 Subject: [PATCH 08/11] commit --- App/ta3test.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/App/ta3test.php b/App/ta3test.php index 060a172..83a2ce5 100644 --- a/App/ta3test.php +++ b/App/ta3test.php @@ -16,7 +16,9 @@ function testworkers(){ $this->assertTrue($w->SetName("Mark Dintelman")); $this->assertTrue($w->Setratesub1("0.9")); $this->assertTrue($w->Setratesub2("0.8")); - + $this->assertTrue($w->insert()); + $this->assertTrue($w->delete()); + $this->assertTrue($w->insert()); $this->assertEquals(array('102'),$w->getworkerID()); $this->assertEquals(array('Mark Dintelman'),$w->getname()); $this->assertEquals(array('0.9'),$w->getrateSub1()); From 58955f2ef9fdcfdfa0ca55b1bb3083acae45276e Mon Sep 17 00:00:00 2001 From: Mark Dintelman Date: Sun, 30 Mar 2014 20:49:19 -0500 Subject: [PATCH 09/11] commit --- App/ta3test.php | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/App/ta3test.php b/App/ta3test.php index 83a2ce5..ace732b 100644 --- a/App/ta3test.php +++ b/App/ta3test.php @@ -11,26 +11,43 @@ class WorkersTestCase extends WebIS\Validator { function testworkers(){ $w= new \WCS\Workers2(); $this->assertTrue($w->SetID("102")); - $this->assertFalse($w->SetID("Mark")); - $this->assertFalse($w->SetName(" ")); $this->assertTrue($w->SetName("Mark Dintelman")); - $this->assertTrue($w->Setratesub1("0.9")); - $this->assertTrue($w->Setratesub2("0.8")); - $this->assertTrue($w->insert()); + $this->assertTrue($w->SetrateSub1("0.9")); + $this->assertTrue($w->SetrateSub2("0.8")); $this->assertTrue($w->delete()); $this->assertTrue($w->insert()); - $this->assertEquals(array('102'),$w->getworkerID()); - $this->assertEquals(array('Mark Dintelman'),$w->getname()); - $this->assertEquals(array('0.9'),$w->getrateSub1()); - $this->assertEquals(array('0.8'),$w->getrateSub2()); + $this->assertEquals(("102"),$w->getworkerIDs()); + $this->assertEquals(("Mark Dintelman"),$w->getnames()); + - - - - - } + + function testworkerApp(){ + $p= new \WCS\Workers2(); + $this->assertTrue($p->SetName("Mark Dintelman")); + $a= new \WCS\Workers2App(); + $this->assertTrue($a->add($p),"Unable to add worker to edit app"); + $this->assertContains("Mark Dintelman",$a->edit("ta3.php"),"Edit app does not edit"); + + + $a=new \WCS\Workers2App(); + $this->assertFalse($a->load(),"Should not load empty person"); + $_REQUEST['action']='Load'; + $_REQUEST['workerID']='102'; + $this->assertTrue($a->load(),"workerID:102 is not in the database"); + $this->assertContains("Mark Dintelman",$p->getnames(),"WorkerID object does not contain name"); + $this->assertEquals(array("0.9"),$p->getrateSub1(),"WorkerID object does not contain name"); + $_REQUEST['action']='Update'; + $_REQUEST['workerID']='102'; + $_REQUEST['name']='Mark Dintelman'; + $_REQUEST['rateSub1']='0.9'; + $_REQUEST['rateSub2']='0.8'; + $this->assertTrue($a->save(),"Cannot save"); + + } + + } if (!defined('PHPUnit_MAIN_METHOD')) { From 2a858b840e52e9593beb0311b1c6bdea708c9302 Mon Sep 17 00:00:00 2001 From: Mark Dintelman Date: Sun, 30 Mar 2014 23:52:03 -0500 Subject: [PATCH 10/11] topic a3 --- App/ta3.php | 4 ++-- App/ta3test.php | 14 ++++++++++++-- Web/ta3.php | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 Web/ta3.php diff --git a/App/ta3.php b/App/ta3.php index 56e9afa..3f66be7 100644 --- a/App/ta3.php +++ b/App/ta3.php @@ -81,8 +81,8 @@ function edit($action){ - - + +
WorkerID
Name
SubCell 1
Subcell 2
SubCell 1
Subcell 2
diff --git a/App/ta3test.php b/App/ta3test.php index ace732b..65bcefc 100644 --- a/App/ta3test.php +++ b/App/ta3test.php @@ -32,12 +32,12 @@ function testworkerApp(){ $a=new \WCS\Workers2App(); - $this->assertFalse($a->load(),"Should not load empty person"); + $this->assertFalse($a->load(),"Should not load empty workerID"); $_REQUEST['action']='Load'; $_REQUEST['workerID']='102'; $this->assertTrue($a->load(),"workerID:102 is not in the database"); $this->assertContains("Mark Dintelman",$p->getnames(),"WorkerID object does not contain name"); - $this->assertEquals(array("0.9"),$p->getrateSub1(),"WorkerID object does not contain name"); + $this->assertEquals(array("0.9"),$p->getrateSub1(),"WorkerID object does not contain rateSub1"); $_REQUEST['action']='Update'; $_REQUEST['workerID']='102'; $_REQUEST['name']='Mark Dintelman'; @@ -46,6 +46,16 @@ function testworkerApp(){ $this->assertTrue($a->save(),"Cannot save"); } + function testTA3Web(){ + $this->assertValidHTML('Web/ta3.php'); + $this->assertValidHTML('Web/ta3.php','Mark Dintelman', + array('action'=>'Load','workerID'=>'102','name'=>'Mark Dintelman','rateSub1'=>'0.9','rateSub2'=>'0.8'), + "unable to load from page"); + $this->assertValidHTML('Web/ta3.php','Max', + array('action'=>'Update','workerID'=>'102','name'=>'Max','rateSub1'=>'1','rateSub2'=>'0.5'), + "unable to save from page"); + + } diff --git a/Web/ta3.php b/Web/ta3.php new file mode 100644 index 0000000..f89f973 --- /dev/null +++ b/Web/ta3.php @@ -0,0 +1,17 @@ + + + + + + +WCS + + +Apply("ta3.php"); +?> + + + From ae501b04f5fc5c5769d951adea5f9e648338d60a Mon Sep 17 00:00:00 2001 From: Mark Dintelman Date: Mon, 31 Mar 2014 08:24:55 -0500 Subject: [PATCH 11/11] topic-a3 --- App/ta3.php | 2 +- App/ta3test.php | 2 +- Config/database.sql | 2 +- Web/ta3.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/App/ta3.php b/App/ta3.php index 3f66be7..65c424f 100644 --- a/App/ta3.php +++ b/App/ta3.php @@ -206,7 +206,7 @@ public function getworkerID() { die("bind error ".$this->db->error); } if($stmt->execute()===FALSE){ - die("execute error ".$this->db->error); + die("execute error ".$this->db->error); } $workerID=array(); while($stmt->fetch()){ diff --git a/App/ta3test.php b/App/ta3test.php index 65bcefc..2289651 100644 --- a/App/ta3test.php +++ b/App/ta3test.php @@ -1,5 +1,5 @@ - + WCS