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
*/
private $contractList = null;
- /**
- * Database result instance
- */
- private $resultInstance = null;
-
// Exception constants
const EXCEPTION_USER_OWNS_NO_COMPANY = 0x200;
*
* @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'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();
}
/**
- * 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
$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;
*/
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
$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]
<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]" />
// 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
?>
*/
private $templateInstance = null;
+ /**
+ * Database result instance
+ */
+ private $resultInstance = null;
+
/**
* The real class name
*/
* 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?
$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ört.",
+ $this->getDebugInstance()->output(sprintf("[%s:] The object <strong>%s</strong> is already destroyed.",
__CLASS__, $this->__toString()
));
}
}
}
+ /**
+ * 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
*
// 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
* 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
}
// 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]
* 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
*
$resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
// Save that resultInstance in this class
- $this->resultInstance = $resultInstance;
+ $this->setResultInstance($resultInstance);
}
}
* 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
*/
// 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
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
*
$criteriaInstance->setLimit(1);
// Get a search result
- $this->resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+ $this->setResultInstance($wrapperInstance->doSelectByCriteria($criteriaInstance));
} else {
// Rewind it
$this->getResultInstance()->rewind();
$criteriaInstance->setLimit(1);
// Get a search resultInstance
- $this->resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+ $this->setResultInstance($wrapperInstance->doSelectByCriteria($criteriaInstance));
} else {
// Rewind it
$this->getResultInstance()->rewind();
$criteriaInstance->setLimit(1);
// Get a search resultInstance
- $this->resultInstance = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+ $this->setResultInstance($wrapperInstance->doSelectByCriteria($criteriaInstance));
// Search for it
if ($this->getResultInstance()->next()) {
// 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
$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');
// Include the application selector
require(PATH . 'inc/selector.php');
-
} // END - main()
} // END - class