first commit
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Feed extends Admin_Controller {
|
||||
|
||||
public function index() {
|
||||
$this->load->helper('url');
|
||||
$data = array();
|
||||
|
||||
$this->load->library('table');
|
||||
$this->table->set_template($this->template);
|
||||
|
||||
}
|
||||
|
||||
public function onboardingsurvey() {
|
||||
$this->load->library('table');
|
||||
//$this->table->set_template($this->survey_template);
|
||||
$this->load->model('onboarding_survey_model');
|
||||
|
||||
$cardCats = $this->db->get('card_category');
|
||||
|
||||
$data['page_title'] = 'Onboarding Survey';
|
||||
$data['surveys'] = $this->onboarding_survey_model->getOnboardingSurvey();
|
||||
$data['card_cats'] = $cardCats->result_array();
|
||||
|
||||
$this->renderFeedPage('view_onboardfeed', $data);
|
||||
}
|
||||
|
||||
private function setFormRuleForSurvey() {
|
||||
$this->form_validation->set_rules('groupKey', 'Group key', 'max_length[10]');
|
||||
$this->form_validation->set_rules('answersKey', 'Answers key', 'max_length[25]');
|
||||
$this->form_validation->set_rules('answers', 'Answers', 'max_length[100]');
|
||||
}
|
||||
|
||||
public function getOnboardingSurvey() {
|
||||
$postData = $this->input->post();
|
||||
|
||||
$postData = array_filter($postData, function($ele) {
|
||||
return $ele !== "" && $ele !== null;
|
||||
});
|
||||
|
||||
$pageNo = !empty($postData['pageNo']) ? $postData['pageNo'] - 1 : 0;
|
||||
|
||||
$this->load->library('form_validation');
|
||||
$this->form_validation->set_data($postData);
|
||||
$this->setFormRuleForSurvey();
|
||||
|
||||
if ($this->form_validation->run() === FALSE) {
|
||||
$errors = $this->form_validation->error_array();
|
||||
header('HTTP/1.1 400 Bad Request');
|
||||
echo json_encode(['errors' => $errors]);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->load->model('onboarding_survey_model');
|
||||
|
||||
$result = $this->onboarding_survey_model->getOnboardingSurvey($postData, $pageNo);
|
||||
|
||||
echo json_encode(['data' => $result]);
|
||||
}
|
||||
|
||||
public function getAvailableAndAssignedSurveyCards() {
|
||||
$postData = $this->input->post();
|
||||
|
||||
$this->load->model('onboarding_survey_model');
|
||||
$result = $this->onboarding_survey_model->getAvailableAndAssignedSurveyCards($postData);
|
||||
|
||||
echo json_encode(['result' => $result]);
|
||||
}
|
||||
|
||||
public function assignSurveyCard() {
|
||||
$postData = $this->input->post();
|
||||
|
||||
$this->load->model('onboarding_survey_model');
|
||||
$this->onboarding_survey_model->assignSurveyCard($postData);
|
||||
|
||||
echo json_encode(['message' => 'Assigned!']);
|
||||
}
|
||||
|
||||
public function unassignSurveyCard() {
|
||||
$postData = $this->input->post();
|
||||
|
||||
$this->load->model('onboarding_survey_model');
|
||||
$this->onboarding_survey_model->unassignSurveyCard($postData);
|
||||
|
||||
echo json_encode(['message' => 'Unassigned!']);
|
||||
}
|
||||
|
||||
public function updateSurveyAnswers() {
|
||||
$postData = $this->input->post();
|
||||
|
||||
$this->load->library('form_validation');
|
||||
$this->form_validation->set_data($postData);
|
||||
$this->setFormRuleForSurvey();
|
||||
|
||||
if ($this->form_validation->run() === FALSE) {
|
||||
$errors = $this->form_validation->error_array();
|
||||
header('HTTP/1.1 400 Bad Request');
|
||||
echo json_encode(['errors' => $errors]);
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $postData['id'];
|
||||
$surveyData = [
|
||||
'answers' => $postData['answers']
|
||||
];
|
||||
|
||||
$this->load->model('onboarding_survey_model');
|
||||
$this->onboarding_survey_model->updateSurvey($id, $surveyData);
|
||||
|
||||
echo json_encode(['message' => 'Updated answers successfully!']);
|
||||
}
|
||||
|
||||
protected function renderFeedPage($page_name, $data) {
|
||||
$this->load->view('admin/view_admin_header', $data);
|
||||
$this->load->view('feed/' . $page_name, $data);
|
||||
$this->load->view('admin/view_admin_footer', $data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user