3 * The simulator system class is the super class of all other classes. This
4 * class handles saving of games etc.
6 * @author Roland Haeder <webmaster@ship-simu.org>
8 * @copyright Copyright (c) 2007 - 2009 Roland Haeder, this is free software
9 * @license GNU GPL 3.0 or any newer version
10 * @link http://www.ship-simu.org
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
27 * Instance of a request class
29 private $requestInstance = null;
32 * Instance of a response class
34 private $responseInstance = null;
37 * Search criteria instance
39 private $searchInstance = null;
42 * Update criteria instance
44 private $updateInstance = null;
47 * The file I/O instance for the template loader
49 private $fileIoInstance = null;
54 private $resolverInstance = null;
57 * Template engine instance
59 private $templateInstance = null;
62 * Database result instance
64 private $resultInstance = null;
67 * Instance for user class
69 private $userInstance = null;
72 * A controller instance
74 private $controllerInstance = null;
79 private $realClass = 'FrameworkSystem';
84 private $thousands = '.'; // German
89 private $decimals = ','; // German
91 /***********************
92 * Exception codes.... *
93 ***********************/
95 const EXCEPTION_IS_NULL_POINTER = 0x001;
96 const EXCEPTION_IS_NO_OBJECT = 0x002;
97 const EXCEPTION_IS_NO_ARRAY = 0x003;
98 const EXCEPTION_MISSING_METHOD = 0x004;
99 const EXCEPTION_CLASSES_NOT_MATCHING = 0x005;
100 const EXCEPTION_INDEX_OUT_OF_BOUNDS = 0x006;
101 const EXCEPTION_DIMENSION_ARRAY_INVALID = 0x007;
102 const EXCEPTION_ITEM_NOT_TRADEABLE = 0x008;
103 const EXCEPTION_ITEM_NOT_IN_PRICE_LIST = 0x009;
104 const EXCEPTION_GENDER_IS_WRONG = 0x00a;
105 const EXCEPTION_BIRTH_DATE_IS_INVALID = 0x00b;
106 const EXCEPTION_EMPTY_STRUCTURES_ARRAY = 0x00c;
107 const EXCEPTION_HAS_ALREADY_PERSONELL_LIST = 0x00d;
108 const EXCEPTION_NOT_ENOUGTH_UNEMPLOYEES = 0x00e;
109 const EXCEPTION_TOTAL_PRICE_NOT_CALCULATED = 0x00f;
110 const EXCEPTION_HARBOR_HAS_NO_SHIPYARDS = 0x010;
111 const EXCEPTION_CONTRACT_PARTNER_INVALID = 0x011;
112 const EXCEPTION_CONTRACT_PARTNER_MISMATCH = 0x012;
113 const EXCEPTION_CONTRACT_ALREADY_SIGNED = 0x013;
114 const EXCEPTION_UNEXPECTED_EMPTY_STRING = 0x014;
115 const EXCEPTION_PATH_NOT_FOUND = 0x015;
116 const EXCEPTION_INVALID_PATH_NAME = 0x016;
117 const EXCEPTION_READ_PROTECED_PATH = 0x017;
118 const EXCEPTION_WRITE_PROTECED_PATH = 0x018;
119 const EXCEPTION_DIR_POINTER_INVALID = 0x019;
120 const EXCEPTION_FILE_POINTER_INVALID = 0x01a;
121 const EXCEPTION_INVALID_DIRECTORY_POINTER = 0x01b;
122 const EXCEPTION_UNEXPECTED_OBJECT = 0x01c;
123 const EXCEPTION_LIMIT_ELEMENT_IS_UNSUPPORTED = 0x01d;
124 const EXCEPTION_GETTER_IS_MISSING = 0x01e;
125 const EXCEPTION_ARRAY_EXPECTED = 0x01f;
126 const EXCEPTION_ARRAY_HAS_INVALID_COUNT = 0x020;
127 const EXCEPTION_ID_IS_INVALID_FORMAT = 0x021;
128 const EXCEPTION_MD5_CHECKSUMS_MISMATCH = 0x022;
129 const EXCEPTION_UNEXPECTED_STRING_SIZE = 0x023;
130 const EXCEPTION_SIMULATOR_ID_INVALID = 0x024;
131 const EXCEPTION_MISMATCHING_COMPRESSORS = 0x025;
132 const EXCEPTION_CONTAINER_ITEM_IS_NULL = 0x026;
133 const EXCEPTION_ITEM_IS_NO_ARRAY = 0x027;
134 const EXCEPTION_CONTAINER_MAYBE_DAMAGED = 0x028;
135 const EXCEPTION_INVALID_STRING = 0x029;
136 const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
137 const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b;
138 const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c;
139 const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d;
140 const EXCEPTION_MISSING_LANGUAGE_HANDLER = 0x02e;
141 const EXCEPTION_MISSING_FILE_IO_HANDLER = 0x02f;
142 const EXCEPTION_MISSING_ELEMENT = 0x030;
143 const EXCEPTION_HEADERS_ALREADY_SENT = 0x031;
144 const EXCEPTION_DEFAULT_CONTROLLER_GONE = 0x032;
145 const EXCEPTION_CLASS_NOT_FOUND = 0x033;
146 const EXCEPTION_REQUIRED_INTERFACE_MISSING = 0x034;
147 const EXCEPTION_FATAL_ERROR = 0x035;
148 const EXCEPTION_FILE_NOT_FOUND = 0x036;
149 const EXCEPTION_ASSERTION_FAILED = 0x037;
150 const EXCEPTION_FILE_CANNOT_BE_READ = 0x038;
151 const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x039;
152 const EXCEPTION_FILTER_CHAIN_INTERCEPTED = 0x040;
155 * In the super constructor these system classes shall be ignored or else
156 * we would get an endless calling loop.
158 *---------------------------------------------------------------------*
159 * ATTENTION: IF YOU REMOVE ONE OF THEM YOU WILL RUN YOUR SERVER IN AN *
161 *---------------------------------------------------------------------*
163 private $systemClasses = array(
164 'DebugMiddleware', // Debug middleware output sub-system
165 'Registry', // Object registry
166 'ObjectFactory', // Object factory
167 'DebugWebOutput', // Debug web output sub-system
168 'WebOutput', // Web output sub-system
169 'CompressorChannel', // Compressor sub-system
170 'DebugConsoleOutput', // Debug console output sub-system
171 'DebugErrorLogOutput', // Debug error_log() output sub-system
172 'FrameworkDirectoryPointer', // Directory handler sub-system
173 'NullCompressor', // Null compressor
174 'Bzip2Compressor', // BZIP2 compressor
175 'GzipCompressor', // GZIP compressor
178 * Protected super constructor
180 * @param $className Name of the class
183 protected function __construct ($className) {
185 $this->setRealClass($className);
187 // Initialize the class if class Registry is there
188 if ((class_exists('Registry')) && (Registry::isInitialized() === false)) {
189 // Initialize the registry automatically
190 $this->initInstance();
195 * Destructor reached...
198 * @todo This is old code. Do we still need this old lost code?
200 public function __destruct() {
201 // Flush any updated entries to the database
202 $this->flushPendingUpdates();
204 // Is this object already destroyed?
205 if ($this->__toString() != 'DestructedObject') {
206 // Destroy all informations about this class but keep some text about it alive
207 $this->setRealClass('DestructedObject');
208 } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
209 // Already destructed object
210 $this->debugOutput(sprintf("[%s:] The object <span class=\"object_name\">%s</span> is already destroyed.",
211 __CLASS__, $this->__toString()
217 * The call method where all non-implemented methods end up
221 public final function __call ($methodName, $args) {
222 // Implode all given arguments
226 $argsString = "NULL";
227 } elseif (is_array($args)) {
228 // Some arguments are there
229 foreach ($args as $arg) {
231 $argsString .= $arg." (".gettype($arg);
233 // Add length if type is string
234 if (gettype($arg) == 'string') $argsString .= ", ".strlen($arg);
237 $argsString .= "), ";
241 if (substr($argsString, -2, 1) === ",") {
242 $argsString = substr($argsString, 0, -2);
245 // Invalid arguments!
246 $argsString = sprintf("!INVALID:%s!", $args);
249 // Output stub message
250 $this->debugOutput(sprintf("[%s->%s] Stub! Args: %s",
261 * Private initializer for this class
265 private final function initInstance () {
266 // Is this a system class?
267 if (!in_array($this->__toString(), $this->systemClasses)) {
268 // Set configuration instance
269 $this->setConfigInstance(FrameworkConfiguration::getInstance());
271 // Add application helper to our class
272 $this->systemclasses[] = $this->getConfigInstance()->readConfig('app_helper_class');
274 // Set debug instance
275 $this->setDebugInstance(DebugMiddleware::createDebugMiddleware($this->getConfigInstance()->readConfig('debug_class')));
277 // Get output instance and set it
278 $outputInstance = ObjectFactory::createObjectByConfiguredName('web_engine', array($this->getConfigInstance()->readConfig('web_content_type')));
279 $this->setWebOutputInstance($outputInstance);
281 // Set the compressor channel
282 $this->setCompressorChannel(CompressorChannel::createCompressorChannel(
283 $this->getConfigInstance()->readConfig('base_path').
284 $this->getConfigInstance()->readConfig('compressor_base_path')
287 // Initialization done! :D
288 Registry::isInitialized('OK');
289 } elseif ($this->__toString() == 'DebugMiddleware') {
290 // Set configuration instance
291 $this->setConfigInstance(FrameworkConfiguration::getInstance());
296 * Setter for database result instance
298 * @param $resultInstance An instance of a database result class
300 * @todo SearchableResult and UpdateableResult shall have a super interface to use here
302 protected final function setResultInstance (SearchableResult $resultInstance) {
303 $this->resultInstance = $resultInstance;
307 * Getter for database result instance
309 * @return $resultInstance An instance of a database result class
311 public final function getResultInstance () {
312 return $this->resultInstance;
316 * Setter for template engine instances
318 * @param $templateInstance An instance of a template engine class
321 protected final function setTemplateInstance (CompileableTemplate $templateInstance) {
322 $this->templateInstance = $templateInstance;
326 * Getter for template engine instances
328 * @return $templateInstance An instance of a template engine class
330 protected final function getTemplateInstance () {
331 return $this->templateInstance;
335 * Setter for search instance
337 * @param $searchInstance Searchable criteria instance
340 public final function setSearchInstance (LocalSearchCriteria $searchInstance) {
341 $this->searchInstance = $searchInstance;
345 * Getter for search instance
347 * @return $searchInstance Searchable criteria instance
349 public final function getSearchInstance () {
350 return $this->searchInstance;
354 * Setter for update instance
356 * @param $updateInstance Searchable criteria instance
359 public final function setUpdateInstance (LocalUpdateCriteria $updateInstance) {
360 $this->updateInstance = $updateInstance;
364 * Getter for update instance
366 * @return $updateInstance Updateable criteria instance
368 public final function getUpdateInstance () {
369 return $this->updateInstance;
373 * Setter for resolver instance
375 * @param $resolverInstance Instance of a command resolver class
378 public final function setResolverInstance (Resolver $resolverInstance) {
379 $this->resolverInstance = $resolverInstance;
383 * Getter for resolver instance
385 * @return $resolverInstance Instance of a command resolver class
387 public final function getResolverInstance () {
388 return $this->resolverInstance;
392 * Setter for language instance
394 * @param $configInstance The configuration instance which shall
395 * be FrameworkConfiguration
398 public final function setConfigInstance (FrameworkConfiguration $configInstance) {
399 Registry::getRegistry()->addInstance('config', $configInstance);
403 * Getter for configuration instance
405 * @return $configInstance Configuration instance
407 public final function getConfigInstance () {
408 $configInstance = Registry::getRegistry()->getInstance('config');
409 return $configInstance;
413 * Setter for debug instance
415 * @param $debugInstance The instance for debug output class
418 public final function setDebugInstance (DebugMiddleware $debugInstance) {
419 Registry::getRegistry()->addInstance('debug', $debugInstance);
423 * Getter for debug instance
425 * @return $debugInstance Instance to class DebugConsoleOutput or DebugWebOutput
427 public final function getDebugInstance () {
428 $debugInstance = Registry::getRegistry()->getInstance('debug');
429 return $debugInstance;
433 * Setter for web output instance
435 * @param $webInstance The instance for web output class
438 public final function setWebOutputInstance (OutputStreamer $webInstance) {
439 Registry::getRegistry()->addInstance('web_output', $webInstance);
443 * Getter for web output instance
445 * @return $webOutputInstance - Instance to class WebOutput
447 public final function getWebOutputInstance () {
448 $webOutputInstance = Registry::getRegistry()->getInstance('web_output');
449 return $webOutputInstance;
453 * Setter for database instance
455 * @param $dbInstance The instance for the database connection
456 * (forced DatabaseConnection)
459 public final function setDatabaseInstance (DatabaseConnection $dbInstance) {
460 Registry::getRegistry()->addInstance('db_instance', $dbInstance);
464 * Getter for database layer
466 * @return $dbInstance The database layer instance
468 public final function getDatabaseInstance () {
469 // Default is invalid db instance
472 // Is the registry there and initialized?
473 if ((class_exists('Registry')) && (Registry::isInitialized() === true)) {
474 $dbInstance = Registry::getRegistry()->getInstance('db_instance');
482 * Setter for compressor channel
484 * @param $compressorInstance An instance of CompressorChannel
487 public final function setCompressorChannel (CompressorChannel $compressorInstance) {
488 Registry::getRegistry()->addInstance('compressor', $compressorInstance);
492 * Getter for compressor channel
494 * @return $compressorInstance The compressor channel
496 public final function getCompressorChannel () {
497 $compressorInstance = Registry::getRegistry()->getInstance('compressor');
498 return $compressorInstance;
502 * Protected getter for a manageable application helper class
504 * @return $applicationInstance An instance of a manageable application helper class
506 protected final function getApplicationInstance () {
507 $applicationInstance = Registry::getRegistry()->getInstance('application');
508 return $applicationInstance;
512 * Setter for a manageable application helper class
514 * @param $applicationInstance An instance of a manageable application helper class
517 public final function setApplicationInstance (ManageableApplication $applicationInstance) {
518 Registry::getRegistry()->addInstance('application', $applicationInstance);
522 * Setter for request instance
524 * @param $requestInstance An instance of a Requestable class
527 public final function setRequestInstance (Requestable $requestInstance) {
528 $this->requestInstance = $requestInstance;
532 * Getter for request instance
534 * @return $requestInstance An instance of a Requestable class
536 public final function getRequestInstance () {
537 return $this->requestInstance;
541 * Setter for response instance
543 * @param $responseInstance An instance of a Responseable class
546 public final function setResponseInstance (Responseable $responseInstance) {
547 $this->responseInstance = $responseInstance;
551 * Getter for response instance
553 * @return $responseInstance An instance of a Responseable class
555 public final function getResponseInstance () {
556 return $this->responseInstance;
560 * Getter for $realClass
562 * @return $realClass The name of the real class (not BaseFrameworkSystem)
564 public final function __toString () {
565 return $this->realClass;
569 * Setter for the real class name
571 * @param $realClass Class name (string)
574 public final function setRealClass ($realClass) {
576 $realClass = (string) $realClass;
579 $this->realClass = $realClass;
583 * Compare class name of this and given class name
585 * @param $className The class name as string from the other class
586 * @return boolean The result of comparing both class names
588 public final function isClass ($className) {
589 return ($this->__toString() == $className);
593 * Stub method (only real cabins shall override it)
595 * @return boolean false = is no cabin, true = is a cabin
598 public function isCabin () {
603 * Stub method for tradeable objects
605 * @return boolean false = is not tradeable by the Merchant class,
606 * true = is a tradeable object
609 public function isTradeable () {
614 * Formats computer generated price values into human-understandable formats
615 * with thousand and decimal seperators.
617 * @param $value The in computer format value for a price
618 * @param $currency The currency symbol (use HTML-valid characters!)
619 * @param $decNum Number of decimals after commata
620 * @return $price The for the current language formated price string
621 * @throws MissingDecimalsThousandsSeperatorException If decimals or
622 * thousands seperator
625 public function formatCurrency ($value, $currency = "€", $decNum = 2) {
626 // Are all required attriutes set?
627 if ((!isset($this->decimals)) || (!isset($this->thousands))) {
628 // Throw an exception
629 throw new MissingDecimalsThousandsSeperatorException($this, self::EXCEPTION_ATTRIBUTES_ARE_MISSING);
633 $value = (float) $value;
635 // Reformat the US number
636 $price = sprintf("%s %s",
637 number_format($value, $decNum, $this->decimals, $this->thousands),
641 // Return as string...
646 * Removes number formating characters
650 public final function removeNumberFormaters () {
651 unset($this->thousands);
652 unset($this->decimals);
656 * Private getter for language instance
658 * @return $langInstance An instance to the language sub-system
660 protected final function getLanguageInstance () {
661 $langInstance = Registry::getRegistry()->getInstance('language');
662 return $langInstance;
666 * Setter for language instance
668 * @param $langInstance An instance to the language sub-system
670 * @see LanguageSystem
672 public final function setLanguageInstance (ManageableLanguage $langInstance) {
673 Registry::getRegistry()->addInstance('language', $langInstance);
677 * Remove the $systemClasses array from memory
681 public final function removeSystemArray () {
682 unset($this->systemClasses);
686 * Appends a trailing slash to a string
688 * @param $str A string (maybe) without trailing slash
689 * @return $str A string with an auto-appended trailing slash
691 public final function addMissingTrailingSlash ($str) {
692 // Is there a trailing slash?
693 if (substr($str, -1, 1) != "/") $str .= "/";
698 * Private getter for file IO instance
700 * @return $fileIoInstance An instance to the file I/O sub-system
702 protected final function getFileIoInstance () {
703 return $this->fileIoInstance;
707 * Setter for file I/O instance
709 * @param $fileIoInstance An instance to the file I/O sub-system
712 public final function setFileIoInstance (FileIoHandler $fileIoInstance) {
713 $this->fileIoInstance = $fileIoInstance;
717 * Prepare the template engine (WebTemplateEngine by default) for a given
718 * application helper instance (ApplicationHelper by default).
720 * @param $appInstance An application helper instance or
721 * null if we shall use the default
722 * @return $templateInstance The template engine instance
723 * @throws NullPointerException If the template engine could not
725 * @throws UnsupportedTemplateEngineException If $templateInstance is an
726 * unsupported template engine
727 * @throws MissingLanguageHandlerException If the language sub-system
728 * is not yet initialized
729 * @throws NullPointerException If the discovered application
730 * instance is still null
732 protected function prepareTemplateInstance (BaseFrameworkSystem $appInstance=null) {
733 // Is the application instance set?
734 if (is_null($appInstance)) {
735 // Get the current instance
736 $appInstance = $this->getApplicationInstance();
739 if (is_null($appInstance)) {
740 // Thrown an exception
741 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
745 // Generate FQFN for all application templates
746 $fqfn = sprintf("%s%s/%s",
747 $this->getConfigInstance()->readConfig('application_path'),
748 strtolower($appInstance->getAppShortName()),
749 $this->getConfigInstance()->readConfig('tpl_base_path')
752 // Are both instances set?
753 if ($appInstance->getLanguageInstance() === null) {
754 // Invalid language instance
755 throw new MissingLanguageHandlerException($appInstance, self::EXCEPTION_MISSING_LANGUAGE_HANDLER);
756 } elseif ($appInstance->getFileIoInstance() === null) {
757 // Invalid language instance
758 throw new MissingFileIoHandlerException($appInstance, self::EXCEPTION_MISSING_FILE_IO_HANDLER);
761 // Initialize the template engine
762 $templateInstance = ObjectFactory::createObjectByConfiguredName('template_class', array($fqfn, $appInstance->getLanguageInstance(), $appInstance->getFileIoInstance()));
764 // Return the prepared instance
765 return $templateInstance;
769 * Debugs this instance by putting out it's full content
771 * @param $message Optional message to show in debug output
774 public final function debugInstance ($message = '') {
775 // Restore the error handler to avoid trouble with missing array elements or undeclared variables
776 restore_error_handler();
782 if (!empty($message)) {
784 $content = sprintf("<div class=\"debug_message\">Message: %s</div>\n", $message);
787 // Generate the output
788 $content .= sprintf("<pre>%s</pre>",
797 ApplicationEntryPoint::app_die(sprintf("<div class=\"debug_header\">%s debug output:</div><div class=\"debug_content\">%s</div>\nLoaded includes: <div class=\"debug_include_list\">%s</div>",
800 ClassLoader::getInstance()->getPrintableIncludeList()
805 * Output a partial stub message for the caller method
807 * @param $message An optional message to display
810 protected function partialStub ($message = '') {
812 $backtrace = debug_backtrace();
814 // Generate the class::method string
815 $methodName = "UnknownClass->unknownMethod";
816 if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) {
817 $methodName = $backtrace[1]['class']."->".$backtrace[1]['function'];
820 // Construct the full message
821 $stubMessage = sprintf("[%s:] Partial stub!",
825 // Is the extra message given?
826 if (!empty($message)) {
827 // Then add it as well
828 $stubMessage .= sprintf(" Message: <span id=\"stub_message\">%s</span>", $message);
831 // Debug instance is there?
832 if (!is_null($this->getDebugInstance())) {
833 // Output stub message
834 $this->debugOutput($stubMessage);
837 trigger_error($stubMessage."<br />\n");
842 * Outputs a debug backtrace and stops further script execution
846 public function debugBackTrace () {
847 // Sorry, there is no other way getting this nice backtrace
849 debug_print_backtrace();
855 * Outputs a debug message wether to debug instance (should be set!) or dies with or pints the message
857 * @param $message Message we shall send out...
858 * @param $doPrint Wether we shall print or die here which first is the default
861 public function debugOutput ($message, $doPrint = true) {
862 // Get debug instance
863 $debugInstance = $this->getDebugInstance();
865 // Is the debug instance there?
866 if (is_object($debugInstance)) {
867 // Use debug output handler
868 $debugInstance->output($message);
869 if ($doPrint === false) die(); // Die here if not printed
875 // DO NOT REWRITE THIS TO app_die() !!!
882 * Converts e.g. a command from URL to a valid class by keeping out bad characters
884 * @param $str The string, what ever it is needs to be converted
885 * @return $className Generated class name
887 public function convertToClassName ($str) {
891 // Convert all dashes in underscores
892 $str = str_replace("-", "_", $str);
894 // Now use that underscores to get classname parts for hungarian style
895 foreach (explode("_", $str) as $strPart) {
896 // Make the class name part lower case and first upper case
897 $className .= ucfirst(strtolower($strPart));
905 * Marks up the code by adding e.g. line numbers
907 * @param $phpCode Unmarked PHP code
908 * @return $markedCode Marked PHP code
910 public function markupCode ($phpCode) {
915 $errorArray = error_get_last();
917 // Init the code with error message
918 if (is_array($errorArray)) {
920 $markedCode = sprintf("<div id=\"error_header\">File: <span id=\"error_data\">%s</span>, Line: <span id=\"error_data\">%s</span>, Message: <span id=\"error_data\">%s</span>, Type: <span id=\"error_data\">%s</span></div>",
921 basename($errorArray['file']),
923 $errorArray['message'],
928 // Add line number to the code
929 foreach (explode("\n", $phpCode) as $lineNo => $code) {
931 $markedCode .= sprintf("<span id=\"code_line\">%s</span>: %s\n",
933 htmlentities($code, ENT_QUOTES)
942 * Filter a given GMT timestamp (non Uni* stamp!) to make it look more
943 * beatiful for web-based front-ends. If null is given a message id
944 * null_timestamp will be resolved and returned.
946 * @param $timestamp Timestamp to prepare (filter) for display
947 * @return $readable A readable timestamp
949 public function doFilterFormatTimestamp ($timestamp) {
950 // Default value to return
953 // Is the timestamp null?
954 if (is_null($timestamp)) {
955 // Get a message string
956 $readable = $this->getLanguageInstance()->getMessage('null_timestamp');
958 switch ($this->getLanguageInstance()->getLanguageCode()) {
959 case "de": // German format is a bit different to default
960 // Split the GMT stamp up
961 $dateTime = explode(" ", $timestamp);
962 $dateArray = explode("-", $dateTime[0]);
963 $timeArray = explode(":", $dateTime[1]);
965 // Construct the timestamp
966 $readable = sprintf($this->getConfigInstance()->readConfig('german_date_time'),
976 default: // Default is pass-through
977 $readable = $timestamp;
987 * "Getter" for databse entry
989 * @return $entry An array with database entries
990 * @throws NullPointerException If the database result is not found
991 * @throws InvalidDatabaseResultException If the database result is invalid
993 protected final function getDatabaseEntry () {
994 // Is there an instance?
995 if (is_null($this->getResultInstance())) {
996 // Throw an exception here
997 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1001 $this->getResultInstance()->rewind();
1003 // Do we have an entry?
1004 if ($this->getResultInstance()->valid() === false) {
1005 throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), DatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
1009 $this->getResultInstance()->next();
1012 $entry = $this->getResultInstance()->current();
1019 * Getter for field name
1021 * @param $fieldName Field name which we shall get
1022 * @return $fieldValue Field value from the user
1023 * @throws NullPointerException If the result instance is null
1025 public final function getField ($fieldName) {
1026 // Default field value
1029 // Get result instance
1030 $resultInstance = $this->getResultInstance();
1032 // Is this instance null?
1033 if (is_null($resultInstance)) {
1034 // Then the user instance is no longer valid (expired cookies?)
1035 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
1038 // Get current array
1039 $fieldArray = $resultInstance->current();
1041 // Does the field exist?
1042 if (isset($fieldArray[$fieldName])) {
1044 $fieldValue = $fieldArray[$fieldName];
1052 * Protected setter for user instance
1054 * @param $userInstance An instance of a user class
1057 protected final function setUserInstance (ManageableAccount $userInstance) {
1058 $this->userInstance = $userInstance;
1062 * Getter for user instance
1064 * @return $userInstance An instance of a user class
1066 public final function getUserInstance () {
1067 return $this->userInstance;
1071 * Setter for controller instance (this surely breaks a bit the MVC patterm)
1073 * @param $controllerInstance An instance of the controller
1076 public final function setControllerInstance (Controller $controllerInstance) {
1077 $this->controllerInstance = $controllerInstance;
1081 * Getter for controller instance (this surely breaks a bit the MVC patterm)
1083 * @return $controllerInstance An instance of the controller
1085 public final function getControllerInstance () {
1086 return $this->controllerInstance;
1090 * Flushs all pending updates to the database layer
1094 public function flushPendingUpdates () {
1095 // Get result instance
1096 $resultInstance = $this->getResultInstance();
1098 // Do we have data to update?
1099 if ((is_object($resultInstance)) && ($resultInstance->ifDataNeedsFlush())) {
1100 // Get wrapper class name config entry
1101 $configEntry = $resultInstance->getUpdateInstance()->getWrapperConfigEntry();
1103 // Create object instance
1104 $wrapperInstance = ObjectFactory::createObjectByConfiguredName($configEntry);
1106 // Yes, then send the whole result to the database layer
1107 $wrapperInstance->doUpdateByResult($this->getResultInstance());