implement copying a complete Seminary (implements issue #7)
This commit is contained in:
parent
a7a4652a0e
commit
b2d00bc624
31 changed files with 2151 additions and 157 deletions
|
|
@ -19,10 +19,55 @@
|
|||
*/
|
||||
class BossfightQuesttypeModel extends \hhu\z\models\QuesttypeModel
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('media');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy a Quest
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceQuestId ID of Quest to copy from
|
||||
* @param int $targetQuestId ID of Quest to copy to
|
||||
* @param int $seminaryMediaIds Mapping of SeminaryMedia-IDs from source Seminary to targetSeminary
|
||||
*/
|
||||
public function copyQuest($userId, $sourceQuestId, $targetQuestId, $seminaryMediaIds)
|
||||
{
|
||||
// Check Seminary media
|
||||
if(is_null($seminaryMediaIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get boss fight
|
||||
$bossfight = $this->getBossFight($sourceQuestId);
|
||||
|
||||
// Copy media
|
||||
$this->Media->copyQuestsmedia($userId, $seminaryMediaIds[$bossfight['boss_seminarymedia_id']]);
|
||||
|
||||
// Copy boss fight
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_bossfight '.
|
||||
'(quest_id, created_user_id, bossname, boss_seminarymedia_id, lives_character, lives_boss) '.
|
||||
'SELECT ?, ?, bossname, ?, lives_character, lives_boss '.
|
||||
'FROM questtypes_bossfight '.
|
||||
'WHERE quest_id = ?',
|
||||
'iiii',
|
||||
$targetQuestId, $userId, $seminaryMediaIds[$bossfight['boss_seminarymedia_id']],
|
||||
$sourceQuestId
|
||||
);
|
||||
|
||||
// Copy stages
|
||||
$stage = $this->getFirstStage($sourceQuestId);
|
||||
$this->copyStage($userId, $targetQuestId, $stage);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a Boss-Fight.
|
||||
*
|
||||
|
|
@ -57,7 +102,7 @@
|
|||
public function getFirstStage($questId)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT id, text, question, livedrain_character, livedrain_boss '.
|
||||
'SELECT id, parent_stage_id, text, question, livedrain_character, livedrain_boss '.
|
||||
'FROM questtypes_bossfight_stages '.
|
||||
'WHERE questtypes_bossfight_quest_id = ? AND parent_stage_id IS NULL',
|
||||
'i',
|
||||
|
|
@ -105,7 +150,7 @@
|
|||
public function getChildStages($parentStageId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, text, question, livedrain_character, livedrain_boss '.
|
||||
'SELECT id, parent_stage_id, text, question, livedrain_character, livedrain_boss '.
|
||||
'FROM questtypes_bossfight_stages '.
|
||||
'WHERE parent_stage_id = ?',
|
||||
'i',
|
||||
|
|
@ -177,6 +222,55 @@
|
|||
|
||||
return (!empty($data));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy a Bossfight stage and its child-stages.
|
||||
*
|
||||
* @param int $userId ID of copying user
|
||||
* @param int $targetQuestId ID of Quest to copy to
|
||||
* @param array $stage Data of stage to copy
|
||||
* @param array $stageIds Mapping of Stage-IDs from source Seminary to target Seminary
|
||||
*/
|
||||
private function copyStage($userId, $targetQuestId, $stage, $stageIds=array())
|
||||
{
|
||||
// Copy stage
|
||||
if(is_null($stage['parent_stage_id']))
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_bossfight_stages '.
|
||||
'(questtypes_bossfight_quest_id, text, question, livedrain_character, livedrain_boss) '.
|
||||
'SELECT ?, text, question, livedrain_character, livedrain_boss '.
|
||||
'FROM questtypes_bossfight_stages '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$targetQuestId,
|
||||
$stage['id']
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_bossfight_stages '.
|
||||
'(questtypes_bossfight_quest_id, parent_stage_id, text, question, livedrain_character, livedrain_boss) '.
|
||||
'SELECT ?, ?, text, question, livedrain_character, livedrain_boss '.
|
||||
'FROM questtypes_bossfight_stages '.
|
||||
'WHERE id = ?',
|
||||
'iii',
|
||||
$targetQuestId, $stageIds[$stage['parent_stage_id']],
|
||||
$stage['id']
|
||||
);
|
||||
}
|
||||
$stageIds[$stage['id']] = $this->db->getInsertId();
|
||||
|
||||
// Copy child stages
|
||||
$childStages = $this->getChildStages($stage['id']);
|
||||
foreach($childStages as $childStage) {
|
||||
$this->copyStage($userId, $targetQuestId, $childStage, $stageIds);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,79 @@
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* Copy a Quest
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceQuestId ID of Quest to copy from
|
||||
* @param int $targetQuestId ID of Quest to copy to
|
||||
* @param int $seminaryMediaIds Mapping of SeminaryMedia-IDs from source Seminary to targetSeminary
|
||||
*/
|
||||
public function copyQuest($userId, $sourceQuestId, $targetQuestId, $seminaryMediaIds)
|
||||
{
|
||||
// Copy choiceinput
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_choiceinput '.
|
||||
'(quest_id, created_user_id, text) '.
|
||||
'SELECT ?, ?, text '.
|
||||
'FROM questtypes_choiceinput '.
|
||||
'WHERE quest_id = ?',
|
||||
'iii',
|
||||
$targetQuestId, $userId,
|
||||
$sourceQuestId
|
||||
);
|
||||
|
||||
// Copy lists
|
||||
$lists = $this->getChoiceinputLists($sourceQuestId);
|
||||
foreach($lists as &$list)
|
||||
{
|
||||
// Copy list
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_choiceinput_lists '.
|
||||
'(questtypes_choiceinput_quest_id, number) '.
|
||||
'SELECT ?, number '.
|
||||
'FROM questtypes_choiceinput_lists '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$targetQuestId,
|
||||
$list['id']
|
||||
);
|
||||
$targetListId = $this->db->getInsertId();
|
||||
|
||||
// Copy choices
|
||||
$choiceIds = array();
|
||||
$choices = $this->getChoiceinputChoices($list['id']);
|
||||
foreach($choices as $choice)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_choiceinput_choices '.
|
||||
'(questtypes_choiceinput_list_id, pos, text) '.
|
||||
'SELECT ?, pos, text '.
|
||||
'FROM questtypes_choiceinput_choices '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$targetListId,
|
||||
$choice['id']
|
||||
);
|
||||
$choiceIds[$choice['id']] = $this->db->getInsertId();
|
||||
}
|
||||
|
||||
// Set correct choice
|
||||
if(!is_null($list['questtypes_choiceinput_choice_id']))
|
||||
{
|
||||
$this->db->query(
|
||||
'UPDATE questtypes_choiceinput_lists '.
|
||||
'SET questtypes_choiceinput_choice_id = ? '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$choiceIds[$list['questtypes_choiceinput_choice_id']],
|
||||
$targetListId
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get choiceinput-text for a Quest.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -23,6 +23,30 @@
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* Copy a Quest
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceQuestId ID of Quest to copy from
|
||||
* @param int $targetQuestId ID of Quest to copy to
|
||||
* @param int $seminaryMediaIds Mapping of SeminaryMedia-IDs from source Seminary to targetSeminary
|
||||
*/
|
||||
public function copyQuest($userId, $sourceQuestId, $targetQuestId, $seminaryMediaIds)
|
||||
{
|
||||
// Copy words
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_crossword_words '.
|
||||
'(quest_id, question, word, vertical, pos_x, pos_y) '.
|
||||
'SELECT ?, question, word, vertical, pos_x, pos_y '.
|
||||
'FROM questtypes_crossword_words '.
|
||||
'WHERE quest_id = ?',
|
||||
'ii',
|
||||
$targetQuestId,
|
||||
$sourceQuestId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all words for a crossword-Quest.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -19,10 +19,115 @@
|
|||
*/
|
||||
class DragndropQuesttypeModel extends \hhu\z\models\QuesttypeModel
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('media');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy a Quest
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceQuestId ID of Quest to copy from
|
||||
* @param int $targetQuestId ID of Quest to copy to
|
||||
* @param int $seminaryMediaIds Mapping of SeminaryMedia-IDs from source Seminary to targetSeminary
|
||||
*/
|
||||
public function copyQuest($userId, $sourceQuestId, $targetQuestId, $seminaryMediaIds)
|
||||
{
|
||||
// Check Seminary media
|
||||
if(is_null($seminaryMediaIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get Dragndrop
|
||||
$dragndrop = $this->getDragndrop($sourceQuestId);
|
||||
|
||||
// Copy media
|
||||
$this->Media->copyQuestsmedia($userId, $seminaryMediaIds[$dragndrop['questmedia_id']]);
|
||||
|
||||
// Copy dran&drop
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_dragndrop '.
|
||||
'(quest_id, created_user_id, questmedia_id, width, height) '.
|
||||
'SELECT ?, ?, ?, width, height '.
|
||||
'FROM questtypes_dragndrop '.
|
||||
'WHERE quest_id = ?',
|
||||
'iiii',
|
||||
$targetQuestId, $userId, $seminaryMediaIds[$dragndrop['questmedia_id']],
|
||||
$sourceQuestId
|
||||
);
|
||||
|
||||
// Copy drags
|
||||
$dragIds = array();
|
||||
$drags = $this->getDrags($sourceQuestId);
|
||||
foreach($drags as &$drag)
|
||||
{
|
||||
// Copy media
|
||||
$this->Media->copyQuestsmedia($userId, $seminaryMediaIds[$drag['questmedia_id']]);
|
||||
|
||||
// Copy drag
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_dragndrop_drags '.
|
||||
'(questtypes_dragndrop_id, questmedia_id) '.
|
||||
'SELECT ?, ? '.
|
||||
'FROM questtypes_dragndrop_drags '.
|
||||
'WHERE id = ?',
|
||||
'iii',
|
||||
$targetQuestId, $seminaryMediaIds[$drag['questmedia_id']],
|
||||
$drag['id']
|
||||
);
|
||||
$dragIds[$drag['id']] = $this->db->getInsertId();
|
||||
}
|
||||
|
||||
// Copy drops
|
||||
$dropIds = array();
|
||||
$drops = $this->getDrops($sourceQuestId);
|
||||
foreach($drops as &$drop)
|
||||
{
|
||||
// Copy drop
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_dragndrop_drops '.
|
||||
'(questtypes_dragndrop_id, top, `left`, width, height) '.
|
||||
'SELECT ?, top, `left`, width, height '.
|
||||
'FROM questtypes_dragndrop_drops '.
|
||||
'WHERE id = ?',
|
||||
'ii',
|
||||
$targetQuestId,
|
||||
$drop['id']
|
||||
);
|
||||
$dropIds[$drop['id']] = $this->db->getInsertId();
|
||||
|
||||
// Link drags and drops
|
||||
$links = $this->db->query(
|
||||
'SELECT questtypes_dragndrop_drag_id '.
|
||||
'FROM questtypes_dragndrop_drops_drags '.
|
||||
'WHERE questtypes_dragndrop_drop_id = ?',
|
||||
'i',
|
||||
$drop['id']
|
||||
);
|
||||
foreach($links as $link)
|
||||
{
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_dragndrop_drops_drags '.
|
||||
'(questtypes_dragndrop_drop_id, questtypes_dragndrop_drag_id, created_user_id) '.
|
||||
'VALUES '.
|
||||
'(?, ?, ?)',
|
||||
'iii',
|
||||
$dropIds[$drop['id']],
|
||||
$dragIds[$link['questtypes_dragndrop_drag_id']],
|
||||
$userId
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get Drag&Drop-field.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -23,6 +23,50 @@
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* Copy a Quest
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceQuestId ID of Quest to copy from
|
||||
* @param int $targetQuestId ID of Quest to copy to
|
||||
* @param int $seminaryMediaIds Mapping of SeminaryMedia-IDs from source Seminary to targetSeminary
|
||||
*/
|
||||
public function copyQuest($userId, $sourceQuestId, $targetQuestId, $seminaryMediaIds)
|
||||
{
|
||||
// Get questions
|
||||
$questions = $this->getQuestionsOfQuest($sourceQuestId);
|
||||
|
||||
// Copy each question
|
||||
foreach($questions as &$question)
|
||||
{
|
||||
// Copy question
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_multiplechoice '.
|
||||
'(created_user_id, quest_id, pos, question) '.
|
||||
'SELECT ?, ?, pos, question '.
|
||||
'FROM questtypes_multiplechoice '.
|
||||
'WHERE id = ?',
|
||||
'iii',
|
||||
$userId, $targetQuestId,
|
||||
$question['id']
|
||||
);
|
||||
$targetQuestionId = $this->db->getInsertId();
|
||||
|
||||
// Copy answers
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_multiplechoice_answers '.
|
||||
'(created_user_id, questtypes_multiplechoice_id, pos, answer, tick) '.
|
||||
'SELECT ?, ?, pos, answer, tick '.
|
||||
'FROM questtypes_multiplechoice_answers '.
|
||||
'WHERE questtypes_multiplechoice_id = ?',
|
||||
'iii',
|
||||
$userId, $targetQuestionId,
|
||||
$question['id']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the count of multiple choice questions for a Quest.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -29,6 +29,19 @@
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* Copy a Quest
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceQuestId ID of Quest to copy from
|
||||
* @param int $targetQuestId ID of Quest to copy to
|
||||
* @param int $seminaryMediaIds Mapping of SeminaryMedia-IDs from source Seminary to targetSeminary
|
||||
*/
|
||||
public function copyQuest($userId, $sourceQuestId, $targetQuestId, $seminaryMediaIds)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save Character’s submitted upload.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -23,6 +23,42 @@
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* Copy a Quest
|
||||
*
|
||||
* @param int $userId ID of creating user
|
||||
* @param int $sourceQuestId ID of Quest to copy from
|
||||
* @param int $targetQuestId ID of Quest to copy to
|
||||
* @param int $seminaryMediaIds Mapping of SeminaryMedia-IDs from source Seminary to targetSeminary
|
||||
*/
|
||||
public function copyQuest($userId, $sourceQuestId, $targetQuestId, $seminaryMediaIds)
|
||||
{
|
||||
// Copy textinput
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_textinput '.
|
||||
'(quest_id, created_user_id, text) '.
|
||||
'SELECT ?, ?, text '.
|
||||
'FROM questtypes_textinput '.
|
||||
'WHERE quest_id = ?',
|
||||
'iii',
|
||||
$targetQuestId, $userId,
|
||||
$sourceQuestId
|
||||
);
|
||||
|
||||
// Copy fields
|
||||
$this->db->query(
|
||||
'INSERT INTO questtypes_textinput_fields '.
|
||||
'(questtypes_textinput_quest_id, number, questtypes_textinput_fieldsize_id, regex) '.
|
||||
'SELECT ?, number, questtypes_textinput_fieldsize_id, regex '.
|
||||
'FROM questtypes_textinput_fields '.
|
||||
'WHERE questtypes_textinput_quest_id = ?',
|
||||
'ii',
|
||||
$targetQuestId,
|
||||
$sourceQuestId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get textinput-text for a Quest.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue