diff --git a/controllers/QrController.inc b/controllers/QrController.inc index b335aad1..ce4111d5 100644 --- a/controllers/QrController.inc +++ b/controllers/QrController.inc @@ -25,7 +25,7 @@ * * @var array */ - public $models = array('seminaries', 'achievements', 'charactergroups', 'charactergroupsquests', 'charactergroupsqueststations', 'charactergroupsachievements'); + public $models = array('seminaries', 'achievements', 'charactertitles', 'charactergroups', 'charactergroupsquests', 'charactergroupsqueststations', 'charactergroupsachievements'); @@ -103,6 +103,47 @@ } + /** + * Action: ct. + * + * Trigger a Character title by a hash typically provided via a QR-code. + * + * @param $titleHash Hash value of Character title + */ + public function ct($titleHash) + { + // Get Character title + $title = $this->Charactertitles->getTitleByHash($titleHash); + + // Get Seminary + $seminary = $this->Seminaries->getSeminaryById($title['seminary_id']); + + // Get Character + $character = $this->Characters->getCharacterForUserAndSeminary( + self::$user['id'], + $seminary['id'] + ); + + // Assign title to Character + $this->Charactertitles->assignTitleToCharacter( + $title['id'], + $character['id'] + ); + + // Redirect + $this->redirect( + $this->linker->link( + array( + 'characters', + 'character', + $seminary['url'], + $character['url'] + ) + ) + ); + } + + /** * Action: cgqs. * diff --git a/controllers/QrcodesController.inc b/controllers/QrcodesController.inc index 3598a223..d0acdc7d 100644 --- a/controllers/QrcodesController.inc +++ b/controllers/QrcodesController.inc @@ -24,7 +24,7 @@ * * @var array */ - public $models = array('seminaries', 'achievements', 'charactergroups', 'charactergroupsquests', 'charactergroupsqueststations', 'charactergroupsachievements'); + public $models = array('seminaries', 'achievements', 'charactertitles', 'charactergroups', 'charactergroupsquests', 'charactergroupsqueststations', 'charactergroupsachievements'); @@ -88,6 +88,37 @@ } + /** + * Action: charactertitles + * + * Display a QR-code for a Character title. + * + * @throws \nre\exceptions\IdNotFoundException + * @param string $seminaryUrl URL-Title of a Seminary + * @param string $titleHash Hash of Character title + * @param int $size Size of QR-code (default: 1) + */ + public function charactertitle($seminaryUrl, $titleHash, $size=1) + { + // Get seminary + $seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl); + + // Get Character title + $title = $this->Charactertitles->getTitleByHash($titleHash); + + // Generate QR-code + $url = $this->linker->link(array('qr', 'ct', $title['hash']), 0, true, null, true, null, true); + $file = $this->generateQRcode($url, $size); + if(is_null($file)) { + return; + } + + + // Pass data to view + $this->set('file', $file); + } + + /** * Action: charactergroupsqueststation * diff --git a/models/CharactertitlesModel.inc b/models/CharactertitlesModel.inc index e61f1e26..a962c36f 100644 --- a/models/CharactertitlesModel.inc +++ b/models/CharactertitlesModel.inc @@ -69,7 +69,7 @@ public function getTitleByHash($titleHash) { $data = $this->db->query( - 'SELECT id, hash, title_male, title_female '. + 'SELECT id, seminary_id, hash, title_male, title_female '. 'FROM charactertitles '. 'WHERE hash = ?', 's', @@ -123,6 +123,26 @@ } + /** + * Add a Character title to the list of titles for a Character. + * + * @param int $titleId ID of title to assign + * @param int $characterId ID of Character to assign title to + */ + public function assignTitleToCharacter($titleId, $characterId) + { + $this->db->query( + 'INSERT IGNORE INTO characters_charactertitles '. + '(character_id, charactertitle_id) '. + 'VALUES '. + '(?, ?)', + 'ii', + $characterId, + $titleId + ); + } + + /** * Check if a title for a Characters already exists. * diff --git a/views/binary/qrcodes/charactertitle.tpl b/views/binary/qrcodes/charactertitle.tpl new file mode 100644 index 00000000..0d6fb0df --- /dev/null +++ b/views/binary/qrcodes/charactertitle.tpl @@ -0,0 +1 @@ + diff --git a/views/html/charactertitles/index.tpl b/views/html/charactertitles/index.tpl index 33c85883..50299645 100644 --- a/views/html/charactertitles/index.tpl +++ b/views/html/charactertitles/index.tpl @@ -16,6 +16,11 @@ diff --git a/views/html/qr/ct.tpl b/views/html/qr/ct.tpl new file mode 100644 index 00000000..e69de29b