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__);
45 * Creates an instance of this wrapper class
47 * @param $companyInstance An instance of a generic company class or null if no specific
48 * @return $wrapperInstance An instance of this wrapper class
49 * @todo Find an interface which is suitable for all companies
51 public final static function createCompanyDatabaseWrapper (ShippingCompany $companyInstance = null) {
52 // Create a new instance
53 $wrapperInstance = new CompanyDatabaseWrapper();
55 // Set (primary!) table name
56 $wrapperInstance->setTableName(self::DB_TABLE_COMPANY_DATA);
58 // Set the company instance if not null
59 if (!is_null($companyInstance)) {
60 $wrapperInstance->setCompanyInstance($companyInstance);
63 // Return the instance
64 return $wrapperInstance;
68 * Checks wether the given user participates in a company
70 * @param $userInstance An instance of a user class
71 * @return $participates Wether the user participates at lease in one company
73 public function ifUserParticipatesInCompany (ManageableAccount $userInstance) {
74 // By default no user owns any company... ;)
75 $participates = false;
77 // Get a search criteria class
78 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
80 // Add the user primary key as a search criteria
81 $criteriaInstance->addCriteria('participant_id', $userInstance->getPrimaryKey());
82 $criteriaInstance->setLimit(1);
84 // Set company->user table
85 $this->setTableName(self::DB_TABLE_COMPANY_USER);
87 // Get the result back
88 $resultInstance = $this->doSelectByCriteria($criteriaInstance);
91 if ($resultInstance->next()) {
93 $this->setResultInstance($resultInstance);
95 // Entry found for further analysis/processing
100 return $participates;
104 * Setter for company instance
106 * @param $companyInstance An instance of a generic company
108 * @todo Find an interface suitable for all types of companies
110 protected final function setCompanyInstance (ShippingCompany $companyInstance) {
111 $this->companyInstance = $companyInstance;
115 * Getter for company instance
117 * @return $companyInstance An instance of a generic company
118 * @todo Find an interface suitable for all types of companies
120 public final function getCompanyInstance () {
121 return $this->companyInstance;