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);
}
}
?>

View file

@ -603,6 +603,45 @@
}
/**
* Create a new map medium.
*
* @param int $userId ID of user that does the upload
* @param int $seminaryId ID of Seminary
* @param string $filename Filename of uploading media
* @param string $description Description for media
* @param string $mimetype Mimetype of media
* @param string $tmpFilename Name of temporary uploaded file
* @return mixed ID of media record or false if upload failed
*/
public function createMapMedia($userId, $seminaryId, $filename, $description, $mimetype, $tmpFilename)
{
$mediaId = false;
$this->db->setAutocommit(false);
try {
// Create Seminary media record
$mediaId = $this->createSeminaryMedia($userId, $seminaryId, $filename, $description, $mimetype);
// Upload file
$filename = ROOT.DS.\nre\configs\AppConfig::$dirs['seminarymedia'].DS.$mediaId;
if(!move_uploaded_file($tmpFilename, $filename))
{
$this->db->rollback();
$mediaId = false;
}
}
catch(\nre\exceptions\DatamodelException $e) {
$this->db->rollback();
$this->db->setAutocommit(true);
}
$this->db->setAutocommit(true);
return $mediaId;
}
/**
* Gather some information about a Seminary medium.
*

View file

@ -24,7 +24,7 @@
*
* @var array
*/
public $models = array('questgroupshierarchy', 'questgroups', 'quests', 'questtopics', 'media', 'charactertypes', 'xplevels', 'avatars', 'achievements', 'charactergroups', 'charactergroupsquests', 'seminarycharacterfields');
public $models = array('questgroupshierarchy', 'questgroups', 'quests', 'questtopics', 'media', 'charactertypes', 'xplevels', 'avatars', 'achievements', 'charactergroups', 'charactergroupsquests', 'seminarycharacterfields', 'map');
@ -259,6 +259,25 @@
}
/**
* Set the moodpic for the map of a Seminary.
*
* @param int $seminaryId ID of Seminary to set moodpic for Map for
* @param int $seminaryMediaId ID of Seminarymedia to set as moodpic
*/
public function setMoodpicForMap($seminaryId, $seminaryMediaId)
{
$this->db->query(
'UPDATE seminaries '.
'SET map_seminarymedia_id = ? '.
'WHERE id = ?',
'ii',
$seminaryMediaId,
$seminaryId
);
}
/**
* (Re-) Calculate the amount of achievable XPs for a Seminary.
*
@ -326,9 +345,10 @@
* @param boolean $copyAchievements Whether to copy Achievements or not
* @param boolean $copyCharactergroupsgroups Whether to copy Character groups-groups or not
* @param boolean $copyCharactergroupsquests Whether to copy Character groups Quests or not
* @param boolean $copyMap Whether to copy Map or not
* @return ID of newly created Seminary
*/
public function copySeminary($userId, $sourceSeminaryId, $title, $course, $description, $copySeminaryfields, $copyMedia, $copyQuestgroupshierarchy, $copyQuestgroups, $copyQuests, $copyQuesttopics, $copyCharactertypes, $copyXPlevels, $copyAvatars, $copyAchievements, $copyCharactergroupsgroups, $copyCharactergroupsquests)
public function copySeminary($userId, $sourceSeminaryId, $title, $course, $description, $copySeminaryfields, $copyMedia, $copyQuestgroupshierarchy, $copyQuestgroups, $copyQuests, $copyQuesttopics, $copyCharactertypes, $copyXPlevels, $copyAvatars, $copyAchievements, $copyCharactergroupsgroups, $copyCharactergroupsquests, $copyMap)
{
// Get Seminary
$seminary = $this->getSeminaryById($sourceSeminaryId);
@ -362,6 +382,9 @@
if(!is_null($seminary['library_seminarymedia_id'])) {
$this->setMoodpicForLibrary($targetSeminaryId, $seminaryMediaIds[$seminary['library_seminarymedia_id']]);
}
if(!is_null($seminary['map_seminarymedia_id'])) {
$this->setMoodpicForMap($targetSeminaryId, $seminaryMediaIds[$seminary['map_seminarymedia_id']]);
}
}
// Copy Quest content
@ -423,6 +446,11 @@
}
}
// Copy Map
if($copyMap && !is_null($seminaryMediaIds)) {
$this->Map->copyMapOfSeminary($sourceSeminaryId, $targetSeminaryId, $seminaryMediaIds);
}
// Recalculate XPs
$this->calculateXPsForSeminary($targetSeminaryId);