improve map feature by using its own database table and model
This commit is contained in:
parent
acfae8f2ca
commit
3ce0a6d710
5 changed files with 85 additions and 7 deletions
|
|
@ -24,7 +24,7 @@
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries');
|
||||
public $models = array('seminaries', 'map');
|
||||
/**
|
||||
* User permissions
|
||||
*
|
||||
|
|
@ -58,9 +58,13 @@
|
|||
// Get Seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get map
|
||||
$map = $this->Map->getMapOfSeminary($seminary['id']);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('map', $map);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'achievements', 'media', 'avatars', 'charactergroups', 'charactergroupsquests');
|
||||
public $models = array('seminaries', 'achievements', 'media', 'avatars', 'charactergroups', 'charactergroupsquests', 'map');
|
||||
|
||||
|
||||
|
||||
|
|
@ -158,8 +158,14 @@
|
|||
// Get Seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get map
|
||||
$map = $this->Map->getMapOfSeminary($seminary['id']);
|
||||
if(is_null($map)) {
|
||||
throw new \nre\exceptions\IdNotFoundException($seminaryUrl);
|
||||
}
|
||||
|
||||
// Get media
|
||||
$media = $this->Media->getSeminaryMediaById($seminary['map_seminarymedia_id']);
|
||||
$media = $this->Media->getSeminaryMediaById($map['seminarymedia_id']);
|
||||
|
||||
// Get file
|
||||
$file = $this->getMediaFile($media);
|
||||
|
|
|
|||
62
models/MapModel.inc
Normal file
62
models/MapModel.inc
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||
*/
|
||||
|
||||
namespace hhu\z\models;
|
||||
|
||||
|
||||
/**
|
||||
* Model to interact with the maps-table.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class MapModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new MapModel.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the map of a Seminary.
|
||||
*
|
||||
* @param int $seminaryId ID of Seminary to get map of
|
||||
* @return array Map data
|
||||
*/
|
||||
public function getMapOfSeminary($seminaryId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT seminary_id, seminarymedia_id, width, height '.
|
||||
'FROM maps '.
|
||||
'WHERE seminary_id = ?',
|
||||
'i',
|
||||
$seminaryId
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
<h1><i class="fa fa-map-marker fa-fw"></i><?=_('Map')?></h1>
|
||||
<div id="map" class="map" style="background-image:url('<?=$linker->link(array('grafics','paper.jpg'))?>')"></div>
|
||||
<script type="text/javascript">
|
||||
var extent = [0, 0, 1200, 857];
|
||||
var extent = [0, 0, <?=$map['width']?>, <?=$map['height']?>];
|
||||
var projection = new ol.proj.Projection({
|
||||
code: 'pixel',
|
||||
units: 'pixels',
|
||||
|
|
@ -29,11 +29,17 @@
|
|||
})
|
||||
})
|
||||
],
|
||||
controls: ol.control.defaults().extend([
|
||||
new ol.control.OverviewMap({
|
||||
collapsed: true,
|
||||
})
|
||||
]),
|
||||
view: new ol.View({
|
||||
projection: projection,
|
||||
center: ol.extent.getCenter(extent),
|
||||
zoom: 1
|
||||
})
|
||||
zoom: 1,
|
||||
extent: extent
|
||||
}),
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@
|
|||
<li><a href="<?=$linker->link(array('charactergroups','index',$loggedSeminary['url']))?>"><i class="fa fa-users fa-fw"></i><?=_('Character Groups')?></a></li>
|
||||
<li><a href="<?=$linker->link(array('achievements','index',$loggedSeminary['url']))?>"><i class="fa fa-trophy fa-fw"></i><?=_('Achievements')?></a></li>
|
||||
<li><a href="<?=$linker->link(array('library','index',$loggedSeminary['url']))?>"><i class="fa fa-book fa-fw"></i><?=_('Library')?></a></li>
|
||||
<?php if(!is_null($loggedSeminary['map_seminarymedia_id'])) : ?><li><a href="<?=$linker->link(array('map','index',$loggedSeminary['url']))?>"><i class="fa fa-map-marker fa-fw"></i><?=_('Map')?></a></li><?php endif ?>
|
||||
<li><a href="<?=$linker->link(array('map','index',$loggedSeminary['url']))?>"><i class="fa fa-map-marker fa-fw"></i><?=_('Map')?></a></li>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue