From 0bfad8004d071adf359c51ef6cf2bf54aebaa5a5 Mon Sep 17 00:00:00 2001 From: Karsten Heiken Date: Sun, 8 May 2011 20:00:27 +0200 Subject: [PATCH] Add create() and delete() to project model --- application/models/project.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/application/models/project.php b/application/models/project.php index 8cac9f4..9e1fa15 100644 --- a/application/models/project.php +++ b/application/models/project.php @@ -139,4 +139,30 @@ class Project extends CI_Model { return array_merge($own_results, $shared_results); } + + /** + * Create a new project. + * + * @param array $data array with "name" and "description" + */ + public function create($data) { + $this->load->helper(array('hash', 'date')); + + $data['owner'] = $this->session->userdata('user_id'); + $data['created'] = mysql_now(); + $data['lastaccess'] = mysql_now(); + $data['id'] = random_hash(); + + return $this->db->insert('projects', $data); + } + + /** + * 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)); + } } \ No newline at end of file