/** Shows the page for a single participant */
 public function get($participant_id)
 {
     $participant = $this->participantModel->get_participant_by_id($participant_id);
     $comments = $this->commentModel->get_comments_by_participant($participant_id);
     $impediments = $this->impedimentModel->get_impediments_by_participant($participant_id);
     $participations = $this->participationModel->get_participations_by_participant($participant_id, TRUE);
     $data['participant'] = $participant;
     $data['last_called'] = $this->participantModel->last_called($participant_id);
     $data['last_experiment'] = $this->participantModel->last_experiment($participant_id);
     $data['comment_size'] = count($comments);
     $data['impediment_size'] = count($impediments);
     $data['participation_size'] = count($participations);
     $data['page_title'] = sprintf(lang('data_for_pp'), name($participant));
     $data['verify_languages'] = language_check($participant);
     $data['verify_dyslexia'] = dyslexia_check($participant);
     $this->load->view('templates/header', $data);
     $this->load->view('participant_view', $data);
     $this->load->view('templates/footer');
 }
 /**
  *
  * Shows the page for calling a participant
  * @param integer $participant_id
  * @param integer $experiment_id
  * @param integer $weeks_ahead
  */
 public function call($participant_id, $experiment_id, $weeks_ahead = WEEKS_AHEAD)
 {
     // Retrieve entities
     $participant = $this->participantModel->get_participant_by_id($participant_id);
     $experiment = $this->experimentModel->get_experiment_by_id($experiment_id);
     // Check current user is caller for experiment
     if (!$this->callerModel->is_caller_for_experiment(current_user_id(), $experiment_id)) {
         $data['error'] = sprintf(lang('not_caller'), $experiment->name);
         $this->load->view('templates/error', $data);
         return;
     }
     // Check current participant is callable for experiment
     if (!in_array($participant, $this->participantModel->find_participants($experiment, $weeks_ahead))) {
         $data['error'] = sprintf(lang('not_callable_for'), name($participant), $experiment->name);
         $this->load->view('templates/error', $data);
         return;
     }
     // Check current participant is not being called
     if ($this->participationModel->is_locked_participant($participant_id, $experiment_id)) {
         $data['error'] = sprintf(lang('in_conversation'), name($participant));
         $this->load->view('templates/error', $data);
         return;
     }
     // Retrieve links
     $comments = $this->commentModel->get_comments_by_participant($participant_id);
     $impediments = $this->impedimentModel->get_impediments_by_participant($participant_id);
     $experiments = $this->experimentModel->get_experiments_by_participant($participant_id);
     $participations = $this->participationModel->get_participations_by_experiment($experiment_id);
     $leaders = $this->leaderModel->get_leader_users_by_experiments($experiment_id);
     $first_visit = count($this->participationModel->get_participations_by_participant($participant_id, TRUE)) == 0;
     // Retrieve or create participation record
     $participation = $this->participationModel->get_participation($experiment_id, $participant_id);
     if ($participation) {
         $participation_id = $participation->id;
     } else {
         $participation_id = $this->participationModel->create_participation($experiment, $participant);
         $participation = $this->participationModel->get_participation_by_id($participation_id);
     }
     // Find the previous call (if is exists)
     $previous_call = $this->callModel->last_call($participation_id);
     // Lock the participation record
     $this->participationModel->lock($participation_id);
     // Create call record
     $call_id = $this->callModel->create_call($participation_id);
     // Find possible combined experiment, first check combinations
     $combinations = $this->relationModel->get_relation_ids_by_experiment($experiment->id, RelationType::Combination);
     $comb_exp = $combinations ? $this->experimentModel->get_experiment_by_id($combinations[0]) : FALSE;
     if (!$comb_exp) {
         // Then check prerequisites
         $prereqs = $this->relationModel->get_relation_ids_by_experiment($experiment->id, RelationType::Prerequisite);
         $comb_exp = $prereqs ? $this->experimentModel->get_experiment_by_id($prereqs[0]) : FALSE;
     }
     // Check if participation to combined experiment already exists
     $comb_part = $comb_exp ? $this->participationModel->get_participation($comb_exp->id, $participant_id) : FALSE;
     if ($comb_part) {
         $comb_exp = FALSE;
     }
     $comb_leaders = $comb_exp ? $this->leaderModel->get_leader_users_by_experiments($comb_exp->id) : array();
     // Create page data
     $data = get_min_max_days($participant, $experiment);
     $data['participant'] = $participant;
     $data['experiment'] = $experiment;
     $data['participation'] = $participation;
     $data['participation_id'] = $participation_id;
     $data['leaders'] = leader_options($leaders);
     $data['call_id'] = $call_id;
     $data['previous_call'] = $previous_call;
     $data['comment_size'] = count($comments);
     $data['impediment_table'] = create_impediment_table($impediments);
     $data['impediment_size'] = count($impediments);
     $data['last_experiment'] = $this->participantModel->last_experiment($participant_id);
     $data['last_called'] = $this->participantModel->last_called($participant_id);
     $data['nr_participations'] = count($participations);
     $data['verify_languages'] = language_check($participant);
     $data['verify_dyslexia'] = dyslexia_check($participant);
     $data['first_visit'] = $first_visit;
     $data['combination_exp'] = $comb_exp;
     $data['combination_leaders'] = leader_options($comb_leaders);
     $data['page_title'] = sprintf(lang('call_participant'), name($participant));
     $this->load->view('templates/header', $data);
     $this->load->view('participation_call', $data);
     $this->load->view('templates/footer');
 }