create abstract StationtypeAgent
This commit is contained in:
parent
54e36ff95c
commit
ea0a283358
10 changed files with 1323 additions and 0 deletions
298
app/agents/StationtypeAgent.inc
Normal file
298
app/agents/StationtypeAgent.inc
Normal file
|
@ -0,0 +1,298 @@
|
|||
<?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 StationtypeAgent.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
abstract class StationtypeAgent extends \nre\agents\BottomlevelAgent
|
||||
{
|
||||
/**
|
||||
* Current request
|
||||
*
|
||||
* @var \nre\core\Request
|
||||
*/
|
||||
private $request;
|
||||
/**
|
||||
* Current response
|
||||
*
|
||||
* @var \nre\core\Response
|
||||
*/
|
||||
private $response;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load a StationtypeAgent.
|
||||
*
|
||||
* @static
|
||||
* @throws \hhu\z\exceptions\StationtypeAgentNotFoundException
|
||||
* @throws \hhu\z\exceptions\StationtypeAgentNotValidException
|
||||
* @param string $stationtypeName Name of the StationtypeAgent to load
|
||||
*/
|
||||
public static function load($stationtypeName)
|
||||
{
|
||||
// Determine full classname
|
||||
$className = self::getClassName($stationtypeName);
|
||||
|
||||
try {
|
||||
// Load class
|
||||
static::loadClass($stationtypeName, $className);
|
||||
|
||||
// Validate class
|
||||
static::checkClass($className, get_class());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotValidException $e) {
|
||||
throw new \hhu\z\exceptions\StationtypeAgentNotValidException($e->getClassName());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotFoundException $e) {
|
||||
throw new \hhu\z\exceptions\StationtypeAgentNotFoundException($e->getClassName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiate a StationtypeAgent (Factory Pattern).
|
||||
*
|
||||
* @static
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\ViewNotFoundException
|
||||
* @throws \hhu\z\exceptions\StationtypeModelNotValidException
|
||||
* @throws \hhu\z\exceptions\StationtypeModelNotFoundException
|
||||
* @throws \hhu\z\exceptions\StationtypeControllerNotValidException
|
||||
* @throws \hhu\z\exceptions\StationtypeControllerNotFoundException
|
||||
* @param string $stationtypeName Name of the StationtypeAgent to instantiate
|
||||
* @param Request $request Current request
|
||||
* @param Response $response Current respone
|
||||
* @param Logger $log Log-system
|
||||
*/
|
||||
public static function factory($stationtypeName, \nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
|
||||
{
|
||||
// Determine full classname
|
||||
$className = self::getClassName($stationtypeName);
|
||||
|
||||
// Construct and return Stationmodule
|
||||
return new $className($request, $response, $log);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the Agent-classname for the given Stationtype-name.
|
||||
*
|
||||
* @static
|
||||
* @param string $stationtypeName Stationtype-name to get Agent-classname of
|
||||
* @param string $agentType Agent type of given Agent name
|
||||
* @return string Classname for the Stationtype-name
|
||||
*/
|
||||
private static function getClassName($stationtypeName, $agentType=null)
|
||||
{
|
||||
$className = \nre\core\ClassLoader::concatClassNames(
|
||||
$stationtypeName,
|
||||
\nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class())),
|
||||
'agent'
|
||||
);
|
||||
|
||||
|
||||
return \nre\configs\AppConfig::$app['namespace']."stationtypes\\$className";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load the class of a StationtypeAgent.
|
||||
*
|
||||
* @static
|
||||
* @throws \nre\exceptions\ClassNotFoundException
|
||||
* @param string $stationtypeName Name of the StationtypeAgent to load
|
||||
* @param string $fullClassName Name of the class to load
|
||||
*/
|
||||
private static function loadClass($stationtypeName, $fullClassName)
|
||||
{
|
||||
// Determine folder to look in
|
||||
$className = explode('\\', $fullClassName);
|
||||
$className = array_pop($className);
|
||||
|
||||
// Determine filename
|
||||
$fileName = ROOT.DS.
|
||||
\nre\configs\AppConfig::$dirs['stationtypes'].DS.
|
||||
strtolower($stationtypeName).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 StationtypeAgent-class.
|
||||
*
|
||||
* @static
|
||||
* @throws \nre\exceptions\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 StationtypeAgent.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\ViewNotFoundException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
* @throws \hhu\z\exceptions\StationtypeModelNotValidException
|
||||
* @throws \hhu\z\exceptions\StationtypeModelNotFoundException
|
||||
* @throws \hhu\z\exceptions\StationtypeControllerNotValidException
|
||||
* @throws \hhu\z\exceptions\StationtypeControllerNotFoundException
|
||||
* @param \nre\core\Request $request Current request
|
||||
* @param \nre\core\Response $response Current response
|
||||
* @param \nre\core\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 answer of a Character group for a Station.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
* @param array $station Current Station data
|
||||
* @param array $group Current Character data
|
||||
* @param array $answers Character answers for the Quest
|
||||
*/
|
||||
public function saveAnswer($seminary, $groupsgroup, $quest, $station, $group, $answer)
|
||||
{
|
||||
$this->controller->saveAnswer(
|
||||
$seminary,
|
||||
$groupsgroup,
|
||||
$quest,
|
||||
$station,
|
||||
$group,
|
||||
$answer
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the answer of a Character group for a Station matches the
|
||||
* correct one.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
* @param array $station Current Station data
|
||||
* @param array $group Current Character group data
|
||||
* @param array $answers Character answers for the Quest
|
||||
*/
|
||||
public function matchAnswer($seminary, $groupsgroup, $quest, $station, $group, $answer)
|
||||
{
|
||||
return $this->controller->matchAnswer(
|
||||
$seminary,
|
||||
$groupsgroup,
|
||||
$quest,
|
||||
$station,
|
||||
$group,
|
||||
$answer
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load the Controller of this Agent.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\ViewNotFoundException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
* @throws \hhu\z\exceptions\StationxuesttypeModelNotValidException
|
||||
* @throws \hhu\z\exceptions\StationtypeModelNotFoundException
|
||||
* @throws \hhu\z\exceptions\StationtypeControllerNotValidException
|
||||
* @throws \hhu\z\exceptions\StationtypeControllerNotFoundException
|
||||
*/
|
||||
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\StationtypeController::load($controllerName);
|
||||
|
||||
// Construct Controller
|
||||
$this->controller = \hhu\z\controllers\StationtypeController::factory(
|
||||
$controllerName,
|
||||
$toplevelAgentName,
|
||||
$action,
|
||||
$this
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
307
app/controllers/StationtypeController.inc
Normal file
307
app/controllers/StationtypeController.inc
Normal file
|
@ -0,0 +1,307 @@
|
|||
<?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 StationtypeController.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
abstract class StationtypeController extends \hhu\z\Controller
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries'); //, 'questgroups', 'quests', 'characters');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Save the answer of a Character group for a Station.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
* @param array $station Current Station data
|
||||
* @param array $charactergroup Current Character group data
|
||||
* @param array $answer Character group answer for the Station
|
||||
*/
|
||||
public abstract function saveAnswer($seminary, $groupsgroup, $quest, $station, $charactergroup, $answer);
|
||||
|
||||
|
||||
/**
|
||||
* Check if answer of a Character group for a Station matches the correct one.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
* @param array $station Current Station data
|
||||
* @param array $charactergroup Current Character group data
|
||||
* @param array $answer Character group answer for the Station
|
||||
* @return boolean True/false for a right/wrong answer
|
||||
*/
|
||||
public abstract function matchAnswer($seminary, $groupsgroup, $quest, $station, $charactergroup, $answer);
|
||||
|
||||
|
||||
/**
|
||||
* Action: quest.
|
||||
*
|
||||
* Show the task of a Station.
|
||||
*
|
||||
* @param array $seminary Current Seminary data
|
||||
* @param array $questgroup Current Questgroup data
|
||||
* @param array $quest Current Quest data
|
||||
* @param array $station Current Station data
|
||||
* @param array $charactergroup Current Character group data
|
||||
*/
|
||||
public abstract function quest($seminary, $groupsgroup, $quest, $station, $charactergroup);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load a StationtypeController.
|
||||
*
|
||||
* @static
|
||||
* @throws \hhu\z\exceptions\StationtypeControllerNotFoundException
|
||||
* @throws \hhu\z\exceptions\StationtypeControllerNotValidException
|
||||
* @param string $controllerName Name of the StationtypeController 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\StationtypeControllerNotValidException($e->getClassName());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotFoundException $e) {
|
||||
throw new \hhu\z\exceptions\StationtypeControllerNotFoundException($e->getClassName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiate a StationtypeController (Factory Pattern).
|
||||
*
|
||||
* @static
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
* @throws \nre\exceptions\ViewNotFoundException
|
||||
* @throws \hhu\z\exceptions\StationtypeModelNotValidException
|
||||
* @throws \hhu\z\exceptions\StationtypeModelNotFoundException
|
||||
* @param string $controllerName Name of the StationtypeController to instantiate
|
||||
* @param string $layoutName Name of the current Layout
|
||||
* @param string $action Current Action
|
||||
* @param \nre\core\Agent $agent Corresponding Agent
|
||||
*/
|
||||
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 Stationtype-name.
|
||||
*
|
||||
* @static
|
||||
* @param string $stationtypeName Stationtype-name to get Controller-classname of
|
||||
* @return string Classname for the Stationtype-name
|
||||
*/
|
||||
private static function getClassName($stationtypeName)
|
||||
{
|
||||
$className = \nre\core\ClassLoader::concatClassNames(
|
||||
$stationtypeName,
|
||||
\nre\core\ClassLoader::stripClassType(\nre\core\ClassLoader::stripNamespace(get_class())),
|
||||
'controller'
|
||||
);
|
||||
|
||||
|
||||
return \nre\configs\AppConfig::$app['namespace']."stationtypes\\$className";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load the class of a StationtypeController
|
||||
*
|
||||
* @static
|
||||
* @throws \nre\exceptions\ClassNotFoundException
|
||||
* @param string $stationtypeName Name of the StationtypeController to load
|
||||
* @param string $fullClassName Name of the class to load
|
||||
*/
|
||||
private static function loadClass($stationtypeName, $fullClassName)
|
||||
{
|
||||
// Determine folder to look in
|
||||
$className = explode('\\', $fullClassName);
|
||||
$className = array_pop($className);
|
||||
|
||||
// Determine filename
|
||||
$fileName = ROOT.DS.
|
||||
\nre\configs\AppConfig::$dirs['stationtypes'].DS.
|
||||
strtolower($stationtypeName).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 StationtypeController-class.
|
||||
*
|
||||
* @static
|
||||
* @throws \nre\exceptions\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 \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
* @throws \nre\exceptions\ViewNotFoundException
|
||||
* @throws \hhu\z\exceptions\StationtypeModelNotValidException
|
||||
* @throws \hhu\z\exceptions\StationtypeModelNotFoundException
|
||||
* @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 \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \nre\exceptions\ModelNotValidException
|
||||
* @throws \nre\exceptions\ModelNotFoundException
|
||||
* @throws \hhu\z\exceptions\StationtypeModelNotValidException
|
||||
* @throws \hhu\z\exceptions\StationtypeModelNotFoundException
|
||||
*/
|
||||
protected function loadModels()
|
||||
{
|
||||
// Load default models
|
||||
parent::loadModels();
|
||||
|
||||
// Load StationtypeModel
|
||||
$this->loadModel();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load the Model of the Stationtype.
|
||||
*
|
||||
* @throws \hhu\z\exceptions\StationtypeModelNotValidException
|
||||
* @throws \hhu\z\exceptions\StationtypeModelNotFoundException
|
||||
*/
|
||||
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\StationtypeModel::load($model);
|
||||
|
||||
// Construct Model
|
||||
$modelName = ucfirst(strtolower($model));
|
||||
$this->$modelName = \hhu\z\models\StationtypeModel::factory($model);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load the View of this StationtypeController.
|
||||
*
|
||||
* @throws \nre\exceptions\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\StationtypeView::loadAndFactory(
|
||||
$layoutName,
|
||||
$controllerName,
|
||||
$action
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
79
app/exceptions/StationtypeAgentNotFoundException.inc
Normal file
79
app/exceptions/StationtypeAgentNotFoundException.inc
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?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\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: StationtypeAgent not found.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class StationtypeAgentNotFoundException extends \nre\core\Exception
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 401;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'StationtypeAgent not found';
|
||||
|
||||
/**
|
||||
* Name of the class that was not found
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $stationtypeName;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $stationtypeName Name of the StationtypeAgent that was not found
|
||||
* @param string $message Error message
|
||||
* @param int $code Error code
|
||||
*/
|
||||
function __construct($stationtypeName, $message=self::MESSAGE, $code=self::CODE)
|
||||
{
|
||||
parent::__construct(
|
||||
$message,
|
||||
$code,
|
||||
$stationtypeName
|
||||
);
|
||||
|
||||
// Store values
|
||||
$this->stationtypeName = $stationtypeName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the StationtypeAgent that was not found.
|
||||
*
|
||||
* @return string Name of the StationtypeAgent that was not found
|
||||
*/
|
||||
public function getClassName()
|
||||
{
|
||||
return $this->stationtypeName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
79
app/exceptions/StationtypeAgentNotValidException.inc
Normal file
79
app/exceptions/StationtypeAgentNotValidException.inc
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?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\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: StationtypeAgent not valid.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class StationtypeAgentNotValidException extends \nre\core\Exception
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 402;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'StationtypeAgent not valid';
|
||||
|
||||
/**
|
||||
* Name of the invalid class
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $stationtypeName;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $stationtypeName Name of the invalid StationtypeAgent
|
||||
* @param string $message Error message
|
||||
* @param int $code Error code
|
||||
*/
|
||||
function __construct($stationtypeName, $message=self::MESSAGE, $code=self::CODE)
|
||||
{
|
||||
parent::__construct(
|
||||
$message,
|
||||
$code,
|
||||
$stationtypeName
|
||||
);
|
||||
|
||||
// Store value
|
||||
$this->stationtypeName = $stationtypeName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the invalid StationtypeAgent.
|
||||
*
|
||||
* @return string Name of the invalid StationtypeAgent
|
||||
*/
|
||||
public function getClassName()
|
||||
{
|
||||
return $this->stationtypeName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
79
app/exceptions/StationtypeControllerNotFoundException.inc
Normal file
79
app/exceptions/StationtypeControllerNotFoundException.inc
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author 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\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: StationtypeController not found.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class StationtypeControllerNotFoundException extends \nre\core\Exception
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 403;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'StationtypeController not found';
|
||||
|
||||
/**
|
||||
* Name of the class that was not found
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $stationtypeName;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $stationtypeName Name of the StationtypeController that was not found
|
||||
* @param string $message Error message
|
||||
* @param int $code Error code
|
||||
*/
|
||||
function __construct($stationtypeName, $message=self::MESSAGE, $code=self::CODE)
|
||||
{
|
||||
parent::__construct(
|
||||
$message,
|
||||
$code,
|
||||
$stationtypeName
|
||||
);
|
||||
|
||||
// Store values
|
||||
$this->stationtypeName = $stationtypeName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the StationtypeController that was not found.
|
||||
*
|
||||
* @return string Name of the StationtypeController that was not found
|
||||
*/
|
||||
public function getClassName()
|
||||
{
|
||||
return $this->stationtypeName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
79
app/exceptions/StationtypeControllerNotValidException.inc
Normal file
79
app/exceptions/StationtypeControllerNotValidException.inc
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?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\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: StationtypeController not valid.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class StationtypeControllerNotValidException extends \nre\core\Exception
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 404;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'StationtypeController not valid';
|
||||
|
||||
/**
|
||||
* Name of the invalid class
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $stationtypeName;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $stationtypeName Name of the invalid StationtypeController
|
||||
* @param string $message Error message
|
||||
* @param int $code Error code
|
||||
*/
|
||||
function __construct($stationtypeName, $message=self::MESSAGE, $code=self::CODE)
|
||||
{
|
||||
parent::__construct(
|
||||
$message,
|
||||
$code,
|
||||
$stationtypeName
|
||||
);
|
||||
|
||||
// Store value
|
||||
$this->stationtypeName = $stationtypeName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the invalid StationtypeController.
|
||||
*
|
||||
* @return string Name of the invalid StationtypeController
|
||||
*/
|
||||
public function getClassName()
|
||||
{
|
||||
return $this->stationtypeName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
79
app/exceptions/StationtypeModelNotFoundException.inc
Normal file
79
app/exceptions/StationtypeModelNotFoundException.inc
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?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\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: StationtypeModel not found.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class StationtypeModelNotFoundException extends \nre\core\Exception
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 405;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'StationtypeModel not found';
|
||||
|
||||
/**
|
||||
* Name of the class that was not found
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $stationtypeName;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $stationtypeName Name of the StationtypeModel that was not found
|
||||
* @param string $message Error message
|
||||
* @param int $code Error code
|
||||
*/
|
||||
function __construct($stationtypeName, $message=self::MESSAGE, $code=self::CODE)
|
||||
{
|
||||
parent::__construct(
|
||||
$message,
|
||||
$code,
|
||||
$stationtypeName
|
||||
);
|
||||
|
||||
// Store values
|
||||
$this->stationtypeName = $stationtypeName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the StationtypeModel that was not found.
|
||||
*
|
||||
* @return string Name of the StationtypeModel that was not found
|
||||
*/
|
||||
public function getClassName()
|
||||
{
|
||||
return $this->stationtypeName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
79
app/exceptions/StationtypeModelNotValidException.inc
Normal file
79
app/exceptions/StationtypeModelNotValidException.inc
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?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\exceptions;
|
||||
|
||||
|
||||
/**
|
||||
* Exception: StationxuesttypeModel not valid.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class StationtypeModelNotValidException extends \nre\core\Exception
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CODE = 406;
|
||||
/**
|
||||
* Error message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MESSAGE = 'StationtypeModel not valid';
|
||||
|
||||
/**
|
||||
* Name of the invalid class
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $stationtypeName;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new exception.
|
||||
*
|
||||
* @param string $stationtypeName Name of the invalid StationtypeModel
|
||||
* @param string $message Error message
|
||||
* @param int $code Error code
|
||||
*/
|
||||
function __construct($stationtypeName, $message=self::MESSAGE, $code=self::CODE)
|
||||
{
|
||||
parent::__construct(
|
||||
$message,
|
||||
$code,
|
||||
$stationtypeName
|
||||
);
|
||||
|
||||
// Store value
|
||||
$this->stationtypeName = $stationtypeName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the name of the invalid StationtypeModel.
|
||||
*
|
||||
* @return string Name of the invalid StationtypeModel
|
||||
*/
|
||||
public function getClassName()
|
||||
{
|
||||
return $this->stationtypeName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
165
app/models/StationtypeModel.inc
Normal file
165
app/models/StationtypeModel.inc
Normal file
|
@ -0,0 +1,165 @@
|
|||
<?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 StationtypeModel.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
abstract class StationtypeModel extends \hhu\z\Model
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load a Model.
|
||||
*
|
||||
* @static
|
||||
* @throws \hhu\z\exceptions\StationtypeModelNotFoundException
|
||||
* @throws \hhu\z\exceptions\StationtypeModelNotValidException
|
||||
* @param string $modelName Name of the StationtypeModel 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\StationtypeModelNotValidException($e->getClassName());
|
||||
}
|
||||
catch(\nre\exceptions\ClassNotFoundException $e) {
|
||||
throw new \hhu\z\exceptions\StationtypeModelNotFoundException($e->getClassName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiate a StationtypeModel (Factory Pattern).
|
||||
*
|
||||
* @static
|
||||
* @param string $stationtypeName Name of the StationtypeModel to instantiate
|
||||
*/
|
||||
public static function factory($stationtypeName)
|
||||
{
|
||||
// Determine full classname
|
||||
$className = self::getClassName($stationtypeName);
|
||||
|
||||
// Construct and return Model
|
||||
return new $className();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the Model-classname for the given Stationtype-name.
|
||||
*
|
||||
* @static
|
||||
* @param string $stationtypeName Stationtype-name to get Model-classname of
|
||||
* @return string Classname for the Stationtype-name
|
||||
*/
|
||||
private static function getClassName($stationtypeName)
|
||||
{
|
||||
$className = \nre\core\ClassLoader::concatClassNames(
|
||||
$stationtypeName,
|
||||
\nre\core\ClassLoader::stripClassType(
|
||||
\nre\core\ClassLoader::stripNamespace(
|
||||
get_class()
|
||||
)
|
||||
),
|
||||
'model'
|
||||
);
|
||||
|
||||
|
||||
return \nre\configs\AppConfig::$app['namespace']."stationtypes\\$className";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load the class of a StationtypeModel.
|
||||
*
|
||||
* @static
|
||||
* @throws \nre\exceptions\ClassNotFoundException
|
||||
* @param string $stationtypeName Name of the StationtypeModel to load
|
||||
* @param string $fullClassName Name of the class to load
|
||||
*/
|
||||
private static function loadClass($stationtypeName, $fullClassName)
|
||||
{
|
||||
// Determine folder to look in
|
||||
$className = explode('\\', $fullClassName);
|
||||
$className = array_pop($className);
|
||||
|
||||
// Determine filename
|
||||
$fileName = ROOT.DS.
|
||||
\nre\configs\AppConfig::$dirs['stationtypes'].DS.
|
||||
strtolower($stationtypeName).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 StationtypeModel-class.
|
||||
*
|
||||
* @static
|
||||
* @throws \nre\exceptions\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 StationtypeModel.
|
||||
*
|
||||
* @throws \nre\exceptions\DatamodelException
|
||||
* @throws \nre\exceptions\DriverNotFoundException
|
||||
* @throws \nre\exceptions\DriverNotValidException
|
||||
* @throws \hhu\z\exceptions\StationtypeModelNotValidException
|
||||
* @throws \hhu\z\exceptions\StationtypeModelNotFoundException
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
79
app/views/StationtypeView.inc
Normal file
79
app/views/StationtypeView.inc
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?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 StationtypeView.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class StationtypeView extends \nre\core\View
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Load and instantiate the StationtypeView of a StationtypeAgent.
|
||||
*
|
||||
* @throws \nre\exceptions\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 StationtypeView($layoutName, $agentName, $action, $isToplevel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new StationtypeView.
|
||||
*
|
||||
* @throws \nre\exceptions\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['stationtypes'].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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Add table
Reference in a new issue