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 {
25 // Constants for database tables
26 const DB_TABLE_COMPANY_DATA = "company";
27 const DB_TABLE_COMPANY_USER = "company_user";
30 * Protected constructor
34 protected function __construct () {
35 // Call parent constructor
36 parent::__construct(__CLASS__);
38 // Set part description
39 $this->setObjectDescription("A wrapper for database access to company data");
41 // Create unique ID number
42 $this->generateUniqueId();
46 * Creates an instance of this wrapper class
48 * @return $wrapperInstance An instance of this wrapper class
50 public final static function createCompanyDatabaseWrapper () {
51 // Create a new instance
52 $wrapperInstance = new CompanyDatabaseWrapper();
54 // Set (primary!) table name
55 $wrapperInstance->setTableName(self::DB_TABLE_COMPANY_DATA);
57 // Return the instance
58 return $wrapperInstance;
62 * Checks wether the given user participates in a company
64 * @param $userInstance An instance of a user class
65 * @return $participates Wether the user participates at lease in one company
67 public function ifUserParticipatesInCompany (BaseUser $userInstance) {
68 // By default no user owns any company... ;)
69 $participates = false;
71 // Get a search criteria class
72 $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
74 // Add the user primary key as a search criteria
75 $criteriaInstance->addCriteria('participant_id', $userInstance->getPrimaryKey());
76 $criteriaInstance->setLimit(1);
78 // Set company->user table
79 $this->setTableName(self::DB_TABLE_COMPANY_USER);
81 // Get the result back
82 $resultInstance = $this->doSelectByCriteria($criteriaInstance);
85 if ($resultInstance->next()) {
87 $this->setResultInstance($resultInstance);
89 // Entry found for further analysis/processing