TODO: We should find something better than BaseFrameworkSystem as a type-hint
[shipsimu.git] / ship-simu / inc / classes / main / database / class_BaseDatabaseFrontend.php
1 <?php
2 /**
3  * An abstract database access class for handling database I/O requests
4  *
5  * @see DatabaseFrontendInterface       An interface for database frontends (front-end to the application)
6  * @author              Roland Haeder <webmaster@ship-simu.org>
7  * @version             0.0
8  * @copyright   Copyright(c) 2007, 2008 Roland Haeder, this is free software
9  * @license             GNU GPL 3.0 or any newer version
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 abstract class BaseDatabaseFrontend extends BaseFrameworkSystem implements DatabaseFrontendInterface, LimitableObject {
25         /**
26          * The limiter instance
27          */
28         private $limitInstance = null;
29
30         /**
31          * Private constructor
32          *
33          * @return      void
34          */
35         private function __construct($class) {
36                 // Call parent constructor
37                 parent::constructor($class);
38
39                 // Debug message
40                 if (((defined('DEBUG_DATABASE')) || (defined('DEBUG_ALL'))) && (defined('DEBUG_CONSTRUCT'))) $this->getDebugInstance()->output(sprintf("[%s:] Konstruktor erreicht.<br />\n",
41                         $this->__toString()
42                 ));
43
44                 // Clean up a little
45                 $this->removeNumberFormaters();
46         }
47
48         /**
49          * The public constructor
50          *
51          * @return      void
52          */
53         public function constructor ($class) {
54                 // Calls just the private one
55                 $this->__construct($class);
56         }
57
58         /**
59          * Getter for limitation instance
60          *
61          * @return      $limitInstance          The instance to the object ObjectLimits
62          */
63         public final function getLimitInstance () {
64                 if ((defined('DEBUG_DATABASE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:] Limitierungsinstanz <strong>%s</strong> angefordert.<br />\n",
65                         $this->__toString(),
66                         $this->limitInstance->__toString()
67                 ));
68                 return $this->limitInstance;
69         }
70
71         /**
72          * Setup limitation for the saving process
73          *
74          * @param               $limitInstance  An instance of ObjectLimits which contains
75          *                                              elements we shall exclusivly include in
76          *                                              saving process
77          * @return      void
78          */
79         public final function limitObject (ObjectLimits $limitInstance) {
80                 // Debug message
81                 if ((defined('DEBUG_DATABASE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:] Limitierungsinstanz <strong>%s</strong> soll verwendet werden.<br />\n",
82                         $this->__toString(),
83                         $limitInstance->__toString()
84                 ));
85
86                 // Get limitArray for validation
87                 $array = $limitInstance->getLimitArray();
88
89                 // Sanity-check if some limitations are in the object
90                 if ($array->count() > 0) {
91                         // Okay, there is enougth
92                         $this->limitInstance = $limitInstance;
93
94                         // Debug message
95                         if ((defined('DEBUG_DATABASE')) || (defined('DEBUG_ALL'))) $this->getDebugInstance()->output(sprintf("[%s:] Limitierungsinstanz <strong>%s</strong> wird verwendet und beinhaltet <strong>%s</strong> Eintr&auml;ge.<br />\n",
96                                 $this->__toString(),
97                                 $limitInstance->__toString(),
98                                 $array->count()
99                         ));
100                 }
101         }
102 }
103
104 // [EOF]
105 ?>