From eb3c026375485481f88033ddbfcf6a3224476b55 Mon Sep 17 00:00:00 2001 From: inghamn Date: Fri, 18 Dec 2009 14:28:25 +0000 Subject: [PATCH] Added cemeteries and deeds git-svn-id: https://rosehill.googlecode.com/svn/branches/php@3 100bd78a-fc82-11de-b5bc-ffd2847a4b57 --- blocks/html/cemeteries/addCemeteryForm.inc | 25 +++ blocks/html/cemeteries/cemeteryList.inc | 38 +++++ blocks/html/cemeteries/updateCemeteryForm.inc | 28 ++++ blocks/html/deeds/addDeedForm.inc | 96 +++++------- blocks/html/deeds/deedList.inc | 18 ++- blocks/html/deeds/findForm.inc | 54 +++++++ blocks/html/deeds/updateDeedForm.inc | 112 ++++++-------- classes/Cemetery.php | 142 ++++++++++++++++++ classes/CemeteryList.php | 87 +++++++++++ classes/Deed.php | 41 ++++- classes/Internment.php | 51 +++++-- classes/InternmentList.php | 4 +- html/cemeteries/addCemetery.php | 32 ++++ html/cemeteries/home.php | 13 ++ html/cemeteries/updateCemetery.php | 32 ++++ html/deeds/home.php | 3 +- scripts/migration/import.sql | 6 + templates/html/partials/panel-one.inc | 14 +- 18 files changed, 642 insertions(+), 154 deletions(-) create mode 100644 blocks/html/cemeteries/addCemeteryForm.inc create mode 100644 blocks/html/cemeteries/cemeteryList.inc create mode 100644 blocks/html/cemeteries/updateCemeteryForm.inc create mode 100644 blocks/html/deeds/findForm.inc create mode 100644 classes/Cemetery.php create mode 100644 classes/CemeteryList.php create mode 100644 html/cemeteries/addCemetery.php create mode 100644 html/cemeteries/home.php create mode 100644 html/cemeteries/updateCemetery.php create mode 100644 scripts/migration/import.sql diff --git a/blocks/html/cemeteries/addCemeteryForm.inc b/blocks/html/cemeteries/addCemeteryForm.inc new file mode 100644 index 0000000..08064d1 --- /dev/null +++ b/blocks/html/cemeteries/addCemeteryForm.inc @@ -0,0 +1,25 @@ + + */ +?> +

Add Cemetery

+
+
Cemetery Info + + + + + + +
+
+ + + +
+
\ No newline at end of file diff --git a/blocks/html/cemeteries/cemeteryList.inc b/blocks/html/cemeteries/cemeteryList.inc new file mode 100644 index 0000000..bd3a9d6 --- /dev/null +++ b/blocks/html/cemeteries/cemeteryList.inc @@ -0,0 +1,38 @@ + + */ +?> +
+

+ + Add + + "; + } + ?> + Cemeteries +

+ +
\ No newline at end of file diff --git a/blocks/html/cemeteries/updateCemeteryForm.inc b/blocks/html/cemeteries/updateCemeteryForm.inc new file mode 100644 index 0000000..713dfeb --- /dev/null +++ b/blocks/html/cemeteries/updateCemeteryForm.inc @@ -0,0 +1,28 @@ + + * @param Cemetery $this->cemetery + */ +?> +

Update Cemetery

+
+
Cemetery Info + + + + + + + +
+
+ + + +
+
\ No newline at end of file diff --git a/blocks/html/deeds/addDeedForm.inc b/blocks/html/deeds/addDeedForm.inc index 3aafcb9..7572676 100644 --- a/blocks/html/deeds/addDeedForm.inc +++ b/blocks/html/deeds/addDeedForm.inc @@ -10,84 +10,60 @@
Deed Info - - + - - - + - - - + - - - + + + - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - + + +
+
+ +
+ + +
+ + + + +
+ +
+ + + + +
-
-
-
-
-
- -
-
-
diff --git a/blocks/html/deeds/deedList.inc b/blocks/html/deeds/deedList.inc index 9076c14..fba6417 100644 --- a/blocks/html/deeds/deedList.inc +++ b/blocks/html/deeds/deedList.inc @@ -34,7 +34,7 @@ $editButton = ''; if (userIsAllowed('Deeds')) { $url = new URL(BASE_URL.'/deeds/updateDeed.php'); - $url->id = $deed->getId(); + $url->deed_id = $deed->getId(); $editButton = " +
+ \ No newline at end of file diff --git a/blocks/html/deeds/updateDeedForm.inc b/blocks/html/deeds/updateDeedForm.inc index 3470484..6c064ef 100644 --- a/blocks/html/deeds/updateDeedForm.inc +++ b/blocks/html/deeds/updateDeedForm.inc @@ -3,92 +3,80 @@ * @copyright 2009 City of Bloomington, Indiana * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt * @author Cliff Ingham + @param Deed $this->deed */ ?>

Update Deed

Deed Info - + - - + - - - + - - - + - - - + + + - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - +
+
+ +
+ + +
+ + + + +
+ +
+ + + + +
-
-
-
-
-
- -
+
-
-
diff --git a/classes/Cemetery.php b/classes/Cemetery.php new file mode 100644 index 0000000..3584e8e --- /dev/null +++ b/classes/Cemetery.php @@ -0,0 +1,142 @@ + + */ +class Cemetery +{ + private $id; + private $name; + + /** + * Populates the object with data + * + * Passing in an associative array of data will populate this object without + * hitting the database. + * + * Passing in a scalar will load the data from the database. + * This will load all fields in the table as properties of this class. + * You may want to replace this with, or add your own extra, custom loading + * + * @param int|array $id + */ + public function __construct($id=null) + { + if ($id) { + if (is_array($id)) { + $result = $id; + } + else { + $zend_db = Database::getConnection(); + if (ctype_digit($id)) { + $sql = 'select * from cemeteries where id=?'; + } + else { + $sql = 'select * from cemeteries where name=?'; + } + $result = $zend_db->fetchRow($sql,array($id)); + } + + if ($result) { + foreach ($result as $field=>$value) { + if ($value) { + $this->$field = $value; + } + } + } + else { + throw new Exception('cemeteries/unknownCemetery'); + } + } + else { + // This is where the code goes to generate a new, empty instance. + // Set any default values for properties that need it here + } + } + + /** + * Throws an exception if anything's wrong + * @throws Exception $e + */ + public function validate() + { + // Check for required fields here. Throw an exception if anything is missing. + if (!$this->name) { + throw new Exception('missingName'); + } + } + + /** + * Saves this record back to the database + */ + public function save() + { + $this->validate(); + + $data = array(); + $data['name'] = $this->name; + + if ($this->id) { + $this->update($data); + } + else { + $this->insert($data); + } + } + + private function update($data) + { + $zend_db = Database::getConnection(); + $zend_db->update('cemeteries',$data,"id='{$this->id}'"); + } + + private function insert($data) + { + $zend_db = Database::getConnection(); + $zend_db->insert('cemeteries',$data); + $this->id = $zend_db->lastInsertId('cemeteries','id'); + } + + //---------------------------------------------------------------- + // Generic Getters + //---------------------------------------------------------------- + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + //---------------------------------------------------------------- + // Generic Setters + //---------------------------------------------------------------- + + /** + * @param string $string + */ + public function setName($string) + { + $this->name = trim($string); + } + + + //---------------------------------------------------------------- + // Custom Functions + // We recommend adding all your custom code down here at the bottom + //---------------------------------------------------------------- + public function __toString() + { + return $this->name; + } +} diff --git a/classes/CemeteryList.php b/classes/CemeteryList.php new file mode 100644 index 0000000..42f45c0 --- /dev/null +++ b/classes/CemeteryList.php @@ -0,0 +1,87 @@ + + */ +class CemeteryList extends ZendDbResultIterator +{ + /** + * Creates a basic select statement for the collection. + * + * Populates the collection if you pass in $fields + * Setting itemsPerPage turns on pagination mode + * In pagination mode, this will only load the results for one page + * + * @param array $fields + * @param int $itemsPerPage Turns on Pagination + * @param int $currentPage + */ + public function __construct($fields=null,$itemsPerPage=null,$currentPage=null) + { + parent::__construct($itemsPerPage,$currentPage); + if (is_array($fields)) { + $this->find($fields); + } + } + + /** + * Populates the collection + * + * @param array $fields + * @param string|array $order Multi-column sort should be given as an array + * @param int $limit + * @param string|array $groupBy Multi-column group by should be given as an array + */ + public function find($fields=null,$order='name',$limit=null,$groupBy=null) + { + $this->select->from('cemeteries'); + + // Finding on fields from the cemeteries table is handled here + if (count($fields)) { + foreach ($fields as $key=>$value) { + $this->select->where("$key=?",$value); + } + } + + // Finding on fields from other tables requires joining those tables. + // You can handle fields from other tables by adding the joins here + // If you add more joins you probably want to make sure that the + // above foreach only handles fields from the cemeteries table. + + $this->select->order($order); + if ($limit) { + $this->select->limit($limit); + } + if ($groupBy) { + $this->select->group($groupBy); + } + $this->populateList(); + } + + /** + * Hydrates all the Cemetery objects from a database result set + * + * This is a callback function, called from ZendDbResultIterator. It is + * called once per row of the result. + * + * @param int $key The index of the result row to load + * @return Cemetery + */ + protected function loadResult($key) + { + return new Cemetery($this->result[$key]); + } +} diff --git a/classes/Deed.php b/classes/Deed.php index 6462b4b..ff1300b 100644 --- a/classes/Deed.php +++ b/classes/Deed.php @@ -18,7 +18,9 @@ class Deed private $issueDate; private $notes; private $lot2; - private $whiteoak; + private $cemetery_id; + + private $cemetery; /** * Populates the object with data @@ -93,7 +95,7 @@ class Deed $data['issueDate'] = $this->issueDate ? $this->issueDate->format('Y-m-d') : null; $data['notes'] = $this->notes ? $this->notes : null; $data['lot2'] = $this->lot2 ? $this->lot2 : null; - $data['whiteoak'] = $this->whiteoak ? $this->whiteoak : null; + $data['cemetery_id'] = $this->cemetery_id ? $this->cemetery_id : null; if ($this->id) { $this->update($data); @@ -229,11 +231,25 @@ class Deed } /** - * @return char + * @return int */ - public function getWhiteoak() + public function getCemetery_id() { - return $this->whiteoak; + return $this->cemetery_id; + } + + /** + * @return Cemetery + */ + public function getCemetery() + { + if ($this->cemetery_id) { + if (!$this->cemetery) { + $this->cemetery = new Cemetery($this->cemetery_id); + } + return $this->cemetery; + } + return null; } //---------------------------------------------------------------- @@ -341,13 +357,22 @@ class Deed } /** - * @param char $char + * @param int $int */ - public function setWhiteoak($char) + public function setCemetery_id($int) { - $this->whiteoak = $char; + $this->cemetery = new Cemetery($int); + $this->cemetery_id = $int; } + /** + * @param Cemetery $cemetery + */ + public function setCemetery($cemetery) + { + $this->cemetery_id = $cemetery->getId(); + $this->cemetery = $cemetery; + } //---------------------------------------------------------------- // Custom Functions diff --git a/classes/Internment.php b/classes/Internment.php index 0ea53bd..c907d17 100644 --- a/classes/Internment.php +++ b/classes/Internment.php @@ -19,10 +19,12 @@ class Internment private $lastResidence; private $age; private $sex; - private $whiteoak; + private $cemetery_id; private $notes; private $lot2; + private $cemetery; + /** * Populates the object with data * @@ -97,7 +99,7 @@ class Internment $data['lastResidence'] = $this->lastResidence ? $this->lastResidence : null; $data['age'] = $this->age ? $this->age : null; $data['sex'] = $this->sex ? $this->sex : null; - $data['whiteoak'] = $this->whiteoak ? $this->whiteoak : null; + $data['cemetery_id'] = $this->cemetery_id ? $this->cemetery_id : null; $data['notes'] = $this->notes ? $this->notes : null; $data['lot2'] = $this->lot2 ? $this->lot2 : null; @@ -242,14 +244,6 @@ class Internment return $this->sex; } - /** - * @return char - */ - public function getWhiteoak() - { - return $this->whiteoak; - } - /** * @return text */ @@ -266,6 +260,27 @@ class Internment return $this->lot2; } + /** + * @return int + */ + public function getCemetery_id() + { + return $this->cemetery_id; + } + + /** + * @return Cemetery + */ + public function getCemetery() + { + if ($this->cemetery_id) { + if (!$this->cemetery) { + $this->cemetery = new Cemetery($this->cemetery_id); + } + return $this->cemetery; + } + return null; + } //---------------------------------------------------------------- // Generic Setters //---------------------------------------------------------------- @@ -379,11 +394,21 @@ class Internment } /** - * @param char $char + * @param int $int */ - public function setWhiteoak($char) + public function setCemetery_id($int) { - $this->whiteoak = $char; + $this->cemetery = new Cemetery($int); + $this->cemetery_id = $int; + } + + /** + * @param Cemetery $cemetery + */ + public function setCemetery($cemetery) + { + $this->cemetery_id = $cemetery->getId(); + $this->cemetery = $cemetery; } /** diff --git a/classes/InternmentList.php b/classes/InternmentList.php index 7a3d880..bd1f67c 100644 --- a/classes/InternmentList.php +++ b/classes/InternmentList.php @@ -49,7 +49,7 @@ class InternmentList extends ZendDbResultIterator { $this->select->from('internments'); - // Finding on fields from the internment table is handled here + // Finding on fields from the internments table is handled here if (count($fields)) { foreach ($fields as $key=>$value) { $this->select->where("$key=?",$value); @@ -59,7 +59,7 @@ class InternmentList extends ZendDbResultIterator // Finding on fields from other tables requires joining those tables. // You can handle fields from other tables by adding the joins here // If you add more joins you probably want to make sure that the - // above foreach only handles fields from the internment table. + // above foreach only handles fields from the internments table. $this->select->order($order); if ($limit) { diff --git a/html/cemeteries/addCemetery.php b/html/cemeteries/addCemetery.php new file mode 100644 index 0000000..bf8a9ec --- /dev/null +++ b/html/cemeteries/addCemetery.php @@ -0,0 +1,32 @@ + + */ +if (!userIsAllowed('Cemeteries')) { + $_SESSION['errorMessages'][] = new Exception('noAccessAllowed'); + header('Location: '.BASE_URL.'/cemeteries'); + exit(); +} + +if (isset($_POST['cemetery'])) { + $cemetery = new Cemetery(); + foreach ($_POST['cemetery'] as $field=>$value) { + $set = 'set'.ucfirst($field); + $cemetery->$set($value); + } + + try { + $cemetery->save(); + header('Location: '.BASE_URL.'/cemeteries'); + exit(); + } + catch(Exception $e) { + $_SESSION['errorMessages'][] = $e; + } +} + +$template = new Template(); +$template->blocks[] = new Block('cemeteries/addCemeteryForm.inc'); +echo $template->render(); \ No newline at end of file diff --git a/html/cemeteries/home.php b/html/cemeteries/home.php new file mode 100644 index 0000000..d415a8b --- /dev/null +++ b/html/cemeteries/home.php @@ -0,0 +1,13 @@ + + */ + +$cemeteryList = new CemeteryList(); +$cemeteryList->find(); + +$template = new Template(); +$template->blocks[] = new Block('cemeteries/cemeteryList.inc',array('cemeteryList'=>$cemeteryList)); +echo $template->render(); \ No newline at end of file diff --git a/html/cemeteries/updateCemetery.php b/html/cemeteries/updateCemetery.php new file mode 100644 index 0000000..235358e --- /dev/null +++ b/html/cemeteries/updateCemetery.php @@ -0,0 +1,32 @@ + + */ +if (!userIsAllowed('Cemeteries')) { + $_SESSION['errorMessages'][] = new Exception('noAccessAllowed'); + header('Location: '.BASE_URL.'/cemeteries'); + exit(); +} + +$cemetery = new Cemetery($_REQUEST['cemetery_id']); +if (isset($_POST['cemetery'])) { + foreach ($_POST['cemetery'] as $field=>$value) { + $set = 'set'.ucfirst($field); + $cemetery->$set($value); + } + + try { + $cemetery->save(); + header('Location: '.BASE_URL.'/cemeteries'); + exit(); + } + catch (Exception $e) { + $_SESSION['errorMessages'][] = $e; + } +} + +$template = new Template(); +$template->blocks[] = new Block('cemeteries/updateCemeteryForm.inc',array('cemetery'=>$cemetery)); +echo $template->render(); \ No newline at end of file diff --git a/html/deeds/home.php b/html/deeds/home.php index 9715e5d..5fe1e9b 100644 --- a/html/deeds/home.php +++ b/html/deeds/home.php @@ -4,8 +4,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt * @author Cliff Ingham */ +$currentPage = isset($_GET['page']) ? (int)$_GET['page'] : 1; -$deedList = new DeedList(); +$deedList = new DeedList(null,20,$currentPage); $deedList->find(); $template = new Template(); diff --git a/scripts/migration/import.sql b/scripts/migration/import.sql new file mode 100644 index 0000000..a164e23 --- /dev/null +++ b/scripts/migration/import.sql @@ -0,0 +1,6 @@ +insert deeds (id,section,lot,lastname1,firstname1,middleInitial1, + lastname2,firstname2,middleInitial2,issueDate,notes,lot2,cemetery_id) +select r.ID,r.SEC,r.LOT,r.LNAME1,r.FNAME1,r.MI1, + r.LNAME2,r.FNAME2,r.MI2,r.DATE_ISSUE,r.NOTES,r.lot2,c.id +from rosehill.DEED r +left join cemeteries c on r.whiteoak=substr(c.name,1,1); diff --git a/templates/html/partials/panel-one.inc b/templates/html/partials/panel-one.inc index fcaf65b..07876fe 100644 --- a/templates/html/partials/panel-one.inc +++ b/templates/html/partials/panel-one.inc @@ -1,7 +1,11 @@