/** * Commit changes to a job * @since Version 3.8 * @return boolean */ public function commit() { try { $this->validate(); } catch (Exception $e) { throw new Exception($e->getMessage()); return false; } /** * Firstly, check if this reference ID exists anywhere in the database. If it does, update, not create. */ if (filter_var($this->reference_id, FILTER_VALIDATE_INT) && $this->reference_id > 0) { $query = "SELECT job_id FROM jn_jobs WHERE reference_id = ?"; if ($id = $this->db->fetchOne($query, $this->reference_id)) { $this->id = $id; } } $data = array("job_title" => $this->title, "reference_id" => $this->reference_id, "organisation_id" => $this->Organisation->id, "job_location_id" => $this->Location->id, "job_description" => $this->desc, "job_added" => $this->Open->format("Y-m-d H:i:s"), "job_expiry" => $this->expiry->format("Y-m-d H:i:s"), "job_classification_id" => $this->Classification->id, "job_salary" => $this->salary, "job_special_cond" => $this->special_cond, "job_duration" => $this->duration, "job_thread_id" => $this->thread_id, "job_urls" => json_encode($this->url->getUrls())); if (filter_var($this->id, FILTER_VALIDATE_INT)) { // Update if ($this->db->update("jn_jobs", $data, "job_id = " . $this->id)) { return true; } } else { // Insert if ($this->db->insert("jn_jobs", $data)) { $this->id = $this->db->lastInsertId(); $this->url = new Url(sprintf("%s?mode=view&id=%d", $this->Module->url, $this->id)); return $this; } } }