From faac255555ccf58cb1ca10768778e16f2bfd61ba Mon Sep 17 00:00:00 2001 From: Eike Foken Date: Tue, 30 Aug 2011 20:46:41 +0200 Subject: [PATCH] Extend create function for jobs --- application/models/job.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/application/models/job.php b/application/models/job.php index 44e1160..f2bcd91 100644 --- a/application/models/job.php +++ b/application/models/job.php @@ -34,7 +34,18 @@ class Job extends CI_Model { * @return bool was the insert successful */ 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; } /**