Summary Files Commits Branches @commit @diff @stats
path: root / src / models / Company.php
blob: 58b1734a6273d39db219ccfe55e663cc0ad74334 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
include_once('models/DBModel.php');

class Company extends DBModel {
	public string $name;

	function __construct(string $name) {
		$this->name = $name;
	}

	/*
	 * Everything from here is static functionality
	 */

	public const TABLE_NAME = 'companies';

	static function __constructStatic() {
		$columns = array(
			'name ' . DB::STRING_TYPE,
		);
		self::$DB->createTable(self::TABLE_NAME, $columns);

		// Since there is no real way to add companies, this serves as the only official way.
		if (sizeof(self::getAllFromDB()) == 0) {
			self::insertIntoDB(new Company("MegaCorp"));
			self::insertIntoDB(new Company("Cool INC."));
			self::insertIntoDB(new Company("Company Awesome Ltd."));
		}
	}

	/* Create */

	/**
	 * Inserts the giveb JobOffer into the databse. The id is automatically generated in the database.
	 *
	 * @param Company $com
	 */
	static function insertIntoDB($com) {
		self::$DB->insertValue(self::TABLE_NAME, $com->name);
	}

	/* Read */

	/**
	 * Returns all Companies from the database.
	 *
	 * @return Company[]
	 */
	static function getAllFromDB() {
		return self::$DB->getAllValues(self::TABLE_NAME);
	}
}

Company::__constructStatic();