/** * The POST call to add a version to a package * Redirect to the package page on success */ public function add() { $submit = $this->input->post('submit'); if ($submit) { $this->load->library('form_validation'); $this->load->model('version'); $this->load->model('spark'); $insert = elements(array('spark_id', 'tag'), $_POST); if ($this->form_validation->run('add-version')) { if (Version::insert($insert)) { UserHelper::setNotice("Version added!"); } } else { UserHelper::setNotice("Try to enter a valid tag!", FALSE); } $spark = Spark::getById($insert['spark_id']); redirect(base_url() . 'packages/' . $spark->name . '/show'); } show_error("Whatcha doin' here?"); }
/** * A CI validation callback to make sure the package being edited is owned by the * logged-in user * @param int $spark_id The id of the spark * @return bool True if the logged in user is the owner, false if not */ public function is_owner($spark_id) { $this->load->model('spark'); if (Spark::getById($spark_id)->contributor_id == UserHelper::getId()) { return true; } $this->form_validation->set_message('is_owner', "Sorry, you don't own that spark. That also means you're an ass."); return FALSE; }