CommentController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  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 CommentController 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. 1=Created;
  33. 2=in process;
  34. 3=Completed;
  35. 4=checking;
  36. 5=bugfixing;
  37. 5=done;
  38. */
  39. }
  40. public function edit_comment_form(Request $req){
  41. $id = $req->id;
  42. $fet = Comment::find($id);
  43. $data['comment'] = $fet->comment;
  44. $data['id'] = $id;
  45. return $data;
  46. }
  47. public function save_update_comment(Request $req){
  48. $comment = $req->comment;
  49. $id = $req->id;
  50. $task_id = $req->task_id;
  51. $sav = Comment::find($id);
  52. $sav->comment = $comment;
  53. //activity log
  54. $task_info = Task::find($task_id);
  55. $task_name = $task_info->name;
  56. $proj_id = $task_info->proj_id;
  57. $msg = "$comment -edited from $task_name.";
  58. $this->task_log($msg,$task_id,$proj_id); //call function
  59. $sav->save();
  60. $data = $this->fetch_comments($task_id); // call function
  61. return $data;
  62. }
  63. public function fetch_comments($task_id){
  64. $fetch = Comment::with('user')->where('task_id',$task_id)->orderBy('id','DESC')->get();
  65. $str = "";
  66. if(count($fetch) > 0){
  67. foreach($fetch as $fet)
  68. {
  69. $immmgg = "assets/document/task/$fet->url";
  70. $str .="<input type='hidden' value=".$fet->id.">";
  71. $str .="* $fet->comment -by ".$fet->user->name;
  72. if(!empty($fet->url)){
  73. $str .="<br/><a target='_blank' href=".url("assets/document/task/$fet->url").">
  74. <img height='150' width='120' src='".asset($immmgg)."'></a>";
  75. }
  76. $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>
  77. <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/>";
  78. }
  79. }
  80. return $str;
  81. }
  82. public function add_task_doc(Request $req)
  83. {
  84. $file = $req->file('file');
  85. $task_id = $req->task_id;
  86. date_default_timezone_set("Asia/Dhaka");
  87. $assign_time = date('Y-m-d H:i:s');
  88. if ($req->hasFile('file')) {
  89. $extension = $file->getClientOriginalExtension();
  90. $os = array("jpg", "jpeg", "png", "gif");
  91. if (in_array($extension, $os)){
  92. $name = $file->getClientOriginalName();
  93. $newFileName = "task_".date('d_m_y_h_m_s').".".$extension;;
  94. $fileee = $file->move('assets/document/task/', $newFileName);
  95. $sav = new Comment;
  96. $sav->comment = $name;
  97. $sav->url = $newFileName;
  98. $sav->task_id = $task_id;
  99. $sav->date_time = $assign_time;
  100. $sav->post_by = Auth::user()->id;
  101. $sav->save();
  102. }
  103. }
  104. }
  105. public function task_log($msg,$task_id,$proj_id)
  106. {
  107. date_default_timezone_set("Asia/Dhaka");
  108. $assign_time = date('Y-m-d H:i:s');
  109. $sav = new ActivityLog;
  110. $sav->msg = $msg;
  111. $sav->proj_id = $proj_id;
  112. $sav->task_id = $task_id;
  113. $sav->logged_user_id = Auth::user()->id;
  114. $sav->created_at = $assign_time;
  115. $sav->save();
  116. }
  117. public function change_notification(Request $req)
  118. {
  119. $user_id = $req->user_id;
  120. \DB::table('notification')
  121. ->where('status', 1)
  122. ->where('user_id', $user_id)
  123. ->update(['status' => 0]);
  124. }
  125. }