From a3a52251435e14a95f94e6672323db04c8dc3139 Mon Sep 17 00:00:00 2001 From: Karsten Heiken Date: Thu, 28 Jul 2011 19:58:55 +0200 Subject: [PATCH] Improve creation of new projects --- application/models/project.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/application/models/project.php b/application/models/project.php index 661df09..2ed2e50 100644 --- a/application/models/project.php +++ b/application/models/project.php @@ -111,21 +111,18 @@ class Project extends CI_Model { public function create($data) { $this->load->helper(array('hash', 'date')); - $data['owner'] = $this->session->userdata('user_id'); + $data['owner'] = '215cd70f310ae6ae'; //$this->session->userdata('user_id'); $data['created'] = mysql_now(); $data['lastaccess'] = mysql_now(); - $data['id'] = random_hash(); - return $this->db->insert('projects', $data); - } + do { + $data['id'] = random_hash(); + } while ($this->db->where('id', $data['id'])->from('projects')->count_all_results() > 0); - /** - * Delete a project. - * - * There is no security check in here to verify if the user has the - * rights to do so. This needs to be done in the controller! - */ - public function delete($project_id) { - return $this->db->delete('projects', array('id' => $project_id)); + + if($this->db->insert('projects', $data)) + return $data['id']; + else + return FALSE; } } \ No newline at end of file