Extend create function for jobs

This commit is contained in:
Eike Foken
2011-08-30 20:46:41 +02:00
parent dbd95d7b55
commit faac255555

View File

@@ -34,7 +34,18 @@ class Job extends CI_Model {
* @return bool was the insert successful * @return bool was the insert successful
*/ */
public function create($data) { public function create($data) {
return $this->db->insert('jobs', $data); $this->load->helper('date');
$this->load->helper('hash');
do { // generate unique hash
$data['id'] = random_hash();
} while ($this->db->where('id', $data['id'])->from('jobs')->count_all_results() > 0);
$data['created_at'] = date('Y-m-d H:i:s', now());
$this->db->insert('jobs', $data);
return $this->db->affected_rows() > 0 ? $data['id'] : false;
} }
/** /**