implement copying of Stations for Seminary copy feature
This commit is contained in:
parent
091d014815
commit
84a3855e47
8 changed files with 166 additions and 25 deletions
|
|
@ -23,6 +23,17 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy a Station.
|
||||||
|
*
|
||||||
|
* @param int $userId ID of creating user
|
||||||
|
* @param int $sourceStationId ID of Station to copy from
|
||||||
|
* @param int $targetStationId ID of Station to copy to
|
||||||
|
* @param int $seminaryMediaIds Mapping of SeminaryMedia-IDs from source Seminary to targetSeminary
|
||||||
|
*/
|
||||||
|
public abstract function copyStation($userId, $sourceStationId, $targetStationId, $seminaryMediaIds);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a Model.
|
* Load a Model.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -452,6 +452,7 @@
|
||||||
array_key_exists('achievements', $elements),
|
array_key_exists('achievements', $elements),
|
||||||
array_key_exists('charactergroupsgroups', $elements),
|
array_key_exists('charactergroupsgroups', $elements),
|
||||||
array_key_exists('charactergroupsquests', $elements),
|
array_key_exists('charactergroupsquests', $elements),
|
||||||
|
array_key_exists('charactergroupsqueststations', $elements),
|
||||||
array_key_exists('map', $elements)
|
array_key_exists('map', $elements)
|
||||||
);
|
);
|
||||||
$seminary = $this->Seminaries->getSeminaryById($seminaryId);
|
$seminary = $this->Seminaries->getSeminaryById($seminaryId);
|
||||||
|
|
|
||||||
|
|
@ -384,9 +384,11 @@
|
||||||
* @param array $groupsgroupIds Mapping of Character groups-group-IDs from source Seminary to target Seminary
|
* @param array $groupsgroupIds Mapping of Character groups-group-IDs from source Seminary to target Seminary
|
||||||
* @param array $questgroupIds Mapping of Questgroup-IDs from source Seminary to target Seminary
|
* @param array $questgroupIds Mapping of Questgroup-IDs from source Seminary to target Seminary
|
||||||
* @param array $seminaryMediaIds Mapping of Seminarymedia-IDs from source Seminary to target Seminary (optional)
|
* @param array $seminaryMediaIds Mapping of Seminarymedia-IDs from source Seminary to target Seminary (optional)
|
||||||
|
* @return array Mapping of Quest-IDs from source Seminary to target Seminary
|
||||||
*/
|
*/
|
||||||
public function copyQuestsOfSeminary($userId, $groupsgroupIds, $questgroupIds, $seminaryMediaIds=null)
|
public function copyQuestsOfSeminary($userId, $groupsgroupIds, $questgroupIds, $seminaryMediaIds=null)
|
||||||
{
|
{
|
||||||
|
$questIds = array();
|
||||||
foreach($groupsgroupIds as $sourceGroupsgroupId => $targetGroupsgroupId)
|
foreach($groupsgroupIds as $sourceGroupsgroupId => $targetGroupsgroupId)
|
||||||
{
|
{
|
||||||
// Get Quests
|
// Get Quests
|
||||||
|
|
@ -406,7 +408,7 @@
|
||||||
$userId, $targetGroupsgroupId, $questgroupIds[$quest['questgroups_id']],
|
$userId, $targetGroupsgroupId, $questgroupIds[$quest['questgroups_id']],
|
||||||
$quest['id']
|
$quest['id']
|
||||||
);
|
);
|
||||||
$targetQuestId = $this->db->getInsertId();
|
$questIds[$quest['id']] = $this->db->getInsertId();
|
||||||
|
|
||||||
// Copy media
|
// Copy media
|
||||||
if(!is_null($seminaryMediaIds) && !is_null($quest['questsmedia_id']))
|
if(!is_null($seminaryMediaIds) && !is_null($quest['questsmedia_id']))
|
||||||
|
|
@ -418,11 +420,18 @@
|
||||||
'WHERE id = ?',
|
'WHERE id = ?',
|
||||||
'ii',
|
'ii',
|
||||||
$seminaryMediaIds[$quest['questsmedia_id']],
|
$seminaryMediaIds[$quest['questsmedia_id']],
|
||||||
$targetQuestId
|
$questIds[$quest['id']]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Copy Stations
|
||||||
|
//$this->Charactergroupsqueststations->copyStationsOfQuest($quest['id'], $targetQuestId, $seminaryMediaIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Return target Quest-IDs
|
||||||
|
return $questIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,13 @@
|
||||||
*/
|
*/
|
||||||
const STATUS_SOLVED = 3;
|
const STATUS_SOLVED = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Required models
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $models = array('stationtypes');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -103,6 +110,7 @@
|
||||||
return $data[0];
|
return $data[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all Stations for a Character groups Quest.
|
* Get all Stations for a Character groups Quest.
|
||||||
*
|
*
|
||||||
|
|
@ -112,7 +120,7 @@
|
||||||
public function getStationsForQuest($questId)
|
public function getStationsForQuest($questId)
|
||||||
{
|
{
|
||||||
return $this->db->query(
|
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 '.
|
'FROM charactergroupsqueststations '.
|
||||||
'WHERE charactergroupsquest_id = ? '.
|
'WHERE charactergroupsquest_id = ? '.
|
||||||
'ORDER BY pos ASC',
|
'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.
|
* Mark a Station as entered for a Character group.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $models = array('questgroupshierarchy', 'questgroups', 'quests', 'questtopics', 'media', 'characters', 'charactertypes', 'xplevels', 'avatars', 'achievements', 'charactergroups', 'charactergroupsquests', 'seminarycharacterfields', 'map', 'uploads');
|
public $models = array('questgroupshierarchy', 'questgroups', 'quests', 'questtopics', 'media', 'characters', 'charactertypes', 'xplevels', 'avatars', 'achievements', 'charactergroups', 'charactergroupsquests', 'charactergroupsqueststations', 'seminarycharacterfields', 'map', 'uploads');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -328,27 +328,28 @@
|
||||||
/**
|
/**
|
||||||
* Copy a Seminary and its content.
|
* Copy a Seminary and its content.
|
||||||
*
|
*
|
||||||
* @param int $userId ID of copying user
|
* @param int $userId ID of copying user
|
||||||
* @param int $sourceSeminaryId ID of Seminary to copy
|
* @param int $sourceSeminaryId ID of Seminary to copy
|
||||||
* @param string $title Title of new Seminary
|
* @param string $title Title of new Seminary
|
||||||
* @param string $course Course of now Seminary
|
* @param string $course Course of now Seminary
|
||||||
* @param string $description Description of new Seminary
|
* @param string $description Description of new Seminary
|
||||||
* @param boolean $copySeminaryfields Whether to copy Seminary Character fields of not
|
* @param boolean $copySeminaryfields Whether to copy Seminary Character fields of not
|
||||||
* @param boolean $copyMedia Whether to copy media or not
|
* @param boolean $copyMedia Whether to copy media or not
|
||||||
* @param boolean $copyQuestgroupshierarchy Whether to copy Questgroupshierarchy or not
|
* @param boolean $copyQuestgroupshierarchy Whether to copy Questgroupshierarchy or not
|
||||||
* @param boolean $copyQuestgroups Whether to copy Questgroups or not
|
* @param boolean $copyQuestgroups Whether to copy Questgroups or not
|
||||||
* @param boolean $copyQuests Whether to copy Quests or not
|
* @param boolean $copyQuests Whether to copy Quests or not
|
||||||
* @param boolean $copyQuesttopics Whether to copy Quest topics or not
|
* @param boolean $copyQuesttopics Whether to copy Quest topics or not
|
||||||
* @param boolean $copyCharactertypes Whether to copy Charactertypes or not
|
* @param boolean $copyCharactertypes Whether to copy Charactertypes or not
|
||||||
* @param boolean $copyXPlevels Whether to copy XP-levels or not
|
* @param boolean $copyXPlevels Whether to copy XP-levels or not
|
||||||
* @param boolean $copyAvatars Whether to copy Avatars or not
|
* @param boolean $copyAvatars Whether to copy Avatars or not
|
||||||
* @param boolean $copyAchievements Whether to copy Achievements or not
|
* @param boolean $copyAchievements Whether to copy Achievements or not
|
||||||
* @param boolean $copyCharactergroupsgroups Whether to copy Character groups-groups 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 $copyCharactergroupsquests Whether to copy Character groups Quests or not
|
||||||
* @param boolean $copyMap Whether to copy Map or not
|
* @param boolean $copyCharactergroupsqueststations Whether to copy Character groups Quest Stations or not
|
||||||
* @return ID of newly created Seminary
|
* @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, $copyMap)
|
public function copySeminary($userId, $sourceSeminaryId, $title, $course, $description, $copySeminaryfields, $copyMedia, $copyQuestgroupshierarchy, $copyQuestgroups, $copyQuests, $copyQuesttopics, $copyCharactertypes, $copyXPlevels, $copyAvatars, $copyAchievements, $copyCharactergroupsgroups, $copyCharactergroupsquests, $copyCharactergroupsqueststations, $copyMap)
|
||||||
{
|
{
|
||||||
// Get Seminary
|
// Get Seminary
|
||||||
$seminary = $this->getSeminaryById($sourceSeminaryId);
|
$seminary = $this->getSeminaryById($sourceSeminaryId);
|
||||||
|
|
@ -437,12 +438,17 @@
|
||||||
|
|
||||||
// Copy Charactergroups content
|
// Copy Charactergroups content
|
||||||
// Charactergroupsgroups
|
// Charactergroupsgroups
|
||||||
|
$characterGroupsgroupIds = null;
|
||||||
|
$charactergroupsquestIds = null;
|
||||||
if($copyCharactergroupsgroups)
|
if($copyCharactergroupsgroups)
|
||||||
{
|
{
|
||||||
$characterGroupsgroupIds = $this->Charactergroups->copyGroupsgroupsOfSeminary($userId, $sourceSeminaryId, $targetSeminaryId);
|
$characterGroupsgroupIds = $this->Charactergroups->copyGroupsgroupsOfSeminary($userId, $sourceSeminaryId, $targetSeminaryId);
|
||||||
// Copy Charactergroupsquests
|
// Copy Charactergroupsquests
|
||||||
if($copyCharactergroupsquests &!is_null($questgroupIds)) {
|
if($copyCharactergroupsquests &!is_null($questgroupIds)) {
|
||||||
$this->Charactergroupsquests->copyQuestsOfSeminary($userId, $characterGroupsgroupIds, $questgroupIds, $seminaryMediaIds);
|
$charactergroupsquestIds = $this->Charactergroupsquests->copyQuestsOfSeminary($userId, $characterGroupsgroupIds, $questgroupIds, $seminaryMediaIds);
|
||||||
|
if($copyCharactergroupsqueststations && !is_null($charactergroupsquestIds)) {
|
||||||
|
$this->Charactergroupsqueststations->copyStationsOfSeminary($userId, $charactergroupsquestIds, $seminaryMediaIds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,30 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy a Station.
|
||||||
|
*
|
||||||
|
* @param int $userId ID of creating user
|
||||||
|
* @param int $sourceStationId ID of Station to copy from
|
||||||
|
* @param int $targetStationId ID of Station to copy to
|
||||||
|
* @param int $seminaryMediaIds Mapping of SeminaryMedia-IDs from source Seminary to targetSeminary
|
||||||
|
*/
|
||||||
|
public function copyStation($userId, $sourceStationId, $targetStationId, $seminaryMediaIds)
|
||||||
|
{
|
||||||
|
// Copy keyword
|
||||||
|
$this->db->query(
|
||||||
|
'INSERT INTO stationtypes_keyword '.
|
||||||
|
'(station_id, created_user_id, keyword_regex) '.
|
||||||
|
'SELECT ?, ?, keyword_regex '.
|
||||||
|
'FROM stationtypes_keyword '.
|
||||||
|
'WHERE station_id = ?',
|
||||||
|
'iii',
|
||||||
|
$targetStationId, $userId,
|
||||||
|
$sourceStationId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the task of a keyword Station
|
* Get the task of a keyword Station
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,30 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy a Station.
|
||||||
|
*
|
||||||
|
* @param int $userId ID of creating user
|
||||||
|
* @param int $sourceStationId ID of Station to copy from
|
||||||
|
* @param int $targetStationId ID of Station to copy to
|
||||||
|
* @param int $seminaryMediaIds Mapping of SeminaryMedia-IDs from source Seminary to targetSeminary
|
||||||
|
*/
|
||||||
|
public function copyStation($userId, $sourceStationId, $targetStationId, $seminaryMediaIds)
|
||||||
|
{
|
||||||
|
// Copy answers
|
||||||
|
$this->db->query(
|
||||||
|
'INSERT INTO stationtypes_multiplechoice '.
|
||||||
|
'(created_user_id, station_id, pos, answer, tick) '.
|
||||||
|
'SELECT ?, ?, pos, answer, tick '.
|
||||||
|
'FROM stationtypes_multiplechoice '.
|
||||||
|
'WHERE station_id = ?',
|
||||||
|
'iii',
|
||||||
|
$userId, $targetStationId,
|
||||||
|
$sourceStationId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all answers for a Station
|
* Get all answers for a Station
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,10 @@
|
||||||
<div class="cond">
|
<div class="cond">
|
||||||
<input type="checkbox" id="elements_charactergroupsquests" name="elements[charactergroupsquests]" <?php if(array_key_exists('charactergroupsquests', $elements)) : ?>checked="checked"<?php endif ?> />
|
<input type="checkbox" id="elements_charactergroupsquests" name="elements[charactergroupsquests]" <?php if(array_key_exists('charactergroupsquests', $elements)) : ?>checked="checked"<?php endif ?> />
|
||||||
<label for="elements_charactergroupsquests"><?=_('Character Groups Quests')?></label>
|
<label for="elements_charactergroupsquests"><?=_('Character Groups Quests')?></label>
|
||||||
|
<div class="cond">
|
||||||
|
<input type="checkbox" id="elements_charactergroupsqueststations" name="elements[charactergroupsqueststations]" <?php if(array_key_exists('charactergroupsqueststations', $elements)) : ?>checked="checked"<?php endif ?> />
|
||||||
|
<label for="elements_charactergroupsqueststations"><?=_('Character Groups Quest Stations')?></label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<input type="checkbox" id="elements_map" name="elements[map]" <?php if(array_key_exists('map', $elements)) : ?>checked="checked"<?php endif ?> />
|
<input type="checkbox" id="elements_map" name="elements[map]" <?php if(array_key_exists('map', $elements)) : ?>checked="checked"<?php endif ?> />
|
||||||
<label for="elements_map"><?=_('Map')?></label>
|
<label for="elements_map"><?=_('Map')?></label>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue