Hi all,
I've been trying to figure out all morning why my callbacks before inserting and updating don't appear to be doing anything. The fields are visible and editable, but I wouldn't think that would be an issue. Whether they're left blank or something is filled in, nothing is ever set.
I'd be happy if I could figure out how to debug the $post_array but I can't figure out how to do that, because the call is done in Ajax.
FWIW I'm using Ion Auth. Otherwise this is a stock installation of GC and CI.
The controller has:
public function jobpostings($filter = false) {
$filtercriteria = ($this->input->get("filter")) ? array("filter" => $this->input->get('filter'), "criteria" => $this->input->get('criteria')) : false;
// Set up table
$this->grocery_crud->set_table('jobpostings');
$this->grocery_crud->set_subject("Job Posting");
$this->grocery_crud->columns("JobStatus", "Community", "Dept", "JobTitles", "FullPartTime", "Shift", "Comments");
$this->grocery_crud->display_as("JobTitles", "Job Title");
$this->grocery_crud->display_as("FullPartTime", "FT / PT");
$this->grocery_crud->display_as("Dept", "Department");
$this->grocery_crud->display_as("SendResumeTo", "Send Resume To:");
$this->grocery_crud->order_by("Community");
if ($filter == "open") {
$this->grocery_crud->where('JobStatus', '1');
} else if ($filtercriteria) {
$this->grocery_crud->where($filtercriteria['filter'], $filtercriteria['criteria']);
}
// Set relations
$this->grocery_crud->set_relation('LastModifiedBy', 'hradm_users', 'username', "username != 'administrator'");
$this->grocery_crud->set_relation('AddedBy', 'hradm_users', 'username', "username != 'administrator'");
// Set up fields we actually want to edit
$this->grocery_crud->fields("JobStatus", "Community", "Dept", "JobTitles", "FullPartTime", "Shift", "Openings", "SendResumeTo", "Comments", "AddedOn", "AddedBy", "LastModified", "LastModifiedBy");
$communities = $this->_callback_getlist("Community", "jobcommunities");
$depts = $this->_callback_getlist("Dept", "jobdepts");
$jobtitles = $this->_callback_getlist("JobTitles", "jobtitlesdescriptions");
$jobstatus = array("1" => "Open", "0" => "Closed");
$this->grocery_crud->field_type("FullPartTime", "dropdown", array("Full Time" => "Full Time", "Part Time" => "Part Time", "Both" => "Both"));
$this->grocery_crud->field_type("Shift", "dropdown", array("N/A" => "N/A", "Day" => "Day", "Afternoon" => "Afternoon", "Night" => "Night", "On-Call" => "On-Call", "Weekend Shifts" => "Weekend Shifts", "All Shifts" => "All Shifts"));
$this->grocery_crud->field_type("SendResumeTo", "dropdown", $communities);
$this->grocery_crud->field_type("Community", "dropdown", $communities);
$this->grocery_crud->field_type("Dept", "dropdown", $depts);
$this->grocery_crud->field_type("JobTitles", "dropdown", $jobtitles);
$this->grocery_crud->field_type("JobStatus", "dropdown", $jobstatus);
$this->grocery_crud->field_type("AddedOn", "datetime");
$this->grocery_crud->field_type("LastModified", "datetime");
// inserts and update callbacks
$this->grocery_crud->callback_before_insert(array($this, '_create_callback'));
$this->grocery_crud->callback_before_update(array($this, '_modified_callback'));
$output = $this->grocery_crud->render();
$this->_output_view($output, "jobpostings", array("filters_communities" => $communities, "filters_depts" => $depts));
}
And then the callbacks (FWIW, I verified that the $user->id is set correctly):
function _created_callback($post_array) {
$user = $this->ion_auth->user()->row();
$post_array['AddedBy'] = $user->id;
$post_array['AddedOn'] = date('Y-m-d H:i:s');
$post_array['LastModified'] = date('Y-m-d H:i:s');
return $post_array;
}
function _modified_callback($post_array) {
$user = $this->ion_auth->user()->row();
$post_array['LastModifiedBy'] = $user->id;
$post_array['LastModified'] = date('Y-m-d H:i:s');
return $post_array;
}
None of these fields are set when I look in the database-- they're all NULL. The purpose is to auto-log creation and modification times, while (at the same time) keeping users from having to remember to enter it.
Eventually they'll be set to read-only for edits, and will only be manually settable on insertsw, but first I'd have to feel confident this was working.
Does anyone have any suggestions?
Thanks!
