From 191f8b71d3aae5e4bb70dbd9a0d14ec82f98e055 Mon Sep 17 00:00:00 2001 From: JBergman Date: Thu, 13 Mar 2014 22:14:07 -0500 Subject: [PATCH 1/2] Topic A2: Create App, Test, and Web for Person and Training Matrix. Create App and Test for Ergo Score Matrix. --- App/ergoApp.php | 109 +++++++++++++++++++++++++++++ App/ergoTest.php | 27 ++++++++ App/personApp.php | 159 +++++++++++++++++++++---------------------- App/personTest.php | 26 +++---- App/trainingApp.php | 50 +++++++------- App/trainingTest.php | 18 ++--- Config/database.sql | 56 ++++++++++----- Web/ergo.php | 49 +++++++++++++ Web/training.php | 18 ++--- 9 files changed, 356 insertions(+), 156 deletions(-) create mode 100644 App/ergoApp.php create mode 100644 App/ergoTest.php create mode 100644 Web/ergo.php diff --git a/App/ergoApp.php b/App/ergoApp.php new file mode 100644 index 0000000..2dc3289 --- /dev/null +++ b/App/ergoApp.php @@ -0,0 +1,109 @@ +"; + $this->db = new \mysqli(\WCS\Config::$dbhost,\WCS\Config::$dbuser,\WCS\Config::$dbpassword,'WCS'); + if($this->db===NULL){ + die("Error unable to connect to database"); + } + } + + public function getEmployeeid() { + $stmt=$this->db->prepare("SELECT DISTINCT employeeid FROM ErgoMatrix ORDER BY employeeid"); + if($stmt===FALSE){ + die("prepare error 1".$this->db->error); + } + if($stmt->bind_result($employeeid)===FALSE){ + die("bind error ".$this->db->error); + } + if($stmt->execute()===FALSE){ + die("execute error ".$this->db->error); + } + $id=array(); + while($stmt->fetch()){ + $id[]=$employeeid; + } + return $id; + } + + public function getSubcell() { + $stmt=$this->db->prepare("SELECT DISTINCT subcell FROM ErgoMatrix"); + if($stmt===FALSE){ + die("prepare error 2".$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); + } + $scell=array(); + while($stmt->fetch()){ + $scell[]=$subcell; + } + return $scell; + } + + function ergo(){ + if($this->ergo_stmt!=NULL){ + return $this->ergo_stmt; + } + $stmt=$this->db->prepare("SELECT ergoscore FROM ErgoMatrix WHERE employeeid=? AND subcell=?"); + if($stmt===FALSE){ + die("prepare error 3".$this->db->error); + } + if($stmt->bind_param('si',$this->ergo_employeeid,$this->ergo_subcell)===FALSE){ + die("bind error ".$this->db->error); + } + if($stmt->bind_result($this->ergo_ergo)===FALSE){ + die("bind error ".$this->db->error); + } + $this->ergo_stmt=$stmt; + return $stmt; + } + + public function getErgo($employeeid,$subcell){ + $this->ergo_employeeid=$employeeid; + $this->ergo_subcell=$subcell; + $stmt=$this->ergo(); + if($stmt->execute()===FALSE){ + die("getErgo: ".$this->db->error); + } + if($stmt->fetch()){ + return $this->ergo_ergo; + } + return 0; + } + + function __destruct() { + if($this->db!=NULL){ + $this->db->close(); + } + } + +} + +?> diff --git a/App/ergoTest.php b/App/ergoTest.php new file mode 100644 index 0000000..f47ba6e --- /dev/null +++ b/App/ergoTest.php @@ -0,0 +1,27 @@ +assertEquals(array('JB','JS','MD'), $e->getEmployeeid()); + $this->assertEquals(array(1,2,3), $e->getSubcell()); + $this->assertEquals(.3,$e->getErgo('JB', '1')); + $this->assertNotEquals(.4,$e->getErgo('JB', '1')); + } + + + +} + +if (!defined('PHPUnit_MAIN_METHOD')) { + ErgoTestCase::main(); +} + +?> \ No newline at end of file diff --git a/App/personApp.php b/App/personApp.php index 11932d0..cb5f3c5 100644 --- a/App/personApp.php +++ b/App/personApp.php @@ -10,123 +10,120 @@ class Person { * @var \mysqli */ private $db=NULL; + public $employeeid=NULL; + public $employeename=NULL; + - public $person=NULL; - public $name=NULL; - public $rate=NULL; - function __construct(){ - //print "WCS/PersonApp>"; - $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"); + $this->db= @new \mysqli(\WCS\Config::$dbhost,\WCS\Config::$dbuser,\WCS\Config::$dbpassword,\WCS\Config::$dbdatabase); + if($this->db->connect_error){ + throw new \Exception("Error unable to connect to database: ".$this->db->connect_error); + } + } + + function destruct(){ + if($this->db!=null){ + $this->db->close(); } } - function __destruct() { - if($this->db!=NULL){ - $this->db->close(); - } - } - - /** - * Set person - * @param string $person Alphanumeric username [a-zA-Z0-9] - * @return bool person set. - */ - public function setPerson($person){ - if(preg_match('/^[a-zA-Z0-9]+$/',$person)){ - $this->person=$person; + function setEmployeeid($employeeid){ + if(preg_match('/^[a-zA-Z0-9]+$/',$employeeid)){ + $this->employeeid=$employeeid; return TRUE; } - return FALSE; + else{ + return FALSE; + } } - /** - * Set name - * @param string $name Persons name - * @return bool name set. - */ - public function setName($name){ - $this->name=$name; - return TRUE; - } - /** - * Display Person - * @return string human readable display. - */ - public function display(){ - $name=''; - if(!\is_null($this->name)){ - $name=" name: $this->name"; + function setEmployeename($employeename){ + if(preg_match('/^[a-zA-Z]+$/',$employeename)){ + $this->employeename=$employeename; + return TRUE; } - return "{person: $this->person".$name."}"; - } + else{ + return FALSE; + } + } + + + function display(){ + $employeename=$this->employeename; + if(!is_null($this->employeename)){ + $employeename=" Employee Name: $this->employeename"; + } + return "Emloyee ID: $this->employeeid".$employeename; + } - public function insert() { - $stmt=$this->db->prepare("INSERT INTO Person (person,name,rate) VALUES (?,?,?)"); + + function insert(){ + $stmt=$this->db->prepare("INSERT INTO Person (employeeid, employeename) VALUES (?,?)"); if($stmt===FALSE){ - error_log("WCS/Person.insert> stmt:".$this->db->error); + die ("WCS/Person.insert> stmt:".$this->db->error); return FALSE; } - if($stmt->bind_param('ssd',$this->person,$this->name,$this->rate)===FALSE){ - error_log("WCS/Person.insert> bind_param:".$this->db->error); - return FALSE; + if($stmt->bind_param('ss',$this->employeeid,$this->employeename)===FALSE){ + die ("WCS/Person.insert> bind_param:".$this->db->error); + return FALSE; } if($stmt->execute()===FALSE){ - if($this->db->errno==1062){ // Duplicate. + if($this->db->errno==1062){ return FALSE; } - error_log("WCS/Person.insert> execute:".$this->db->errno." ".$this->db->error); + die ("WCS/Person.insert> execute:".$this->db->errno." ".$this->db->error); return FALSE; } return TRUE; } - - /** - * Remove Person - * @return bool TRUE on success (even if record did not exist); - */ - public function delete() { - $stmt=$this->db->prepare("DELETE FROM Person WHERE person=?"); - if($stmt===FALSE){ - error_log("WCS/Person.delete> stmt:".$this->db->error); - return FALSE; - } - if($stmt->bind_param('s',$this->person)===FALSE){ - error_log("WCS/Person.delete> bind_param:".$this->db->error); - return FALSE; - } - if($stmt->execute()===FALSE){ - error_log("WCS/Person.delete> execute:".$this->db->errno." ".$this->db->error); - return FALSE; - } - return TRUE; - } - - public function get() { - $stmt=$this->db->prepare("SELECT name,rate FROM Person WHERE person=?"); + + + function delete(){ + $stmt=$this->db->prepare("DELETE FROM Person WHERE employeeid=?"); if($stmt===FALSE){ - error_log("WCS/Person.get> stmt:".$this->db->error); + die("WCS/Person.delete> stmt:".$this->db->error); + return FALSE; + } + if($stmt->bind_param('s',$this->employeeid)===FALSE){ + die("WCS/Person.delete> bind_param:".$this->db->error); + return FALSE; + } + if($stmt->execute()===FALSE){ + die("WCS/Person.delete> execute:".$this->db->error); return FALSE; } + return TRUE; - if($stmt->bind_param('s',$this->person)===FALSE){ - error_log("WCS/Person.get> bind_param:".$this->db->error); + } + + + function select(){ + $stmt=$this->db->prepare("SELECT employeename FROM Person WHERE employeeid=?"); + if($stmt===FALSE){ + die("WCS/Person.select> stmt:".$this->db->error); return FALSE; } - if($stmt->bind_result($this->name,$this->rate)===FALSE){ - error_log("WCS/Person.get> bind_result:".$this->db->error); + if($stmt->bind_param('s',$this->employeeid)===FALSE){ + die("WCS/Person.select> bind_param:".$this->db->error); + return FALSE; + } + if($stmt->bind_result($this->employeename)===FALSE){ + die("WCS/Person.select> bind_result:".$this->db->error); return FALSE; } if($stmt->execute()===FALSE){ - error_log("WCS/Person.get> bind_result:".$this->db->error); + die("WCS/Person.select> execute:".$this->db->error); return FALSE; } return $stmt->fetch(); } - + + + + + + } ?> diff --git a/App/personTest.php b/App/personTest.php index 49bcaa2..c30ec8a 100644 --- a/App/personTest.php +++ b/App/personTest.php @@ -8,21 +8,21 @@ class PersonTestCase extends WebIS\Validator { protected static $__CLASS__=__CLASS__; - function testTrainingApp() { + function testPersonApp(){ $p=new \WCS\Person(); - $this->assertTrue($p->setPerson("DrMiddelkoop")); - $this->assertFalse($p->setPerson("Dr.Middelkoop")); - $this->assertEquals("{person: DrMiddelkoop}",$p->display()); - $this->assertTrue($p->setName("Dr. Middelkoop")); - $this->assertEquals("{person: DrMiddelkoop name: Dr. Middelkoop}",$p->display()); + $this->assertTrue($p->setEmployeeid('Jennifer')); + $this->assertEquals("Emloyee ID: Jennifer",$p->display()); + $this->assertFalse($p->setEmployeeid('Jen.B')); + $this->assertTrue($p->setEmployeename('Jen')); + $this->assertFalse($p->setEmployeename('Jen1')); + $this->assertEquals("Emloyee ID: Jennifer Employee Name: Jen",$p->display()); $this->assertTrue($p->delete()); - $this->assertTrue($p->delete()); // second one should also succeed. - $this->assertTrue($p->insert()); - $this->assertFalse($p->insert(),"record exists, should return false"); - $p=new \WCS\Person(); - $this->assertTrue($p->setPerson("DrMiddelkoop")); - $this->assertTrue($p->get()); - $this->assertEquals("{person: DrMiddelkoop name: Dr. Middelkoop}",$p->display()); + $this->assertTrue($p->delete()); + $this->assertTrue($p->insert()); + $this->assertFalse($p->insert()); + $this->assertTrue($p->select()); + + } } diff --git a/App/trainingApp.php b/App/trainingApp.php index 2aeef0c..155ec39 100644 --- a/App/trainingApp.php +++ b/App/trainingApp.php @@ -19,9 +19,9 @@ class TrainingMatrix{ * Training CRW that the staement binds to. * @var unknown */ - private $training_person; - private $training_workstation; - private $training_wsp; + private $training_employeeid; + private $training_subcell; + private $training_training; function __construct(){ //print "TrainingMatrix>"; @@ -31,69 +31,69 @@ function __construct(){ } } - public function getPeople() { - $stmt=$this->db->prepare("SELECT DISTINCT person FROM TrainingMatrix ORDER BY person"); + public function getEmployeeid() { + $stmt=$this->db->prepare("SELECT DISTINCT employeeid FROM TrainingMatrix ORDER BY employeeid"); if($stmt===FALSE){ - die("prepare error ".$this->db->error); + die("prepare error 1".$this->db->error); } - if($stmt->bind_result($person)===FALSE){ + if($stmt->bind_result($employeeid)===FALSE){ die("bind error ".$this->db->error); } if($stmt->execute()===FALSE){ die("execute error ".$this->db->error); } - $people=array(); + $id=array(); while($stmt->fetch()){ - $people[]=$person; + $id[]=$employeeid; } - return $people; + return $id; } - public function getWorkstations() { - $stmt=$this->db->prepare("SELECT DISTINCT workstation FROM TrainingMatrix ORDER BY workstation"); + public function getSubcell() { + $stmt=$this->db->prepare("SELECT DISTINCT subcell FROM TrainingMatrix"); if($stmt===FALSE){ - die("prepare error ".$this->db->error); + die("prepare error 2".$this->db->error); } - if($stmt->bind_result($workstation)===FALSE){ + if($stmt->bind_result($subcell)===FALSE){ die("bind error ".$this->db->error); } if($stmt->execute()===FALSE){ die("execute error ".$this->db->error); } - $workstations=array(); + $scell=array(); while($stmt->fetch()){ - $workstations[]=$workstation; + $scell[]=$subcell; } - return $workstations; + return $scell; } function training(){ if($this->training_stmt!=NULL){ return $this->training_stmt; } - $stmt=$this->db->prepare("SELECT wsp FROM TrainingMatrix WHERE person=? AND workstation=?"); + $stmt=$this->db->prepare("SELECT training FROM TrainingMatrix WHERE employeeid=? AND subcell=?"); if($stmt===FALSE){ - die("prepare error ".$this->db->error); + die("prepare error 3".$this->db->error); } - if($stmt->bind_param('ss',$this->training_person,$this->training_workstation)===FALSE){ + if($stmt->bind_param('si',$this->training_employeeid,$this->training_subcell)===FALSE){ die("bind error ".$this->db->error); } - if($stmt->bind_result($this->training_wsp)===FALSE){ + if($stmt->bind_result($this->training_training)===FALSE){ die("bind error ".$this->db->error); } $this->training_stmt=$stmt; return $stmt; } - public function getTraining($person,$workstation){ - $this->training_person=$person; - $this->training_workstation=$workstation; + public function getTraining($employeeid,$subcell){ + $this->training_employeeid=$employeeid; + $this->training_subcell=$subcell; $stmt=$this->training(); if($stmt->execute()===FALSE){ die("getTraining: ".$this->db->error); } if($stmt->fetch()){ - return $this->training_wsp; + return $this->training_training; } return 0; } diff --git a/App/trainingTest.php b/App/trainingTest.php index af1de14..875ddf9 100644 --- a/App/trainingTest.php +++ b/App/trainingTest.php @@ -1,5 +1,5 @@ assertEquals(array('Dr.Middelkoop','JD'),$t->getPeople()); - $this->assertEquals(array(1010,1020,1030),$t->getWorkstations()); - $this->assertEquals(0.99,$t->getTraining('JD',1010)); - $this->assertEquals(0.00,$t->getTraining('Dr.Middelkoop',1040)); + $this->assertEquals(array('JB','JS','MD'), $t->getEmployeeid()); + $this->assertEquals(array(1,2,3), $t->getSubcell()); + $this->assertEquals(1,$t->getTraining('JB', '1')); + $this->assertNotEquals(0,$t->getTraining('JB', '1')); } - /** - * @depends testTrainingApp - */ - function testTrainingPage(){ - $this->assertValidHTML("Web/training.php","Dr.Middelkoop"); - } + } if (!defined('PHPUnit_MAIN_METHOD')) { TrainingTestCase::main(); } + ?> \ No newline at end of file diff --git a/Config/database.sql b/Config/database.sql index bcb8168..3f3ca54 100644 --- a/Config/database.sql +++ b/Config/database.sql @@ -3,29 +3,49 @@ -- Person DROP TABLE IF EXISTS Person; CREATE TABLE Person ( - person VARCHAR(30), - name VARCHAR(128), - rate FLOAT, - PRIMARY KEY (person) + employeeid VARCHAR(30), + employeename VARCHAR(30), + PRIMARY KEY (employeeid) ); + -- Training Matrix DROP TABLE IF EXISTS TrainingMatrix; CREATE TABLE TrainingMatrix ( - person VARCHAR(30), - cell integer, - workstation integer, - wcp double, - wsp double, - PRIMARY KEY (person,cell,workstation) + employeeid VARCHAR(30), + employeename VARCHAR(30), + subcell integer, + training integer, + PRIMARY KEY (employeeid,employeename,subcell) +); + +INSERT INTO TrainingMatrix (employeeid,employeename,subcell,training) VALUES + ('JB','Jen Bergman',1,1), + ('JB','Jen Bergman',2,1), + ('JS','JD Stumpf',2,1), + ('MD','Mike Daniel',1,1), + ('MD','Mike Daniel',3,1); + + +SELECT * FROM TrainingMatrix; + + +-- Ergo Score Matrix +DROP TABLE IF EXISTS ErgoMatrix; +CREATE TABLE ErgoMatrix ( + employeeid VARCHAR(30), + employeename VARCHAR(30), + subcell integer, + ergoscore double, + PRIMARY KEY (employeeid,employeename,subcell) ); -INSERT INTO TrainingMatrix (person,cell,workstation,wcp,wsp) VALUES - ('Dr.Middelkoop',1000,1010,0.19,0.19), - ('Dr.Middelkoop',1000,1020,0.55,0.32), - ('JD',1000,1010,0.99,0.99), - ('JD',1000,1030,0.90,0.10); +INSERT INTO ErgoMatrix (employeeid,employeename,subcell,ergoscore) VALUES + ('JB','Jen Bergman',1,.3), + ('JB','Jen Bergman',2,.4), + ('JS','JD Stumpf',2,.4), + ('MD','Mike Daniel',1,.6), + ('MD','Mike Daniel',3,.8); + - --- SELECT * FROM TrainingMatrix; --- SELECT person,cell,w \ No newline at end of file +SELECT * FROM ErgoMatrix; diff --git a/Web/ergo.php b/Web/ergo.php new file mode 100644 index 0000000..c6098cb --- /dev/null +++ b/Web/ergo.php @@ -0,0 +1,49 @@ + + + + + +WCS Ergo Score + + +

WCS Ergo Score Matrix

+ + + + + + +getSubcell() as $s){ + echo ""; + } +?> + + +getEmployeeid() as $id){ + echo ""; + foreach ($e->getSubcell() as $s){ + echo ""; + } + ""; + } +?> + + + + + + + + + + + + +
$s
$id".$e->getErgo($id, $s)."
+ + + \ No newline at end of file diff --git a/Web/training.php b/Web/training.php index f97ab5b..bf11713 100644 --- a/Web/training.php +++ b/Web/training.php @@ -6,27 +6,29 @@ WCS Training -

Ping

-

App: +

WCS Training Matrix

+ - +getWorkstations() as $w){ - echo " + getPeople() as $p){ +foreach($t->getEmployeeid() as $p){ echo ""; - foreach($t->getWorkstations() as $w) { + foreach($t->getSubcell() as $w) { echo ""; } - echo "\n"; + ""; } + ?>
Employee ID \ Subcell $w\n"; +foreach($t->getSubcell() as $w){ + echo "$w"; } ?>
$p".$t->getTraining($p,$w)."
From cb31e2d0ed8e8458c0cc05ea526aaaf92f1f4d8c Mon Sep 17 00:00:00 2001 From: JBergman Date: Mon, 31 Mar 2014 01:13:30 -0500 Subject: [PATCH 2/2] Update person App, Training App, and Subcell App --- App/personApp.php | 96 +++++++++++++++++++++++++++ App/personTest.php | 23 ++++++- App/subcellApp.php | 156 ++++++++++++++++++++++++++++++++++++++++++++ App/subcellTest.php | 45 +++++++++++++ App/trainingApp.php | 51 +++++++++++++++ Config/database.sql | 26 +++++++- Web/person.php | 26 ++++++++ Web/subcell.php | 28 ++++++++ Web/training.php | 27 ++++++++ 9 files changed, 475 insertions(+), 3 deletions(-) create mode 100644 App/subcellApp.php create mode 100644 App/subcellTest.php create mode 100644 Web/person.php create mode 100644 Web/subcell.php diff --git a/App/personApp.php b/App/personApp.php index cb5f3c5..0d2d8cb 100644 --- a/App/personApp.php +++ b/App/personApp.php @@ -3,6 +3,94 @@ namespace WCS; require_once 'Work-Cell-Scheduler/Config/global.php'; + +class PersonApp { + private $person=NULL; + + function add(Person $person){ + $this->person=$person; + return TRUE; + } + + function process($page){ + $this->load(); + $this->save(); + echo $this->edit($page); + } + + function get(){ + if($this->person===NULL){ + $this->person=new Person(); + } + if(!$this->person->setEmployeeid($_REQUEST['person'])){ + //print ":PersonApp.process: unable to set person |".$_REQUEST['person']."|"); + return FALSE; + } + if(isset($_REQUEST['name']) and !$this->person->setEmployeename($_REQUEST['name'])){ + //print ":PersonApp.process: unable to set person |".$_REQUEST['name']."|"); + return FALSE; + } + } + + function load(){ + if(!isset($_REQUEST['action'])){ + return FALSE; + } + if($_REQUEST['action']!='Load'){ + return FALSE; + } + $this->get(); + if($this->person->select()===FALSE){ + return FALSE; + } + return TRUE; + } + + function save(){ + if($this->person===NULL){ + $this->person=new Person(); + } + if(!isset($_REQUEST['action'])){ + return FALSE; + } + if($_REQUEST['action']!='Update'){ + return FALSE; + } + $this->get(); + if($this->person->delete()===FALSE){ + print ":PersonApp.save: unable to delete()"; + return FALSE; + } + if($this->person->insert()===FALSE){ + print ":PersonApp.save: unable to write()"; + return FALSE; + } + return TRUE; + } + + function edit($action){ + $person=htmlspecialchars($this->person->getID()); + $name=htmlspecialchars($this->person->getName()); + return << + + + +
Employee ID:
Name:
+ + + +HTML; + } + + + +} + + + + + class Person { /** @@ -57,6 +145,14 @@ function display(){ return "Emloyee ID: $this->employeeid".$employeename; } + function getID(){ + return $this->employeeid; + } + + function getName(){ + return $this->employeename; + } + function insert(){ $stmt=$this->db->prepare("INSERT INTO Person (employeeid, employeename) VALUES (?,?)"); diff --git a/App/personTest.php b/App/personTest.php index c30ec8a..a69721c 100644 --- a/App/personTest.php +++ b/App/personTest.php @@ -8,7 +8,7 @@ class PersonTestCase extends WebIS\Validator { protected static $__CLASS__=__CLASS__; - function testPersonApp(){ + function testPerson(){ $p=new \WCS\Person(); $this->assertTrue($p->setEmployeeid('Jennifer')); $this->assertEquals("Emloyee ID: Jennifer",$p->display()); @@ -25,6 +25,27 @@ function testPersonApp(){ } + function testPersonApp(){ + $p=new \WCS\Person(); + $this->assertTrue($p->setEmployeename('Jen')); + + $a=new \WCS\PersonApp(); + $this->assertTrue($a->add($p)); + $this->assertContains('Jen', $a->edit("person.php"),"edit problem"); + + $a=new \WCS\PersonApp(); + $this->assertFalse($a->load()); + $_REQUEST["action"]='Load'; + $_REQUEST["person"]='Jennifer'; + $this->assertTrue($a->load()); + $this->assertContains('Jen',$p->getName()); + $_REQUEST["action"]='Update'; + $_REQUEST["person"]='Jennifer'; + $_REQUEST["name"]='Jen'; + $this->assertTrue($a->save()); + } + + } if (!defined('PHPUnit_MAIN_METHOD')) { diff --git a/App/subcellApp.php b/App/subcellApp.php new file mode 100644 index 0000000..ce66b3d --- /dev/null +++ b/App/subcellApp.php @@ -0,0 +1,156 @@ +subcell=$subcell; + return TRUE; + } + + function process($page){ + $this->save(); + echo $this->edit($page); + } + + function get(){ + if($this->subcell===NULL){ + $this->subcell=new Subcell(); + } + if(!$this->subcell->setSubcell($_REQUEST['subcell'])){ + //print ":PersonApp.process: unable to set person |".$_REQUEST['person']."|"); + return FALSE; + } + } + + + function save(){ + if($this->subcell===NULL){ + $this->subcell=new Subcell(); + } + if(!isset($_REQUEST['action'])){ + return FALSE; + } + if($_REQUEST['action']!='Update'){ + return FALSE; + } + $this->get(); + if($this->subcell->delete()===FALSE){ + print ":PersonApp.save: unable to delete()"; + return FALSE; + } + if($this->subcell->insert()===FALSE){ + print ":PersonApp.save: unable to write()"; + return FALSE; + } + return TRUE; + } + + function edit($action){ + $subcell=htmlspecialchars($this->subcell->getSubcell()); + return << + + +
Subcell:
+ + +HTML; + } + + + +} + + + + + +class Subcell{ + + private $db=NULL; + public $subcell=NULL; + + + + function __construct(){ + $this->db= @new \mysqli(\WCS\Config::$dbhost,\WCS\Config::$dbuser,\WCS\Config::$dbpassword,\WCS\Config::$dbdatabase); + if($this->db->connect_error){ + throw new \Exception("Error unable to connect to database: ".$this->db->connect_error); + } + } + + function destruct(){ + if($this->db!=null){ + $this->db->close(); + } + } + + + function setSubcell($subcell){ + if(preg_match('/^[0-9]+$/',$subcell)){ + $this->subcell=$subcell; + return TRUE; + } + else{ + return FALSE; + } + } + + + function getSubcell(){ + return $this->subcell; + } + + + + function insert(){ + $stmt=$this->db->prepare("INSERT INTO Subcell (subcell) VALUES (?)"); + if($stmt===FALSE){ + die ("WCS/Person.insert1> stmt:".$this->db->error); + print "1"; + return FALSE; + } + if($stmt->bind_param('i',$this->subcell)===FALSE){ + die ("WCS/Person.insert2> bind_param:".$this->db->error); + return FALSE; + } + if($stmt->execute()===FALSE){ + if($this->db->errno==1048){ + return FALSE; + } + if($this->db->errno==1062){ + echo "Subcell already in database. Go back and add a unique cell"; + } + die ("WCS/Person.insert3> execute:".$this->db->errno." ".$this->db->error); + return FALSE; + } + return TRUE; + } + + function delete(){ + $stmt=$this->db->prepare("DELETE FROM Subcell WHERE subcell=?"); + if($stmt===FALSE){ + die("WCS/Person.delete> stmt:".$this->db->error); + return FALSE; + } + if($stmt->bind_param('s',$this->subcell)===FALSE){ + die("WCS/Person.delete> bind_param:".$this->db->error); + return FALSE; + } + if($stmt->execute()===FALSE){ + die("WCS/Person.delete> execute:".$this->db->error); + return FALSE; + } + return TRUE; + + } + + + +} +?> \ No newline at end of file diff --git a/App/subcellTest.php b/App/subcellTest.php new file mode 100644 index 0000000..d14c9c4 --- /dev/null +++ b/App/subcellTest.php @@ -0,0 +1,45 @@ +assertTrue($t->setSubcell('6')); + $this->assertFalse($t->setSubcell('J1')); + $this->assertEquals(6,$t->getSubcell()); + $this->assertTrue($t->delete()); + $this->assertTrue($t->delete()); + $this->assertTrue($t->insert()); + + + + } + + function testsubcellApp() { + $t=new \WCS\Subcell(); + $this->assertTrue($t->setSubcell('5')); + + $a=new \WCS\SubcellApp(); + $this->assertTrue($a->add($t)); + $this->assertContains("5",$a->edit("subcell.php"),"Edit app does not edit"); + + $a=new \WCS\SubcellApp(); + $_REQUEST['action']='Update'; + $_REQUEST['subcell']='5'; + $this->assertTrue($a->save(),"can't save"); + } + + +} + +if (!defined('PHPUnit_MAIN_METHOD')) { + SubcellTestCase::main(); +} + +?> \ No newline at end of file diff --git a/App/trainingApp.php b/App/trainingApp.php index 155ec39..8e185d3 100644 --- a/App/trainingApp.php +++ b/App/trainingApp.php @@ -3,6 +3,52 @@ namespace WCS; require_once 'Work-Cell-Scheduler/Config/global.php'; + +class TrainingMatrixApp{ + + public $employeeid=NULL; + public $subcell=NULL; + public $training=NULL; + + function addemployeeid(TrainingMatrix $training_employeeid){ + $this->employeeid=$training_employeeid; + } + + function addsubcell(TrainingMatrix $training_subcell){ + $this->subcell=$training_subcell; + } + + + function process($page){ +// $this->load(); +// $this->save(); + echo $this->edit($page); + } + + + + + function edit($action){ + $employeeid=htmlspecialchars($this->employeeid); + $subcell=htmlspecialchars($this->subcell); + $training=htmlspecialchars($this->training); + return << + + + + +
Employee ID:
Subcell:
Training:
+ + + +HTML; + } + + +} + + class TrainingMatrix{ /** @@ -98,6 +144,11 @@ public function getTraining($employeeid,$subcell){ return 0; } + + + + + function __destruct() { if($this->db!=NULL){ $this->db->close(); diff --git a/Config/database.sql b/Config/database.sql index 3f3ca54..b1b5839 100644 --- a/Config/database.sql +++ b/Config/database.sql @@ -8,6 +8,28 @@ CREATE TABLE Person ( PRIMARY KEY (employeeid) ); +INSERT INTO Person (employeeid,employeename) VALUES + ('JB','Jen Bergman'), + ('JS','JD Stumpf'), + ('MD','Mike Daniel'); + +SELECT * FROM Person; + + +-- Subcell +DROP TABLE IF EXISTS Subcell; +CREATE TABLE Subcell ( + subcell integer, + PRIMARY KEY (subcell) +); + +INSERT INTO Subcell (subcell) VALUES + (1), + (2), + (3); + +SELECT * FROM Subcell; + -- Training Matrix DROP TABLE IF EXISTS TrainingMatrix; @@ -16,7 +38,7 @@ CREATE TABLE TrainingMatrix ( employeename VARCHAR(30), subcell integer, training integer, - PRIMARY KEY (employeeid,employeename,subcell) + PRIMARY KEY (employeeid,subcell) ); INSERT INTO TrainingMatrix (employeeid,employeename,subcell,training) VALUES @@ -28,7 +50,7 @@ INSERT INTO TrainingMatrix (employeeid,employeename,subcell,training) VALUES SELECT * FROM TrainingMatrix; - +SELECT training FROM TrainingMatrix WHERE employeeid='JB' AND subcell='1'; -- Ergo Score Matrix DROP TABLE IF EXISTS ErgoMatrix; diff --git a/Web/person.php b/Web/person.php new file mode 100644 index 0000000..2615628 --- /dev/null +++ b/Web/person.php @@ -0,0 +1,26 @@ + + + + + +Add and Update Employee Information + + +Add and Update Employee Information below: +process("person.php"); +?> + +

+ + +Go to index page + + + + + + diff --git a/Web/subcell.php b/Web/subcell.php new file mode 100644 index 0000000..f944313 --- /dev/null +++ b/Web/subcell.php @@ -0,0 +1,28 @@ + + + + + +Insert Subcells + + +Insert a New Subcell +

+process("subcell.php"); + +?> + + + +

+ +Go to index page + + + + + \ No newline at end of file diff --git a/Web/training.php b/Web/training.php index bf11713..aec4c0c 100644 --- a/Web/training.php +++ b/Web/training.php @@ -29,9 +29,36 @@ ""; } + ?> + + + +

+ +Add training below: +process("training.php"); +?> + + +

+ + + +Go to index page + + + + + + + + \ No newline at end of file