diff --git a/html/exhi/application/controllers/General.php b/html/exhi/application/controllers/General.php index b2d860c7fcb14a269cb9b0c015ae44fbb23cc4d7..67af59ae09aed4b64f8070af591b27f86574f6cb 100644 --- a/html/exhi/application/controllers/General.php +++ b/html/exhi/application/controllers/General.php @@ -114,7 +114,7 @@ class general extends Exhibition_Controller $tag = $_GET['tag']; $page = $_GET['page']; $limit = $_GET['limit']; - ($tag == '') ?: $tag = implode(',', $tag); + // ($tag == '') ?: $tag = implode(',', $tag); $this->load->model('general/M_general', 'pagination'); $data['pagination'] = $this->pagination->get_data_search_pagination($year, $grade, $cluster, $team, $company, $pname, $tag, $page, $limit)->result(); echo json_encode($data); @@ -235,49 +235,51 @@ class general extends Exhibition_Controller $this->load->view('general/v_search', $data); } - public function show_select($id){ - $this->load->model('project/M_project','project'); - $this->load->model('project_tag/M_project_tag','project_tag'); - $this->load->model('detail/M_detail','detail'); - $this->load->model('member/M_member','member'); - $this->load->model('cluster/M_cluster','cluster'); - $this->load->model('team/M_team','team'); - $this->load->model('instructor/M_instructor','instructor'); - $data['project'] = $this->project->get_project_by_id($id)->row(); - $select = ''; - if($data['project']->cluster_id != 0){ - $select = $this->cluster->get_cluster_by_id($data['project']->cluster_id)->row(); - }else if($data['project']->team_id != 0){ - $select = $this->team->get_team_by_id($data['project']->team_id)->row(); - }else{ - $select = $this->instructor->get_by_id($data['project']->instructor_id)->row(); - } - $data['project']->select = $select->name; - $data['project_tag'] = $this->project_tag->get_by_id($id)->result(); - $data['detail'] = $this->detail->get_detail_by_project_id($id)->result(); - $data['member'] = $this->member->get_member_frontend($id)->result(); - // echo '<pre>'; - // print_r($data); - // echo '</pre>'; - - $this->output_frontend('general/v_general_select', $data); - } + public function show_select($id) + { + $this->load->model('project/M_project', 'project'); + $this->load->model('project_tag/M_project_tag', 'project_tag'); + $this->load->model('detail/M_detail', 'detail'); + $this->load->model('member/M_member', 'member'); + $this->load->model('cluster/M_cluster', 'cluster'); + $this->load->model('team/M_team', 'team'); + $this->load->model('instructor/M_instructor', 'instructor'); + $data['project'] = $this->project->get_project_by_id($id)->row(); + $select = ''; + if ($data['project']->cluster_id != 0) { + $select = $this->cluster->get_cluster_by_id($data['project']->cluster_id)->row(); + } else if ($data['project']->team_id != 0) { + $select = $this->team->get_team_by_id($data['project']->team_id)->row(); + } else { + $select = $this->instructor->get_by_id($data['project']->instructor_id)->row(); + } + $data['project']->select = $select->name; + $data['project_tag'] = $this->project_tag->get_by_id($id)->result(); + $data['detail'] = $this->detail->get_detail_by_project_id($id)->result(); + $data['member'] = $this->member->get_member_frontend($id)->result(); + // echo '<pre>'; + // print_r($data); + // echo '</pre>'; - public function get_comment() - { - $id = $this->input->post('id'); - $this->load->model('general/M_general', 'general'); - $data['comment'] = $this->general->get_comment_all($id)->result(); - echo json_encode($data); - } + $this->output_frontend('general/v_general_select', $data); + } - public function insert_comment(){ - $sender = $this->input->post('sender'); - $detail = $this->input->post('detail'); - $id = $this->input->post('id'); - $this->load->model('general/M_general', 'general'); - $this->general->insert_comment($sender, $detail, date("Y-m-d"), $id); - $data['message'] = true; - echo json_encode($data); - } + public function get_comment() + { + $id = $this->input->post('id'); + $this->load->model('general/M_general', 'general'); + $data['comment'] = $this->general->get_comment_all($id)->result(); + echo json_encode($data); + } + + public function insert_comment() + { + $sender = $this->input->post('sender'); + $detail = $this->input->post('detail'); + $id = $this->input->post('id'); + $this->load->model('general/M_general', 'general'); + $this->general->insert_comment($sender, $detail, date("Y-m-d"), $id); + $data['message'] = true; + echo json_encode($data); + } } diff --git a/html/exhi/application/models/general/M_general.php b/html/exhi/application/models/general/M_general.php index f8f50178e69ffc2849784488286890a70fca367b..431bf5818f1b420fec752a0516d8d440f31e1e27 100644 --- a/html/exhi/application/models/general/M_general.php +++ b/html/exhi/application/models/general/M_general.php @@ -14,16 +14,12 @@ class M_general extends Da_general public function get_num_project($year) { - $sql = "SELECT count(project_id) AS cluster, team, project, all_project, by_year FROM project, - (SELECT count(project_id) AS team FROM project - WHERE status = 1 and team_id != 0 and YEAR(date) = $year) AS team, - (SELECT count(project_id) AS project FROM project - WHERE status = 1 and team_id = 0 AND cluster_id = 0 and YEAR(date) = $year) AS project, - (SELECT count(project_id) AS all_project FROM project - WHERE status = 1) AS all_project, - (SELECT count(project_id) as by_year FROM project - Where status = 1 and YEAR(date) = $year) as by_year - WHERE status = 1 and cluster_id != 0 and YEAR(date) = $year"; + $sql = "SELECT + (SELECT COUNT(project_id) FROM project WHERE status = 1) AS all_project, + (SELECT COUNT(project_id) FROM project WHERE status = 1 AND date = 2022) AS by_year, + (SELECT COUNT(project_id) FROM project WHERE status = 1 AND cluster_id != 0 AND date = 2022) AS cluster, + (SELECT COUNT(project_id) FROM project WHERE status = 1 AND team_id != 0 AND date = 2022) AS team, + (SELECT COUNT(project_id) FROM project WHERE status = 1 AND team_id = 0 AND cluster_id = 0 AND date = 2022) AS project;"; $query = $this->db->query($sql); return $query; } @@ -32,16 +28,16 @@ class M_general extends Da_general { $sql = "SELECT *,project.name_th as pj_name,cluster.name AS ct_name FROM {$this->db_name}.project JOIN cluster ON project.cluster_id = cluster.cluster_id - WHERE status = 1 AND project.cluster_id != 0 AND YEAR(date) = $year"; + WHERE status = 1 AND project.cluster_id != 0 AND date = $year"; $query = $this->db->query($sql); return $query; } public function get_project_year() { - $sql = "SELECT YEAR(date) AS year FROM {$this->db_name}.project + $sql = "SELECT date AS year FROM {$this->db_name}.project WHERE status = 1 - GROUP BY YEAR(date) + GROUP BY date ORDER BY year DESC"; $query = $this->db->query($sql); return $query; @@ -49,9 +45,9 @@ class M_general extends Da_general public function get_project_2_year() { - $sql = "SELECT YEAR(date) AS year FROM {$this->db_name}.project + $sql = "SELECT date AS year FROM {$this->db_name}.project WHERE status = 1 AND cluster_id != 0 - GROUP BY YEAR(date) + GROUP BY date ORDER BY year DESC"; $query = $this->db->query($sql); return $query; @@ -61,16 +57,16 @@ class M_general extends Da_general { $sql = "SELECT *,project.name_th as pj_name,team.name AS t_name FROM {$this->db_name}.project JOIN team ON project.team_id = team.team_id - WHERE status = 1 AND project.team_id !=0 AND YEAR(date) = $year"; + WHERE status = 1 AND project.team_id !=0 AND date = $year"; $query = $this->db->query($sql); return $query; } public function get_project_3_year() { - $sql = "SELECT YEAR(date) AS year FROM {$this->db_name}.project + $sql = "SELECT date AS year FROM {$this->db_name}.project WHERE status = 1 AND team_id != 0 - GROUP BY YEAR(date) + GROUP BY date ORDER BY year DESC"; $query = $this->db->query($sql); return $query; @@ -80,16 +76,16 @@ class M_general extends Da_general { $sql = "SELECT project_id, name_th as pj_name, image_logo, image_cover, user.student_id, user.first_name, user.last_name FROM {$this->db_name}.project join user on project.user_id = user.user_id - Where project.status = 1 AND cluster_id = 0 AND team_id = 0 AND YEAR(date) = $year"; + Where project.status = 1 AND cluster_id = 0 AND team_id = 0 AND date = $year"; $query = $this->db->query($sql); return $query; } public function get_project_4_year() { - $sql = "SELECT YEAR(date) AS year FROM {$this->db_name}.project + $sql = "SELECT date AS year FROM {$this->db_name}.project WHERE status = 1 AND cluster_id = 0 AND team_id = 0 - GROUP BY YEAR(date) + GROUP BY date ORDER BY year DESC"; $query = $this->db->query($sql); return $query; @@ -100,7 +96,7 @@ class M_general extends Da_general $offset = ($page - 1) * $limit; $sql = "SELECT project_id, name_th as pj_name, image_logo, image_cover, user.student_id, user.first_name, user.last_name FROM {$this->db_name}.project join user on project.user_id = user.user_id - Where project.status = 1 AND cluster_id = 0 AND team_id = 0 AND YEAR(date) = $year + Where project.status = 1 AND cluster_id = 0 AND team_id = 0 AND date = $year LIMIT $limit OFFSET $offset"; $query = $this->db->query($sql); return $query; @@ -108,6 +104,8 @@ class M_general extends Da_general public function get_data_search_pagination($year, $grade, $cluster, $team, $company, $pname, $tag, $page, $limit) { + $having_count = ($tag == '') ? $having_count = '' : $having_count = 'HAVING COUNT(DISTINCT project_tag.tag_id) = ' . count($tag); + ($tag == '') ?: $tag = implode(',', $tag); $tag = ($tag == '') ? $tag = 'AND (project_tag.tag_id = project_tag.tag_id OR project_tag.tag_id IS NULL)' : $tag = 'AND project_tag.tag_id IN (' . $tag . ')'; $offset = ($page - 1) * $limit; $sql = "SELECT *, project.project_id as project_id @@ -116,13 +114,15 @@ class M_general extends Da_general WHERE (project_tag.project_id IS NULL OR project_tag.project_id = project_tag.project_id) $pname - AND YEAR(date) = $year + AND date = $year AND company_id = $company AND cluster_id = $cluster AND team_id = $team $grade AND status = 1 $tag + GROUP BY project.project_id + $having_count LIMIT $limit OFFSET $offset"; $query = $this->db->query($sql); return $query; @@ -131,27 +131,31 @@ class M_general extends Da_general public function get_num_page($year) { $sql = "SELECT count(project_id) AS num_project FROM {$this->db_name}.project - Where status = 1 AND cluster_id = 0 AND team_id = 0 AND YEAR(date) = $year"; + Where status = 1 AND cluster_id = 0 AND team_id = 0 AND date = $year"; $query = $this->db->query($sql); return $query; } public function get_num_search_page($year, $grade, $cluster, $team, $company, $pname, $tag) { - $tag = ($tag == '') ? $tag = 'AND (project_tag.tag_id = project_tag.tag_id OR project_tag.tag_id IS NULL)' : $tag = 'AND project_tag.tag_id IN (' . $tag . ')'; + $having_count = ($tag == '') ? $having_count = '' : $having_count = 'HAVING COUNT(DISTINCT project_tag.tag_id) = ' . count($tag); + ($tag == '') ?: $tag = implode(',', $tag); + $tag = ($tag == '') ? $tag = 'AND (project_tag.tag_id = project_tag.tag_id)' : $tag = 'AND project_tag.tag_id IN (' . $tag . ')'; $sql = "SELECT count(project.project_id) AS num_project FROM project LEFT JOIN project_tag ON project_tag.project_id = project.project_id WHERE (project_tag.project_id IS NULL OR project_tag.project_id = project_tag.project_id) $pname - AND YEAR(date) = $year + AND date = $year AND company_id = $company AND cluster_id = $cluster AND team_id = $team $grade AND status = 1 $tag + GROUP BY project.project_id + $having_count "; $query = $this->db->query($sql); // print_r($sql); @@ -166,7 +170,7 @@ class M_general extends Da_general WHERE (project_tag.project_id IS NULL OR project_tag.project_id = project_tag.project_id) AND name = $pname - AND YEAR(date) = $year + AND date = $year AND company_id = $company AND cluster_id = $cluster AND team_id = $team @@ -178,10 +182,11 @@ class M_general extends Da_general return $query; } - public function get_comment_all($id){ - $sql = "SELECT * FROM {$this->db_name}.comment + public function get_comment_all($id) + { + $sql = "SELECT * FROM {$this->db_name}.comment Where project_id = $id"; $query = $this->db->query($sql); return $query; - } + } } diff --git a/html/exhi/application/views/general/v_search.php b/html/exhi/application/views/general/v_search.php index 94d11fb64c263a5328509fbb654476cb2953f5bd..1ee5b6f26289250dbfedd020f45c483aa8ee208d 100644 --- a/html/exhi/application/views/general/v_search.php +++ b/html/exhi/application/views/general/v_search.php @@ -151,18 +151,18 @@ function create_project(data) { let html = ''; data.forEach((row, index) => { - html += `<a href="<?php echo site_url() . '/General/show_select/' ?>` + row.project_id + `" class="col-md-2">`; + html += `<a href="<?php echo site_url() . '/General/show_select/' ?>` + row.project_id + `" target="_blank" class="col-md-2">`; html += `<div class="card card-widget widget-user">`; - html += `<div class="widget-user-header text-white" style="background: url('` + row.image_cover + `') center center;">`; + html += `<div class="widget-user-header text-white" style="background: url('<?php echo base_url() ?>` + row.image_cover + `') center center;">`; html += `</div>`; html += `<div class="widget-user-image">`; - html += `<img class="img-circle" src="` + row.image_logo + `" alt="User Avatar">`; + html += `<img class="img-circle" src="<?php echo base_url() ?>` + row.image_logo + `" alt="User Avatar">`; html += `</div>`; html += `<div class="card-body">`; html += `<h5 class="description-header"><b>` + row.name_th + `</b></h5><br>`; html += `<div class="description-block">`; - html += `<h5 class="description-header">` + row.first_name + ' ' + row.last_name + `</h5>`; - html += `<h5 class="description-header">` + row.student_id + `</h5>`; + // html += `<h5 class="description-header">` + row.first_name + ' ' + row.last_name + `</h5>`; + // html += `<h5 class="description-header">` + row.student_id + `</h5>`; html += `</div>`; html += `</div>`; html += `</div>`; diff --git a/html/exhi/image/profile_default.png b/html/exhi/image/profile_default.png new file mode 100644 index 0000000000000000000000000000000000000000..2b3617b4a0f404262f0397143e2769aa090b295b Binary files /dev/null and b/html/exhi/image/profile_default.png differ