search for the first text of a Questgroup recursively (Issue #77)
This commit is contained in:
parent
6b74bb4d79
commit
1d04ee0508
3 changed files with 53 additions and 16 deletions
|
|
@ -126,10 +126,9 @@
|
|||
|
||||
// Get first Questgroup text
|
||||
$text = $this->Questgroups->getFirstQuestgroupText($questgroup['id']);
|
||||
if(!empty($text))
|
||||
if(!is_null($text))
|
||||
{
|
||||
$text = \hhu\z\Utils::shortenString($text['text'], 100, 120).' …';
|
||||
$questgroup['text'] = $text;
|
||||
$questgroup['text'] = \hhu\z\Utils::shortenString($text, 100, 120).' …';
|
||||
}
|
||||
|
||||
// Get cumulated data
|
||||
|
|
|
|||
|
|
@ -179,27 +179,47 @@
|
|||
|
||||
|
||||
/**
|
||||
* Get first texts of a Questgroup.
|
||||
* Get the first text of a Questgroup.
|
||||
*
|
||||
* @param int $questgroupId ID of a Questgroup
|
||||
* @return array First Text of this Questgroup
|
||||
* @return string First text of this Questgroup or NULL
|
||||
*/
|
||||
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];
|
||||
// Text of Questgroup itself
|
||||
$questgroupTexts = $this->getQuestgroupTexts($questgroupId);
|
||||
if(!empty($questgroupTexts)) {
|
||||
return $questgroupTexts[0]['text'];
|
||||
}
|
||||
|
||||
// Text of first Quest
|
||||
$quest = $this->Quests->getFirstQuestOfQuestgroup($questgroupId);
|
||||
if(!is_null($quest))
|
||||
{
|
||||
$questText = $this->Questtexts->getFirstQuestText($quest['id']);
|
||||
if(!is_null($questText)) {
|
||||
return $questText;
|
||||
}
|
||||
}
|
||||
|
||||
// Text of ChildQuestgroups
|
||||
$questgroupHierarchy = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroupId);
|
||||
$childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroupHierarchy['id']);
|
||||
foreach($childQuestgroupshierarchy as &$hierarchy)
|
||||
{
|
||||
// Get Questgroups
|
||||
$questgroups = $this->getQuestgroupsForHierarchy($hierarchy['id'], $questgroupId);
|
||||
foreach($questgroups as &$group)
|
||||
{
|
||||
$childQuestgroupText = $this->getFirstQuestgroupText($group['id']);
|
||||
if(!is_null($childQuestgroupText)) {
|
||||
return $childQuestgroupText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// No text found
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,24 @@
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* Get the first text of a Quest.
|
||||
*
|
||||
* @param int $questId ID of a Quest
|
||||
* @return string First text of this Quest or NULL
|
||||
*/
|
||||
public function getFirstQuestText($questId)
|
||||
{
|
||||
$prolog = $this->getQuesttextsOfQuest($questId, 'Prolog');
|
||||
if(!empty($prolog)) {
|
||||
return $prolog[0]['text'];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Questtexts for a Quest.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue