improve map implementation including edit functionality

This commit is contained in:
oliver 2015-05-17 20:53:00 +02:00
commit 1f1d91850e
10 changed files with 341 additions and 10 deletions

View file

@ -19,6 +19,12 @@
*/
class MapModel extends \hhu\z\Model
{
/**
* Required models
*
* @var array
*/
public $models = array('media');
@ -57,6 +63,85 @@
return null;
}
/**
* Set map of a Seminary.
*
* @param int $seminaryId ID of Seminary to set map of
* @param int $seminarymediaId ID of Seminary media of map to set
*/
public function setMapOfSeminary($seminaryId, $seminarymediaId)
{
// Get image measurements
$infos = $this->Media->getSeminarymediaInfos($seminarymediaId);
// Insert record
$this->db->query(
'INSERT INTO maps '.
'(seminary_id, seminarymedia_id, width, height) '.
'VALUES '.
'(?, ?, ?, ?) '.
'ON DUPLICATE KEY UPDATE '.
'seminarymedia_id = ?, width = ?, height = ?',
'iiiiiii',
$seminaryId, $seminarymediaId, $infos['width'], $infos['height'],
$seminarymediaId, $infos['width'], $infos['height']
);
}
/**
* Copy the map of a Seminary.
*
* @param int $sourceSeminaryId Seminary to copy from
* @param int $targetSeminaryId Seminary to copy to
* @param array $seminaryMediaIds Mapping of Seminarymedia-IDs from source Seminary to target Seminary
*/
public function copyMapOfSeminary($sourceSeminaryId, $targetSeminaryId, $seminaryMediaIds)
{
// Get map of source Seminary
$map = $this->getMapOfSeminary($sourceSeminaryId);
// Set map of targetSeminary
$this->setMapOfSeminary($targetSeminaryId, $seminaryMediaIds[$map['seminarymedia_id']]);
}
/**
* Delete the map of a Seminary.
*
* @param int $seminaryId ID of Seminary to delete map of
*/
public function deleteMapOfSeminary($seminaryId)
{
// Get map
$map = $this->getMap($seminaryId);
if(is_null($map)) {
return;
}
// Delete map
$this->db->setAutocommit(false);
try {
// Delete map record
$this->db->query(
'DELETE FROM maps '.
'WHERE seminary_id = ?',
'i',
$seminaryId
);
// Delete Seminary media
$this->Media->deleteSeminaryMedia($map['seminarymedia_id']);
$this->db->commit();
}
catch(\nre\exceptions\DatamodelException $e) {
$this->db->rollback();
}
$this->db->setAutocommit(true);
}
}
?>