From e10d1d065002ce36aedcb530d45d560ee677241f Mon Sep 17 00:00:00 2001 From: coderkun Date: Wed, 19 Mar 2014 00:49:19 +0100 Subject: [PATCH] add correct abstract to seminary page --- app/Utils.inc | 32 ++++++++++++++++++++++++++++ controllers/SeminariesController.inc | 18 +++++++++++++--- models/QuestgroupsModel.inc | 26 ++++++++++++++++++++++ views/html/seminaries/seminary.tpl | 8 ++++--- 4 files changed, 78 insertions(+), 6 deletions(-) diff --git a/app/Utils.inc b/app/Utils.inc index 76ccc7fe..d248dee1 100644 --- a/app/Utils.inc +++ b/app/Utils.inc @@ -46,6 +46,38 @@ return htmlspecialchars($string, ENT_COMPAT, 'UTF-8'); } + + /** + * Cut a string to the given length but only word boundaries. + * + * @static + * @param string $string String to cut + * @param int $length Length to cut string + * @param int $scope Maximum length to cut string regardless word boundaries + * @return string Cutted string + */ + public static function shortenString($string, $length, $scope) + { + // Determine length + $length = min($length, strlen($string)); + + // Look for word boundary + if(($pos = strpos($string, ' ', $length)) !== false) + { + // Check if boundary is outside of scope + if($pos > $length + $scope) { + $pos = strrpos(substr($string, 0, $pos), ' '); + } + } + else { + $pos = strlen($string); + } + + + // Cut string and return it + return substr($string, 0, $pos); + } + } ?> diff --git a/controllers/SeminariesController.inc b/controllers/SeminariesController.inc index bf89b9f2..571e636f 100644 --- a/controllers/SeminariesController.inc +++ b/controllers/SeminariesController.inc @@ -100,9 +100,21 @@ // Get Questgroups $hierarchy['questgroups'] = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id']); - // Check permission of Questgroups - for($i=1; $iQuestgroups->hasCharacterSolvedQuestgroup($hierarchy['questgroups'][$i-1]['id'], $character['id']); + // Get additional data + for($i=0; $iQuestgroups->getFirstQuestgroupText($hierarchy['questgroups'][$i]['id']); + if(!empty($text)) + { + $text = \hhu\z\Utils::shortenString($text['text'], 100, 120).' …'; + $hierarchy['questgroups'][$i]['text'] = $text; + } + + // Check permission of Questgroups + if($i >= 1) { + $hierarchy['questgroups'][$i]['access'] = $this->Questgroups->hasCharacterSolvedQuestgroup($hierarchy['questgroups'][$i-1]['id'], $character['id']); + } } } diff --git a/models/QuestgroupsModel.inc b/models/QuestgroupsModel.inc index 088d54c0..d19795d2 100644 --- a/models/QuestgroupsModel.inc +++ b/models/QuestgroupsModel.inc @@ -145,6 +145,32 @@ } + /** + * Get first texts of a Questgroup. + * + * @param int $questgroupId ID of a Questgroup + * @return array First Text of this Questgroup + */ + public function getFirstQuestgroupText($questgroupId) + { + $data = $this->db->query( + 'SELECT id, pos, text '. + 'FROM questgrouptexts '. + 'WHERE questgroup_id = ? '. + 'ORDER BY pos ASC '. + 'LIMIT 1', + 'i', + $questgroupId + ); + if(!empty($data)) { + return $data[0]; + } + + + return null; + } + + /** * Get the next Questgroup. * diff --git a/views/html/seminaries/seminary.tpl b/views/html/seminaries/seminary.tpl index d902183e..eadd7b0b 100644 --- a/views/html/seminaries/seminary.tpl +++ b/views/html/seminaries/seminary.tpl @@ -1,6 +1,6 @@

-

Beschreibung

+

@@ -18,7 +18,9 @@

350 / 450 XP

-

Einleitungstext: Mit völlig verseuchtem Tagewerk machst du dich an die Arbeit und stellst schnell fest...

+ +

+ Auf ins Abenteuer!

@@ -39,4 +41,4 @@

format(new \DateTime($seminary['created'])))?> -

\ No newline at end of file +