Summary Files Commits Branches @commit @diff @stats
path: root / src / models / JobOffer.php
diff options
context:
space:
mode:
Commitf8c1df9a9a24be0ff3811dc33e00f92bf51465ab (patch)
Author
 Kamen Mladenov <kamen.d.mladenov@protonmail.com>
2021-04-03 11:54:52 +0300
Committer
 GitHub <noreply@github.com>
2021-04-03 11:54:52 +0300
Files56dfbe9d57e3150b480928da543b3dba30e11692 /src/models/JobOffer.php
devrix-job-board-f8c1df9a9a24be0ff3811dc33e00f92bf51465ab.tar
devrix-job-board-f8c1df9a9a24be0ff3811dc33e00f92bf51465ab.tar.gz
devrix-job-board-f8c1df9a9a24be0ff3811dc33e00f92bf51465ab.zip
Parentaa2e361c3114b53ac7858e118454b9dfaf51ebe4 (diff)
Parentfff8c08ad7f3845eb32671292392cbf08bb738c9 (diff)
Merge pull request #1 from Syndamia/dev v0.1
Implemented main functionality
1 files changed, 93 insertions, 0 deletions
-rw-r--r--src/models/JobOffer.php93
diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php
new file mode 100644
index 0000000..b86ff86
--- /dev/null
+++ b/src/models/JobOffer.php
@@ -0,0 +1,93 @@
+<?php
+include_once("models/DBModel.php");
+include_once("models/Company.php");
+
+/**
+ * Model that contains the required JobOffer properties. It also contains the request methods to the job_offers table.
+ */
+class JobOffer extends DBModel {
+ public string $title;
+ public string $description;
+ public int $companyId;
+ public float $salary;
+
+ function __construct(string $title, string $description, int $companyId, float $salary) {
+ $this->title = $title;
+ $this->description = $description;
+ $this->companyId = $companyId;
+ $this->salary = $salary;
+ }
+
+ /*
+ * Everything from here is static functionality
+ */
+
+ public const TABLE_NAME = "job_offers";
+
+ static function __constructStatic() {
+ $columns = array(
+ "title " . DB::STRING_TYPE,
+ "description " . DB::STRING_TYPE,
+ "companyId " . DB::INTEGER_TYPE, // Requires a foreign key
+ "salary " . DB::FLOAT_TYPE,
+ );
+ $foreignKeys = array(
+ DB::genFK("companyId", Company::TABLE_NAME, "id")
+ );
+ self::$DB->createTable(self::TABLE_NAME, $columns, $foreignKeys);
+ }
+
+ /* Create */
+
+ /**
+ * Inserts the giveb JobOffer into the databse. The id is automatically generated in the database.
+ *
+ * @param JobOffer $jb
+ */
+ static function insertIntoDB($jb) {
+ self::$DB->insertValue(self::TABLE_NAME, $jb->title, $jb->description, $jb->companyId, $jb->salary);
+ }
+
+ /* Read */
+
+ /**
+ * Returns the JobOffer with the given id from the database.
+ *
+ * @return JobOffer
+ */
+ static function getFromDBById(int $id) {
+ return self::$DB->getById(self::TABLE_NAME, $id);
+ }
+
+ /**
+ * Returns all JobOffers from the database.
+ *
+ * @return JobOffer[]
+ */
+ static function getAllFromDB() {
+ return self::$DB->getAllValues(self::TABLE_NAME);
+ }
+
+ /* Update */
+
+ /**
+ * Updates the given JobOffer from the database.
+ * **WARNING**: the JobOffer **MUST** have it's database id.
+ *
+ * @param JobOffer $jb
+ */
+ static function updateFromDB($jb) {
+ self::$DB->updateById(self::TABLE_NAME, $jb->id, "title", $jb->title, "description", $jb->description, "companyId", $jb->companyId, "salary", $jb->salary);
+ }
+
+ /* Delete */
+
+ /**
+ * Deletes the JobOffer with the given id from the database.
+ */
+ static function deleteFromDB(int $id) {
+ self::$DB->deleteById(self::TABLE_NAME, $id);
+ }
+}
+
+JobOffer::__constructStatic();