Updated Sections CRUD
This commit is contained in:
parent
9cef7f867d
commit
cdac3ec49c
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright 2014 City of Bloomington, Indiana
|
||||
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
|
||||
* @author Cliff Ingham <inghamn@bloomington.in.gov>
|
||||
*/
|
||||
namespace Application\Controllers;
|
||||
use Application\Models\Cemetery;
|
||||
use Application\Models\Section;
|
||||
use Blossom\Classes\Controller;
|
||||
use Blossom\Classes\Block;
|
||||
|
||||
class SectionsController extends Controller
|
||||
{
|
||||
public function index() { }
|
||||
|
||||
public function update()
|
||||
{
|
||||
if (!empty($_REQUEST['section_id'])) {
|
||||
try {
|
||||
$section = new Section($_REQUEST['section_id']);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$_SESSION['errorMessages'][] = $e;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!empty($_REQUEST['cemetery_id'])) {
|
||||
try {
|
||||
$section = new Section();
|
||||
$section->setCemetery_id($_REQUEST['cemetery_id']);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$_SESSION['errorMessages'][] = $e;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$_SESSION['errorMessages'][] = new \Exception('cemeteries/unknownCemetery');
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($section)) {
|
||||
header('Location: '.BASE_URL.'/cemeteries');
|
||||
exit();
|
||||
}
|
||||
|
||||
if (isset($_POST['code'])) {
|
||||
try {
|
||||
$section->handleUpdate($_POST);
|
||||
$section->save();
|
||||
|
||||
if (isset($_FILES)) {
|
||||
if (isset($_FILES['highlight_map']) && $_FILES['highlight_map']['tmp_name']) {
|
||||
$section->saveMap($_FILES['highlight_map'], 'highlight');
|
||||
}
|
||||
if (isset($_FILES['zoom_map']) && $_FILES['zoom_map']['tmp_name']) {
|
||||
$section->saveMap($_FILES['zoom_map'], 'zoom');
|
||||
}
|
||||
}
|
||||
|
||||
header('Location: '.BASE_URL.'/cemeteries/view?cemetery_id='.$section->getCemetery_id());
|
||||
exit();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$_SESSION['errorMessages'][] = $e;
|
||||
}
|
||||
}
|
||||
|
||||
$this->template->blocks[] = new Block('sections/updateForm.inc', ['section'=>$section]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright 2009-2014 City of Bloomington, Indiana
|
||||
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
|
||||
* @author Cliff Ingham <inghamn@bloomington.in.gov>
|
||||
*/
|
||||
namespace Application\Models;
|
||||
use Blossom\Classes\ActiveRecord;
|
||||
use Blossom\Classes\Database;
|
||||
use Blossom\Classes\ExternalIdentity;
|
||||
|
||||
class Section extends ActiveRecord
|
||||
{
|
||||
protected $tablename = 'sections';
|
||||
|
||||
protected $cemetery;
|
||||
|
||||
/**
|
||||
* 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|string|array $id (ID, email, username)
|
||||
*/
|
||||
public function __construct($id=null)
|
||||
{
|
||||
if ($id) {
|
||||
if (is_array($id)) {
|
||||
$this->exchangeArray($id);
|
||||
}
|
||||
else {
|
||||
$zend_db = Database::getConnection();
|
||||
$sql = 'select * from sections where id=?';
|
||||
$result = $zend_db->createStatement($sql)->execute([$id]);
|
||||
if (count($result)) {
|
||||
$this->exchangeArray($result->current());
|
||||
}
|
||||
else {
|
||||
throw new \Exception('sections/unknownSection');
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// This is where the code goes to generate a new, empty instance.
|
||||
// Set any default values for properties that need it here
|
||||
}
|
||||
}
|
||||
|
||||
public function validate()
|
||||
{
|
||||
if (!$this->getCemetery_id() || !$this->getCode()) {
|
||||
throw new Excepction('missingRequiredFields');
|
||||
}
|
||||
}
|
||||
|
||||
public function save() { parent::save(); }
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Generic Getters and Setters
|
||||
//----------------------------------------------------------------
|
||||
public function getId() { return parent::get('id'); }
|
||||
public function getCode() { return parent::get('code'); }
|
||||
public function getName() { return parent::get('name'); }
|
||||
public function getCemetery_id() { return parent::get('cemetery_id'); }
|
||||
public function getCemetery() { return parent::getForeignKeyObject(__namespace__.'\Cemetery', 'cemetery_id'); }
|
||||
|
||||
public function setCode($s) { parent::set('code', $s); }
|
||||
public function setName($s) { parent::set('name', $s); }
|
||||
public function setCemetery_id($i) { parent::setForeignKeyField (__namespace__.'\Cemetery', 'cemetery_id', $i); }
|
||||
public function setCemetery ($o) { parent::setForeignKeyObject(__namespace__.'\Cemetery', 'cemetery_id', $o); }
|
||||
|
||||
public function handleUpdate($post)
|
||||
{
|
||||
$this->setCode($post['code']);
|
||||
$this->setName($post['name']);
|
||||
$this->setCemetery_id($post['cemetery_id']);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Custom Functions
|
||||
//----------------------------------------------------------------
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getName() ? $this->getName() : $this->getCode();
|
||||
}
|
||||
|
||||
private function getMapDirectory()
|
||||
{
|
||||
return 'images/cemeteries/'.$this->getCemetery_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL to the map image
|
||||
*
|
||||
* @param string $type Either 'highlight' or 'zoom'
|
||||
* @return string
|
||||
*/
|
||||
public function getMap($type='highlight')
|
||||
{
|
||||
$imageDir = $this->getMapDirectory();
|
||||
$type = $type=='highlight' ? 'highlight' : 'zoom';
|
||||
|
||||
$glob = glob(APPLICATION_HOME."/public/$imageDir/$type/{$this->getId()}.*");
|
||||
if (count($glob)) {
|
||||
$filename = basename($glob[0]);
|
||||
return BASE_URI."/$imageDir/$type/$filename";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|string $file Either an entry from $_FILES or a path to a file
|
||||
*/
|
||||
public function saveMap($file, $type)
|
||||
{
|
||||
$imageDir = $this->getMapDirectory();
|
||||
$type = $type=='highlight' ? 'highlight' : 'zoom';
|
||||
|
||||
$directory = APPLICATION_HOME."/public/$imageDir/$type";
|
||||
|
||||
Map::saveFile($directory, $file, $this->getId());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright 2010-2014 City of Bloomington, Indiana
|
||||
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
|
||||
* @author Cliff Ingham <inghamn@bloomington.in.gov>
|
||||
*/
|
||||
namespace Application\Models;
|
||||
|
||||
use Blossom\Classes\TableGateway;
|
||||
use Zend\Db\Sql\Select;
|
||||
|
||||
class SectionsTable extends TableGateway
|
||||
{
|
||||
public function __construct() { parent::__construct('sections', __namespace__.'\Section'); }
|
||||
}
|
|
@ -1,38 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright 2009 City of Bloomington, Indiana
|
||||
* @copyright 2009-2014 City of Bloomington, Indiana
|
||||
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
|
||||
* @author Cliff Ingham <inghamn@bloomington.in.gov>
|
||||
* @param Cemetery $this->cemetery
|
||||
*/
|
||||
use Blossom\Classes\View;
|
||||
|
||||
$name = View::escape($this->cemetery->getName());
|
||||
$googleMapURL = View::escape($this->cemetery->getGoogleMapURL());
|
||||
|
||||
$title = $this->cemetery->getId() ? $this->translate('edit_cemetery') : $this->translate('add_cemetery');
|
||||
?>
|
||||
<h2>Update Cemetery</h2>
|
||||
<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" enctype="multipart/form-data">
|
||||
<fieldset><legend>Cemetery Info</legend>
|
||||
<h2><?php echo $title; ?></h2>
|
||||
<form method="post" action="<?php echo BASE_URI; ?>/cemeteries/update" enctype="multipart/form-data">
|
||||
<fieldset><legend><?php echo $this->translate('info_cemetery'); ?></legend>
|
||||
<input name="cemetery_id" type="hidden" value="<?php echo $this->cemetery->getId(); ?>" />
|
||||
|
||||
<table>
|
||||
|
||||
<tr><td><label for="cemetery-name" class="required">Name</label></td>
|
||||
<td><input name="cemetery[name]" id="cemetery-name"
|
||||
value="<?php echo View::escape($this->cemetery->getName()); ?>" />
|
||||
</td>
|
||||
<tr><td><label for="name" class="required">Name</label></td>
|
||||
<td><input name="name" id="name" value="<?php echo $name; ?>" /></td>
|
||||
</tr>
|
||||
<tr><td><label for="cemetery-googleMapURL">Google Map URL</label></td>
|
||||
<td><input name="cemetery[googleMapURL]" id="cemetery-googleMapURL"
|
||||
value="<?php echo View::escape($this->cemetery->getGoogleMapURL()); ?>" />
|
||||
</td>
|
||||
<tr><td><label for="googleMapURL">Google Map URL</label></td>
|
||||
<td><input name="googleMapURL" id="googleMapURL" value="<?php echo $googleMapURL; ?>" /></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<button type="submit" class="submit">Submit</button>
|
||||
<button type="button" class="cancel" onclick="document.location.href='<?php echo BASE_URL; ?>/cemeteries';">
|
||||
Cancel
|
||||
</button>
|
||||
<?php
|
||||
$h = $this->template->getHelper('saveAndCancelButtons');
|
||||
echo $h->saveAndCancelButtons(BASE_URI.'/cemeteries');
|
||||
?>
|
||||
</fieldset>
|
||||
<fieldset><legend>Maps</legend>
|
||||
<fieldset><legend><?php echo $this->translate(['map', 'maps', 2]); ?></legend>
|
||||
<div>
|
||||
<label for="map">Map</lable>
|
||||
<label for="map"><?php echo $this->translate(['map', 'maps', 1]); ?></lable>
|
||||
<input type="file" name="map" id="map" />
|
||||
</div>
|
||||
<?php
|
||||
|
@ -42,7 +42,7 @@
|
|||
}
|
||||
?>
|
||||
<div>
|
||||
<label for="thumbnail">Thumbnail</lable>
|
||||
<label for="thumbnail"><?php echo $this->translate('thumbnail'); ?></lable>
|
||||
<input type="file" name="thumbnail" id="thumbnail" />
|
||||
</div>
|
||||
<?php
|
||||
|
@ -52,4 +52,4 @@
|
|||
}
|
||||
?>
|
||||
</fieldset>
|
||||
</form>
|
||||
</form>
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright 2010 City of Bloomington, Indiana
|
||||
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
|
||||
* @author Cliff Ingham <inghamn@bloomington.in.gov>
|
||||
* @param Cemetery $this->cemetery
|
||||
*/
|
||||
?>
|
||||
<h2>Add Section</h2>
|
||||
<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" enctype="multipart/form-data">
|
||||
<fieldset><legend>Section Info</legend>
|
||||
<input type="hidden" name="cemetery_id" value="<?php echo $this->cemetery->getId(); ?>" />
|
||||
<table>
|
||||
|
||||
<tr><td><label for="code" class="required">Code</label></td>
|
||||
<td><input name="code" id="code" size="5" maxlength="5" /></td>
|
||||
</tr>
|
||||
|
||||
<tr><td><label for="name">Name</label></td>
|
||||
<td><input name="name" id="name" /></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<button type="submit" class="submit">Submit</button>
|
||||
<button type="button" class="cancel"
|
||||
onclick="document.location.href='<?php echo $this->cemetery->getURL(); ?>';">
|
||||
Cancel
|
||||
</button>
|
||||
</fieldset>
|
||||
|
||||
<fieldset><legend>Maps</legend>
|
||||
<div>
|
||||
<label for="highlight_map">Highlight Map</lable>
|
||||
<input type="file" name="highlight_map" id="highlight_map" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="zoom_map">Zoomed Map</lable>
|
||||
<input type="file" name="zoom_map" id="zoom_map" />
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright 2009-2014 City of Bloomington, Indiana
|
||||
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
|
||||
* @author Cliff Ingham <inghamn@bloomington.in.gov>
|
||||
* @param Section $this->section
|
||||
*/
|
||||
use Blossom\Classes\View;
|
||||
|
||||
$code = View::escape($this->section->getCode());
|
||||
$name = View::escape($this->section->getName());
|
||||
|
||||
$title = $this->section->getId() ? $this->translate('edit_section') : $this->translate('add_section');
|
||||
?>
|
||||
<h2><?php echo $title; ?></h2>
|
||||
<form method="post" action="<?php echo BASE_URI; ?>/sections/update" enctype="multipart/form-data">
|
||||
<fieldset><legend><?php echo $this->translate('info_section'); ?></legend>
|
||||
<input name="section_id" type="hidden" value="<?php echo $this->section->getId(); ?>" />
|
||||
<input name="cemetery_id" type="hidden" value="<?php echo $this->section->getCemetery_id(); ?>" />
|
||||
|
||||
<table>
|
||||
<tr><td><label for="code" class="required"><?php echo $this->translate('code'); ?></label></td>
|
||||
<td><input name="code" id="code" value="<?php echo $code; ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr><td><label for="name"><?php echo $this->translate('name'); ?></label></td>
|
||||
<td><input name="name" id="name" value="<?php echo $name; ?>" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
$h = $this->template->getHelper('saveAndCancelButtons');
|
||||
echo $h->saveAndCancelButtons($this->section->getCemetery()->getUri());
|
||||
?>
|
||||
</fieldset>
|
||||
|
||||
<fieldset><legend><?php echo $this->translate(['map', 'maps', 2]); ?></legend>
|
||||
<div>
|
||||
<label for="highlight_map"><?php echo $this->translate('map_highlight'); ?></lable>
|
||||
<input type="file" name="highlight_map" id="highlight_map" />
|
||||
</div>
|
||||
<?php
|
||||
$highlight = $this->section->getMap('highlight');
|
||||
if ($highlight) {
|
||||
echo "<div><img src=\"$highlight\" /></div>";
|
||||
}
|
||||
?>
|
||||
<div>
|
||||
<label for="zoom_map"><?php echo $this->translate('map_zoomed'); ?></lable>
|
||||
<input type="file" name="zoom_map" id="zoom_map" />
|
||||
</div>
|
||||
<?php
|
||||
$zoom = $this->section->getMap('zoom');
|
||||
if ($zoom) {
|
||||
echo "<div><img src=\"$zoom\" /></div>";
|
||||
}
|
||||
?>
|
||||
</fieldset>
|
||||
</form>
|
|
@ -1,56 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright 2009 City of Bloomington, Indiana
|
||||
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
|
||||
* @author Cliff Ingham <inghamn@bloomington.in.gov>
|
||||
* @param Section $this->section
|
||||
*/
|
||||
?>
|
||||
<h2>Update Section</h2>
|
||||
<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" enctype="multipart/form-data">
|
||||
<fieldset><legend>Section Info</legend>
|
||||
<input name="section_id" type="hidden" value="<?php echo $this->section->getId(); ?>" />
|
||||
<table>
|
||||
|
||||
<tr><td><label for="code" class="required">Code</label></td>
|
||||
<td><input name="code" id="code" value="<?php echo View::escape($this->section->getCode()); ?>" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr><td><label for="name">Name</label></td>
|
||||
<td><input name="name" id="name" value="<?php echo View::escape($this->section->getName()); ?>" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<button type="submit" class="submit">Submit</button>
|
||||
<button type="button" class="cancel"
|
||||
onclick="document.location.href='<?php echo $this->section->getCemetery()->getURL(); ?>';">
|
||||
Cancel
|
||||
</button>
|
||||
</fieldset>
|
||||
|
||||
<fieldset><legend>Maps</legend>
|
||||
<div>
|
||||
<label for="highlight_map">Highlight Map</lable>
|
||||
<input type="file" name="highlight_map" id="highlight_map" />
|
||||
</div>
|
||||
<?php
|
||||
$highlight = $this->section->getMap('highlight');
|
||||
if ($highlight) {
|
||||
echo "<div><img src=\"$highlight\" /></div>";
|
||||
}
|
||||
?>
|
||||
<div>
|
||||
<label for="zoom_map">Zoomed Map</lable>
|
||||
<input type="file" name="zoom_map" id="zoom_map" />
|
||||
</div>
|
||||
<?php
|
||||
$zoom = $this->section->getMap('zoom');
|
||||
if ($zoom) {
|
||||
echo "<div><img src=\"$zoom\" /></div>";
|
||||
}
|
||||
?>
|
||||
</fieldset>
|
||||
</form>
|
|
@ -1,235 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright 2009 City of Bloomington, Indiana
|
||||
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
|
||||
* @author Cliff Ingham <inghamn@bloomington.in.gov>
|
||||
*/
|
||||
class Section
|
||||
{
|
||||
private $id;
|
||||
private $cemetery_id;
|
||||
private $code;
|
||||
private $name;
|
||||
|
||||
private $cemetery;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
$sql = 'select * from sections where id=?';
|
||||
$result = $zend_db->fetchRow($sql,array($id));
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
foreach ($result as $field=>$value) {
|
||||
if ($value) {
|
||||
$this->$field = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Exception('sections/unknownSection');
|
||||
}
|
||||
}
|
||||
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->cemetery_id || !$this->code) {
|
||||
throw new Excepction('missingRequiredFields');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves this record back to the database
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
$data = array();
|
||||
$data['cemetery_id'] = $this->cemetery_id;
|
||||
$data['code'] = $this->code;
|
||||
$data['name'] = $this->name ? $this->name : null;
|
||||
|
||||
if ($this->id) {
|
||||
$this->update($data);
|
||||
}
|
||||
else {
|
||||
$this->insert($data);
|
||||
}
|
||||
}
|
||||
|
||||
private function update($data)
|
||||
{
|
||||
$zend_db = Database::getConnection();
|
||||
$zend_db->update('sections',$data,"id='{$this->id}'");
|
||||
}
|
||||
|
||||
private function insert($data)
|
||||
{
|
||||
$zend_db = Database::getConnection();
|
||||
$zend_db->insert('sections',$data);
|
||||
$this->id = $zend_db->lastInsertId('sections','id');
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Generic Getters
|
||||
//----------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCemetery_id()
|
||||
{
|
||||
return $this->cemetery_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
//----------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @param int $int
|
||||
*/
|
||||
public function setCemetery_id($int)
|
||||
{
|
||||
$this->cemetery = new Cemetery($int);
|
||||
$this->cemetery_id = $int;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*/
|
||||
public function setCode($string)
|
||||
{
|
||||
$this->code = trim($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*/
|
||||
public function setName($string)
|
||||
{
|
||||
$this->name = trim($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Cemetery $cemetery
|
||||
*/
|
||||
public function setCemetery($cemetery)
|
||||
{
|
||||
$this->cemetery_id = $cemetery->getId();
|
||||
$this->cemetery = $cemetery;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Custom Functions
|
||||
// We recommend adding all your custom code down here at the bottom
|
||||
//----------------------------------------------------------------
|
||||
public function __toString()
|
||||
{
|
||||
return $this->name ? $this->name : $this->code;
|
||||
}
|
||||
|
||||
private function getMapDirectory()
|
||||
{
|
||||
return 'images/cemeteries/'.$this->cemetery_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL to the map image
|
||||
*
|
||||
* @param string $type Either 'highlight' or 'zoom'
|
||||
* @return string
|
||||
*/
|
||||
public function getMap($type='highlight')
|
||||
{
|
||||
$imageDir = $this->getMapDirectory();
|
||||
$type = $type=='highlight' ? 'highlight' : 'zoom';
|
||||
|
||||
$glob = glob(APPLICATION_HOME."/html/$imageDir/$type/{$this->id}.*");
|
||||
if (count($glob)) {
|
||||
$filename = basename($glob[0]);
|
||||
return BASE_URL."/$imageDir/$type/$filename";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|string $file Either an entry from $_FILES or a path to a file
|
||||
*/
|
||||
public function saveMap($file,$type)
|
||||
{
|
||||
$imageDir = $this->getMapDirectory();
|
||||
$type = $type=='highlight' ? 'highlight' : 'zoom';
|
||||
|
||||
$directory = APPLICATION_HOME."/html/$imageDir/$type";
|
||||
|
||||
Map::saveFile($directory,$file,$this->id);
|
||||
}
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* A collection class for Section objects
|
||||
*
|
||||
* This class creates a zend_db select statement.
|
||||
* ZendDbResultIterator handles iterating and paginating those results.
|
||||
* As the results are iterated over, ZendDbResultIterator will pass each desired
|
||||
* row back to this class's loadResult() which will be responsible for hydrating
|
||||
* each Section object
|
||||
*
|
||||
* Beyond the basic $fields handled, you will need to write your own handling
|
||||
* of whatever extra $fields you need
|
||||
*
|
||||
* @copyright 2010 City of Bloomington, Indiana
|
||||
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
|
||||
* @author Cliff Ingham <inghamn@bloomington.in.gov>
|
||||
*/
|
||||
class SectionList 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='code',$limit=null,$groupBy=null)
|
||||
{
|
||||
$this->select->from('sections');
|
||||
|
||||
// Finding on fields from the sections 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 sections table.
|
||||
|
||||
$this->select->order($order);
|
||||
if ($limit) {
|
||||
$this->select->limit($limit);
|
||||
}
|
||||
if ($groupBy) {
|
||||
$this->select->group($groupBy);
|
||||
}
|
||||
$this->populateList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Hydrates all the Section 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 Section
|
||||
*/
|
||||
protected function loadResult($key)
|
||||
{
|
||||
return new Section($this->result[$key]);
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright 2009 City of Bloomington, Indiana
|
||||
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
|
||||
* @author Cliff Ingham <inghamn@bloomington.in.gov>
|
||||
*/
|
||||
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();
|
||||
if (isset($_FILES)) {
|
||||
if (isset($_FILES['map']) && $_FILES['map']['tmp_name']) {
|
||||
$cemetery->saveMap($_FILES['map'],'full');
|
||||
}
|
||||
if (isset($_FILES['thumbnail']) && $_FILES['thumbnail']['tmp_name']) {
|
||||
$section->saveMap($_FILES['thumbnail'],'thumbnail');
|
||||
}
|
||||
}
|
||||
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();
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright 2009-2010 City of Bloomington, Indiana
|
||||
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
|
||||
* @author Cliff Ingham <inghamn@bloomington.in.gov>
|
||||
*/
|
||||
$cemeteryList = new CemeteryList();
|
||||
$cemeteryList->find();
|
||||
|
||||
$template = isset($_GET['format']) ? new Template('default',$_GET['format']) : new Template();
|
||||
$template->blocks[] = new Block('cemeteries/cemeteryList.inc',array('cemeteryList'=>$cemeteryList));
|
||||
echo $template->render();
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright 2009 City of Bloomington, Indiana
|
||||
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
|
||||
* @author Cliff Ingham <inghamn@bloomington.in.gov>
|
||||
*/
|
||||
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();
|
||||
if (isset($_FILES)) {
|
||||
if (isset($_FILES['map']) && $_FILES['map']['tmp_name']) {
|
||||
$cemetery->saveMap($_FILES['map'],'full');
|
||||
}
|
||||
if (isset($_FILES['thumbnail']) && $_FILES['thumbnail']['tmp_name']) {
|
||||
$section->saveMap($_FILES['thumbnail'],'thumbnail');
|
||||
}
|
||||
}
|
||||
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();
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright 2009 City of Bloomington, Indiana
|
||||
* @license http://www.gnu.org/licenses/agpl.txt GNU/AGPL, see LICENSE.txt
|
||||
* @author Cliff Ingham <inghamn@bloomington.in.gov>
|
||||
* @param $_GET cemetery_id
|
||||
* @param $_GET section (optional)
|
||||
*/
|
||||
try {
|
||||
if (!isset($_GET['cemetery_id']) || !$_GET['cemetery_id']) {
|
||||
throw new Exception('cemeteries/unknownCemetery');
|
||||
}
|
||||
$cemetery = new Cemetery($_GET['cemetery_id']);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$_SESSION['errorMessages'][] = $e;
|
||||
header('Location: '.BASE_URL);
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
$template = isset($_GET['format'])
|
||||
? new Template('default',$_GET['format'])
|
||||
: $template = new Template();
|
||||
$template->blocks[] = new Block('cemeteries/cemeteryInfo.inc',array('cemetery'=>$cemetery));
|
||||
echo $template->render();
|
Binary file not shown.
|
@ -8,7 +8,7 @@ msgstr ""
|
|||
"Project-Id-Version: uReport 1.9\n"
|
||||
"Report-Msgid-Bugs-To: dev@bloomington.in.gov\n"
|
||||
"POT-Creation-Date: 2013-09-20 16:33-0400\n"
|
||||
"PO-Revision-Date: 2014-08-18 16:18-0500\n"
|
||||
"PO-Revision-Date: 2014-08-19 11:42-0500\n"
|
||||
"Last-Translator: Cliff Ingham <inghamn@bloomington.in.gov>\n"
|
||||
"Language-Team: City of Bloomington <dev@bloomington.in.gov>\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
|
@ -59,6 +59,9 @@ msgstr "Help"
|
|||
msgid "name"
|
||||
msgstr "Name"
|
||||
|
||||
msgid "code"
|
||||
msgstr "Code"
|
||||
|
||||
msgid "firstname"
|
||||
msgstr "First Name"
|
||||
|
||||
|
@ -120,7 +123,41 @@ msgid_plural "cemeteries"
|
|||
msgstr[0] "Cemetery"
|
||||
msgstr[1] "Cemeteries"
|
||||
|
||||
msgid "add_cemetery"
|
||||
msgstr "Add Cemetery"
|
||||
|
||||
msgid "edit_cemetery"
|
||||
msgstr "Edit Cemetery"
|
||||
|
||||
msgid "info_cemetery"
|
||||
msgstr "Cemetery Info"
|
||||
|
||||
msgid "deed"
|
||||
msgid_plural "deeds"
|
||||
msgstr[0] "Deed"
|
||||
msgstr[1] "Deeds"
|
||||
|
||||
msgid "section"
|
||||
msgid_plural "sections"
|
||||
msgstr[0] "Section"
|
||||
msgstr[1] "Sections"
|
||||
|
||||
msgid "add_section"
|
||||
msgstr "Add Section"
|
||||
|
||||
msgid "edit_section"
|
||||
msgstr "Edit Section"
|
||||
|
||||
msgid "info_section"
|
||||
msgstr "Section Info"
|
||||
|
||||
msgid "map"
|
||||
msgid_plural "maps"
|
||||
msgstr[0] "Map"
|
||||
msgstr[1] "Maps"
|
||||
|
||||
msgid "map_highlight"
|
||||
msgstr "Highlight Map"
|
||||
|
||||
msgid "map_zoomed"
|
||||
msgstr "Zoomed Map"
|
||||
|
|
|
@ -20,8 +20,8 @@ class SaveAndCancelButtons
|
|||
public function saveAndCancelButtons($cancelURL)
|
||||
{
|
||||
return "
|
||||
<button type=\"submit\" class=\"save\">{$this->template->_('labels.save')}</button>
|
||||
<a href=\"$cancelURL\" class=\"cancel\">{$this->template->_('labels.cancel')}</a>
|
||||
<button type=\"submit\" class=\"save\">{$this->template->_('save')}</button>
|
||||
<a href=\"$cancelURL\" class=\"cancel\">{$this->template->_('cancel')}</a>
|
||||
";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue