UCommentController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. namespace App\Http\Controllers\User;
  3. use Illuminate\Http\Request;
  4. use App\Http\Requests;
  5. use App\Http\Controllers\Controller;
  6. use App\Models\Comment;
  7. use App\Models\ActivityLog;
  8. use App\Models\Task;
  9. use Auth;
  10. use Illuminate\Support\Facades\File;
  11. class UCommentController extends Controller
  12. {
  13. public function remove_comment(Request $req){
  14. $id = $req->id;
  15. $task_id = $req->task_id;
  16. $del = Comment::find($id);
  17. if (File::exists('assets/document/task/'.$del->url) && !empty($del->url))
  18. {
  19. File::delete('assets/document/task/'.$del->url);
  20. }
  21. //activity log
  22. $task_info = Task::find($task_id);
  23. $task_name = $task_info->name;
  24. $proj_id = $task_info->proj_id;
  25. $comment = $del->comment;
  26. $msg = "$comment -removed from $task_name.";
  27. $this->task_log($msg,$task_id,$proj_id); //call function
  28. $del->delete();
  29. $str = $this->fetch_comments($task_id); // call function
  30. return $str;
  31. }
  32. public function edit_comment_form(Request $req){
  33. $id = $req->id;
  34. $fet = Comment::find($id);
  35. $data['comment'] = $fet->comment;
  36. $data['id'] = $id;
  37. return $data;
  38. }
  39. public function save_update_comment(Request $req){
  40. $comment = $req->comment;
  41. $id = $req->id;
  42. $task_id = $req->task_id;
  43. $sav = Comment::find($id);
  44. $sav->comment = $comment;
  45. //activity log
  46. $task_info = Task::find($task_id);
  47. $task_name = $task_info->name;
  48. $proj_id = $task_info->proj_id;
  49. $msg = "$comment -edited from $task_name.";
  50. $this->task_log($msg,$task_id,$proj_id); //call function
  51. $sav->save();
  52. $data = $this->fetch_comments($task_id); // call function
  53. return $data;
  54. }
  55. public function fetch_comments($task_id){
  56. $fetch = Comment::with('user')->where('task_id',$task_id)->orderBy('id','DESC')->get();
  57. $str = "";
  58. $login_user = Auth::user()->id;
  59. if(count($fetch) > 0){
  60. foreach($fetch as $fet)
  61. {
  62. $immmgg = "assets/document/task/$fet->url";
  63. $str .="<input type='hidden' value=".$fet->id.">";
  64. $str .="* $fet->comment -by ".$fet->user->name;
  65. if(!empty($fet->url)){
  66. $str .="<br/><a target='_blank' href=".url("assets/document/task/$fet->url").">
  67. <img height='150' width='120' src='".asset($immmgg)."'></a>";
  68. }
  69. $str .="<span style='color:#FD4B39;cursor:pointer;margin-left:10px' data-id='".$fet->id."' class='edit_comment pull-right'><i class='fa fa-pencil-square-o' aria-hidden='true'></i></span>
  70. <span style='color:#FD4B39;cursor:pointer;' data-id='".$fet->id."' class='remove_comment'><i class='fa fa-times pull-right' aria-hidden='true'></i></span><br/>";
  71. }
  72. }
  73. return $str;
  74. }
  75. public function add_task_doc(Request $req)
  76. {
  77. $file = $req->file('file');
  78. $task_id = $req->task_id;
  79. date_default_timezone_set("Asia/Dhaka");
  80. $assign_time = date('Y-m-d H:i:s');
  81. if ($req->hasFile('file')){
  82. $extension = $file->getClientOriginalExtension();
  83. $os = array("jpg", "jpeg", "png", "gif");
  84. if (in_array($extension, $os)){
  85. $name = $file->getClientOriginalName();
  86. $newFileName = "task_".date('d_m_y_h_m_s').".".$extension;;
  87. $fileee = $file->move('assets/document/task/', $newFileName);
  88. $sav = new Comment;
  89. $sav->comment = $name;
  90. $sav->url = $newFileName;
  91. $sav->task_id = $task_id;
  92. $sav->date_time = $assign_time;
  93. $sav->post_by = Auth::user()->id;
  94. $sav->save();
  95. }
  96. }
  97. }
  98. public function task_log($msg,$task_id,$proj_id)
  99. {
  100. date_default_timezone_set("Asia/Dhaka");
  101. $assign_time = date('Y-m-d H:i:s');
  102. $sav = new ActivityLog;
  103. $sav->msg = $msg;
  104. $sav->proj_id = $proj_id;
  105. $sav->task_id = $task_id;
  106. $sav->logged_user_id = Auth::user()->id;
  107. $sav->created_at = $assign_time;
  108. $sav->save();
  109. }
  110. }