Question

I wanted to allow user to send application to a certain job. I originally allowed editing but had some issues as in here: How do I completely overwrite previously edited data such that only the latest one is displayed in Codeigniter? After trying different ways to solve it, I still could not. But it almost does not matter now because I realized the original plan I had would produce more issues. Besides, in real life, proposal should be made once, so the best should be submitted. My issue now is, even if a certain user has already sent an application, every time he tries to visit the same job post, "Apply" button still works, thus multiple application is still made. I tried to change something on my model, but it still did not work.

Here's what I have in my provider controller:

public function write_proposal() 
{
    //allows provider to send proposal to client
    $this->validateRole('provider');
    $this->load->model('job_model');

    $id = $this->uri->segment(3, 0);
    $data['my_preference'] = $this->job_model->get_my_job_proposals($id);   
    //$data['id'] = $id;        

    $data['job'] = $this->job_model->get_job($id);
    $this->load->view('provider/write_proposal', $data);

}

public function job_proposal_submit() 
{
    //completes proposal submission
    $this->validateRole('provider');
    $this->load->model('job_model');

    $this->job_model->add_job_proposal_from_provider($_POST);       

    redirect('provider/view_job/' . $_POST['job_id'] . "?message=Proposal submitted.");

}

And this corresponding one in my job model..

    public function add_job_proposal_from_provider($obj) 
{
    //I wanted to make here the condition that adding new proposal will only work if the user has not yet submitted any proposal for the specific job but it produced another error, and that is none of the at least two proposals made is shown or probably even saved
    //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);
    //}
}

I look forward to any help. Thanks

Was it helpful?

Solution

A few things,

First, consider implementing a view-side limitation, while it won't stop someone clever it will improve your UI alot(users won't have buttons that work but won't do anything).

I'm assuming users have to login to send applications, else this whole thing wouldn't be too useful.

What I would do is create a table with all the job IDs, every time a user applies to a job, you add him to that table.

When a user tries to apply for a job, you first check if there's a match for that jobID/userID in this table, If there's no match, You can move along and check if the information was posted correctly and actually add the information to the database, and also to that jobID/userID table(so he can't post twice).

On the view side, I would send a variable to the view with all the jobID's this current user has applied to and use simple ifs or javascript to disable the buttons(or show alerts when the user tries to push the buttons).

I hope this helps a bit

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top