3 * A wrapper for database access to shipping company data
5 * @author Roland Haeder <webmaster@ship-simu.org>
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
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.
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.
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/>.
24 class CompanyDatabaseWrapper extends BaseDatabaseWrapper {
28 private $companyInstance = null;
30 // Constants for database tables
31 const DB_TABLE_COMPANY_DATA = "company";
32 const DB_TABLE_COMPANY_USER = "company_user";
35 * Protected constructor
39 protected function __construct () {
40 // Call parent constructor
41 parent::__construct(__CLASS__);
43 // Set part description
44 $this->setObjectDescription("A wrapper for database access to company data");
46 // Create unique ID number
47 $this->generateUniqueId();
51 * Creates an instance of this wrapper class
53 * @param $companyInstance An instance of a generic company class or null if no specific
54 * @return $wrapperInstance An instance of this wrapper class
55 * @todo Find an interface which is suitable for all companies
57 public final static function createCompanyDatabaseWrapper (ShippingCompany $companyInstance = null) {
58 // Create a new instance
59 $wrapperInstance = new CompanyDatabaseWrapper();
61 // Set (primary!) table name
62 $wrapperInstance->setTableName(self::DB_TABLE_COMPANY_DATA);
64 // Set the company instance if not null
65 if (!is_null($companyInstance)) {
66 $wrapperInstance->setCompanyInstance($companyInstance);
69 // Return the instance
70 return $wrapperInstance;
74 * Checks wether the given user participates in a company
76 * @param $userInstance An instance of a user class
77 * @return $participates Wether the user participates at lease in one company
79 public function ifUserParticipatesInCompany (ManageableAccount $userInstance) {
80 // By default no user owns any company... ;)
81 $participates = false;
83 // Get a search criteria class
84 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
86 // Add the user primary key as a search criteria
87 $criteriaInstance->addCriteria('participant_id', $userInstance->getPrimaryKey());
88 $criteriaInstance->setLimit(1);
90 // Set company->user table
91 $this->setTableName(self::DB_TABLE_COMPANY_USER);
93 // Get the result back
94 $resultInstance = $this->doSelectByCriteria($criteriaInstance);
97 if ($resultInstance->next()) {
99 $this->setResultInstance($resultInstance);
101 // Entry found for further analysis/processing
102 $participates = true;
106 return $participates;
110 * Setter for company instance
112 * @param $companyInstance An instance of a generic company
114 * @todo Find an interface suitable for all types of companies
116 protected final function setCompanyInstance (ShippingCompany $companyInstance) {
117 $this->companyInstance = $companyInstance;
121 * Getter for company instance
123 * @return $companyInstance An instance of a generic company
124 * @todo Find an interface suitable for all types of companies
126 public final function getCompanyInstance () {
127 return $this->companyInstance;