123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- namespace App\Http\Controllers\Admin;
- use Illuminate\Http\Request;
- use App\Http\Requests;
- use App\Http\Controllers\Controller;
- use App\Models\Comment;
- use App\Models\ActivityLog;
- use App\Models\Task;
- use Auth;
- use Illuminate\Support\Facades\File;
- class CommentController extends Controller
- {
- public function remove_comment(Request $req){
- $id = $req->id;
- $task_id = $req->task_id;
- $del = Comment::find($id);
- if (File::exists('assets/document/task/'.$del->url) && !empty($del->url))
- {
- File::delete('assets/document/task/'.$del->url);
- }
- //activity log
- $task_info = Task::find($task_id);
- $task_name = $task_info->name;
- $proj_id = $task_info->proj_id;
- $comment = $del->comment;
- $msg = "$comment -removed from $task_name.";
- $this->task_log($msg,$task_id,$proj_id); //call function
- $del->delete();
- $str = $this->fetch_comments($task_id); // call function
- return $str;
- /*
- 1=Created;
- 2=in process;
- 3=Completed;
- 4=checking;
- 5=bugfixing;
- 5=done;
- */
- }
- public function edit_comment_form(Request $req){
- $id = $req->id;
- $fet = Comment::find($id);
- $data['comment'] = $fet->comment;
- $data['id'] = $id;
-
- return $data;
- }
- public function save_update_comment(Request $req){
- $comment = $req->comment;
- $id = $req->id;
- $task_id = $req->task_id;
- $sav = Comment::find($id);
- $sav->comment = $comment;
- //activity log
- $task_info = Task::find($task_id);
- $task_name = $task_info->name;
- $proj_id = $task_info->proj_id;
- $msg = "$comment -edited from $task_name.";
- $this->task_log($msg,$task_id,$proj_id); //call function
- $sav->save();
- $data = $this->fetch_comments($task_id); // call function
- return $data;
- }
- public function fetch_comments($task_id){
- $fetch = Comment::with('user')->where('task_id',$task_id)->orderBy('id','DESC')->get();
- $str = "";
- if(count($fetch) > 0){
-
- foreach($fetch as $fet)
- {
- $immmgg = "assets/document/task/$fet->url";
- $str .="<input type='hidden' value=".$fet->id.">";
-
- $str .="* $fet->comment -by ".$fet->user->name;
-
- if(!empty($fet->url)){
- $str .="<br/><a target='_blank' href=".url("assets/document/task/$fet->url").">
- <img height='150' width='120' src='".asset($immmgg)."'></a>";
- }
-
- $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>
- <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/>";
- }
- }
- return $str;
- }
- public function add_task_doc(Request $req)
- {
- $file = $req->file('file');
- $task_id = $req->task_id;
- date_default_timezone_set("Asia/Dhaka");
- $assign_time = date('Y-m-d H:i:s');
-
- if ($req->hasFile('file')) {
- $extension = $file->getClientOriginalExtension();
- $os = array("jpg", "jpeg", "png", "gif");
- if (in_array($extension, $os)){
- $name = $file->getClientOriginalName();
- $newFileName = "task_".date('d_m_y_h_m_s').".".$extension;;
- $fileee = $file->move('assets/document/task/', $newFileName);
- $sav = new Comment;
- $sav->comment = $name;
- $sav->url = $newFileName;
- $sav->task_id = $task_id;
- $sav->date_time = $assign_time;
- $sav->post_by = Auth::user()->id;
- $sav->save();
- }
- }
- }
- public function task_log($msg,$task_id,$proj_id)
- {
- date_default_timezone_set("Asia/Dhaka");
- $assign_time = date('Y-m-d H:i:s');
- $sav = new ActivityLog;
- $sav->msg = $msg;
- $sav->proj_id = $proj_id;
- $sav->task_id = $task_id;
- $sav->logged_user_id = Auth::user()->id;
- $sav->created_at = $assign_time;
- $sav->save();
- }
- public function change_notification(Request $req)
- {
- $user_id = $req->user_id;
- \DB::table('notification')
- ->where('status', 1)
- ->where('user_id', $user_id)
- ->update(['status' => 0]);
- }
- }
|