From 76ba31c04e3deb08cb1d7f63455a223caac09225 Mon Sep 17 00:00:00 2001 From: oliver Date: Tue, 2 Feb 2016 10:38:52 +0100 Subject: [PATCH] merge branch ?charactergroupsqueststations? --- app/controllers/StationtypeController.inc | 2 +- app/models/StationtypeModel.inc | 11 ++ .../CharactergroupsquestsController.inc | 35 ++++- ...CharactergroupsqueststationsController.inc | 16 ++- controllers/PagesController.inc | 1 - controllers/SeminariesController.inc | 1 + models/CharactergroupsquestsModel.inc | 13 +- models/CharactergroupsqueststationsModel.inc | 125 +++++++++++++++--- models/SeminariesModel.inc | 50 ++++--- .../keyword/KeywordStationtypeController.inc | 7 + .../keyword/KeywordStationtypeModel.inc | 25 +++- .../MultiplechoiceStationtypeModel.inc | 24 ++++ .../charactergroupsqueststations/index.tpl | 10 ++ views/html/charactergroupsquests/manage.tpl | 1 + views/html/charactergroupsquests/quest.tpl | 67 +++++++--- .../charactergroupsqueststations/edit.tpl | 8 +- .../charactergroupsqueststations/station.tpl | 35 +++-- views/html/seminaries/copy.tpl | 4 + 18 files changed, 351 insertions(+), 84 deletions(-) diff --git a/app/controllers/StationtypeController.inc b/app/controllers/StationtypeController.inc index 00e2d3b1..fbf48ba4 100644 --- a/app/controllers/StationtypeController.inc +++ b/app/controllers/StationtypeController.inc @@ -24,7 +24,7 @@ * * @var array */ - public $models = array('seminaries'); //, 'questgroups', 'quests', 'characters'); + public $models = array('seminaries'); diff --git a/app/models/StationtypeModel.inc b/app/models/StationtypeModel.inc index 4af53507..2121d9ff 100644 --- a/app/models/StationtypeModel.inc +++ b/app/models/StationtypeModel.inc @@ -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. * diff --git a/controllers/CharactergroupsquestsController.inc b/controllers/CharactergroupsquestsController.inc index 23e18f5c..e12fc02d 100644 --- a/controllers/CharactergroupsquestsController.inc +++ b/controllers/CharactergroupsquestsController.inc @@ -103,15 +103,31 @@ $station['id'], $charactergroup['id'] ); - $station['solved'] = $this->Charactergroupsqueststations->hasCharactergroupSolvedStation( - $station['id'], - $charactergroup['id'] - ); + if($station['entered']) { + $station['tried'] = $this->Charactergroupsqueststations->hasCharactergroupTriedStation( + $station['id'], + $charactergroup['id'] + ); + if($station['tried']) { + $station['solved'] = $this->Charactergroupsqueststations->hasCharactergroupSolvedStation( + $station['id'], + $charactergroup['id'] + ); + } + } } } - // Get Character groups-groups + // Get Character groups $groups = $this->Charactergroups->getGroupsForQuest($quest['id']); + foreach($groups as &$group) + { + // Get count of solved Stations + $group['stations'] = $this->Charactergroupsqueststations->getSolvedStationsForQuestAndGroup( + $quest['id'], + $group['id'] + ); + } // Get uploads $uploads = $this->Charactergroupsquests->getMediaForQuest($quest['id']); @@ -164,6 +180,14 @@ // Get Character groups $groups = $this->Charactergroups->getGroupsForGroupsgroup($groupsgroup['id']); + foreach($groups as &$group) + { + // Get count of solved Stations + $group['stations'] = $this->Charactergroupsqueststations->getSolvedStationsForQuestAndGroup( + $quest['id'], + $group['id'] + ); + } // Get allowed mimetypes $mimetypes = \nre\configs\AppConfig::$mimetypes['charactergroupsquests']; @@ -219,7 +243,6 @@ if(!is_null($this->request->getPostParam('deletemedia'))) { $uploadIds = $this->request->getPostParam('uploads'); - var_dump($uploadIds); foreach($uploadIds as $uploadId) { $this->Uploads->deleteSeminaryupload($uploadId); } diff --git a/controllers/CharactergroupsqueststationsController.inc b/controllers/CharactergroupsqueststationsController.inc index db71f747..7a5491eb 100644 --- a/controllers/CharactergroupsqueststationsController.inc +++ b/controllers/CharactergroupsqueststationsController.inc @@ -98,7 +98,7 @@ $stations = $this->Charactergroupsqueststations->getStationsForQuest($quest['id']); } elseif(!is_null($charactergroup)) { - $stations = $this->Charactergroupsqueststations->getStationsForQuestAndGroup($quest['id'], $charactergroup['id']); + $stations = $this->Charactergroupsqueststations->getEnteredStationsForQuestAndGroup($quest['id'], $charactergroup['id']); } @@ -169,10 +169,16 @@ { $groups = $this->Charactergroups->getGroupsForQueststation($station['id']); foreach($groups as &$group) { - $group['solved'] = $this->Charactergroupsqueststations->hasCharactergroupSolvedStation( + $group['tried'] = $this->Charactergroupsqueststations->hasCharactergroupTriedStation( $station['id'], $group['id'] ); + if($group['tried']) { + $group['solved'] = $this->Charactergroupsqueststations->hasCharactergroupSolvedStation( + $station['id'], + $group['id'] + ); + } } } @@ -194,9 +200,9 @@ $solved = false; $tried = false; if(!is_null($charactergroup)) { - $solved = $this->Charactergroupsqueststations->hasCharactergroupSolvedStation($station['id'], $charactergroup['id']); - if(!$solved) { - $tried = $this->Charactergroupsqueststations->hasCharactergroupTriedStation($station['id'], $charactergroup['id']); + $tried = $this->Charactergroupsqueststations->hasCharactergroupTriedStation($station['id'], $charactergroup['id']); + if($tried) { + $solved = $this->Charactergroupsqueststations->hasCharactergroupSolvedStation($station['id'], $charactergroup['id']); } } diff --git a/controllers/PagesController.inc b/controllers/PagesController.inc index eb6b2cdd..757379a3 100644 --- a/controllers/PagesController.inc +++ b/controllers/PagesController.inc @@ -162,7 +162,6 @@ $validation = $this->Validation->addValidationResult($validation, 'title', 'exist', true); } $text = $this->request->getPostParam('text'); - var_dump($text); // Edit if($validation === true) diff --git a/controllers/SeminariesController.inc b/controllers/SeminariesController.inc index 95c41cab..874b2d01 100644 --- a/controllers/SeminariesController.inc +++ b/controllers/SeminariesController.inc @@ -452,6 +452,7 @@ array_key_exists('achievements', $elements), array_key_exists('charactergroupsgroups', $elements), array_key_exists('charactergroupsquests', $elements), + array_key_exists('charactergroupsqueststations', $elements), array_key_exists('map', $elements) ); $seminary = $this->Seminaries->getSeminaryById($seminaryId); diff --git a/models/CharactergroupsquestsModel.inc b/models/CharactergroupsquestsModel.inc index 7b21674f..69393322 100644 --- a/models/CharactergroupsquestsModel.inc +++ b/models/CharactergroupsquestsModel.inc @@ -384,9 +384,11 @@ * @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 $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) { + $questIds = array(); foreach($groupsgroupIds as $sourceGroupsgroupId => $targetGroupsgroupId) { // Get Quests @@ -406,7 +408,7 @@ $userId, $targetGroupsgroupId, $questgroupIds[$quest['questgroups_id']], $quest['id'] ); - $targetQuestId = $this->db->getInsertId(); + $questIds[$quest['id']] = $this->db->getInsertId(); // Copy media if(!is_null($seminaryMediaIds) && !is_null($quest['questsmedia_id'])) @@ -418,11 +420,18 @@ 'WHERE id = ?', 'ii', $seminaryMediaIds[$quest['questsmedia_id']], - $targetQuestId + $questIds[$quest['id']] ); } + + // TODO Copy Stations + //$this->Charactergroupsqueststations->copyStationsOfQuest($quest['id'], $targetQuestId, $seminaryMediaIds); } } + + + // Return target Quest-IDs + return $questIds; } diff --git a/models/CharactergroupsqueststationsModel.inc b/models/CharactergroupsqueststationsModel.inc index 7aee5f95..cfe60632 100644 --- a/models/CharactergroupsqueststationsModel.inc +++ b/models/CharactergroupsqueststationsModel.inc @@ -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', @@ -123,28 +131,84 @@ /** - * Get all Stations for a Character groups Quest and a Character group. + * Get all Stations for a Character groups Quest that have been entered + * by a Character group. * * @param int $questId ID of Character groups Quest * @param int $groupId ID of Character group * @return array List of Station */ - public function getStationsForQuestAndGroup($questId, $groupId) + private function getEnteredStationsForQuestAndGroup($questId, $groupId) { - return $this->db->query( - 'SELECT charactergroupsqueststations.id, charactergroupsqueststations_charactergroups.created, title, url, stationpicture_id, latitude, longitude '. - 'FROM charactergroupsqueststations_charactergroups '. - 'INNER JOIN charactergroupsqueststations ON charactergroupsqueststations.id = charactergroupsqueststations_charactergroups.charactergroupsqueststation_id '. - 'WHERE '. - 'charactergroupsqueststations_charactergroups.charactergroup_id = ? AND '. - 'charactergroupsqueststations_charactergroups.status = ? AND '. - 'charactergroupsquest_id = ? '. - 'ORDER BY charactergroupsqueststations_charactergroups.created ASC', - 'iii', - $groupId, - self::STATUS_ENTERED, - $questId - ); + return $this->getStationsForQuestAndGroup($questId, $groupId, self::STATUS_ENTERED); + } + + + /** + * Get all Stations for a Character groups Quest that have been solved + * by a Character group. + * + * @param int $questId ID of Character groups Quest + * @param int $groupId ID of Character group + * @return array List of Station + */ + public function getSolvedStationsForQuestAndGroup($questId, $groupId) + { + return $this->getStationsForQuestAndGroup($questId, $groupId, self::STATUS_SOLVED); + } + + + /** + * 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); + } + } + } } @@ -508,6 +572,33 @@ ); } + + /** + * Get all Stations for a Character groups Quest with a minimum status. + * + * @param int $questId ID of Character groups Quest + * @param int $groupId ID of Character group + * @param int $statusMin Minimum status + * @return array List of Station + */ + private function getStationsForQuestAndGroup($questId, $groupId, $statusMin) + { + return $this->db->query( + 'SELECT charactergroupsqueststations.id, charactergroupsqueststations_charactergroups.created, title, url, stationpicture_id, latitude, longitude '. + 'FROM charactergroupsqueststations_charactergroups '. + 'INNER JOIN charactergroupsqueststations ON charactergroupsqueststations.id = charactergroupsqueststations_charactergroups.charactergroupsqueststation_id '. + 'WHERE '. + 'charactergroupsqueststations_charactergroups.charactergroup_id = ? AND '. + 'charactergroupsqueststations_charactergroups.status >= ? AND '. + 'charactergroupsquest_id = ? '. + 'ORDER BY charactergroupsqueststations_charactergroups.created ASC', + 'iii', + $groupId, + $statusMin, + $questId + ); + } + } ?> diff --git a/models/SeminariesModel.inc b/models/SeminariesModel.inc index 20984de6..ec5ee101 100644 --- a/models/SeminariesModel.inc +++ b/models/SeminariesModel.inc @@ -24,7 +24,7 @@ * * @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. * - * @param int $userId ID of copying user - * @param int $sourceSeminaryId ID of Seminary to copy - * @param string $title Title of new Seminary - * @param string $course Course of now Seminary - * @param string $description Description of new Seminary - * @param boolean $copySeminaryfields Whether to copy Seminary Character fields of not - * @param boolean $copyMedia Whether to copy media or not - * @param boolean $copyQuestgroupshierarchy Whether to copy Questgroupshierarchy or not - * @param boolean $copyQuestgroups Whether to copy Questgroups or not - * @param boolean $copyQuests Whether to copy Quests or not - * @param boolean $copyQuesttopics Whether to copy Quest topics or not - * @param boolean $copyCharactertypes Whether to copy Charactertypes or not - * @param boolean $copyXPlevels Whether to copy XP-levels or not - * @param boolean $copyAvatars Whether to copy Avatars or not - * @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 + * @param int $userId ID of copying user + * @param int $sourceSeminaryId ID of Seminary to copy + * @param string $title Title of new Seminary + * @param string $course Course of now Seminary + * @param string $description Description of new Seminary + * @param boolean $copySeminaryfields Whether to copy Seminary Character fields of not + * @param boolean $copyMedia Whether to copy media or not + * @param boolean $copyQuestgroupshierarchy Whether to copy Questgroupshierarchy or not + * @param boolean $copyQuestgroups Whether to copy Questgroups or not + * @param boolean $copyQuests Whether to copy Quests or not + * @param boolean $copyQuesttopics Whether to copy Quest topics or not + * @param boolean $copyCharactertypes Whether to copy Charactertypes or not + * @param boolean $copyXPlevels Whether to copy XP-levels or not + * @param boolean $copyAvatars Whether to copy Avatars or not + * @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 $copyCharactergroupsqueststations Whether to copy Character groups Quest Stations 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, $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 $seminary = $this->getSeminaryById($sourceSeminaryId); @@ -437,12 +438,17 @@ // Copy Charactergroups content // Charactergroupsgroups + $characterGroupsgroupIds = null; + $charactergroupsquestIds = null; if($copyCharactergroupsgroups) { $characterGroupsgroupIds = $this->Charactergroups->copyGroupsgroupsOfSeminary($userId, $sourceSeminaryId, $targetSeminaryId); // Copy Charactergroupsquests 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); + } } } diff --git a/stationtypes/keyword/KeywordStationtypeController.inc b/stationtypes/keyword/KeywordStationtypeController.inc index cf219885..c5a2609b 100644 --- a/stationtypes/keyword/KeywordStationtypeController.inc +++ b/stationtypes/keyword/KeywordStationtypeController.inc @@ -157,9 +157,16 @@ */ private function isMatching($regex, $answer) { + // Check regex + if(empty($regex)) { + return false; + } + + // Execute regex $score = preg_match($regex, trim($answer)); + // Return result return ($score !== false && $score > 0); } diff --git a/stationtypes/keyword/KeywordStationtypeModel.inc b/stationtypes/keyword/KeywordStationtypeModel.inc index 8ba39749..eef2e2e8 100644 --- a/stationtypes/keyword/KeywordStationtypeModel.inc +++ b/stationtypes/keyword/KeywordStationtypeModel.inc @@ -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 * @@ -89,7 +113,6 @@ 'iiss', $stationId, $charactergroupId, $answer, $answer ); - var_dump("saved"); } } diff --git a/stationtypes/multiplechoice/MultiplechoiceStationtypeModel.inc b/stationtypes/multiplechoice/MultiplechoiceStationtypeModel.inc index 312f0070..6756bc05 100644 --- a/stationtypes/multiplechoice/MultiplechoiceStationtypeModel.inc +++ b/stationtypes/multiplechoice/MultiplechoiceStationtypeModel.inc @@ -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 * diff --git a/views/ajax/charactergroupsqueststations/index.tpl b/views/ajax/charactergroupsqueststations/index.tpl index 4a15f972..ef03b88d 100644 --- a/views/ajax/charactergroupsqueststations/index.tpl +++ b/views/ajax/charactergroupsqueststations/index.tpl @@ -12,9 +12,19 @@ floatval($station['latitude']) ); $coordinates[] = $coordinate; + // Marker $features[] = array( 'type' => 'Feature', 'id' => $station['id'], + 'geometry' => array( + 'type' => 'Point', + 'coordinates' => $coordinate + ) + ); + // Label + $features[] = array( + 'type' => 'Feature', + 'id' => $station['id'].'-label', 'properties' => array( 'name' => $station['title'], ), diff --git a/views/html/charactergroupsquests/manage.tpl b/views/html/charactergroupsquests/manage.tpl index 1064e7f3..c82b02b7 100644 --- a/views/html/charactergroupsquests/manage.tpl +++ b/views/html/charactergroupsquests/manage.tpl @@ -78,6 +78,7 @@
  • + , checked="checked" /> +
    + checked="checked" /> + +
    checked="checked" />