Question

I realized a very significant problem in my application. It's about apply and hire functions. Ideally, an applicant can only apply once to a certain job post.However, what happens in my program is not like this. After some more tests, I realized, an applicant can send two, three, four and so on which should not be the case. Correspondingly, the client can hire or reject the applicant more than once (depending on the number of proposals sent), what's more erroneous is, even an applicant has already been hired, if the client clicks the reject button on the proposals page, the status changes from "Approved" to rejected.

I think I should change something in this part:

 public function add_job_proposal_from_provider($obj) 
{
    if ($obj['proposal'] == NULL){
    $data = array
    (
        'proposal' => $obj['proposal'],
        'job_id' => $obj['job_id'],
        'status' => "Open",
        'provider_id' => $this->auth_model->get_user_id()
    );

    $this->db->insert('job_proposal', $data);
    }

}

in terms of application.. I am looking forward to any help.

Was it helpful?

Solution

You could check your database before you insert, to ensure there is no proposal from that user for that particular job. Here's a brief example that you could add to the start of your add_job_proposal_from_provider($obj) method:

$this->db->from('job_proposal');
$this->db->where('job_id', $obj['job_id']);
$this->db->where('provider_id', $this->auth_model->get_user_id());
$result = $this->db->get();
if ($result->num_rows() > 0) {
    // Set some error message?
    return;
}

Alternatively, you could set a UNIQUE index in your database across the job_id and provider_id fields. An example in MySQL is:

ALTER TABLE job_proposal ADD UNIQUE INDEX(provider_id, job_id);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top