implement copying of Stations for Seminary copy feature

This commit is contained in:
oliver 2016-01-30 20:15:13 +01:00
commit 84a3855e47
8 changed files with 166 additions and 25 deletions

View file

@ -39,6 +39,13 @@
*/
const STATUS_SOLVED = 3;
/**
* Required models
*
* @var array
*/
public $models = array('stationtypes');
@ -103,6 +110,7 @@
return $data[0];
}
/**
* Get all Stations for a Character groups Quest.
*
@ -112,7 +120,7 @@
public function getStationsForQuest($questId)
{
return $this->db->query(
'SELECT id, title, url, stationpicture_id, latitude, longitude '.
'SELECT id, stationtype_id, title, url, stationpicture_id, latitude, longitude, rightimage_id, rightav_id, wrongimage_id, wrongav_id '.
'FROM charactergroupsqueststations '.
'WHERE charactergroupsquest_id = ? '.
'ORDER BY pos ASC',
@ -148,6 +156,60 @@
}
/**
* Copy all Character groups Quest Stations of a Seminary.
*
* @param int $userId ID of creating user
* @param array $charactergroupsquestIds Mapping of Character groups Quest-IDs from source Seminary to target Seminary
* @param array $seminaryMediaIds Mapping of Seminary-media-IDs from source Seminary to target Seminary (optional)
*/
public function copyStationsOfSeminary($userId, $charactergroupsquestIds, $seminaryMediaIds)
{
// Go through each Quest
foreach($charactergroupsquestIds as $sourceQuestId => $targetQuestId)
{
// Get Stations
$stations = $this->getStationsForQuest($sourceQuestId);
// Copy each station
foreach($stations as &$station)
{
// Copy Station
$this->db->query(
'INSERT INTO charactergroupsqueststations '.
'(charactergroupsquest_id, stationtype_id, title, url, pos, stationpicture_id, prolog, task, latitude, longitude, righttext, wrongtext, rightimage_id, rightav_id, wrongimage_id, wrongav_id) '.
'SELECT ?, stationtype_id, title, url, pos, ?, prolog, task, latitude, longitude, righttext, wrongtext, ?, ?, ?, ? '.
'FROM charactergroupsqueststations '.
'WHERE id = ?',
'iiiiiii',
$targetQuestId,
(!is_null($station['stationpicture_id'])) ? $seminaryMediaIds[$station['stationpicture_id']] : null,
(!is_null($station['rightimage_id'])) ? $seminaryMediaIds[$station['rightimage_id']] : null,
(!is_null($station['rightav_id'])) ? $seminaryMediaIds[$station['rightav_id']] : null,
(!is_null($station['wrongimage_id'])) ? $seminaryMediaIds[$station['wrongimage_id']] : null,
(!is_null($station['wrongav_id'])) ? $seminaryMediaIds[$station['wrongav_id']] : null,
$station['id']
);
$targetStationId = $this->db->getInsertId();
// Copy content
$stationtype = $this->Stationtypes->getStationtypeById($station['stationtype_id']);
if(!is_null($stationtype['classname']))
{
// Load Stationtype Model
\hhu\z\models\StationtypeModel::load($stationtype['classname']);
// Construct Station Model
$stationtypeModel = \hhu\z\models\StationtypeModel::factory($stationtype['classname']);
// Copy content
$stationtypeModel->copyStation($userId, $station['id'], $targetStationId, $seminaryMediaIds);
}
}
}
}
/**
* Mark a Station as entered for a Character group.
*