b49b1d050c4a56c4038baac528721ec8d7127803
[shipsimu.git] / application / ship-simu / main / wrapper / class_CompanyDatabaseWrapper.php
1 <?php
2 /**
3  * A wrapper for database access to shipping company data
4  *
5  * @author              Roland Haeder <webmaster@ship-simu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, this is free software
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 CompanyDatabaseWrapper extends BaseDatabaseWrapper {
25         // Constants for database tables
26         const DB_TABLE_COMPANY_DATA = "company";
27         const DB_TABLE_COMPANY_USER = "company_user";
28
29         /**
30          * Protected constructor
31          *
32          * @return      void
33          */
34         protected function __construct () {
35                 // Call parent constructor
36                 parent::__construct(__CLASS__);
37
38                 // Set part description
39                 $this->setObjectDescription("A wrapper for database access to company data");
40
41                 // Create unique ID number
42                 $this->generateUniqueId();
43         }
44
45         /**
46          * Creates an instance of this wrapper class
47          *
48          * @return      $wrapperInstance        An instance of this wrapper class
49          */
50         public final static function createCompanyDatabaseWrapper () {
51                 // Create a new instance
52                 $wrapperInstance = new CompanyDatabaseWrapper();
53
54                 // Set (primary!) table name
55                 $wrapperInstance->setTableName(self::DB_TABLE_COMPANY_DATA);
56
57                 // Return the instance
58                 return $wrapperInstance;
59         }
60
61         /**
62          * Checks wether the given user participates in a company
63          *
64          * @param       $userInstance   An instance of a user class
65          * @return      $participates   Wether the user participates at lease in one company
66          */
67         public function ifUserParticipatesInCompany (BaseUser $userInstance)  {
68                 // By default no user owns any company... ;)
69                 $participates = false;
70
71                 // Get a search criteria class
72                 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
73
74                 // Add the user primary key as a search criteria
75                 $criteriaInstance->addCriteria('participant_id', $userInstance->getPrimaryKey());
76                 $criteriaInstance->setLimit(1);
77
78                 // Set company->user table
79                 $this->setTableName(self::DB_TABLE_COMPANY_USER);
80
81                 // Get the result back
82                 $resultInstance = $this->doSelectByCriteria($criteriaInstance);
83
84                 // Is there a result?
85                 if ($resultInstance->next()) {
86                         // Then cache it
87                         $this->setResultInstance($resultInstance);
88
89                         // Entry found for further analysis/processing
90                         $participates = true;
91                 } // END - if
92
93                 // Return the result
94                 return $participates;
95         }
96 }
97
98 // [EOF]
99 ?>