]> git.mxchange.org Git - shipsimu.git/commitdiff
More stubs added, code "made" generic:
authorRoland Häder <roland@mxchange.org>
Sat, 28 Jun 2008 00:51:37 +0000 (00:51 +0000)
committerRoland Häder <roland@mxchange.org>
Sat, 28 Jun 2008 00:51:37 +0000 (00:51 +0000)
- Database results are now supported by all objects by moving setter/getter to
  the super class BaseFrameworkSystem
- Login area with more stubs (still working on company data output)
- Obsolete $content[some_var] replaced by {?some_var?} in header templates
- app_die() slightly improved

application/ship-simu/main/companies/class_ShippingCompany.php
application/ship-simu/main/wrapper/class_CompanyDatabaseWrapper.php
application/ship-simu/templates/de/code/header.ctp
application/ship-simu/templates/de/code/login_main.ctp
inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/helper/captcha/images/class_ImageHelper.php
inc/classes/main/helper/class_BaseHelper.php
inc/classes/main/reader/class_DefaultNewsReader.php
inc/classes/main/user/class_BaseUser.php
index.php

index d3ab6985dec4c5d08e602f645dcaa330de337044..e3bd59167a0ba6b84edea35b98529d05e8fcabc1 100644 (file)
@@ -38,14 +38,14 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
        private $founderInstance = null;
 
        /**
-        * Employed people by this company
+        * Headquarter harbor instance
         */
-       private $employeeList    = null;
+       private $hqInstance      = null;
 
        /**
-        * Headquarter harbor instance
+        * Employed people by this company
         */
-       private $hqInstance      = null;
+       private $employeeList    = null;
 
        /**
         * List of all assigned shipyards
@@ -62,11 +62,6 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
         */
        private $contractList    = null;
 
-       /**
-        * Database result instance
-        */
-       private $resultInstance = null;
-
        // Exception constants
        const EXCEPTION_USER_OWNS_NO_COMPANY = 0x200;
 
@@ -95,21 +90,18 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
         *
         * @param       $userInstance           A user class
         * @return      $companyInstance        Prepared company instance
-        * @throws      NoShippingCompanyOwnedException         If the user owns no shipping companies
         */
        public final static function createShippingCompany (BaseUser $userInstance) {
                // Get new instance
                $companyInstance = new ShippingCompany();
 
                // Does the given user owns a company?
-               if (!$companyInstance->ifUserOwnsShippingCompany($userInstance)) {
-                       // Throw an exception here
-                       throw new NoShippingCompanyOwnedException(array($companyInstance, $userInstance), self::EXCEPTION_USER_OWNS_NO_COMPANY);
+               if ($companyInstance->ifUserParticipatesInCompany($userInstance)) {
+                       // Then do some nastly caching here but don't throw an exception
+                       // because then you will hurt our web helpers... :/
+                       $companyInstance->partialStub("Don&#39;t throw exceptions here.");
                } // END - if
 
-               // Set the user instance. We don't care here if he is founder or employee.
-               $companyInstance->setUserInstance($userInstance);
-
                // Init all lists
                $companyInstance->initCompanyLists();
 
@@ -118,34 +110,43 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
        }
 
        /**
-        * Checks wether the given user owns a company or not
+        * Checks wether the given user participates in a company
         *
         * @param       $userInstance   An instance of a user class
-        * @return      $ownsCompany    Wether the user owns at least one company
+        * @return      $participates   Wether the user participates at lease in one company
         */
-       protected function ifUserOwnsShippingCompany (BaseUser $userInstance)  {
+       protected function ifUserParticipatesInCompany (BaseUser $userInstance)  {
                // By default no user owns any company... ;)
-               $ownsCompany = false;
+               $participates = false;
 
                // Get a company database wrapper class
                $wrapperInstance = ObjectFactory::createObjectByConfiguredName('company_db_wrapper_class');
 
-               // Get a search criteria class
-               $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+               // Ask the wrapper if this user participates
+               $participates = $wrapperInstance->ifUserParticipatesInCompany($userInstance);
 
-               // Add the user primary key as a search criteria
-               $criteriaInstance->addCriteria('company_owner', $userInstance->getPrimaryKey());
-               $criteriaInstance->setLimit(1);
+               // Get the result instance
+               $resultInstance = $wrapperInstance->getResultInstance();
 
-               // Get the result back
-               $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
-               $resultInstance->debugInstance();
+               // Caches the result instance here, if set (we don't the wrapper anymore!)
+               if ($resultInstance instanceof SearchableResult) {
+                       // Set the result instance
+                       $this->setResultInstance($resultInstance);
+               } // END - if
+
+               // Return result
+               return $participates;
        }
 
+       //----------------------------------------------------------------------------
+       // From here is very old code which needs to be translated and changed heavily
+       //----------------------------------------------------------------------------
+
        /**
         * Intialize all lists
         *
         * @return      void
+        * @todo        Maybe we don't need these big lists anymore?! So we can deprecate/remove it
         */
        protected function initCompanyLists () {
                // Employees
@@ -158,10 +159,6 @@ class ShippingCompany extends BaseSimulator implements Customer, ContractPartner
                $this->contractList = new FrameworkArrayObject("FakedContractList");
        }
 
-       //----------------------------------------------------------------------------
-       // From here is very old code which needs to be translated and changed heavily
-       //----------------------------------------------------------------------------
-
        // Setter-Methode fuer Firmennamen
        public final function setCompanyName ($companyName) {
                $this->companyName = (string) $companyName;
index d403d18b8530d0646719b9a5f2e1d318a2895184..b49b1d050c4a56c4038baac528721ec8d7127803 100644 (file)
@@ -23,7 +23,8 @@
  */
 class CompanyDatabaseWrapper extends BaseDatabaseWrapper {
        // Constants for database tables
-       const DB_TABLE_COMPANY = "company";
+       const DB_TABLE_COMPANY_DATA = "company";
+       const DB_TABLE_COMPANY_USER = "company_user";
 
        /**
         * Protected constructor
@@ -51,11 +52,47 @@ class CompanyDatabaseWrapper extends BaseDatabaseWrapper {
                $wrapperInstance = new CompanyDatabaseWrapper();
 
                // Set (primary!) table name
-               $wrapperInstance->setTableName(self::DB_TABLE_COMPANY);
+               $wrapperInstance->setTableName(self::DB_TABLE_COMPANY_DATA);
 
                // Return the instance
                return $wrapperInstance;
        }
+
+       /**
+        * Checks wether the given user participates in a company
+        *
+        * @param       $userInstance   An instance of a user class
+        * @return      $participates   Wether the user participates at lease in one company
+        */
+       public function ifUserParticipatesInCompany (BaseUser $userInstance)  {
+               // By default no user owns any company... ;)
+               $participates = false;
+
+               // Get a search criteria class
+               $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+               // Add the user primary key as a search criteria
+               $criteriaInstance->addCriteria('participant_id', $userInstance->getPrimaryKey());
+               $criteriaInstance->setLimit(1);
+
+               // Set company->user table
+               $this->setTableName(self::DB_TABLE_COMPANY_USER);
+
+               // Get the result back
+               $resultInstance = $this->doSelectByCriteria($criteriaInstance);
+
+               // Is there a result?
+               if ($resultInstance->next()) {
+                       // Then cache it
+                       $this->setResultInstance($resultInstance);
+
+                       // Entry found for further analysis/processing
+                       $participates = true;
+               } // END - if
+
+               // Return the result
+               return $participates;
+       }
 }
 
 // [EOF]
index 2134e431fa4795f99805c901e0625407676ea494..3a508c0fb39c83864ae0e48fe176621e3724961e 100644 (file)
@@ -2,7 +2,7 @@
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
 <head>
        <title>
-               Ship-Simu Schiffsimulator - $content[title]
+               Ship-Simu Schiffsimulator - {?title?}
        </title>
 
        <meta name="author" content="$config[meta_author]" />
index 3326c51f4405e4c7f7c2bcca1cd686d4b1ed8eeb..97fbbd368877a2753b94388be19643fe46c0041b 100644 (file)
@@ -28,14 +28,30 @@ $blockInstance->flushContent();
 // Get a new instance for personal data
 $blockInstance = WebBlockHelper::createWebBlockHelper($this, 'company_data');
 
-// Get the user instance 
-$userInstance = Registry::getRegistry()->getInstance('user');
-
-// Get a shipping company instance ready
-$companyInstance = ObjectFactory::createObjectByConfiguredName('company_class', array($userInstance));
+// Set the data source instance
+$blockInstance->prefetchValueInstance('company', 'user');
+
+// Assign the company name
+if ($blockInstance->getValueInstance()->ifUserIsFounder()) {
+       // User is the founder of the company
+       $blockInstance->assignMessageField('company_stats', "user_is_company_founder");
+       $blockInstance->assignLinkFieldWithAction('company_link' , "company_overview");
+} elseif ($blockInstance->getValueInstance()->ifUserIsOwner()) {
+       // User owns the company
+       $blockInstance->assignMessageField('company_stats', "user_is_company_owner");
+       $blockInstance->assignLinkFieldWithAction('company_link' , "company_overview");
+} elseif ($blockInstance->getValueInstance()->ifUserIsEmployee()) {
+       // User is employed in company
+       $blockInstance->assignMessageField('company_stats', "user_is_employed_in_company");
+       $blockInstance->assignLinkFieldWithAction('company_link' , "employee_overview");
+} else {
+       // No company participation!
+       $blockInstance->assignMessageField('company_stats', "user_not_assigned_company");
+       $blockInstance->assignLinkFieldWithAction('company_link' , "found_new_company");
+}
 
 // Flush the content out to a template variable
-//$blockInstance->flushContent();
+$blockInstance->flushContent();
 
 // End of all PHP commands
 ?>
index de854be0232e2d440c09d9784daf581896c765ec..08abd1f8001ec6046bd603f487a638f08ea8fd75 100644 (file)
@@ -68,6 +68,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         */
        private $templateInstance = null;
 
+       /**
+        * Database result instance
+        */
+       private $resultInstance = null;
+
        /**
         * The real class name
         */
@@ -201,6 +206,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * Destructor reached...
         *
         * @return      void
+        * @todo        This is old code. Do we still need this old lost code?
         */
        public function __destruct() {
                // Is this object already destroyed?
@@ -211,7 +217,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                        $this->resetUniqueID();
                } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
                        // Already destructed object
-                       $this->getDebugInstance()->output(sprintf("[%s:] Das Objekt <strong>%s</strong> wurde bereits zerst&ouml;rt.",
+                       $this->getDebugInstance()->output(sprintf("[%s:] The object <strong>%s</strong> is already destroyed.",
                                __CLASS__, $this->__toString()
                        ));
                }
@@ -320,6 +326,26 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                }
        }
 
+       /**
+        * Setter for database result instance
+        *
+        * @param       $resultInstance         An instance of a database result class
+        * @return      void
+        * @todo        SearchableResult and UpdateableResult shall have a super interface to use here
+        */
+       protected final function setResultInstance (SearchableResult $resultInstance) {
+               $this->resultInstance =  $resultInstance;
+       }
+
+       /**
+        * Getter for database result instance
+        *
+        * @return      $resultInstance         An instance of a database result class
+        */
+       public final function getResultInstance () {
+               return $this->resultInstance;
+       }
+
        /**
         * Setter for template engine instances
         *
index 6e28c9f0f00f2ad6d0509264607aab5ec0d90e9e..0f5af546d31a8905de293b74ec91d8df6f68e787 100644 (file)
@@ -369,7 +369,7 @@ class ImageHelper extends BaseCaptcha implements HelpableTemplate {
 
                // Add all strings
                foreach ($this->imageStrings as $id=>$imageString) {
-                       // Set current string id
+                       // Set current string id to keep this helper in sync with template engine
                        $this->currString = $id;
 
                        // Set variable group
index dab6791f0e8830a4bdd4b2abce2fff30d4b3f4b7..a40193d3d3adec9a7040f0a6eca61947b048af9e 100644 (file)
@@ -109,17 +109,33 @@ class BaseHelper extends BaseFrameworkSystem {
         * Pre-fetches field default values from the given registry key instance into this class
         *
         * @param       $registryKey    Registry key which holds an object with values
+        * @param       $extraKey               Extra value instance key used if registryKey is null
         * @return      void
-        * @throws      NullPointerException    If an instance from registry is null
+        * @throws      NullPointerException    If recovery of requested value instance failed
         */
-       public function prefetchValueInstance ($registryKey) {
+       public function prefetchValueInstance ($registryKey, $extraKey = null) {
                // Get the required instance
                $this->valueInstance = Registry::getRegistry()->getInstance($registryKey);
 
                // Is the instance valid?
                if (is_null($this->valueInstance)) {
-                       // Throw an exception
-                       throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+                       // Try to create it "from scratch", by first init extra instance
+                       $extraInstance = null;
+
+                       // Shall we get an extra instance?
+                       if (!is_null($extraKey)) {
+                               // Get the extra instance.
+                               $extraInstance = Registry::getRegistry()->getInstance($extraKey);
+                       } // END - if
+
+                       // Get the requested instance
+                       try {
+                               $this->valueInstance = ObjectFactory::createObjectByConfiguredName($registryKey . '_class', array($extraInstance));
+
+                       } catch (FrameworkException $e) {
+                               // Okay, nothing found so throw a null pointer exception here
+                               throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+                       }
                } // END - if
        }
 
@@ -136,6 +152,15 @@ class BaseHelper extends BaseFrameworkSystem {
                // Return it
                return $fieldValue;
        }
+
+       /**
+        * Getter for value instance
+        *
+        * @return      $valueInstance  Instance of the class holding our values
+        */
+       public final function getValueInstance () {
+               return $this->valueInstance;
+       }
 }
 
 // [EOF]
index d6b8fc9b08d4f031304ceb0f067a31a7784a200a..65b2e3f6fdc2631e82a6e836a2bc1da4fe1fa69f 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 class DefaultNewsReader extends BaseFrameworkSystem implements ReadableNews, Registerable {
-       /**
-        * Result set with news
-        */
-       private $resultInstance = null;
-
        /**
         * Protected constructor
         *
@@ -90,7 +85,7 @@ class DefaultNewsReader extends BaseFrameworkSystem implements ReadableNews, Reg
                $resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
 
                // Save that resultInstance in this class
-               $this->resultInstance = $resultInstance;
+               $this->setResultInstance($resultInstance);
        }
 }
 
index e7e4541e70623d0dcaf99a6150777ece46fa41b7..e9ce25c3f45061a9b66c7361fc2372ab5960d8ee 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class BaseUser extends BaseFrameworkSystem {
-       /**
-        * Instance of the database result
-        */
-       private $resultInstance = null;
-
        /**
         * Username of current user
         */
@@ -71,7 +66,7 @@ class BaseUser extends BaseFrameworkSystem {
 
                // Do we have an entry?
                if (!$this->getResultInstance()->valid()) {
-                       throw new InvalidDatabaseResultException(array($this, $this->resultInstance), DatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
+                       throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), DatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
                } // END - if
 
                // Get next entry
@@ -122,15 +117,6 @@ class BaseUser extends BaseFrameworkSystem {
                return $this->email;
        }
 
-       /**
-        * Getter for database result instance
-        *
-        * @return      $resultInstance         An instance of a database result class
-        */
-       protected final function getResultInstance () {
-               return $this->resultInstance;
-       }
-
        /**
         * Determines wether the username exists or not
         *
@@ -153,7 +139,7 @@ class BaseUser extends BaseFrameworkSystem {
                        $criteriaInstance->setLimit(1);
 
                        // Get a search result
-                       $this->resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+                       $this->setResultInstance($wrapperInstance->doSelectByCriteria($criteriaInstance));
                } else {
                        // Rewind it
                        $this->getResultInstance()->rewind();
@@ -191,7 +177,7 @@ class BaseUser extends BaseFrameworkSystem {
                        $criteriaInstance->setLimit(1);
 
                        // Get a search resultInstance
-                       $this->resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+                       $this->setResultInstance($wrapperInstance->doSelectByCriteria($criteriaInstance));
                } else {
                        // Rewind it
                        $this->getResultInstance()->rewind();
@@ -229,7 +215,7 @@ class BaseUser extends BaseFrameworkSystem {
                $criteriaInstance->setLimit(1);
 
                // Get a search resultInstance
-               $this->resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+               $this->setResultInstance($wrapperInstance->doSelectByCriteria($criteriaInstance));
 
                // Search for it
                if ($this->getResultInstance()->next()) {
index 9ad3a004105a12bfcd8a035112395d454870a184..9986c919adc14c8d5ffa75ed95e6ee855a80b55e 100644 (file)
--- a/index.php
+++ b/index.php
@@ -83,31 +83,19 @@ class ApplicationEntryPoint {
                        // Use the template engine for putting out (nicer look) the message
                        try {
                                // Get the template instance from our object factory
-                               $tplEngine = ObjectFactory::createObjectByConfiguredName('template_class', array(FrameworkConfiguration::getInstance()->readConfig('tpl_base_path'), $lang, $io));
-                       } catch (BasePathIsEmptyException $e) {
-                               die(sprintf("[Main:] Could not initialize template engine for this reason: <strong>%s</strong>",
-                                       $e->getMessage()
-                               ));
-                       } catch (InvalidBasePathStringException $e) {
-                               die(sprintf("[Main:] Could not initialize template engine for this reason: <strong>%s</strong>",
-                                       $e->getMessage()
-                               ));
-                       } catch (BasePathIsNoDirectoryException $e) {
-                               die(sprintf("[Main:] Could not initialize template engine for this reason: <strong>%s</strong>",
-                                       $e->getMessage()
-                               ));
-                       } catch (BasePathReadProtectedException $e) {
-                               die(sprintf("[Main:] Could not initialize template engine for this reason: <strong>%s</strong>",
+                               $tplEngine = ObjectFactory::createObjectByName($tpl, array(FrameworkConfiguration::getInstance()->readConfig('tpl_base_path'), $lang, $io));
+                       } catch (FrameworkException $e) {
+                               die(sprintf("[Main:] Could not initialize template engine for reason: <strong>%s</strong>",
                                        $e->getMessage()
                                ));
                        }
 
-                       // Backtrace holen und aufbereiten
+                       // Get and prepare backtrace for output
                        $backtraceArray = debug_backtrace();
                        $backtrace = "";
                        foreach ($backtraceArray as $key=>$trace) {
                                if (!isset($trace['file'])) $trace['file'] = __FILE__;
-                               if (!isset($trace['line'])) $trace['line'] = 5;
+                               if (!isset($trace['line'])) $trace['line'] = __LINE__;
                                if (!isset($trace['args'])) $trace['args'] = array();
                                $backtrace .= "<span class=\"backtrace_file\">".basename($trace['file'])."</span>:".$trace['line'].", <span class=\"backtrace_function\">".$trace['function']."(".count($trace['args']).")</span><br />";
                        } // END - foreach
@@ -119,6 +107,7 @@ class ApplicationEntryPoint {
                        $tplEngine->assignVariable('backtrace', $backtrace);
                        $tplEngine->assignVariable('total_includes', ClassLoader::getInstance()->getTotal());
                        $tplEngine->assignVariable('total_objects', ObjectFactory::getTotal());
+                       $tplEngine->assignVariable('title', $lang->getMessage('emergency_exit_title'));
 
                        // Load the template
                        $tplEngine->loadCodeTemplate('emergency_exit');
@@ -168,7 +157,6 @@ class ApplicationEntryPoint {
 
                // Include the application selector
                require(PATH . 'inc/selector.php');
-
        } // END - main()
 
 } // END - class