restructure application classes
This commit is contained in:
parent
0e15287639
commit
ff849bd72c
29 changed files with 53 additions and 36 deletions
|
|
@ -17,7 +17,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
class BinaryAgent extends \hhu\z\ToplevelAgent
|
class BinaryAgent extends \hhu\z\agents\ToplevelAgent
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
class HtmlAgent extends \hhu\z\ToplevelAgent
|
class HtmlAgent extends \hhu\z\agents\ToplevelAgent
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
284
app/agents/QuesttypeAgent.inc
Normal file
284
app/agents/QuesttypeAgent.inc
Normal file
|
|
@ -0,0 +1,284 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Legend of Z
|
||||||
|
*
|
||||||
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
|
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||||
|
* @license http://www.gnu.org/licenses/gpl.html
|
||||||
|
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace hhu\z\agents;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class for implementing a QuesttypeAgent.
|
||||||
|
*
|
||||||
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
|
*/
|
||||||
|
abstract class QuesttypeAgent extends \nre\agents\BottomlevelAgent
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Current request
|
||||||
|
*
|
||||||
|
* @var Request
|
||||||
|
*/
|
||||||
|
private $request;
|
||||||
|
/**
|
||||||
|
* Current response
|
||||||
|
*
|
||||||
|
* @var Response
|
||||||
|
*/
|
||||||
|
private $response;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a QuesttypeAgent.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @throws QuesttypeAgentNotFoundException
|
||||||
|
* @throws QuesttypeAgentNotValidException
|
||||||
|
* @param string $questtypeName Name of the QuesttypeAgent to load
|
||||||
|
*/
|
||||||
|
public static function load($questtypeName)
|
||||||
|
{
|
||||||
|
// Determine full classname
|
||||||
|
$className = self::getClassName($questtypeName);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Load class
|
||||||
|
static::loadClass($questtypeName, $className);
|
||||||
|
|
||||||
|
// Validate class
|
||||||
|
static::checkClass($className, get_class());
|
||||||
|
}
|
||||||
|
catch(\nre\exceptions\ClassNotValidException $e) {
|
||||||
|
throw new \hhu\z\exceptions\QuesttypeAgentNotValidException($e->getClassName());
|
||||||
|
}
|
||||||
|
catch(\nre\exceptions\ClassNotFoundException $e) {
|
||||||
|
throw new \hhu\z\exceptions\QuesttypeAgentNotFoundException($e->getClassName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate a QuesttypeAgent (Factory Pattern).
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @throws DatamodelException
|
||||||
|
* @throws DriverNotValidException
|
||||||
|
* @throws DriverNotFoundException
|
||||||
|
* @throws ViewNotFoundException
|
||||||
|
* @throws QuesttypeModelNotValidException
|
||||||
|
* @throws QuesttypeModelNotFoundException
|
||||||
|
* @throws QuesttypeControllerNotValidException
|
||||||
|
* @throws QuesttypeControllerNotFoundException
|
||||||
|
* @param string $questtypeName Name of the QuesttypeAgent to instantiate
|
||||||
|
* @param Request $request Current request
|
||||||
|
* @param Response $respone Current respone
|
||||||
|
* @param Logger $log Log-system
|
||||||
|
*/
|
||||||
|
public static function factory($questtypeName, \nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
|
||||||
|
{
|
||||||
|
// Determine full classname
|
||||||
|
$className = self::getClassName($questtypeName);
|
||||||
|
|
||||||
|
// Construct and return Questmodule
|
||||||
|
return new $className($request, $response, $log);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine the Agent-classname for the given Questtype-name.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @param string $questtypeName Questtype-name to get Agent-classname of
|
||||||
|
* @return string Classname for the Questtype-name
|
||||||
|
*/
|
||||||
|
private static function getClassName($questtypeName)
|
||||||
|
{
|
||||||
|
$className = \nre\core\ClassLoader::concatClassNames($questtypeName, \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class())), 'agent');
|
||||||
|
|
||||||
|
|
||||||
|
return \nre\configs\AppConfig::$app['namespace']."questtypes\\$className";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine the classname for the given Agent name.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @param string $agentName Agent name to get classname of
|
||||||
|
* @param string $agentType Agent type of given Agent name
|
||||||
|
* @return string Classname for the Agent name
|
||||||
|
*/
|
||||||
|
/*private static function getClassName($agentName, $agentType)
|
||||||
|
{
|
||||||
|
$className = ClassLoader::concatClassNames($agentName, 'agent');
|
||||||
|
|
||||||
|
|
||||||
|
return \nre\configs\AppConfig::$app['namespace']."agents\\$agentType\\$className";
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the class of a QuesttypeAgent.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @throws ClassNotFoundException
|
||||||
|
* @param string $questtypeName Name of the QuesttypeAgent to load
|
||||||
|
* @param string $fullClassName Name of the class to load
|
||||||
|
*/
|
||||||
|
private static function loadClass($questtypeName, $fullClassName)
|
||||||
|
{
|
||||||
|
// Determine folder to look in
|
||||||
|
$className = explode('\\', $fullClassName);
|
||||||
|
$className = array_pop($className);
|
||||||
|
|
||||||
|
// Determine filename
|
||||||
|
$fileName = ROOT.DS.\nre\configs\AppConfig::$dirs['questtypes'].DS.strtolower($questtypeName).DS.$className.\nre\configs\CoreConfig::getFileExt('includes');
|
||||||
|
|
||||||
|
// Check file
|
||||||
|
if(!file_exists($fileName))
|
||||||
|
{
|
||||||
|
throw new \nre\exceptions\ClassNotFoundException(
|
||||||
|
$fullClassName
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Include file
|
||||||
|
include_once($fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check inheritance of the QuesttypeAgent-class.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @throws ClassNotValidException
|
||||||
|
* @param string $className Name of the class to check
|
||||||
|
* @param string $parentClassName Name of the parent class
|
||||||
|
*/
|
||||||
|
public static function checkClass($className, $parentClassName)
|
||||||
|
{
|
||||||
|
// Check if class is subclass of parent class
|
||||||
|
if(!is_subclass_of($className, $parentClassName)) {
|
||||||
|
throw new \nre\exceptions\ClassNotValidException(
|
||||||
|
$className
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new QuesttypeAgent.
|
||||||
|
*
|
||||||
|
* @throws DatamodelException
|
||||||
|
* @throws DriverNotValidException
|
||||||
|
* @throws DriverNotFoundException
|
||||||
|
* @throws ViewNotFoundException
|
||||||
|
* @throws ModelNotValidException
|
||||||
|
* @throws ModelNotFoundException
|
||||||
|
* @throws QuesttypeModelNotValidException
|
||||||
|
* @throws QuesttypeModelNotFoundException
|
||||||
|
* @throws QuesttypeControllerNotValidException
|
||||||
|
* @throws QuesttypeControllerNotFoundException
|
||||||
|
* @param Request $request Current request
|
||||||
|
* @param Response $respone Current response
|
||||||
|
* @param Logger $log Log-system
|
||||||
|
*/
|
||||||
|
protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
|
||||||
|
{
|
||||||
|
// Store values
|
||||||
|
$this->request = $request;
|
||||||
|
$this->response = $response;
|
||||||
|
|
||||||
|
|
||||||
|
// Call parent constructor
|
||||||
|
parent::__construct($request, $response, $log);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the answers of a Character for a Quest.
|
||||||
|
*
|
||||||
|
* @param array $seminary Current Seminary data
|
||||||
|
* @param array $questgroup Current Questgroup data
|
||||||
|
* @param array $quest Current Quest data
|
||||||
|
* @param array $character Current Character data
|
||||||
|
* @param array $answers Character answers for the Quest
|
||||||
|
*/
|
||||||
|
public function saveAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers)
|
||||||
|
{
|
||||||
|
$this->controller->saveAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if answers of a Character for a Quest match the correct ones.
|
||||||
|
*
|
||||||
|
* @param array $seminary Current Seminary data
|
||||||
|
* @param array $questgroup Current Questgroup data
|
||||||
|
* @param array $quest Current Quest data
|
||||||
|
* @param array $character Current Character data
|
||||||
|
* @param array $answers Character answers for the Quest
|
||||||
|
*/
|
||||||
|
public function matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers)
|
||||||
|
{
|
||||||
|
return $this->controller->matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the Controller of this Agent.
|
||||||
|
*
|
||||||
|
* @throws DatamodelException
|
||||||
|
* @throws DriverNotValidException
|
||||||
|
* @throws DriverNotFoundException
|
||||||
|
* @throws ViewNotFoundException
|
||||||
|
* @throws ModelNotValidException
|
||||||
|
* @throws ModelNotFoundException
|
||||||
|
* @throws QuesttypeModelNotValidException
|
||||||
|
* @throws QuesttypeModelNotFoundException
|
||||||
|
* @throws QuesttypeControllerNotValidException
|
||||||
|
* @throws QuesttypeControllerNotFoundException
|
||||||
|
*/
|
||||||
|
protected function loadController()
|
||||||
|
{
|
||||||
|
// Determine Controller name
|
||||||
|
$controllerName = \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::getClassName(get_class($this)));
|
||||||
|
|
||||||
|
// Determine ToplevelAgent
|
||||||
|
$toplevelAgentName = $this->response->getParam(0);
|
||||||
|
if(is_null($toplevelAgentName)) {
|
||||||
|
$toplevelAgentName = $this->request->getParam(0, 'toplevel');
|
||||||
|
$this->response->addParam($toplevelAgentName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine Action
|
||||||
|
$action = $this->response->getParam(2);
|
||||||
|
if(is_null($action)) {
|
||||||
|
$action = $this->request->getParam(2, 'action');
|
||||||
|
$this->response->addParam($action);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Load Controller
|
||||||
|
\hhu\z\controllers\QuesttypeController::load($controllerName);
|
||||||
|
|
||||||
|
// Construct Controller
|
||||||
|
$this->controller = \hhu\z\controllers\QuesttypeController::factory($controllerName, $toplevelAgentName, $action, $this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
36
app/agents/ToplevelAgent.inc
Normal file
36
app/agents/ToplevelAgent.inc
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Legend of Z
|
||||||
|
*
|
||||||
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
|
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||||
|
* @license http://www.gnu.org/licenses/gpl.html
|
||||||
|
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace hhu\z\agents;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class for implementing an application Controller.
|
||||||
|
*
|
||||||
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
|
*/
|
||||||
|
abstract class ToplevelAgent extends \nre\agents\ToplevelAgent
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
|
||||||
|
{
|
||||||
|
parent::__construct($request, $response, $log);
|
||||||
|
|
||||||
|
|
||||||
|
// Set timezone
|
||||||
|
date_default_timezone_set(\nre\configs\AppConfig::$app['timeZone']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
308
app/controllers/QuesttypeController.inc
Normal file
308
app/controllers/QuesttypeController.inc
Normal file
|
|
@ -0,0 +1,308 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Legend of Z
|
||||||
|
*
|
||||||
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
|
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||||
|
* @license http://www.gnu.org/licenses/gpl.html
|
||||||
|
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace hhu\z\controllers;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class for implementing a QuesttypeController.
|
||||||
|
*
|
||||||
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
|
*/
|
||||||
|
abstract class QuesttypeController extends \hhu\z\Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Required models
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $models = array('seminaries', 'questgroups', 'quests', 'characters');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the answers of a Character for a Quest.
|
||||||
|
*
|
||||||
|
* @param array $seminary Current Seminary data
|
||||||
|
* @param array $questgroup Current Questgroup data
|
||||||
|
* @param array $quest Current Quest data
|
||||||
|
* @param array $character Current Character data
|
||||||
|
* @param array $answers Character answers for the Quest
|
||||||
|
*/
|
||||||
|
public abstract function saveAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save additional data for the answers of a Character for a Quest.
|
||||||
|
*
|
||||||
|
* @param array $seminary Current Seminary data
|
||||||
|
* @param array $questgroup Current Questgroup data
|
||||||
|
* @param array $quest Current Quest data
|
||||||
|
* @param array $character Current Character data
|
||||||
|
* @param array $data Additional (POST-) data
|
||||||
|
*/
|
||||||
|
public abstract function saveDataForCharacterAnswers($seminary, $questgroup, $quest, $character, $data);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if answers of a Character for a Quest match the correct ones.
|
||||||
|
*
|
||||||
|
* @param array $seminary Current Seminary data
|
||||||
|
* @param array $questgroup Current Questgroup data
|
||||||
|
* @param array $quest Current Quest data
|
||||||
|
* @param array $character Current Character data
|
||||||
|
* @param array $answers Character answers for the Quest
|
||||||
|
* @return boolean True/false for a right/wrong answer or null for moderator evaluation
|
||||||
|
*/
|
||||||
|
public abstract function matchAnswersOfCharacter($seminary, $questgroup, $quest, $character, $answers);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action: quest.
|
||||||
|
*
|
||||||
|
* Show the task of a Quest.
|
||||||
|
*
|
||||||
|
* @param array $seminary Current Seminary data
|
||||||
|
* @param array $questgroup Current Questgroup data
|
||||||
|
* @param array $quest Current Quest data
|
||||||
|
* @param array $character Current Character data
|
||||||
|
* @param Exception $exception Character submission exception
|
||||||
|
*/
|
||||||
|
public abstract function quest($seminary, $questgroup, $quest, $character, $exception);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action: submission.
|
||||||
|
*
|
||||||
|
* Show the submission of a Character for a Quest.
|
||||||
|
*
|
||||||
|
* @param array $seminary Current Seminary data
|
||||||
|
* @param array $questgroup Current Questgroup data
|
||||||
|
* @param array $quest Current Quest data
|
||||||
|
* @param array $character Current Character data
|
||||||
|
*/
|
||||||
|
public abstract function submission($seminary, $questgroup, $quest, $character);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a QuesttypeController.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @throws QuesttypeControllerNotFoundException
|
||||||
|
* @throws QuesttypeControllerNotValidException
|
||||||
|
* @param string $controllerName Name of the QuesttypeController to load
|
||||||
|
*/
|
||||||
|
public static function load($controllerName)
|
||||||
|
{
|
||||||
|
// Determine full classname
|
||||||
|
$className = self::getClassName($controllerName);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Load class
|
||||||
|
static::loadClass($controllerName, $className);
|
||||||
|
|
||||||
|
// Validate class
|
||||||
|
static::checkClass($className, get_class());
|
||||||
|
}
|
||||||
|
catch(\nre\exceptions\ClassNotValidException $e) {
|
||||||
|
throw new \hhu\z\exceptions\QuesttypeControllerNotValidException($e->getClassName());
|
||||||
|
}
|
||||||
|
catch(\nre\exceptions\ClassNotFoundException $e) {
|
||||||
|
throw new \hhu\z\exceptions\QuesttypeControllerNotFoundException($e->getClassName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate a QuesttypeController (Factory Pattern).
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @throws DatamodelException
|
||||||
|
* @throws DriverNotFoundException
|
||||||
|
* @throws DriverNotValidException
|
||||||
|
* @throws ModelNotValidException
|
||||||
|
* @throws ModelNotFoundException
|
||||||
|
* @throws QuesttypeModelNotValidException
|
||||||
|
* @throws QuesttypeModelNotFoundException
|
||||||
|
* @throws ViewNotFoundException
|
||||||
|
* @param string $controllerName Name of the QuesttypeController to instantiate
|
||||||
|
* @param string $layoutName Name of the current Layout
|
||||||
|
* @param string $action Current Action
|
||||||
|
*/
|
||||||
|
public static function factory($controllerName, $layoutName, $action, $agent)
|
||||||
|
{
|
||||||
|
// Determine full classname
|
||||||
|
$className = self::getClassName($controllerName);
|
||||||
|
|
||||||
|
// Construct and return Controller
|
||||||
|
return new $className($layoutName, $action, $agent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine the Controller-classname for the given Questtype-name.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @param string $questtypeName Questtype-name to get Controller-classname of
|
||||||
|
* @return string Classname for the Questtype-name
|
||||||
|
*/
|
||||||
|
private static function getClassName($questtypeName)
|
||||||
|
{
|
||||||
|
$className = \nre\core\ClassLoader::concatClassNames($questtypeName, \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class())), 'controller');
|
||||||
|
|
||||||
|
|
||||||
|
return \nre\configs\AppConfig::$app['namespace']."questtypes\\$className";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the class of a QuesttypeController
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @throws ClassNotFoundException
|
||||||
|
* @param string $questtypeName Name of the QuesttypeController to load
|
||||||
|
* @param string $fullClassName Name of the class to load
|
||||||
|
*/
|
||||||
|
private static function loadClass($questtypeName, $fullClassName)
|
||||||
|
{
|
||||||
|
// Determine folder to look in
|
||||||
|
$className = explode('\\', $fullClassName);
|
||||||
|
$className = array_pop($className);
|
||||||
|
|
||||||
|
// Determine filename
|
||||||
|
$fileName = ROOT.DS.\nre\configs\AppConfig::$dirs['questtypes'].DS.strtolower($questtypeName).DS.$className.\nre\configs\CoreConfig::getFileExt('includes');
|
||||||
|
|
||||||
|
// Check file
|
||||||
|
if(!file_exists($fileName))
|
||||||
|
{
|
||||||
|
throw new \nre\exceptions\ClassNotFoundException(
|
||||||
|
$fullClassName
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Include file
|
||||||
|
include_once($fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check inheritance of the QuesttypeController-class.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @throws ClassNotValidException
|
||||||
|
* @param string $className Name of the class to check
|
||||||
|
* @param string $parentClassName Name of the parent class
|
||||||
|
*/
|
||||||
|
public static function checkClass($className, $parentClassName)
|
||||||
|
{
|
||||||
|
// Check if class is subclass of parent class
|
||||||
|
if(!is_subclass_of($className, $parentClassName)) {
|
||||||
|
throw new \nre\exceptions\ClassNotValidException(
|
||||||
|
$className
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new application Controller.
|
||||||
|
*
|
||||||
|
* @throws DriverNotFoundException
|
||||||
|
* @throws DriverNotValidException
|
||||||
|
* @throws ModelNotValidException
|
||||||
|
* @throws ModelNotFoundException
|
||||||
|
* @throws QuesttypeModelNotValidException
|
||||||
|
* @throws QuesttypeModelNotFoundException
|
||||||
|
* @throws ViewNotFoundException
|
||||||
|
* @param string $layoutName Name of the current Layout
|
||||||
|
* @param string $action Current Action
|
||||||
|
* @param Agent $agent Corresponding Agent
|
||||||
|
*/
|
||||||
|
public function __construct($layoutName, $action, $agent)
|
||||||
|
{
|
||||||
|
parent::__construct($layoutName, $action, $agent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the Models of this Controller.
|
||||||
|
*
|
||||||
|
* @throws DatamodelException
|
||||||
|
* @throws DriverNotFoundException
|
||||||
|
* @throws DriverNotValidException
|
||||||
|
* @throws ModelNotValidException
|
||||||
|
* @throws ModelNotFoundException
|
||||||
|
* @throws QuesttypeModelNotValidException
|
||||||
|
* @throws QuesttypeModelNotFoundException
|
||||||
|
*/
|
||||||
|
protected function loadModels()
|
||||||
|
{
|
||||||
|
// Load default models
|
||||||
|
parent::loadModels();
|
||||||
|
|
||||||
|
// Load QuesttypeModel
|
||||||
|
$this->loadModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the Model of the Questtype.
|
||||||
|
*
|
||||||
|
* @throws QuesttypeModelNotValidException
|
||||||
|
* @throws QuesttypeModelNotFoundException
|
||||||
|
*/
|
||||||
|
private function loadModel()
|
||||||
|
{
|
||||||
|
// Determine Model
|
||||||
|
$model = \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class($this))));
|
||||||
|
|
||||||
|
// Load class
|
||||||
|
\hhu\z\models\QuesttypeModel::load($model);
|
||||||
|
|
||||||
|
// Construct Model
|
||||||
|
$modelName = ucfirst(strtolower($model));
|
||||||
|
$this->$modelName = \hhu\z\models\QuesttypeModel::factory($model);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the View of this QuesttypeController.
|
||||||
|
*
|
||||||
|
* @throws ViewNotFoundException
|
||||||
|
* @param string $layoutName Name of the current Layout
|
||||||
|
* @param string $action Current Action
|
||||||
|
*/
|
||||||
|
protected function loadView($layoutName, $action)
|
||||||
|
{
|
||||||
|
// Check Layout name
|
||||||
|
if(is_null($layoutName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine controller name
|
||||||
|
$controllerName = \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::getClassName(get_class($this)));
|
||||||
|
|
||||||
|
|
||||||
|
// Load view
|
||||||
|
$this->view = \hhu\z\views\QuesttypeView::loadAndFactory($layoutName, $controllerName, $action);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
154
app/models/QuesttypeModel.inc
Normal file
154
app/models/QuesttypeModel.inc
Normal file
|
|
@ -0,0 +1,154 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Legend of Z
|
||||||
|
*
|
||||||
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
|
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||||
|
* @license http://www.gnu.org/licenses/gpl.html
|
||||||
|
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace hhu\z\models;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class for implementing a QuesttypeModel.
|
||||||
|
*
|
||||||
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
|
*/
|
||||||
|
abstract class QuesttypeModel extends \hhu\z\Model
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a Model.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @throws QuesttypeModelNotFoundException
|
||||||
|
* @throws QuesttypeModelNotValidException
|
||||||
|
* @param string $modelName Name of the QuesttypeModel to load
|
||||||
|
*/
|
||||||
|
public static function load($modelName)
|
||||||
|
{
|
||||||
|
// Determine full classname
|
||||||
|
$className = self::getClassName($modelName);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Load class
|
||||||
|
static::loadClass($modelName, $className);
|
||||||
|
|
||||||
|
// Validate class
|
||||||
|
static::checkClass($className, get_class());
|
||||||
|
}
|
||||||
|
catch(\nre\exceptions\ClassNotValidException $e) {
|
||||||
|
throw new \hhu\z\exceptions\QuesttypeModelNotValidException($e->getClassName());
|
||||||
|
}
|
||||||
|
catch(\nre\exceptions\ClassNotFoundException $e) {
|
||||||
|
throw new \hhu\z\exceptions\QuesttypeModelNotFoundException($e->getClassName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate a QuesttypeModel (Factory Pattern).
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @param string $questtypeName Name of the QuesttypeModel to instantiate
|
||||||
|
*/
|
||||||
|
public static function factory($questtypeName)
|
||||||
|
{
|
||||||
|
// Determine full classname
|
||||||
|
$className = self::getClassName($questtypeName);
|
||||||
|
|
||||||
|
// Construct and return Model
|
||||||
|
return new $className();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine the Model-classname for the given Questtype-name.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @param string $questtypeName Questtype-name to get Model-classname of
|
||||||
|
* @return string Classname for the Questtype-name
|
||||||
|
*/
|
||||||
|
private static function getClassName($questtypeName)
|
||||||
|
{
|
||||||
|
$className = \nre\core\ClassLoader::concatClassNames($questtypeName, \nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class())), 'model');
|
||||||
|
|
||||||
|
|
||||||
|
return \nre\configs\AppConfig::$app['namespace']."questtypes\\$className";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the class of a QuesttypeModel.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @throws ClassNotFoundException
|
||||||
|
* @param string $questtypeName Name of the QuesttypeModel to load
|
||||||
|
* @param string $fullClassName Name of the class to load
|
||||||
|
*/
|
||||||
|
private static function loadClass($questtypeName, $fullClassName)
|
||||||
|
{
|
||||||
|
// Determine folder to look in
|
||||||
|
$className = explode('\\', $fullClassName);
|
||||||
|
$className = array_pop($className);
|
||||||
|
|
||||||
|
// Determine filename
|
||||||
|
$fileName = ROOT.DS.\nre\configs\AppConfig::$dirs['questtypes'].DS.strtolower($questtypeName).DS.$className.\nre\configs\CoreConfig::getFileExt('includes');
|
||||||
|
|
||||||
|
// Check file
|
||||||
|
if(!file_exists($fileName))
|
||||||
|
{
|
||||||
|
throw new \nre\exceptions\ClassNotFoundException(
|
||||||
|
$fullClassName
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Include file
|
||||||
|
include_once($fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check inheritance of the QuesttypeModel-class.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @throws ClassNotValidException
|
||||||
|
* @param string $className Name of the class to check
|
||||||
|
* @param string $parentClassName Name of the parent class
|
||||||
|
*/
|
||||||
|
public static function checkClass($className, $parentClassName)
|
||||||
|
{
|
||||||
|
// Check if class is subclass of parent class
|
||||||
|
if(!is_subclass_of($className, $parentClassName)) {
|
||||||
|
throw new \nre\exceptions\ClassNotValidException(
|
||||||
|
$className
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new QuesttypeModel.
|
||||||
|
*
|
||||||
|
* @throws DatamodelException
|
||||||
|
* @throws DriverNotFoundException
|
||||||
|
* @throws DriverNotValidException
|
||||||
|
* @throws QuesttypeModelNotValidException
|
||||||
|
* @throws QuesttypeModelNotFoundException
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
76
app/views/QuesttypeView.inc
Normal file
76
app/views/QuesttypeView.inc
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Legend of Z
|
||||||
|
*
|
||||||
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
|
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||||
|
* @license http://www.gnu.org/licenses/gpl.html
|
||||||
|
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace hhu\z\views;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class for implementing a QuesttypeView.
|
||||||
|
*
|
||||||
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
|
*/
|
||||||
|
class QuesttypeView extends \nre\core\View
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load and instantiate the QuesttypeView of a QuesttypeAgent.
|
||||||
|
*
|
||||||
|
* @throws ViewNotFoundException
|
||||||
|
* @param string $layoutName Name of Layout in use
|
||||||
|
* @param string $agentName Name of the Agent
|
||||||
|
* @param string $action Current Action
|
||||||
|
* @param bool $isToplevel Agent is a ToplevelAgent
|
||||||
|
*/
|
||||||
|
public static function loadAndFactory($layoutName, $agentName=null, $action=null, $isToplevel=false)
|
||||||
|
{
|
||||||
|
return new QuesttypeView($layoutName, $agentName, $action, $isToplevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new QuesttypeView.
|
||||||
|
*
|
||||||
|
* @throws ViewNotFoundException
|
||||||
|
* @param string $layoutName Name of Layout in use
|
||||||
|
* @param string $agentName Name of the Agent
|
||||||
|
* @param string $action Current Action
|
||||||
|
* @param bool $isToplevel Agent is a ToplevelAgent
|
||||||
|
*/
|
||||||
|
protected function __construct($layoutName, $agentName=null, $action=null, $isToplevel=false)
|
||||||
|
{
|
||||||
|
// Create template filename
|
||||||
|
// LayoutName
|
||||||
|
$fileName = ROOT.DS.\nre\configs\AppConfig::$dirs['questtypes'].DS.strtolower($agentName).DS.strtolower($layoutName).DS;
|
||||||
|
|
||||||
|
// Action
|
||||||
|
$fileName .= strtolower($action);
|
||||||
|
|
||||||
|
// File extension
|
||||||
|
$fileName .= \nre\configs\CoreConfig::getFileExt('views');
|
||||||
|
|
||||||
|
|
||||||
|
// Check template file
|
||||||
|
if(!file_exists($fileName)) {
|
||||||
|
throw new \nre\exceptions\ViewNotFoundException($fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save filename
|
||||||
|
$this->templateFilename = $fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -43,7 +43,7 @@
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $seminaryPermissions = array(
|
public $seminaryPermissions = array(
|
||||||
'index' => array('admin', 'moderator', 'user'),
|
'index' => array('admin', 'moderator'),
|
||||||
'quest' => array('admin', 'moderator', 'user'),
|
'quest' => array('admin', 'moderator', 'user'),
|
||||||
'submissions' => array('admin', 'moderator'),
|
'submissions' => array('admin', 'moderator'),
|
||||||
'submission' => array('admin', 'moderator'),
|
'submission' => array('admin', 'moderator'),
|
||||||
|
|
@ -813,11 +813,11 @@
|
||||||
private function loadQuesttypeAgent($questtypeClassname, $request, $response)
|
private function loadQuesttypeAgent($questtypeClassname, $request, $response)
|
||||||
{
|
{
|
||||||
// Load Agent
|
// Load Agent
|
||||||
\hhu\z\QuesttypeAgent::load($questtypeClassname);
|
\hhu\z\agents\QuesttypeAgent::load($questtypeClassname);
|
||||||
|
|
||||||
|
|
||||||
// Construct and return Agent
|
// Construct and return Agent
|
||||||
return \hhu\z\QuesttypeAgent::factory($questtypeClassname, $request, $response);
|
return \hhu\z\agents\QuesttypeAgent::factory($questtypeClassname, $request, $response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
class BossfightQuesttypeAgent extends \hhu\z\QuesttypeAgent
|
class BossfightQuesttypeAgent extends \hhu\z\agents\QuesttypeAgent
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
class BossfightQuesttypeController extends \hhu\z\QuesttypeController
|
class BossfightQuesttypeController extends \hhu\z\controllers\QuesttypeController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Required models
|
* Required models
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
class BossfightQuesttypeModel extends \hhu\z\QuesttypeModel
|
class BossfightQuesttypeModel extends \hhu\z\models\QuesttypeModel
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
class ChoiceinputQuesttypeAgent extends \hhu\z\QuesttypeAgent
|
class ChoiceinputQuesttypeAgent extends \hhu\z\agents\QuesttypeAgent
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
class ChoiceinputQuesttypeController extends \hhu\z\QuesttypeController
|
class ChoiceinputQuesttypeController extends \hhu\z\controllers\QuesttypeController
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
class ChoiceinputQuesttypeModel extends \hhu\z\QuesttypeModel
|
class ChoiceinputQuesttypeModel extends \hhu\z\models\QuesttypeModel
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
class CrosswordQuesttypeAgent extends \hhu\z\QuesttypeAgent
|
class CrosswordQuesttypeAgent extends \hhu\z\agents\QuesttypeAgent
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
class CrosswordQuesttypeController extends \hhu\z\QuesttypeController
|
class CrosswordQuesttypeController extends \hhu\z\controllers\QuesttypeController
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
class CrosswordQuesttypeModel extends \hhu\z\QuesttypeModel
|
class CrosswordQuesttypeModel extends \hhu\z\models\QuesttypeModel
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
class DragndropQuesttypeAgent extends \hhu\z\QuesttypeAgent
|
class DragndropQuesttypeAgent extends \hhu\z\agents\QuesttypeAgent
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
class DragndropQuesttypeController extends \hhu\z\QuesttypeController
|
class DragndropQuesttypeController extends \hhu\z\controllers\QuesttypeController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Required models
|
* Required models
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
*
|
*
|
||||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||||
*/
|
*/
|
||||||
class DragndropQuesttypeModel extends \hhu\z\QuesttypeModel
|
class DragndropQuesttypeModel extends \hhu\z\models\QuesttypeModel
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue