--- /dev/null
+<?php
+/**
+ * A database wrapper for node list
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements Registerable {
+ // Table names
+ const DB_TABLE_NODE_LIST = 'node_list';
+
+ // Constants for column name
+ const DB_COLUMN_NODE_SESSION_ID = 'node_session_id';
+ const DB_COLUMN_NODE_IP_PORT = 'node_ipport';
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this database wrapper by a provided user class
+ *
+ * @return $wrapperInstance An instance of the created wrapper class
+ */
+ public static final function createNodeListDatabaseWrapper () {
+ // Get a new instance
+ $wrapperInstance = new NodeListDatabaseWrapper();
+
+ // Set (primary!) table name
+ $wrapperInstance->setTableName(self::DB_TABLE_NODE_LIST);
+
+ // Return the instance
+ return $wrapperInstance;
+ }
+
+ /**
+ * Getter for index key
+ *
+ * @return $indexKey Index key
+ */
+ public final function getIndexKey () {
+ return $this->getDatabaseInstance()->getIndexKey();
+ }
+
+ /**
+ * Resolves a session id into an ip:port combination
+ *
+ * @param $sessionId A valid session id
+ * @return $recipient Recipient as ip:port combination
+ */
+ public function resolveIpPortBySessionId ($sessionId) {
+ // Set invalid ip:port combination
+ $recipient = 'invalid:invalid';
+
+ // Now get a search criteria instance
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Search for the node number zero which is hard-coded the default
+ $searchInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_NODE_SESSION_ID, 1);
+ $searchInstance->setLimit(1);
+
+ // Get a result back
+ $resultInstance = $this->doSelectByCriteria($searchInstance);
+
+ // Is it valid?
+ if ($resultInstance->next()) {
+ // Save the result instance in this class
+ $this->setResultInstance($resultInstance);
+
+ // Get the node id from result and set it
+ $recipient = $this->getField(NodeListDatabaseWrapper::DB_COLUMN_NODE_IP_PORT);
+ } // END - if
+
+ // Return result
+ return $recipient;
+ }
+}
+
+// [EOF]
+?>