Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if($this->session->userdata('user_id')): ?>
- <hr>
- <?php echo form_open('/attendees/add/'.$event['id']); ?>
- <input type="hidden" name="user_id" value="<?php echo $_SESSION['user_id']; ?>">
- <input type="submit" value="I'm in!" class="btn btn-success">
- </form>
- <?php endif; ?>
- <?php
- class Attendees extends CI_Controller {
- public function add($event_id) {
- // Check login
- if(!$this->session->userdata('logged_in')){
- redirect('users/login');
- }
- $this->form_validation->set_rules('user_id', 'required|callback_check_userid_eventid');
- if($this->form_validation->run() === FALSE){
- $this->session->set_flashdata('attendee_not_added', 'You are already on the list.');
- redirect('home');
- } else {
- $this->attendee_model->add_attendee($event_id);
- // Set message
- $this->session->set_flashdata('attendee_added', 'You have been added to this event.');
- redirect('events');
- }
- }
- }
- <?php
- class Attendee_model extends CI_Model {
- public function __contruct() {
- }
- public function get_attendees($id = FALSE){
- if($id === FALSE) {
- $query = $this->db->get('attendees');
- return $query->result_array();
- }
- $this->db->select('attendees.id, attendees.team, attendees.is_goalie, event.id, user.first_name, user.last_name');
- $this->db->from('attendees');
- $this->db->join('event', 'attendees.event_id = event.id', 'inner');
- $this->db->join('user', 'attendees.user_id = user.id', 'inner');
- $this->db->where('event.id', $id);
- $query = $this->db->get();
- return $query->row_array();
- }
- public function add_attendee($event_id){
- $data = array(
- 'event_id' => $event_id,
- 'user_id' => $this->session->userdata('user_id')
- );
- return $this->db->insert('attendees', $data);
- }
- // Check attendee exists in event
- public function check_userid_eventid($event_id, $user_id){
- $query = $this->db->get_where('attendees', array('user_id' => $user_id, 'event_id' => $event_id));
- if(empty($query->row_array())){
- return true;
- } else {
- return false;
- }
- }
- }
Add Comment
Please, Sign In to add comment