# \hhu\z\modelsQuestgroupsModel

Model to interact with Questgroups-table.

## Summary

Methods
Properties
Constants
__construct()
load()
factory()
getQuestgroupsForHierarchy()
getQuestgroupsForSeminary()
getQuestgroupById()
getQuestgroupByUrl()
getNextQuestgroup()
getPreviousQuestgroup()
setQuestgroupEntered()
hasCharacterEnteredQuestgroup()
hasCharacterSolvedQuestgroup()
getRelatedQuestsgroupsOfQuesttext()
getRelatedQuestsgroupsOfQuest()
getRelatedQuestsgroupsOfQuestgroup()
getAchievedXPsForQuestgroup()
questgroupTitleExists()
createQuestgroup()
setMoodpicForQuestgroup()
addQuestgroupToHierarchy()
moveQuestgroup()
editQuestgroup()
deleteQuestgroup()
calculateXPsForQuestgroup()
$models
QUESTGROUP_STATUS_ENTERED
No protected methods found
$db
N/A
loadDriver()
connect()
getClassName()
loadModels()
_getNextQuestgroup()
_getPreviousQuestgroup()
setQuestgroupStatus()
_getAchievedXPsForQuestgroup()
_calculateXPsForQuestgroup()
setXPsForQuestgroup()
No private properties found
N/A

File
  models/QuestgroupsModel.inc
Package
  Default
Class hierarchy
  \nre\core\Model
  \nre\models\DatabaseModel
  \hhu\z\Model
  \hhu\z\models\QuestgroupsModel

## Tags

author | Oliver Hanraths oliver.hanraths@uni-duesseldorf.de

## Constants

### QUESTGROUP_STATUS_ENTERED

    QUESTGROUP_STATUS_ENTERED

Questgroup-status: Entered

#

## Tags

None found

## Properties

### $models

    $models : array

Required models

#### Type

array

#

## Tags

None found

### $db

    $db : \nre\models\DatabaseDriver

Database connection

#### Type

\nre\models\DatabaseDriver

#

Inherited from
  \nre\models\DatabaseModel

## Tags

static |

## Methods

### __construct()

    __construct()

Construct a new QuestgroupsModel.

TODO Catch exception

#

## Tags

None found

### load()

    load(string  $modelName)

Load the class of a Model.

#### Parameters

string | $modelName | Name of the Model to load

#### Throws

\nre\exceptions\ModelNotFoundException
\nre\exceptions\ModelNotValidException

#

static

Inherited from
  \nre\core\Model

## Tags

None found

### factory()

    factory(string  $modelName)

Instantiate a Model (Factory Pattern).

#### Parameters

string | $modelName | Name of the Model to instantiate

#

static

Inherited from
  \nre\core\Model

## Tags

None found

### getQuestgroupsForHierarchy()

    getQuestgroupsForHierarchy(integer  $hierarchyId, integer  $parentQuestgroupId = null) : array

Get all Questgroups for a Questgroup hierarchy.

#### Parameters

integer | $hierarchyId | ID of the Questgroup hierarchy to get Questgroups for
integer | $parentQuestgroupId | ID of the parent Questgroup hierarchy

#### Returns

array —

Questgroups for the given hierarchy

#

## Tags

None found

### getQuestgroupsForSeminary()

    getQuestgroupsForSeminary(integer  $seminaryId) : array

Get all Questgroups for a Seminary.

#### Parameters

integer | $seminaryId | ID of Seminary

#### Returns

array —

List of Questgroups

#

## Tags

None found

### getQuestgroupById()

    getQuestgroupById(integer  $questgroupId) : array

Get a Questgroup by its ID.

#### Parameters

integer | $questgroupId | ID of a Questgroup

#### Throws

\nre\exceptions\IdNotFoundException

#### Returns

array —

Questgroup data

#

## Tags

None found

### getQuestgroupByUrl()

    getQuestgroupByUrl(integer  $seminaryId,   $questgroupUrl) : array

Get a Questgroup by its URL.

#### Parameters

integer | $seminaryId | ID of the corresponding seminary
| $questgroupUrl |

#### Throws

\nre\exceptions\IdNotFoundException

#### Returns

array —

Questgroup data

#

## Tags

None found

### getNextQuestgroup()

    getNextQuestgroup(integer  $questgroupId) : array

Get the next Questgroup.

Determine the next Questgroup. If there is no next Questgroup on the same level as the given Quest then the followed-up Questgroup from a higher hierarchy level is returned.

#### Parameters

integer | $questgroupId | ID of Questgroup to get next Questgroup of

#### Returns

array —

Questgroup data

#

## Tags

None found

### getPreviousQuestgroup()

    getPreviousQuestgroup(integer  $questgroupId) : array

Get the previous Questgroup.

Determine the previous Questgroup. If there is no previous Questgroup on the same level as the given Quest then the followed-up Questgroup from a higher hierarchy level is returned.

#### Parameters

integer | $questgroupId | ID of Questgroup to get previous Questgroup of

#### Returns

array —

Questgroup data

#

## Tags

None found

### setQuestgroupEntered()

    setQuestgroupEntered(  $questgroupId, integer  $characterId)

Mark a Questgroup as entered for a Character.

#### Parameters

| $questgroupId |
integer | $characterId | ID of Character that entered the Quest

#

## Tags

None found

### hasCharacterEnteredQuestgroup()

    hasCharacterEnteredQuestgroup(integer  $questgroupId, integer  $characterId)

Determine if the given Character has entered a Questgroup.

#### Parameters

integer | $questgroupId | ID of Questgroup to check
integer | $characterId | ID of Character to check

#

## Tags

result | boolean Whether Character has entered the Questgroup or not

### hasCharacterSolvedQuestgroup()

    hasCharacterSolvedQuestgroup(integer  $questgroupId, integer  $characterId)

Determine if the given Character has solved a Questgroup.

#### Parameters

integer | $questgroupId | ID of Questgroup to check
integer | $characterId | ID of Character to check

#

## Tags

result | boolean Whether Character has solved the Questgroup or not

### getRelatedQuestsgroupsOfQuesttext()

    getRelatedQuestsgroupsOfQuesttext(integer  $questtextId) : array

Get all related Questgroups of a Questtext.

#### Parameters

integer | $questtextId | ID of the Questtext

#### Returns

array —

Related Questgroups for the Questtext

#

## Tags

None found

### getRelatedQuestsgroupsOfQuest()

    getRelatedQuestsgroupsOfQuest(integer  $questId) : array

Get all related Questgroups of a Quest.

#### Parameters

integer | $questId | ID of the Quest

#### Returns

array —

Related Quests for the Quest

#

## Tags

None found

### getRelatedQuestsgroupsOfQuestgroup()

    getRelatedQuestsgroupsOfQuestgroup(integer  $questgroupId) : array

Get all related Questgroups of a Questgroup.

#### Parameters

integer | $questgroupId | ID of the Questgroup

#### Returns

array —

Related Questgroups for the Questgroup

#

## Tags

None found

### getAchievedXPsForQuestgroup()

    getAchievedXPsForQuestgroup(integer  $questgroupId, integer  $characterId) : integer

Summarize XPs of all Quests for a Questgroup and its sub-Questgroups solved by a Character.

#### Parameters

integer | $questgroupId | ID of Questgroup
integer | $characterId | ID of Character

#### Returns

integer —

Sum of XPs

#

## Tags

None found

### questgroupTitleExists()

    questgroupTitleExists(integer  $seminaryId, string  $title, integer  $questgroupId = null) : boolean

Check if a Questgroups title already exists for a Seminary.

#### Parameters

integer | $seminaryId | ID of Seminary
string | $title | Questgroup title to check
integer | $questgroupId | Do not check this ID (for editing)

#### Returns

boolean —

Whether Questgroup title exists or not

#

## Tags

None found

### createQuestgroup()

    createQuestgroup(integer  $userId, integer  $seminaryId, string  $title) : integer

Create a new Questgroup.

#### Parameters

integer | $userId | User-ID that creates the new character
integer | $seminaryId | ID of Seminary
string | $title | Title for new Questgroup

#### Returns

integer —

ID of new Questgroup

#

## Tags

None found

### setMoodpicForQuestgroup()

    setMoodpicForQuestgroup(integer  $questgroupId, integer  $mediaId)

Set the moodpic for a Questgroup.

#### Parameters

integer | $questgroupId | ID of Questgroup to set moodpic for
integer | $mediaId | ID of moodpic media

#

## Tags

None found

### addQuestgroupToHierarchy()

    addQuestgroupToHierarchy(integer  $questgroupId, integer  $hierarchyId, integer  $parentQuestgroupId)

Add a Questgroup to a Questgroupshierarchy.

#### Parameters

integer | $questgroupId | Id of Questgroup to add
integer | $hierarchyId | Id of Hierarchy to add Questgroup to
integer | $parentQuestgroupId | Id of parent Questgroup

#

## Tags

None found

### moveQuestgroup()

    moveQuestgroup(array  $questgroup, boolean  $up)

Move a Questgroup up (decrement position) or down (increment position).

#### Parameters

array | $questgroup | Questgroup to move
boolean | $up | True for moving up, false for down

#

## Tags

None found

### editQuestgroup()

    editQuestgroup(integer  $questgroupId, string  $title)

Edit a Questgroup.

#### Parameters

integer | $questgroupId | ID of Questgroup to edit
string | $title | New title of Questgroup

#### Throws

\nre\exceptions\DatamodelException

#

## Tags

None found

### deleteQuestgroup()

    deleteQuestgroup(integer  $questgroupId)

Delete a Questgroup.

#### Parameters

integer | $questgroupId | ID of Questgroup to delete

#

## Tags

None found

### calculateXPsForQuestgroup()

    calculateXPsForQuestgroup(integer  $questgroupId, array  $calculatedQuests = array()) : integer

Calculate the total amount of achievable XPs for a Questgroup, its sub-Questgroups, related Questgroups etc. and store this value in the database.

#### Parameters

integer | $questgroupId | ID of Questgroup
array | $calculatedQuests | Already calculated Quests

#### Returns

integer —

Sum of calculated XPs

#

## Tags

None found

### loadDriver()

    loadDriver(string  $driverName)

Load the database driver.

#### Parameters

string | $driverName | Name of the database driver

#### Throws

\nre\exceptions\DriverNotFoundException
\nre\exceptions\DriverNotValidException

#

Inherited from
  \nre\models\DatabaseModel

## Tags

None found

### connect()

    connect(string  $driverName, array  $config)

Establish a connection to the database.

#### Parameters

string | $driverName | Name of the database driver
array | $config | Connection settings

#### Throws

\nre\exceptions\DatamodelException

#

Inherited from
  \nre\models\DatabaseModel

## Tags

None found

### getClassName()

    getClassName(string  $modelName) : string

Determine the classname for the given Model name.

#### Parameters

string | $modelName | Model name to get classname of

#### Returns

string —

Classname fore the Model name

#

static

Inherited from
  \nre\core\Model

## Tags

None found

### loadModels()

    loadModels()

Load the Models of this Model.

#### Throws

\nre\exceptions\DatamodelException
\nre\exceptions\DriverNotFoundException
\nre\exceptions\DriverNotValidException
\nre\exceptions\ModelNotValidException
\nre\exceptions\ModelNotFoundException

#

Inherited from
  \nre\core\Model

## Tags

None found

### _getNextQuestgroup()

    _getNextQuestgroup(integer  $parentQuestgroupId, integer  $questgroupPos) : array

Get the next (direct) Questgroup.

#### Parameters

integer | $parentQuestgroupId | ID of parent Questgroup to get next Questgroup of
integer | $questgroupPos | Position of Questgroup to get next Questgroup of

#### Returns

array —

Data of next Questgroup or NULL

#

## Tags

None found

### _getPreviousQuestgroup()

    _getPreviousQuestgroup(integer  $parentQuestgroupId, integer  $questgroupPos) : array

Get the previous (direct) Questgroup.

#### Parameters

integer | $parentQuestgroupId | ID of parent Questgroup to get previous Questgroup of
integer | $questgroupPos | Position of Questgroup to get previous Questgroup of

#### Returns

array —

Data of previous Questgroup or NULL

#

## Tags

None found

### setQuestgroupStatus()

    setQuestgroupStatus(integer  $questgroupId, integer  $characterId, integer  $status, boolean  $repeated = true)

Mark a Questgroup for a Character.

#### Parameters

integer | $questgroupId | ID of Questgroup to mark
integer | $characterId | ID of Character to mark the Questgroup for
integer | $status | Questgroup status to mark
boolean | $repeated | Insert although status is already set for this Questgroup and Character

#

## Tags

None found

### _getAchievedXPsForQuestgroup()

    _getAchievedXPsForQuestgroup(integer  $questgroupId, integer  $characterId) : integer

Get the sum of XPs of Quests for a Questgroup solved by a Character.

#### Parameters

integer | $questgroupId | ID of Questgroup
integer | $characterId | ID of Character

#### Returns

integer —

Sum of XPs of Quests

#

## Tags

None found

### _calculateXPsForQuestgroup()

    _calculateXPsForQuestgroup(integer  $quest, array  $calculatedQuests = array()) : integer

Calculate the total amount of achievable XPs for a Quest and its following Quests by choosing the path with the highest amount of XPs.

#### Parameters

integer | $quest | Quest data
array | $calculatedQuests | Already calculated Quests

#### Returns

integer —

Sum of calculated XPs

#

## Tags

None found

### setXPsForQuestgroup()

    setXPsForQuestgroup(integer  $questgroupId, integer  $xps)

Set achievable XPs for a Questgroup.

#### Parameters

integer | $questgroupId | ID of Questgroup
integer | $xps | XPs to set

#

## Tags

None found

### QuestgroupsModel.inc