]> git.mxchange.org Git - hub.git/blob - application/hub/main/database/wrapper/node/class_NodeInformationDatabaseWrapper.php
5f803f95b917a3bb4b760a22c56c295a68986ab3
[hub.git] / application / hub / main / database / wrapper / node / class_NodeInformationDatabaseWrapper.php
1 <?php
2 /**
3  * A database wrapper for node informations
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.ship-simu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 class NodeInformationDatabaseWrapper extends BaseDatabaseWrapper {
25         // Constants for database table names
26         const DB_TABLE_NODE_INFORMATION = 'node_data';
27
28         // Constants for database column names
29         const DB_COLUMN_NODE_NR    = 'node_nr';
30         const DB_COLUMN_NODE_ID    = 'node_id';
31         const DB_COLUMN_SESSION_ID = 'session_id';
32         const DB_COLUMN_NODE_TYPE  = 'node_type';
33
34         /**
35          * Protected constructor
36          *
37          * @return      void
38          */
39         protected function __construct () {
40                 // Call parent constructor
41                 parent::__construct(__CLASS__);
42         }
43
44         /**
45          * Creates an instance of this database wrapper by a provided user class
46          *
47          * @return      $wrapperInstance        An instance of the created wrapper class
48          */
49         public static final function createNodeInformationDatabaseWrapper () {
50                 // Get a new instance
51                 $wrapperInstance = new NodeInformationDatabaseWrapper();
52
53                 // Set (primary!) table name
54                 $wrapperInstance->setTableName(self::DB_TABLE_NODE_INFORMATION);
55
56                 // Return the instance
57                 return $wrapperInstance;
58         }
59
60         /**
61          * 'Registers' a new node id along with data provided in the node instance.
62          * This may sound confusing but avoids double code very nicely...
63          *
64          * @param       $nodeInstance           A node instance
65          * @param       $requestInstance        An instance of a Requestable class
66          * @return      void
67          */
68         public function registerNodeId (BaseHubNode $nodeInstance, Requestable $requestInstance) {
69                 // Get a dataset instance
70                 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION));
71
72                 // Set the primary key
73                 $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
74
75                 // Add registration elements to the dataset
76                 $nodeInstance->addElementsToDataSet($dataSetInstance, $requestInstance);
77
78                 // "Insert" this dataset instance completely into the database
79                 $this->queryInsertDataSet($dataSetInstance);
80         }
81
82         /**
83          * 'Registers' a new session id along with data provided in the node instance.
84          * This may sound confusing but avoids double code very nicely...
85          *
86          * @param       $nodeInstance           A node instance
87          * @param       $requestInstance        An instance of a Requestable class
88          * @return      void
89          */
90         public function registerSessionId (BaseHubNode $nodeInstance, Requestable $requestInstance) {
91                 // Get a dataset instance
92                 $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION));
93
94                 // Set the primary key
95                 $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
96
97                 // Add registration elements to the dataset
98                 $nodeInstance->addElementsToDataSet($dataSetInstance, $requestInstance);
99
100                 // "Insert" this dataset instance completely into the database
101                 $this->queryInsertDataSet($dataSetInstance);
102         }
103 }
104
105 // [EOF]
106 ?>