Commit 033d243d by Phạm Văn Đoan

review code liên quan đến bài hát

parent 0403ee6f
...@@ -97,7 +97,6 @@ class CmsTrack extends CI_Controller ...@@ -97,7 +97,6 @@ class CmsTrack extends CI_Controller
$this->_data['loadPage'] = 'backend/cms_track/edit_track_view'; $this->_data['loadPage'] = 'backend/cms_track/edit_track_view';
$this->load->view('backend/admin_template_view', $this->_data); $this->load->view('backend/admin_template_view', $this->_data);
} else { } else {
$title = $this->input->post('title'); $title = $this->input->post('title');
$update_singer = $this->input->post('update_singer'); $update_singer = $this->input->post('update_singer');
$singer = ($track_user != '') ? $track_user[0]['user_id']: ''; $singer = ($track_user != '') ? $track_user[0]['user_id']: '';
...@@ -132,13 +131,15 @@ class CmsTrack extends CI_Controller ...@@ -132,13 +131,15 @@ class CmsTrack extends CI_Controller
$art = $track[0]['art']; $art = $track[0]['art'];
$this->track_model->update($track_id, $title, $art); $this->track_model->update($track_id, $title, $art);
} }
// MyHelper::echoPreDie($config);
$this->track_model->update_track_artists($track_id, $id_artists, $id_artist, $active_artist); $this->track_model->update_track_artists($track_id, $id_artists, $id_artist, $active_artist);
$this->track_model->update_track_user($track_id, $id_singer, $id_user, $active_singer); $this->track_model->update_track_user($track_id, $id_singer, $id_user, $active_singer);
// Ghi log
$this->actionlog_model->add('UPDATED', 'Cập nhật bài hát.', 'Actionlog_model', 'action_log', $track_id);
$this->session->set_flashdata('success', 'Cập nhật bài hát thành công'); $this->session->set_flashdata('success', 'Cập nhật bài hát thành công');
redirect(base_url().'backend/cmsTrack/showTrack/'.$track_id); redirect(base_url('backend/cmsTrack/showTrack/'.$track_id));
} }
} }
...@@ -248,7 +249,11 @@ class CmsTrack extends CI_Controller ...@@ -248,7 +249,11 @@ class CmsTrack extends CI_Controller
}else{ }else{
$this->session->set_flashdata('error', 'Tạo Bài hát không thành công'); $this->session->set_flashdata('error', 'Tạo Bài hát không thành công');
} }
redirect(base_url().'backend/cmsTrack/listTrack');
// Ghi log
$this->actionlog_model->add('ADDED', 'Thêm mới bài hát.', 'Actionlog_model', 'action_log', null);
redirect(base_url('backend/cmsTrack/listTrack'));
} }
} }
...@@ -259,6 +264,9 @@ class CmsTrack extends CI_Controller ...@@ -259,6 +264,9 @@ class CmsTrack extends CI_Controller
*/ */
public function addSinger($track_id) public function addSinger($track_id)
{ {
// Thêm đoạn check sự tồn tại của bài hát
//
$this->_data['track'] = $contest = $this->track_model->getById($track_id); $this->_data['track'] = $contest = $this->track_model->getById($track_id);
$this->_data['list_user'] = $list_user = $this->track_model->getListUsers(); $this->_data['list_user'] = $list_user = $this->track_model->getListUsers();
...@@ -281,14 +289,75 @@ class CmsTrack extends CI_Controller ...@@ -281,14 +289,75 @@ class CmsTrack extends CI_Controller
$this->load->view('backend/admin_template_view', $this->_data); $this->load->view('backend/admin_template_view', $this->_data);
} else { } else {
$singer = $this->input->post('singer'); $singer = $this->input->post('singer');
$this->track_model->add_singer($singer,$track_id); $this->track_model->add_singer($singer,$track_id);
$this->session->set_flashdata('success', 'Thêm ca sĩ vào bài hát thành công'); $this->session->set_flashdata('success', 'Thêm ca sĩ vào bài hát thành công');
redirect(base_url().'backend/cmsTrack/showTrack/'.$track_id); // Ghi log
$this->actionlog_model->add('ADDED', 'Thêm mới Ca sĩ cho bài hát.', 'Actionlog_model', 'action_log', $track_id);
redirect(base_url('backend/cmsTrack/showTrack/'.$track_id));
}
}
/**
* Xử lý xóa ca sĩ khỏi bài hát
*
* @param $track_id
* @param $singer_id
*/
public function removeSinger($track_id, $singer_id)
{
// Thêm đoạn check tồn tại bài hát và ca sĩ, ok thì mới gọi xóa
// Xử lý
$this->track_model->removeSinger($track_id, $singer_id);
// Ghi log
$this->actionlog_model->add('DELETED', 'Xóa Ca sĩ khỏi bài hát.', 'Actionlog_model', 'action_log', $track_id);
redirect(base_url('backend/cmsTrack/showTrack/'.$track_id));
}
/**
* Hàm xử lý thêm Nhạc sĩ cho bài hát
*
* @param $track_id
*/
public function addComposer($track_id)
{
// Thêm đoạn check sự tồn tại của bài hát
// Xử lý
$this->_data['track'] = $contest = $this->track_model->getById($track_id);
$this->_data['list_user'] = $list_user = $this->track_model->getListUsers();
$this->form_validation->set_rules(
'composer',
'Nhạc sĩ',
'trim|required|callback_check_default|xss_clean'
);
$this->form_validation->set_message('required', '<li class="list-unstyled">Bắt buộc nhập, chọn.</li>');
$this->form_validation->set_message('is_unique', '<li class="list-unstyled">Đã tồn tại.</li>');
// Xử lý form
if($this->form_validation->run($this) == false) {
$this->_data['composer'] = $this->input->post('composer');
$this->_data['functionName'] = 'Thêm Người thể hiện vào bài hát';
$this->_data['action'] = 'addComposer';
$this->_data['titlePage'] = 'Thêm Người thể hiện vào bài hát';
$this->_data['loadPage'] = 'backend/cms_track/add_composer_view';
$this->load->view('backend/admin_template_view', $this->_data);
} else {
$composer = $this->input->post('composer');
$this->track_model->add_artist($composer, $track_id);
$this->session->set_flashdata('success', 'Thêm Nhạc sĩ vào bài hát thành công');
// Ghi log
$this->actionlog_model->add('ADDED', 'Thêm Nhạc sĩ cho bài hát.', 'Actionlog_model', 'action_log', $track_id);
redirect(base_url('backend/cmsTrack/showTrack/'.$track_id));
} }
} }
/** /**
...@@ -298,7 +367,11 @@ class CmsTrack extends CI_Controller ...@@ -298,7 +367,11 @@ class CmsTrack extends CI_Controller
*/ */
public function showTrack($track_id) public function showTrack($track_id)
{ {
// Thêm đoạn check sự tồn tại của bài hát
//
$this->_data['track']= $this->track_model->getById($track_id); $this->_data['track']= $this->track_model->getById($track_id);
$this->_data['singers']= $this->track_model->getSingerLítByTrackId($track_id);
// //
$this->_data['functionName'] = 'Thông tin Bài Hát'; $this->_data['functionName'] = 'Thông tin Bài Hát';
$this->_data['action'] = 'showTrack'; $this->_data['action'] = 'showTrack';
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
class Track_model extends CI_Model class Track_model extends CI_Model
{ {
protected $_table = 'tracks'; protected $_table = 'tracks';
protected $track_user = 'track_user'; protected $_table_track_user = 'track_user';
protected $track_artists = 'track_artists'; protected $_table_track_artists = 'track_artists';
public function __construct() public function __construct()
{ {
...@@ -19,30 +19,42 @@ class Track_model extends CI_Model ...@@ -19,30 +19,42 @@ class Track_model extends CI_Model
return $insert_id; return $insert_id;
} }
/**
* Xử lý thông tin ca sĩ
*
* @param $user_id
* @param $track_id
*/
public function add_singer($user_id, $track_id) public function add_singer($user_id, $track_id)
{ {
$this->db->select('full_name'); $this->db->select('full_name');
$this->db->where('id', $user_id); $this->db->where('id', $user_id);
$query = $this->db->get('users')->result_array(); $query = $this->db->get('users')->result_array();
$this->db->set('user_id', $user_id);
if ($query) { if ($query) {
$this->db->set('name', $query[0]['full_name']); $this->db->set('name', $query[0]['full_name']);
} }
$this->db->set('user_id', $user_id);
$this->db->set('track_id', $track_id); $this->db->set('track_id', $track_id);
$this->db->insert($this->track_user); $this->db->insert($this->_table_track_user);
} }
/**
* Xử lý thông tin nhạc sĩ
*
* @param $user_id
* @param $track_id
*/
public function add_artist($user_id, $track_id) public function add_artist($user_id, $track_id)
{ {
$this->db->select('full_name'); $this->db->select('full_name');
$this->db->where('id', $user_id); $this->db->where('id', $user_id);
$query = $this->db->get('users')->result_array(); $query = $this->db->get('users')->result_array();
$this->db->set('user_id', $user_id);
if ($query) { if ($query) {
$this->db->set('name', $query[0]['full_name']); $this->db->set('name', $query[0]['full_name']);
} }
$this->db->set('user_id', $user_id);
$this->db->set('track_id', $track_id); $this->db->set('track_id', $track_id);
$this->db->insert($this->track_artists); $this->db->insert($this->_table_track_artists);
} }
public function update($id, $dataUpdate, $art_path) public function update($id, $dataUpdate, $art_path)
...@@ -65,11 +77,11 @@ class Track_model extends CI_Model ...@@ -65,11 +77,11 @@ class Track_model extends CI_Model
} }
if ($active == 'insert') { if ($active == 'insert') {
$this->db->set('track_id', $id_track); $this->db->set('track_id', $id_track);
$this->db->insert($this->track_artists); $this->db->insert($this->_table_track_artists);
} else { } else {
$this->db->where('track_id', $id_track); $this->db->where('track_id', $id_track);
$this->db->where('id', $id); $this->db->where('id', $id);
$this->db->update($this->track_artists); $this->db->update($this->_table_track_artists);
} }
} }
...@@ -84,11 +96,11 @@ class Track_model extends CI_Model ...@@ -84,11 +96,11 @@ class Track_model extends CI_Model
} }
if ($active == 'insert') { if ($active == 'insert') {
$this->db->set('track_id', $id_track); $this->db->set('track_id', $id_track);
$this->db->insert($this->track_user); $this->db->insert($this->_table_track_user);
} else { } else {
$this->db->where('track_id', $id_track); $this->db->where('track_id', $id_track);
$this->db->where('id', $id); $this->db->where('id', $id);
$this->db->update($this->track_user); $this->db->update($this->_table_track_user);
} }
} }
...@@ -99,12 +111,44 @@ class Track_model extends CI_Model ...@@ -99,12 +111,44 @@ class Track_model extends CI_Model
track_artists.name AS artist, track_artists.name AS artist,
track_artists.id AS id_track_artist'); track_artists.id AS id_track_artist');
$this->db->from($this->_table); $this->db->from($this->_table);
$this->db->join($this->track_user, 'track_user.track_id = tracks.id', 'left'); $this->db->join($this->_table_track_user, 'track_user.track_id = tracks.id', 'left');
$this->db->join($this->track_artists, 'track_artists.track_id = tracks.id', 'left'); $this->db->join($this->_table_track_artists, 'track_artists.track_id = tracks.id', 'left');
$this->db->where($this->_table . '.id', $id); $this->db->where($this->_table . '.id', $id);
$query = $this->db->get(); $query = $this->db->get();
return $query->result_array(); return $query->result_array();
} }
/**
* Lấy ds ca sĩ theo ID của bài hát từ bảng track_user
*
* @param $id
* @return mixed
*/
public function getSingerLítByTrackId($id)
{
$this->db->select('track_user.name AS name_singer, track_user.user_id AS id_singer');
$this->db->from($this->_table_track_user);
$this->db->join('tracks', 'tracks.id = track_user.track_id', 'left');
$this->db->where($this->_table_track_user . '.track_id', $id);
$query = $this->db->get();
return $query->result_array();
}
/**
* Hàm xóa ca sĩ khỏi bài hát
*
* @param $track_id
* @param $singer_id
* @return boolean
*/
public function removeSinger($track_id, $singer_id)
{
$this->db->where('track_id', $track_id);
$this->db->where('user_id', $singer_id);
$this->db->delete($this->_table_track_user);
return true;
}
public function getByIdUser($table, $id) { public function getByIdUser($table, $id) {
if ($id != 0) { if ($id != 0) {
...@@ -183,8 +227,8 @@ class Track_model extends CI_Model ...@@ -183,8 +227,8 @@ class Track_model extends CI_Model
track_user.name AS singer_name2, track_user.id AS id_user, track_user.name AS singer_name2, track_user.id AS id_user,
track_artists.name AS composer_name2, track_artists.id AS id_artist'); track_artists.name AS composer_name2, track_artists.id AS id_artist');
$this->db->from($this->_table); $this->db->from($this->_table);
$this->db->join($this->track_user, 'track_user.track_id = tracks.id', 'left'); $this->db->join($this->_table_track_user, 'track_user.track_id = tracks.id', 'left');
$this->db->join($this->track_artists, 'track_artists.track_id = tracks.id', 'left'); $this->db->join($this->_table_track_artists, 'track_artists.track_id = tracks.id', 'left');
$this->db->join('users u1', 'u1.id = track_user.user_id', 'left'); $this->db->join('users u1', 'u1.id = track_user.user_id', 'left');
$this->db->join('users u2', 'u2.id = track_artists.user_id', 'left'); $this->db->join('users u2', 'u2.id = track_artists.user_id', 'left');
if ($name != null) { if ($name != null) {
...@@ -347,7 +391,7 @@ class Track_model extends CI_Model ...@@ -347,7 +391,7 @@ class Track_model extends CI_Model
//if ($query) $users = $query->result_array(); //if ($query) $users = $query->result_array();
//return $users; //return $users;
$this->db->from($this->track_user); $this->db->from($this->_table_track_user);
$this->db->where('track_id =', $track_id); $this->db->where('track_id =', $track_id);
$query = $this->db->get(); $query = $this->db->get();
...@@ -359,7 +403,7 @@ class Track_model extends CI_Model ...@@ -359,7 +403,7 @@ class Track_model extends CI_Model
//if ($query) $users = $query->result_array(); //if ($query) $users = $query->result_array();
//return $users; //return $users;
$this->db->from($this->track_artists); $this->db->from($this->_table_track_artists);
$this->db->where('track_id =', $track_id); $this->db->where('track_id =', $track_id);
$query = $this->db->get(); $query = $this->db->get();
......
<div class="row">
<div class="widget-box">
<div class="widget-header">
<p class="widget-title">Cập nhật thông tin Nhạc sĩ</p>
</div>
<div class="widget-body">
<div class="widget-main">
<?php
$attributes = array('class' => 'form-horizontal', 'id' => 'myform');
echo form_open_multipart(base_url('backend/cmsTrack/addComposer/'.$track[0]['id']), $attributes);
?>
<div class="form-group">
<label class="col-lg-3"></label>
<div class="col-lg-3">
<input type="hidden" name="id" value="<?php echo $track[0]['id']; ?>" />
<?php
if(validation_errors()){echo form_error('id', '<div class="error">', '</div>');}
?>
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Tên bài hát (*)</label>
<div class="col-lg-3">
<p><?php echo $track[0]['title']; ?></p>
</div>
</div>
<div class="form-group">
<label class="col-lg-3">Chọn Nhạc sĩ</label>
<div class="col-lg-3">
<select id='form-field-select-3' name="composer" style='width: 200px;'
class="chosen-select form-control" data-placeholder="Choose a State...">
<option value="0">- Chọn -</option>
<?php foreach ($list_user as $composers): ?>
<option value="<?php echo $composers['id']; ?>"
<?php if($composer && $composer == $composers['id']){ echo 'selected="selected"'; } else echo ''; ?>>
<?php echo $composers['full_name']; ?>
</option>
<?php endforeach; ?>
</select>
<?php if(validation_errors()){echo form_error('composer', '<div class="error">', '</div>');} ?>
</div>
</div>
<div class="form-group">
<div class="col-lg-3">
<a href="<?php echo base_url('backend/cmsTrack/showTrack/'.$track[0]['id']);?>"
onclick="return confirm('Bạn có chắc chắn muốn quay lại trang chi tiết không?')">
<button type="button" class="btn btn-sm btn-default">
<i class="ace-icon fa fa-arrow-left"></i>Quay lại
</button>
</a>
</div>
<div class="col-lg-4">
<button class="btn btn-sm btn-primary" type="submit" name="btnSave">
<i class="ace-icon fa fa-check bigger-110"></i>Lưu lại
</button>
</div>
</div>
<?php echo form_close(); ?>
</div>
</div>
</div>
</div><!-- /.row -->
<script>
$(document).ready(function () {
$('.chosen-select').chosen({
allow_single_deselect: true,
no_results_text: "Không có kết quả cần tìm"
});
});
</script>
...@@ -39,9 +39,6 @@ ...@@ -39,9 +39,6 @@
</select> </select>
<?php if(validation_errors()){echo form_error('singer', '<div class="error">', '</div>');} ?> <?php if(validation_errors()){echo form_error('singer', '<div class="error">', '</div>');} ?>
</div> </div>
<div id="add_composer" style="display: none;">
<a href="#myModal" role="button" class="btn btn-success" data-toggle="modal">Thêm nghệ sĩ</a>
</div>
</div> </div>
<div class="form-group"> <div class="form-group">
...@@ -57,9 +54,6 @@ ...@@ -57,9 +54,6 @@
<button class="btn btn-sm btn-primary" type="submit" name="btnSave"> <button class="btn btn-sm btn-primary" type="submit" name="btnSave">
<i class="ace-icon fa fa-check bigger-110"></i>Lưu lại <i class="ace-icon fa fa-check bigger-110"></i>Lưu lại
</button> </button>
<button class="btn btn-sm" type="reset">
<i class="ace-icon fa fa-undo bigger-110"></i>Xóa form
</button>
</div> </div>
</div> </div>
<?php echo form_close(); ?> <?php echo form_close(); ?>
...@@ -67,3 +61,11 @@ ...@@ -67,3 +61,11 @@
</div> </div>
</div> </div>
</div><!-- /.row --> </div><!-- /.row -->
<script>
$(document).ready(function () {
$('.chosen-select').chosen({
allow_single_deselect: true,
no_results_text: "Không có kết quả cần tìm"
});
});
</script>
...@@ -24,10 +24,10 @@ ...@@ -24,10 +24,10 @@
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">
<a class="btn btn-sm btn-success" href="<?php echo base_url('backend/cmsTrack/addSinger/'.$track[0]['id']);?>"> <a class="btn btn-sm btn-success" href="<?php echo base_url('backend/cmsTrack/addSinger/'.$track[0]['id']);?>">
<i class="glyphicon-plus"></i> Thêm Ca sĩ <i class="glyphicon-plus"></i> Cập nhật Ca sĩ
</a> </a>
<a class="btn btn-sm btn-primary" href="<?php echo base_url('backend/cmsTrack/addComposer/'.$track[0]['id']);?>"> <a class="btn btn-sm btn-primary" href="<?php echo base_url('backend/cmsTrack/addComposer/'.$track[0]['id']);?>">
<i class="glyphicon-plus"></i> Thêm Nhạc sĩ / Sáng tác <i class="glyphicon-plus"></i> Cập nhật Nhạc sĩ
</a> </a>
</div> </div>
</div> </div>
...@@ -68,24 +68,24 @@ ...@@ -68,24 +68,24 @@
<div class="profile-info-row"> <div class="profile-info-row">
<div class="profile-info-name">Số người biểu diễn</div> <div class="profile-info-name">Số người biểu diễn</div>
<div class="profile-info-value"> <div class="profile-info-value">
<span><?php echo count($track); ?></span> <span><?php echo count($singers); ?></span>
</div> </div>
</div> </div>
<div class="profile-info-row"> <div class="profile-info-row">
<div class="profile-info-name">Biểu diễn</div> <div class="profile-info-name">Biểu diễn</div>
<div class="profile-info-value"> <div class="profile-info-value">
<?php if(count($track) > 0) : foreach ($track as $key => $tracks) : ?> <?php if(count($singers) > 0) : ?>
<div <?php foreach ($singers as $key => $singer) : ?>
style="<?php if(count($track) >1 ) : echo 'width: 50%; float:left; text-align: left;'; endif; if(count($track) -1 > $key) : echo 'border-right: solid #dddddd 2px;'; endif; ?>"> <div style="<?php if(count($track) >1 ) : echo 'width: 50%; float:left; text-align: left;'; endif; if(count($track) -1 > $key) : echo 'border-right: solid #dddddd 2px;'; endif; ?>">
<?php echo $tracks['name_singer']; ?> <?php echo $singer['name_singer']; ?>
<a href="<?php echo base_url('backend/cmsTrack/editTrack/'.$track[0]['id'].'/'.$tracks['id_singer'].'/'.$tracks['id_track_artist']); ?>" <a href="<?php echo base_url('backend/cmsTrack/removeSinger/'.$track[0]['id'].'/'.$singer['id_singer']); ?>"
title="Click để thay đổi ca sĩ"> title="Click để xóa Ca sĩ">
<i class="ace-icon fa fa-pencil-square-o bigger-150" style="color: red;"></i> <i class="ace-icon fa fa-trash bigger-150" style="color: red;"></i>
</a> </a>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
<?php else: echo '<span class="text-danger">Chưa có</span>'; ?> <?php else: echo '<span class="text-danger">Chưa có, cập nhật </span> <a href="' . base_url('backend/cmsTrack/addSinger/'.$track[0]['id']) .'">tại đây.</a>'; ?>
<?php endif ?> <?php endif ?>
</div> </div>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment